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 FALSE 0
|
||||
#define BYTE uint8_t
|
||||
#define MIN_X_TERMINAL_SIZE 80
|
||||
#define MIN_Y_TERMINAL_SIZE 30
|
||||
#define MIN_X_TERMINAL_SIZE 50
|
||||
#define MIN_Y_TERMINAL_SIZE 20
|
||||
|
||||
void handle_sigint(int sig);
|
||||
|
||||
int main(int argc, char const **argv);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -7,9 +7,12 @@
|
||||
typedef struct
|
||||
{
|
||||
char *uart_address;
|
||||
BYTE *uart_status;
|
||||
list_t *person_list_head;
|
||||
} UartThreadArgs;
|
||||
|
||||
|
||||
|
||||
// UART handler thread
|
||||
void *uartListener(void *arg);
|
||||
|
||||
|
||||
+28
@@ -33,6 +33,7 @@ int main(int argc, char const **argv)
|
||||
}
|
||||
|
||||
int y_max, x_max;
|
||||
BYTE uart_status = false;
|
||||
char uart_address[51];
|
||||
pthread_t uart_thread;
|
||||
|
||||
@@ -67,6 +68,11 @@ int main(int argc, char const **argv)
|
||||
start_color();
|
||||
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);
|
||||
erase();
|
||||
printw("LightTAM Server");
|
||||
@@ -77,9 +83,31 @@ int main(int argc, char const **argv)
|
||||
UartThreadArgs *args = malloc(sizeof(UartThreadArgs));
|
||||
args->uart_address = uart_address;
|
||||
args->person_list_head = &person_list;
|
||||
args->uart_status = &uart_status;
|
||||
|
||||
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);
|
||||
|
||||
+4
-1
@@ -17,13 +17,16 @@ void *uartListener(void *arg)
|
||||
|
||||
char *uart_address = thread_args->uart_address;
|
||||
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);
|
||||
if (uart == -1)
|
||||
{
|
||||
perror("Failed to open UART");
|
||||
//perror("Failed to open UART");
|
||||
*uart_status = FALSE;
|
||||
return NULL;
|
||||
}
|
||||
*uart_status = TRUE;
|
||||
|
||||
struct termios 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 input[51] = {"\0"};
|
||||
|
||||
int win_height = 15;
|
||||
int win_height = 8;
|
||||
int win_width = 80;
|
||||
int start_y = (terminal_y - win_height) / 2;
|
||||
int start_x = (terminal_x - win_width) / 2;
|
||||
|
||||
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);
|
||||
|
||||
@@ -26,8 +24,10 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
||||
|
||||
box(uartwin, 0, 0);
|
||||
wattron(uartwin, COLOR_PAIR(1));
|
||||
wattron(uartwin, A_BOLD);
|
||||
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));
|
||||
wrefresh(uartwin);
|
||||
|
||||
@@ -46,9 +46,9 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
||||
else
|
||||
wattron(uartwin, COLOR_PAIR(1));
|
||||
|
||||
mvwprintw(uartwin, 5, text_x, "[%50s]", input);
|
||||
mvwprintw(uartwin, 4, text_x, "[%50s]", input);
|
||||
if (!strcmp(input, "\0"))
|
||||
mvwprintw(uartwin, 5, text_x, "[__________________________________________________]");
|
||||
mvwprintw(uartwin, 4, text_x, "[__________________________________________________]");
|
||||
|
||||
if (highlight == 0)
|
||||
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));
|
||||
else
|
||||
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)
|
||||
wattroff(uartwin, COLOR_PAIR(2));
|
||||
else
|
||||
wattroff(uartwin, COLOR_PAIR(1));
|
||||
wattroff(uartwin, A_BOLD);
|
||||
|
||||
wrefresh(uartwin);
|
||||
|
||||
flushinp();
|
||||
@@ -79,9 +83,9 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
||||
{
|
||||
if (highlight == 0)
|
||||
{
|
||||
mvwprintw(uartwin, 5, (win_width - 52) / 2, "[__________________________________________________]");
|
||||
mvwprintw(uartwin, 4, (win_width - 52) / 2, "[__________________________________________________]");
|
||||
echo();
|
||||
wmove(uartwin, 5, ((win_width - 52) / 2) + 1);
|
||||
wmove(uartwin, 4, ((win_width - 52) / 2) + 1);
|
||||
curs_set(1);
|
||||
flushinp();
|
||||
wgetnstr(uartwin, input, 50);
|
||||
@@ -108,8 +112,8 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
||||
|
||||
void mainMenu(list_t *person_list, int terminal_x, int terminal_y)
|
||||
{
|
||||
int win_height = 30;
|
||||
int win_width = 80;
|
||||
int win_height = 10;
|
||||
int win_width = 50;
|
||||
int start_y = (terminal_y - win_height) / 2;
|
||||
int start_x = (terminal_x - win_width) / 2;
|
||||
|
||||
@@ -119,55 +123,70 @@ void mainMenu(list_t *person_list, int terminal_x, int terminal_y)
|
||||
int highlight = 0;
|
||||
|
||||
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);
|
||||
wattron(uartwin, COLOR_PAIR(1));
|
||||
|
||||
wattroff(uartwin, COLOR_PAIR(1));
|
||||
keypad(uartwin, true);
|
||||
box(mainmenu, 0, 0);
|
||||
wattron(mainmenu, COLOR_PAIR(1));
|
||||
wattron(mainmenu, A_BOLD);
|
||||
mvwprintw(mainmenu, 0, (win_width - strlen("Administration")) / 2, "%s", "Administration");
|
||||
wattroff(mainmenu, A_BOLD);
|
||||
wattroff(mainmenu, COLOR_PAIR(1));
|
||||
keypad(mainmenu, true);
|
||||
|
||||
int text_x = (win_width - 52) / 2;
|
||||
|
||||
wrefresh(uartwin);
|
||||
wrefresh(mainmenu);
|
||||
|
||||
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();
|
||||
keboard_input = wgetch(uartwin);
|
||||
keboard_input = wgetch(mainmenu);
|
||||
|
||||
if (keboard_input == '\t')
|
||||
{
|
||||
highlight = !highlight;
|
||||
if (highlight < 5)
|
||||
highlight++;
|
||||
else
|
||||
highlight = 0;
|
||||
}
|
||||
|
||||
else if (keboard_input == '\n')
|
||||
{
|
||||
if (highlight == 0)
|
||||
switch (highlight)
|
||||
{
|
||||
|
||||
}
|
||||
else if (highlight == 1)
|
||||
{
|
||||
case 5:
|
||||
if (keboard_input == '\n')
|
||||
{
|
||||
wclear(uartwin);
|
||||
wrefresh(uartwin);
|
||||
wclear(mainmenu);
|
||||
wrefresh(mainmenu);
|
||||
touchwin(stdscr);
|
||||
refresh();
|
||||
delwin(uartwin);
|
||||
delwin(mainmenu);
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user