-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
78 lines (61 loc) · 2.25 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include "menu/Menu.hh"
#include "utils/AllSignals.hh"
#include "utils/Display.hh"
#include "menu/config_inline/ConfigInlineSingleValue.hh"
#include <ncurses.h>
#include <thread>
#include <cstring>
void handleButtons(utils::AllSignals& sig)
{
int ch;
while ((ch = getch()) != 'q') {
switch(ch) {
case KEY_UP:
sig.buttonUp.emit();
break;
case KEY_DOWN:
sig.buttonDown.emit();
break;
case ' ':
sig.buttonEnter.emit();
break;
}
}
}
int main()
{
using namespace menu;
utils::AllSignals allSignals;
utils::Display display(allSignals);
initscr();
raw();
keypad(stdscr, TRUE);
noecho();
Menu menu(allSignals);
MenuPage pageFirst;
MenuPage pagePid;
MenuPage pageCos;
config_inline::ConfigInlineSingleValue<int> configP("P", 5, 2);
config_inline::ConfigInlineSingleValue<int> configI("I", -2, 1);
config_inline::ConfigInlineSingleValue<double> configD("D", 8.5, 0.1);
config_inline::ConfigInlineSingleValue<int> configCos("cos", -55, 5);
config_inline::ConfigInlineSingleValue<bool> configBool("win?", true);
auto dummy = [](utils::AllSignals&){};
pageFirst.AddOption(MenuOption("PID", OptionType::Page, &pagePid));
pageFirst.AddOption(MenuOption("cos", OptionType::Page, &pageCos));
pageFirst.AddOption(MenuOption("Opcja 2", OptionType::ConfigCallback, dummy));
pagePid.AddOption(MenuOption("Set P", OptionType::ConfigInline, &configP));
pagePid.AddOption(MenuOption("Set I", OptionType::ConfigInline, &configI));
pagePid.AddOption(MenuOption("Set D", OptionType::ConfigInline, &configD));
pagePid.AddOption(MenuOption("Return", OptionType::Page, &pageFirst));
pageCos.AddOption(MenuOption("ustaw cos", OptionType::ConfigInline, &configCos));
pageCos.AddOption(MenuOption("ustaw boola", OptionType::ConfigInline, &configBool));
pageCos.AddOption(MenuOption("Return", OptionType::Page, &pageFirst));
menu.setDefaultMenuPage(&pageFirst);
// Constructs the new thread and runs it. Does not block execution.
std::thread t1(handleButtons, std::ref(allSignals));
t1.join();
refresh();
endwin();
}