ncurses begin
This commit is contained in:
parent
1b36640c4f
commit
282a0dbc34
|
@ -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)
|
||||
|
|
BIN
driver/cli
BIN
driver/cli
Binary file not shown.
115
driver/cli.cpp
115
driver/cli.cpp
|
@ -1,51 +1,97 @@
|
|||
#include <stdio.h>
|
||||
#include <ncurses.h> // sudo apt-get install libncurses5-dev
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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<std::string> 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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
BIN
driver/test_plot
BIN
driver/test_plot
Binary file not shown.
Loading…
Reference in a new issue