diff --git a/driver/Makefile b/driver/Makefile index c3b752a..6978a7d 100644 --- a/driver/Makefile +++ b/driver/Makefile @@ -12,7 +12,7 @@ OBJ_MAIN = main.o OUT_CLI = cli OBJ_CLI = cli.o CFLAGS = -std=c++14 -O3 -Wall -Wextra -LDFLAGS = +LDFLAGS = -lcurses OBJECTS = drv/usart.o drv/b15f.o drv/plottyfile.o drv/dot.o COMPILE = $(COMPILER_PATH) $(CFLAGS) diff --git a/driver/cli b/driver/cli index 8ae139b..664d5db 100755 Binary files a/driver/cli and b/driver/cli differ diff --git a/driver/cli.cpp b/driver/cli.cpp index 7254a58..dd77457 100644 --- a/driver/cli.cpp +++ b/driver/cli.cpp @@ -1,51 +1,97 @@ #include #include // sudo apt-get install libncurses5-dev +#include +#include +#include +#include +#include -#define WIDTH 30 -#define HEIGHT 10 +#define width 30 +#define height 10 -int startx = 0; -int starty = 0; +WINDOW *win_menu; -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Exit", - }; -int n_choices = sizeof(choices) / sizeof(char *); -void print_menu(WINDOW *menu_win, int highlight); +std::vector choices = { + "Choice 1", + "Choice 2", + "Choice 3", + "Choice 4", + "Exit", +}; + + +void init_win(WINDOW*& win) +{ + struct winsize size; + if (ioctl(0, TIOCGWINSZ, (char *) &size) < 0) + throw std::runtime_error("TIOCGWINSZ error"); + + int start_x = (size.ws_col - width); + int start_y = (size.ws_row - height); + if(start_x % 2) + start_x++; + if(start_y % 2) + start_y++; + start_x /= 2; + start_y /= 2; + + win = newwin(height, width, start_y, start_x); + keypad(win, TRUE); + refresh(); +} + +void print_menu(WINDOW *win_menu, int highlight) +{ + + + + int x, y, i; + + x = 2; + y = 2; + box(win_menu, 0, 0); + for(i = 0; i < choices.size(); ++i) + { if(highlight == i + 1) /* High light the present choice */ + { wattron(win_menu, A_REVERSE); + mvwprintw(win_menu, y, x, "%s", choices[i].c_str()); + wattroff(win_menu, A_REVERSE); + } + else + mvwprintw(win_menu, y, x, "%s", choices[i].c_str()); + ++y; + } + wrefresh(win_menu); +} int main() -{ WINDOW *menu_win; +{ int highlight = 1; int choice = 0; int c; initscr(); + start_color(); + curs_set(0); // 0: invisible, 1: normal, 2: very visible clear(); noecho(); cbreak(); /* Line buffering disabled. pass on everything */ - startx = (80 - WIDTH) / 2; - starty = (24 - HEIGHT) / 2; - menu_win = newwin(HEIGHT, WIDTH, starty, startx); - keypad(menu_win, TRUE); + init_win(win_menu); mvprintw(0, 0, "Use arrow keys to go up and down, Press enter to select a choice"); + print_menu(win_menu, highlight); refresh(); - print_menu(menu_win, highlight); + while(1) - { c = wgetch(menu_win); + { c = wgetch(win_menu); switch(c) { case KEY_UP: if(highlight == 1) - highlight = n_choices; + highlight = choices.size(); else --highlight; break; case KEY_DOWN: - if(highlight == n_choices) + if(highlight == choices.size()) highlight = 1; else ++highlight; @@ -58,34 +104,13 @@ int main() refresh(); break; } - print_menu(menu_win, highlight); + print_menu(win_menu, highlight); if(choice != 0) /* User did a choice come out of the infinite loop */ break; } - mvprintw(23, 0, "You chose choice %d with choice string %s\n", choice, choices[choice - 1]); + //mvprintw(23, 0, "You chose choice %d with choice string %s\n", choice, choices[choice - 1].c_str()); clrtoeol(); refresh(); endwin(); return 0; } - - -void print_menu(WINDOW *menu_win, int highlight) -{ - int x, y, i; - - x = 2; - y = 2; - box(menu_win, 0, 0); - for(i = 0; i < n_choices; ++i) - { if(highlight == i + 1) /* High light the present choice */ - { wattron(menu_win, A_REVERSE); - mvwprintw(menu_win, y, x, "%s", choices[i]); - wattroff(menu_win, A_REVERSE); - } - else - mvwprintw(menu_win, y, x, "%s", choices[i]); - ++y; - } - wrefresh(menu_win); -} diff --git a/driver/gnuplotscript.gp b/driver/gnuplotscript.gp index 06749ca..b106bab 100644 --- a/driver/gnuplotscript.gp +++ b/driver/gnuplotscript.gp @@ -6,14 +6,15 @@ set xlabel 'U_{DS} [V]' set ylabel 'I_D [mA]' set xrange [0:5] set yrange [0:50] -set label at 4,3 'U_{GS} [V] = 460' left +set label at 4,2 'U_{GS} [V] = 440' left +set label at 4,4 'U_{GS} [V] = 460' left set label at 4,7 'U_{GS} [V] = 480' left -set label at 3,13 'U_{GS} [V] = 500' left +set label at 3,14 'U_{GS} [V] = 500' left set label at 2,22 'U_{GS} [V] = 520' left set label at 1,33 'U_{GS} [V] = 540' left -set label at 0,39 'U_{GS} [V] = 560' left -set label at 0,39 'U_{GS} [V] = 580' left -set label at 0,39 'U_{GS} [V] = 600' left +set label at 0,38 'U_{GS} [V] = 560' left +set label at 0,38 'U_{GS} [V] = 580' left +set label at 0,38 'U_{GS} [V] = 600' left unset output set terminal qt unset output diff --git a/driver/test_plot b/driver/test_plot index e71ea12..e1c894d 100644 Binary files a/driver/test_plot and b/driver/test_plot differ