diff --git a/driver/Makefile b/driver/Makefile index 3dbeb0c..723f21f 100644 --- a/driver/Makefile +++ b/driver/Makefile @@ -12,9 +12,9 @@ OBJ_MAIN = main.o OUT_CLI = cli OBJ_CLI = cli.o CFLAGS = -std=c++14 -O3 -Wall -Wextra -LDFLAGS = -lcurses +LDFLAGS = -lcurses -lpthread OBJECTS_DRV = drv/usart.o drv/b15f.o drv/plottyfile.o drv/dot.o -OBJECTS_UI = ui/view.o ui/view_selection.o ui/view_info.o +OBJECTS_UI = ui/view.o ui/view_selection.o ui/view_info.o ui/view_monitor.o COMPILE = $(COMPILER_PATH) $(CFLAGS) diff --git a/driver/cli b/driver/cli index 9cbf19d..ee76f2f 100755 Binary files a/driver/cli and b/driver/cli differ diff --git a/driver/cli.cpp b/driver/cli.cpp index dc7e688..391a125 100644 --- a/driver/cli.cpp +++ b/driver/cli.cpp @@ -1,7 +1,7 @@ /** TODO * * - throw exception -> raise SIGINT - * + * - delete view stack */ @@ -16,6 +16,7 @@ #include #include "ui/view_selection.h" #include "ui/view_info.h" +#include "ui/view_monitor.h" //#include "drv/b15f.h" // global error message @@ -113,10 +114,23 @@ void show_info(int) input(0); } +void show_monitor(int) +{ + ViewMonitor* view = new ViewMonitor(); + view->setTitle("Monitor"); + view->setText("U0 = "); + view->setLabelClose("[ Zurueck ]"); + view->repaint(); + + win_stack.push_back(view); + input(0); +} + void show_main(int) { ViewSelection* view = new ViewSelection(); view->setTitle("B15F - Command Line Interface"); + view->addChoice("[ Monitor - Eingaben beobachten ]", &show_monitor); view->addChoice("[ Informationen ]", &show_info); view->addChoice("", nullptr); view->addChoice("[ Beenden ]", &finish); diff --git a/driver/ui/view_monitor.cpp b/driver/ui/view_monitor.cpp new file mode 100644 index 0000000..96d808e --- /dev/null +++ b/driver/ui/view_monitor.cpp @@ -0,0 +1,44 @@ +#include "view_monitor.h" + +ViewMonitor::ViewMonitor() : t_worker(&ViewMonitor::worker, this) +{ +} + +std::function ViewMonitor::keypress(int& key) +{ + switch(key) + { + + case KEY_MOUSE: + { + // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml + MEVENT event; + if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) + { + size_t column = start_x + close_offset_x; + size_t row = start_y + close_offset_y; + if(event.y == row && event.x >= column && event.x < column + label_close.length()) + key = -1; // do return from view + } + break; + } + case KEY_ENT: + run_worker = false; + key = -1; // do return from view + wclear(win); + wrefresh(win); + t_worker.join(); + break; + default: + break; + } + return calls[0]; +} + +void ViewMonitor::worker() +{ + while(run_worker) + { + std::this_thread::sleep_for(std::chrono::seconds(1)); + } +} diff --git a/driver/ui/view_monitor.h b/driver/ui/view_monitor.h new file mode 100644 index 0000000..5c9e0e0 --- /dev/null +++ b/driver/ui/view_monitor.h @@ -0,0 +1,22 @@ +#ifndef VIEW_MONITOR_H +#define VIEW_MONITOR_H + +#include +#include +#include "view_info.h" + +class ViewMonitor : public ViewInfo +{ + +public: + ViewMonitor(void); + virtual std::function keypress(int& key) override; + +protected: + virtual void worker(void); + volatile bool run_worker = true; + std::thread t_worker; + +}; + +#endif // VIEW_MONITOR_H