-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate_menu.cpp
More file actions
89 lines (76 loc) · 1.67 KB
/
state_menu.cpp
File metadata and controls
89 lines (76 loc) · 1.67 KB
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
79
80
81
82
83
84
85
86
87
88
/*
* state_menu.cpp
*
* Created on: Apr 2, 2018
* Author: MisterCavespider
*/
#include "state_menu.h"
MenuState::MenuState(StateManager *mgr, const char* title) : ProgramState(mgr, title)
{
menu = new Menu(mgr->disp, title, true);
needsPush = true;
needsUpdate = false;
}
result_t MenuState::onScrollPri(uint8_t flag, int16_t v)
{
result_t r = NULL_POINTER;
if(v == 0) return EVENT_IGNORED;
if(v > 0)
{
r = menu->setFocus(menu->getFocus() + 1);
}
else if(menu->getFocus() > 0) // && v < 0
{
r = menu->setFocus(menu->getFocus() - 1);
}
if(r == SUCCESS) needsUpdate = true;
return EVENT_CONSUMED;
}
result_t MenuState::onScrollSec(uint8_t flag, int16_t v)
{
if(v == 0) return EVENT_IGNORED;
uint8_t i = menu->getFocus();
int s = (flag==0) ? 1 : 10;
if(menu->getItemType(i) == TEXT)
{
return EVENT_CONSUMED; // This terminates the function without updating values
}
else if(menu->getItemType(i) == ItemType::VALUE_BOUNDED)
{
BoundedValue *val = (BoundedValue *)menu->getValue(i);
(v>0)? *(val) += s : *(val) -= s;
}
else if(menu->getItemType(i) == ItemType::VALUE_ENUM)
{
EnumValue *val = (EnumValue *)menu->getValue(i);
(v>0)? *(val) += s : *(val) -= s;
}
disp->setCursor(5,5);
disp->printf("um%d", i);
/*
* TODO: the -1 is here because the first item
* in the menu is the temporary title of the
* module. Make a way to modify the actual title,
* remove the title item, and remove this -1
*/
updateForValue(i-1);
menu->updateItem(i);
return EVENT_CONSUMED;
}
void MenuState::setup()
{
if(needsPush)
{
isetup();
needsPush = false;
}
menu->show();
}
void MenuState::loop()
{
iloop();
}
MenuState::~MenuState()
{
delete menu;
}