diff --git a/.vscode/settings.json b/.vscode/settings.json index 5ffbbf2..14f9ba3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,7 @@ { "files.associations": { - "users.h": "c" + "users.h": "c", + "ncurses.h": "c", + "stdlib.h": "c" } } \ No newline at end of file diff --git a/include/tui.h b/include/tui.h index 8d1d04e..2f2473f 100644 --- a/include/tui.h +++ b/include/tui.h @@ -8,6 +8,6 @@ #define MIN_X_TERMINAL_SIZE 80 #define MIN_Y_TERMINAL_SIZE 30 -void uartDialog(int terminal_x, int terminal_y); +char * uartDialog(int terminal_x, int terminal_y); #endif \ No newline at end of file diff --git a/output/main b/output/main index daa5f49..6666d1a 100755 Binary files a/output/main and b/output/main differ diff --git a/src/main.c b/src/main.c index ccfed78..247003a 100644 --- a/src/main.c +++ b/src/main.c @@ -47,7 +47,6 @@ int main(int argc, char const *argv[]) pthread_create(&uart_thread, NULL, uartListener, NULL); // - getch(); pthread_join(uart_thread, NULL); diff --git a/src/tui.c b/src/tui.c index 9f47f04..bb0e25b 100644 --- a/src/tui.c +++ b/src/tui.c @@ -3,10 +3,11 @@ #include #include -void uartDialog(int terminal_x, int terminal_y) +char *uartDialog(int terminal_x, int terminal_y) { char *prompt = "Please enter UART device address for RFID reader (probably /dev/ttyUSB0): "; char *header = "Enter UART Address"; + char input[51] = {"\0"}; int win_height = 15; int win_width = 80; @@ -15,6 +16,7 @@ void uartDialog(int terminal_x, int terminal_y) 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); @@ -27,12 +29,64 @@ void uartDialog(int terminal_x, int terminal_y) wattroff(uartwin, COLOR_PAIR(1)); wrefresh(uartwin); - getch(); + // menu... + int choice; + int highlight = 0; - wclear(uartwin); - wrefresh(uartwin); - touchwin(stdscr); - refresh(); - delwin(uartwin); - refresh(); -} \ No newline at end of file + keypad(uartwin, TRUE); + while (1) + { + int text_x = (win_width - 52) / 2; + if (highlight == 0) + { + wattron(uartwin, COLOR_PAIR(2)); + mvwprintw(uartwin, 5, text_x, "[__________________________________________________]"); + wattroff(uartwin, COLOR_PAIR(2)); + } + mvwprintw(uartwin, 5, text_x, "[%50s]", input); + + int button_x = (win_width - 7) / 2; + if (highlight == 1) + { + wattron(uartwin, COLOR_PAIR(2)); + mvwprintw(uartwin, 7, button_x, ""); + wattroff(uartwin, COLOR_PAIR(2)); + } + mvwprintw(uartwin, 7, button_x, ""); + + wrefresh(uartwin); + + choice = wgetch(uartwin); + if (choice == '\t') + { + highlight=!highlight; + } + + if (highlight == 0) + { + wattron(uartwin, COLOR_PAIR(2)); + mvwprintw(uartwin, 5, (win_width - 52) / 2, "[__________________________________________________]"); + echo(); + wmove(uartwin, 5, ((win_width - 52) / 2) + 1); + curs_set(1); + flushinp(); + wgetnstr(uartwin, input, 50); + curs_set(0); + wattroff(uartwin, COLOR_PAIR(2)); + noecho(); + } + else if (highlight == 1) + { + if (choice == '\n') + { + wclear(uartwin); + wrefresh(uartwin); + touchwin(stdscr); + refresh(); + delwin(uartwin); + refresh(); + return input; + } + } + } +}