diff --git a/include/tui.h b/include/tui.h index 82fe874..8d1d04e 100644 --- a/include/tui.h +++ b/include/tui.h @@ -5,4 +5,9 @@ #include #include +#define MIN_X_TERMINAL_SIZE 80 +#define MIN_Y_TERMINAL_SIZE 30 + +void uartDialog(int terminal_x, int terminal_y); + #endif \ No newline at end of file diff --git a/output/main b/output/main index 02ef14f..daa5f49 100755 Binary files a/output/main and b/output/main differ diff --git a/src/main.c b/src/main.c index e49f551..ccfed78 100644 --- a/src/main.c +++ b/src/main.c @@ -3,8 +3,14 @@ #include #include #include +#include +#include +#include #include "users.h" +#include "tui.h" + + void *uartListener(void *arg) { @@ -15,11 +21,17 @@ void *uartListener(void *arg) int main(int argc, char const *argv[]) { int y_max, x_max; + char * uart_address; pthread_t uart_thread; initscr(); getmaxyx(stdscr, y_max, x_max); + if (x_max <= MIN_X_TERMINAL_SIZE || y_max <= MIN_Y_TERMINAL_SIZE) + { + puts("Terminal is too small. Exiting...\n"); + return EXIT_FAILURE; + } noecho(); noraw(); @@ -30,9 +42,12 @@ int main(int argc, char const *argv[]) erase(); refresh(); + uartDialog(x_max, y_max); + pthread_create(&uart_thread, NULL, uartListener, NULL); // + getch(); pthread_join(uart_thread, NULL); diff --git a/src/tui.c b/src/tui.c index 3f492c3..9f47f04 100644 --- a/src/tui.c +++ b/src/tui.c @@ -1,3 +1,38 @@ #include #include -#include \ No newline at end of file +#include +#include + +void 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"; + + int win_height = 15; + 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); + + WINDOW *uartwin = newwin(win_height, win_width, start_y, start_x); + + wbkgd(uartwin, COLOR_PAIR(1)); + + box(uartwin, 0, 0); + wattron(uartwin, COLOR_PAIR(1)); + mvwprintw(uartwin, 0, (win_width - strlen(header)) / 2, "%s", header); + mvwprintw(uartwin, 3, (win_width - strlen(prompt)) / 2, "%s", prompt); + wattroff(uartwin, COLOR_PAIR(1)); + wrefresh(uartwin); + + getch(); + + wclear(uartwin); + wrefresh(uartwin); + touchwin(stdscr); + refresh(); + delwin(uartwin); + refresh(); +} \ No newline at end of file