Refactor UART handling: update UART status management, improve dialog window dimensions, and enhance main menu display.
This commit is contained in:
+5
-2
@@ -8,9 +8,12 @@
|
|||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
#define BYTE uint8_t
|
#define BYTE uint8_t
|
||||||
#define MIN_X_TERMINAL_SIZE 80
|
#define MIN_X_TERMINAL_SIZE 50
|
||||||
#define MIN_Y_TERMINAL_SIZE 30
|
#define MIN_Y_TERMINAL_SIZE 20
|
||||||
|
|
||||||
|
void handle_sigint(int sig);
|
||||||
|
|
||||||
int main(int argc, char const **argv);
|
int main(int argc, char const **argv);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -7,9 +7,12 @@
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char *uart_address;
|
char *uart_address;
|
||||||
|
BYTE *uart_status;
|
||||||
list_t *person_list_head;
|
list_t *person_list_head;
|
||||||
} UartThreadArgs;
|
} UartThreadArgs;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// UART handler thread
|
// UART handler thread
|
||||||
void *uartListener(void *arg);
|
void *uartListener(void *arg);
|
||||||
|
|
||||||
|
|||||||
+28
@@ -33,6 +33,7 @@ int main(int argc, char const **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int y_max, x_max;
|
int y_max, x_max;
|
||||||
|
BYTE uart_status = false;
|
||||||
char uart_address[51];
|
char uart_address[51];
|
||||||
pthread_t uart_thread;
|
pthread_t uart_thread;
|
||||||
|
|
||||||
@@ -67,6 +68,11 @@ int main(int argc, char const **argv)
|
|||||||
start_color();
|
start_color();
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
|
init_pair(1, COLOR_BLACK, COLOR_WHITE);
|
||||||
|
init_pair(2, COLOR_WHITE, COLOR_RED);
|
||||||
|
init_pair(3, COLOR_GREEN, COLOR_BLUE);
|
||||||
|
init_pair(4, COLOR_RED, COLOR_BLUE);
|
||||||
|
|
||||||
assume_default_colors(COLOR_WHITE, COLOR_BLUE);
|
assume_default_colors(COLOR_WHITE, COLOR_BLUE);
|
||||||
erase();
|
erase();
|
||||||
printw("LightTAM Server");
|
printw("LightTAM Server");
|
||||||
@@ -77,9 +83,31 @@ int main(int argc, char const **argv)
|
|||||||
UartThreadArgs *args = malloc(sizeof(UartThreadArgs));
|
UartThreadArgs *args = malloc(sizeof(UartThreadArgs));
|
||||||
args->uart_address = uart_address;
|
args->uart_address = uart_address;
|
||||||
args->person_list_head = &person_list;
|
args->person_list_head = &person_list;
|
||||||
|
args->uart_status = &uart_status;
|
||||||
|
|
||||||
pthread_create(&uart_thread, NULL, uartListener, args);
|
pthread_create(&uart_thread, NULL, uartListener, args);
|
||||||
|
|
||||||
|
usleep(1000);
|
||||||
|
|
||||||
|
attron(A_BOLD);
|
||||||
|
if (uart_status == TRUE)
|
||||||
|
{
|
||||||
|
mvprintw(y_max - 1, 0, "RFID reader status: ");
|
||||||
|
attron(COLOR_PAIR(3));
|
||||||
|
printw("READY");
|
||||||
|
attroff(COLOR_PAIR(3));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mvprintw(y_max - 1, 0, "RFID reader status: ");
|
||||||
|
attron(COLOR_PAIR(4));
|
||||||
|
printw("ERROR");
|
||||||
|
attroff(COLOR_PAIR(4));
|
||||||
|
}
|
||||||
|
attroff(A_BOLD);
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
mainMenu(&person_list, x_max, y_max);
|
||||||
//
|
//
|
||||||
|
|
||||||
pthread_join(uart_thread, NULL);
|
pthread_join(uart_thread, NULL);
|
||||||
|
|||||||
+4
-1
@@ -17,13 +17,16 @@ void *uartListener(void *arg)
|
|||||||
|
|
||||||
char *uart_address = thread_args->uart_address;
|
char *uart_address = thread_args->uart_address;
|
||||||
list_t *person_list = thread_args->person_list_head;
|
list_t *person_list = thread_args->person_list_head;
|
||||||
|
BYTE *uart_status = thread_args->uart_status;
|
||||||
|
|
||||||
int uart = open(uart_address, O_RDWR | O_NOCTTY | O_NDELAY);
|
int uart = open(uart_address, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||||
if (uart == -1)
|
if (uart == -1)
|
||||||
{
|
{
|
||||||
perror("Failed to open UART");
|
//perror("Failed to open UART");
|
||||||
|
*uart_status = FALSE;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
*uart_status = TRUE;
|
||||||
|
|
||||||
struct termios options;
|
struct termios options;
|
||||||
tcgetattr(uart, &options);
|
tcgetattr(uart, &options);
|
||||||
|
|||||||
@@ -11,14 +11,12 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
|||||||
char *header = "Enter UART Address";
|
char *header = "Enter UART Address";
|
||||||
char input[51] = {"\0"};
|
char input[51] = {"\0"};
|
||||||
|
|
||||||
int win_height = 15;
|
int win_height = 8;
|
||||||
int win_width = 80;
|
int win_width = 80;
|
||||||
int start_y = (terminal_y - win_height) / 2;
|
int start_y = (terminal_y - win_height) / 2;
|
||||||
int start_x = (terminal_x - win_width) / 2;
|
int start_x = (terminal_x - win_width) / 2;
|
||||||
|
|
||||||
start_color();
|
start_color();
|
||||||
init_pair(1, COLOR_BLACK, COLOR_WHITE);
|
|
||||||
init_pair(2, COLOR_WHITE, COLOR_RED);
|
|
||||||
|
|
||||||
WINDOW *uartwin = newwin(win_height, win_width, start_y, start_x);
|
WINDOW *uartwin = newwin(win_height, win_width, start_y, start_x);
|
||||||
|
|
||||||
@@ -26,8 +24,10 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
|||||||
|
|
||||||
box(uartwin, 0, 0);
|
box(uartwin, 0, 0);
|
||||||
wattron(uartwin, COLOR_PAIR(1));
|
wattron(uartwin, COLOR_PAIR(1));
|
||||||
|
wattron(uartwin, A_BOLD);
|
||||||
mvwprintw(uartwin, 0, (win_width - strlen(header)) / 2, "%s", header);
|
mvwprintw(uartwin, 0, (win_width - strlen(header)) / 2, "%s", header);
|
||||||
mvwprintw(uartwin, 3, (win_width - strlen(prompt)) / 2, "%s", prompt);
|
wattroff(uartwin, A_BOLD);
|
||||||
|
mvwprintw(uartwin, 2, (win_width - strlen(prompt)) / 2, "%s", prompt);
|
||||||
wattroff(uartwin, COLOR_PAIR(1));
|
wattroff(uartwin, COLOR_PAIR(1));
|
||||||
wrefresh(uartwin);
|
wrefresh(uartwin);
|
||||||
|
|
||||||
@@ -46,9 +46,9 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
|||||||
else
|
else
|
||||||
wattron(uartwin, COLOR_PAIR(1));
|
wattron(uartwin, COLOR_PAIR(1));
|
||||||
|
|
||||||
mvwprintw(uartwin, 5, text_x, "[%50s]", input);
|
mvwprintw(uartwin, 4, text_x, "[%50s]", input);
|
||||||
if (!strcmp(input, "\0"))
|
if (!strcmp(input, "\0"))
|
||||||
mvwprintw(uartwin, 5, text_x, "[__________________________________________________]");
|
mvwprintw(uartwin, 4, text_x, "[__________________________________________________]");
|
||||||
|
|
||||||
if (highlight == 0)
|
if (highlight == 0)
|
||||||
wattroff(uartwin, COLOR_PAIR(2));
|
wattroff(uartwin, COLOR_PAIR(2));
|
||||||
@@ -60,11 +60,15 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
|||||||
wattron(uartwin, COLOR_PAIR(2));
|
wattron(uartwin, COLOR_PAIR(2));
|
||||||
else
|
else
|
||||||
wattron(uartwin, COLOR_PAIR(1));
|
wattron(uartwin, COLOR_PAIR(1));
|
||||||
mvwprintw(uartwin, 7, button_x - 2, " %s ", "<Enter>");
|
wattron(uartwin, A_BOLD);
|
||||||
|
|
||||||
|
mvwprintw(uartwin, 6, button_x - 2, " %s ", "<Enter>");
|
||||||
if (highlight == 1)
|
if (highlight == 1)
|
||||||
wattroff(uartwin, COLOR_PAIR(2));
|
wattroff(uartwin, COLOR_PAIR(2));
|
||||||
else
|
else
|
||||||
wattroff(uartwin, COLOR_PAIR(1));
|
wattroff(uartwin, COLOR_PAIR(1));
|
||||||
|
wattroff(uartwin, A_BOLD);
|
||||||
|
|
||||||
wrefresh(uartwin);
|
wrefresh(uartwin);
|
||||||
|
|
||||||
flushinp();
|
flushinp();
|
||||||
@@ -79,9 +83,9 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
|||||||
{
|
{
|
||||||
if (highlight == 0)
|
if (highlight == 0)
|
||||||
{
|
{
|
||||||
mvwprintw(uartwin, 5, (win_width - 52) / 2, "[__________________________________________________]");
|
mvwprintw(uartwin, 4, (win_width - 52) / 2, "[__________________________________________________]");
|
||||||
echo();
|
echo();
|
||||||
wmove(uartwin, 5, ((win_width - 52) / 2) + 1);
|
wmove(uartwin, 4, ((win_width - 52) / 2) + 1);
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
flushinp();
|
flushinp();
|
||||||
wgetnstr(uartwin, input, 50);
|
wgetnstr(uartwin, input, 50);
|
||||||
@@ -108,66 +112,81 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
|||||||
|
|
||||||
void mainMenu(list_t *person_list, int terminal_x, int terminal_y)
|
void mainMenu(list_t *person_list, int terminal_x, int terminal_y)
|
||||||
{
|
{
|
||||||
int win_height = 30;
|
int win_height = 10;
|
||||||
int win_width = 80;
|
int win_width = 50;
|
||||||
int start_y = (terminal_y - win_height) / 2;
|
int start_y = (terminal_y - win_height) / 2;
|
||||||
int start_x = (terminal_x - win_width) / 2;
|
int start_x = (terminal_x - win_width) / 2;
|
||||||
|
|
||||||
char choices[6][30] = {"List all employees","Find employee","Edit database","Save","Save as...","Exit"};
|
char choices[6][30] = {"List all employees", "Find employee", "Edit database", "Save", "Save as...", "Exit"};
|
||||||
|
|
||||||
char keboard_input;
|
char keboard_input;
|
||||||
int highlight = 0;
|
int highlight = 0;
|
||||||
|
|
||||||
start_color();
|
start_color();
|
||||||
init_pair(1, COLOR_BLACK, COLOR_WHITE);
|
|
||||||
init_pair(2, COLOR_WHITE, COLOR_RED);
|
|
||||||
|
|
||||||
WINDOW *uartwin = newwin(win_height, win_width, start_y, start_x);
|
WINDOW *mainmenu = newwin(win_height, win_width, start_y, start_x);
|
||||||
|
|
||||||
wbkgd(uartwin, COLOR_PAIR(1));
|
wbkgd(mainmenu, COLOR_PAIR(1));
|
||||||
|
|
||||||
box(uartwin, 0, 0);
|
box(mainmenu, 0, 0);
|
||||||
wattron(uartwin, COLOR_PAIR(1));
|
wattron(mainmenu, COLOR_PAIR(1));
|
||||||
|
wattron(mainmenu, A_BOLD);
|
||||||
wattroff(uartwin, COLOR_PAIR(1));
|
mvwprintw(mainmenu, 0, (win_width - strlen("Administration")) / 2, "%s", "Administration");
|
||||||
keypad(uartwin, true);
|
wattroff(mainmenu, A_BOLD);
|
||||||
|
wattroff(mainmenu, COLOR_PAIR(1));
|
||||||
|
keypad(mainmenu, true);
|
||||||
|
|
||||||
int text_x = (win_width - 52) / 2;
|
int text_x = (win_width - 52) / 2;
|
||||||
|
|
||||||
wrefresh(uartwin);
|
wrefresh(mainmenu);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
if (i == highlight)
|
||||||
|
wattron(mainmenu, COLOR_PAIR(2));
|
||||||
|
else
|
||||||
|
wattron(mainmenu, COLOR_PAIR(1));
|
||||||
|
wattron(mainmenu, A_BOLD);
|
||||||
|
mvwprintw(mainmenu, 2 + i, (win_width - strlen(choices[i])) / 2, "%s", choices[i]);
|
||||||
|
wattroff(mainmenu, A_BOLD);
|
||||||
|
|
||||||
|
if (i == highlight)
|
||||||
|
wattroff(mainmenu, COLOR_PAIR(2));
|
||||||
|
else
|
||||||
|
wattroff(mainmenu, COLOR_PAIR(1));
|
||||||
|
}
|
||||||
|
wrefresh(mainmenu);
|
||||||
flushinp();
|
flushinp();
|
||||||
keboard_input = wgetch(uartwin);
|
keboard_input = wgetch(mainmenu);
|
||||||
|
|
||||||
if (keboard_input == '\t')
|
if (keboard_input == '\t')
|
||||||
{
|
{
|
||||||
highlight = !highlight;
|
if (highlight < 5)
|
||||||
|
highlight++;
|
||||||
|
else
|
||||||
|
highlight = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (keboard_input == '\n')
|
else if (keboard_input == '\n')
|
||||||
{
|
{
|
||||||
if (highlight == 0)
|
switch (highlight)
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (highlight == 1)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
case 5:
|
||||||
if (keboard_input == '\n')
|
if (keboard_input == '\n')
|
||||||
{
|
{
|
||||||
wclear(uartwin);
|
wclear(mainmenu);
|
||||||
wrefresh(uartwin);
|
wrefresh(mainmenu);
|
||||||
touchwin(stdscr);
|
touchwin(stdscr);
|
||||||
refresh();
|
refresh();
|
||||||
delwin(uartwin);
|
delwin(mainmenu);
|
||||||
refresh();
|
refresh();
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user