Enhance UART handling and improve TUI input management
This commit is contained in:
@@ -51,4 +51,6 @@ modules.order
|
|||||||
Module.symvers
|
Module.symvers
|
||||||
Mkfile.old
|
Mkfile.old
|
||||||
dkms.conf
|
dkms.conf
|
||||||
|
output/
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
|||||||
BIN
Binary file not shown.
+12
-1
@@ -12,7 +12,15 @@
|
|||||||
|
|
||||||
void *uartListener(void *arg)
|
void *uartListener(void *arg)
|
||||||
{
|
{
|
||||||
|
char *uart_address = (char *)arg;
|
||||||
|
int uart = open(uart_address, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||||
|
if (uart == -1)
|
||||||
|
{
|
||||||
|
perror("Failed to open UART");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(uart);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,12 +35,15 @@ int main(int argc, char const *argv[])
|
|||||||
getmaxyx(stdscr, y_max, x_max);
|
getmaxyx(stdscr, y_max, x_max);
|
||||||
if (x_max <= MIN_X_TERMINAL_SIZE || y_max <= MIN_Y_TERMINAL_SIZE)
|
if (x_max <= MIN_X_TERMINAL_SIZE || y_max <= MIN_Y_TERMINAL_SIZE)
|
||||||
{
|
{
|
||||||
|
endwin();
|
||||||
|
clear();
|
||||||
puts("Terminal is too small. Exiting...\n");
|
puts("Terminal is too small. Exiting...\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
noecho();
|
noecho();
|
||||||
noraw();
|
noraw();
|
||||||
|
cbreak();
|
||||||
start_color();
|
start_color();
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
@@ -42,7 +53,7 @@ int main(int argc, char const *argv[])
|
|||||||
|
|
||||||
uartDialog(uart_address, x_max, y_max);
|
uartDialog(uart_address, x_max, y_max);
|
||||||
|
|
||||||
pthread_create(&uart_thread, NULL, uartListener, NULL);
|
pthread_create(&uart_thread, NULL, uartListener, uart_address);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|||||||
@@ -29,42 +29,54 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
|||||||
wattroff(uartwin, COLOR_PAIR(1));
|
wattroff(uartwin, COLOR_PAIR(1));
|
||||||
wrefresh(uartwin);
|
wrefresh(uartwin);
|
||||||
|
|
||||||
// menu...
|
char choice;
|
||||||
int choice;
|
|
||||||
int highlight = 0;
|
int highlight = 0;
|
||||||
|
|
||||||
keypad(uartwin, TRUE);
|
int text_x = (win_width - 52) / 2;
|
||||||
|
int button_x = (win_width - 7) / 2;
|
||||||
|
|
||||||
|
keypad(uartwin, true);
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int text_x = (win_width - 52) / 2;
|
// Input array
|
||||||
if (highlight == 0)
|
if (highlight == 0)
|
||||||
{
|
|
||||||
wattron(uartwin, COLOR_PAIR(2));
|
wattron(uartwin, COLOR_PAIR(2));
|
||||||
mvwprintw(uartwin, 5, text_x, "[__________________________________________________]");
|
else
|
||||||
wattroff(uartwin, COLOR_PAIR(2));
|
wattron(uartwin, COLOR_PAIR(1));
|
||||||
}
|
|
||||||
mvwprintw(uartwin, 5, text_x, "[%50s]", input);
|
mvwprintw(uartwin, 5, text_x, "[%50s]", input);
|
||||||
|
if (!strcmp(input, "\0"))
|
||||||
|
mvwprintw(uartwin, 5, text_x, "[__________________________________________________]");
|
||||||
|
|
||||||
int button_x = (win_width - 7) / 2;
|
if (highlight == 0)
|
||||||
if (highlight == 1)
|
|
||||||
{
|
|
||||||
wattron(uartwin, COLOR_PAIR(2));
|
|
||||||
mvwprintw(uartwin, 7, button_x, "<Enter>");
|
|
||||||
wattroff(uartwin, COLOR_PAIR(2));
|
wattroff(uartwin, COLOR_PAIR(2));
|
||||||
}
|
else
|
||||||
mvwprintw(uartwin, 7, button_x, "<Enter>");
|
wattroff(uartwin, COLOR_PAIR(1));
|
||||||
|
|
||||||
|
// Enter button
|
||||||
|
if (highlight == 1)
|
||||||
|
wattron(uartwin, COLOR_PAIR(2));
|
||||||
|
else
|
||||||
|
wattron(uartwin, COLOR_PAIR(1));
|
||||||
|
mvwprintw(uartwin, 7, button_x - 2, " %s ", "<Enter>");
|
||||||
|
if (highlight == 1)
|
||||||
|
wattroff(uartwin, COLOR_PAIR(2));
|
||||||
|
else
|
||||||
|
wattroff(uartwin, COLOR_PAIR(1));
|
||||||
wrefresh(uartwin);
|
wrefresh(uartwin);
|
||||||
|
|
||||||
|
flushinp();
|
||||||
choice = wgetch(uartwin);
|
choice = wgetch(uartwin);
|
||||||
|
|
||||||
if (choice == '\t')
|
if (choice == '\t')
|
||||||
{
|
{
|
||||||
highlight=!highlight;
|
highlight = !highlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (choice == '\n')
|
||||||
|
{
|
||||||
if (highlight == 0)
|
if (highlight == 0)
|
||||||
{
|
{
|
||||||
wattron(uartwin, COLOR_PAIR(2));
|
|
||||||
mvwprintw(uartwin, 5, (win_width - 52) / 2, "[__________________________________________________]");
|
mvwprintw(uartwin, 5, (win_width - 52) / 2, "[__________________________________________________]");
|
||||||
echo();
|
echo();
|
||||||
wmove(uartwin, 5, ((win_width - 52) / 2) + 1);
|
wmove(uartwin, 5, ((win_width - 52) / 2) + 1);
|
||||||
@@ -72,7 +84,6 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
|||||||
flushinp();
|
flushinp();
|
||||||
wgetnstr(uartwin, input, 50);
|
wgetnstr(uartwin, input, 50);
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
wattroff(uartwin, COLOR_PAIR(2));
|
|
||||||
noecho();
|
noecho();
|
||||||
}
|
}
|
||||||
else if (highlight == 1)
|
else if (highlight == 1)
|
||||||
@@ -90,4 +101,5 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user