This repository has been archived on 2026-05-29. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
LightTAM/src/tui.c
T

130 lines
3.5 KiB
C

#include <ncurses.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "main.h"
#include "tui.h"
void uartDialog(char *uart_adress, 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;
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);
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);
char choice;
int highlight = 0;
int text_x = (win_width - 52) / 2;
int button_x = (win_width - 7) / 2;
keypad(uartwin, true);
while (1)
{
// Input array
if (highlight == 0)
wattron(uartwin, COLOR_PAIR(2));
else
wattron(uartwin, COLOR_PAIR(1));
mvwprintw(uartwin, 5, text_x, "[%50s]", input);
if (!strcmp(input, "\0"))
mvwprintw(uartwin, 5, text_x, "[__________________________________________________]");
if (highlight == 0)
wattroff(uartwin, COLOR_PAIR(2));
else
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);
flushinp();
choice = wgetch(uartwin);
if (choice == '\t')
{
highlight = !highlight;
}
else if (choice == '\n')
{
if (highlight == 0)
{
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);
noecho();
}
else if (highlight == 1)
{
if (choice == '\n')
{
wclear(uartwin);
wrefresh(uartwin);
touchwin(stdscr);
refresh();
delwin(uartwin);
refresh();
strcpy(uart_adress, input);
break;
}
}
}
}
}
void mainMenu(list_t *person_list, int terminal_x, int terminal_y)
{
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);
init_pair(2, COLOR_WHITE, COLOR_RED);
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));
wattroff(uartwin, COLOR_PAIR(1));
wrefresh(uartwin);
}