-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuHandler.cpp
More file actions
234 lines (217 loc) · 6.06 KB
/
Copy pathMenuHandler.cpp
File metadata and controls
234 lines (217 loc) · 6.06 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "MenuHandler.h"
#include "Keypad.h"
#include "ModemConfigSlot.h"
MenuHandler::MenuHandler(Adafruit_PCD8544* d, ScreenHandler* scr, Configuration* conf) {
display = d;
screen = scr;
configuration = conf;
isFirstRun = true;
isScreenShowing = false;
currentMenuCode = MENU_MAIN;
menuDepthIndex = 0;
for (int i = 0; i < sizeof(menuPoss); i++) {
menuPoss[i] = 0;
}
for (int i = 0; i < sizeof(menuDepthArray); i++) {
menuDepthArray[i] = 0;
}
menuDepthArray[0] = MENU_MAIN;
}
void MenuHandler::pressedKey(byte button) {
byte screenButton;
if (!isScreenShowing) {
switch (button) {
case BUTTON_UP: {
if (menuPoss[currentMenuCode] > 0) {
menuPoss[currentMenuCode]--;
}
break;
}
case BUTTON_DOWN: {
int rowsCount = getMenuRows();
if (menuPoss[currentMenuCode] < rowsCount - 1) {
menuPoss[currentMenuCode]++;
}
break;
}
case BUTTON_ENTER: {
byte mode = getNextMenu();
if (mode > SRC_START_INDEX) {
currentScreenCode = mode;
isScreenShowing = true;
screen->cleanData();
} else {
currentMenuCode = mode;
menuDepthIndex++;
menuDepthArray[menuDepthIndex] = mode;
if (currentMenuCode == MENU_MAIN) {
menuPoss[currentMenuCode] = 0;
}
}
break;
}
case BUTTON_ESC: {
if (currentMenuCode != MENU_MAIN) {
menuPoss[currentMenuCode] = 0;
menuDepthIndex--;
currentMenuCode = menuDepthArray[menuDepthIndex];
}
break;
}
}
} else {
switch (button) {
case BUTTON_UP: {
screenButton = BUTTON_UP;
break;
}
case BUTTON_DOWN: {
screenButton = BUTTON_DOWN;
break;
}
case BUTTON_ENTER: {
break;
}
case BUTTON_ESC: {
currentScreenCode = 0;
isScreenShowing = false;
screen->cleanData();
break;
}
}
}
if (isScreenShowing) {
screen->showSelectedScreen(currentScreenCode, screenButton);
} else {
showCurrentMenu();
}
}
void MenuHandler::init(void) {
}
void MenuHandler::start(void) {
if (isFirstRun) {
isFirstRun = false;
showCurrentMenu();
}
}
byte MenuHandler::getNextMenu(void) {
byte poss = menuPoss[currentMenuCode];
switch (currentMenuCode) {
case MENU_MAIN: {
return menuMainMap[poss];
}
case MENU_CONFIG_MODEM: {
return menuConfigModemMap[poss];
}
case MENU_CONFIG_MODEM_MODEM_TO_MEM: {
return menuConfigModemModemToMemMap[poss];
}
case MENU_CONFIG_MODEM_MEM_TO_SCREEN: {
return menuConfigModemMemToScreenMap[poss];
}
case MENU_CONFIG_MODEM_MEM_TO_MODEM: {
return menuConfigModemMemToModemMap[poss];
}
case MENU_CONFIG_SLOTS: {
return menuConfigSlotsMap[poss];
}
case MENU_CONFIG_SLOTS_DEL_ONE: {
return menuConfigSlotsDelOneMap[poss];
}
case MENU_CONFIGURATIONS: {
return menuConfigMap[poss];
}
case MENU_CONFIG_LANG: {
return menuConfigLangMap[poss];
}
case MENU_CONFIG_SPEED: {
return menuConfigSerialSpeedMap[poss];
}
}
return MENU_MAIN;
}
// set appropriate menu rows into 'currentMenuRows' array based on menu code from 'currentMenuCode' variable. Return number of rows in array.
int MenuHandler::getMenuRows(void) {
int itemCount = 0;
switch (currentMenuCode) {
case MENU_MAIN: {
itemCount = readMenuRows(menuMainRows, sizeof(menuMainRows));
break;
}
case MENU_CONFIGURATIONS: {
itemCount = readMenuRows(menuConfigRows, sizeof(menuConfigRows));
break;
}
case MENU_CONFIG_MODEM: {
itemCount = readMenuRows(menuConfigModemRowsNew, sizeof(menuConfigModemRowsNew));
break;
}
case MENU_CONFIG_MODEM_MODEM_TO_MEM: {
itemCount = readMenuRows(menuSlotListNew, sizeof(menuSlotListNew));
updateMenuSlotList();
break;
}
case MENU_CONFIG_MODEM_MEM_TO_SCREEN: {
itemCount = readMenuRows(menuSlotListNew, sizeof(menuSlotListNew));
updateMenuSlotList();
break;
}
case MENU_CONFIG_MODEM_MEM_TO_MODEM: {
itemCount = readMenuRows(menuSlotListNew, sizeof(menuSlotListNew));
updateMenuSlotList();
break;
}
case MENU_CONFIG_SLOTS: {
itemCount = readMenuRows(menuConfigSlotsRowsNew, sizeof(menuConfigSlotsRowsNew));
break;
}
case MENU_CONFIG_SLOTS_DEL_ONE: {
itemCount = readMenuRows(menuSlotListNew, sizeof(menuSlotListNew));
updateMenuSlotList();
break;
}
case MENU_CONFIG_LANG: {
itemCount = readMenuRows(menuConfigLangRows, sizeof(menuConfigLangRows));
break;
}
case MENU_CONFIG_SPEED: {
itemCount = readMenuRows(menuConfigSerialSpeedRows, sizeof(menuConfigSerialSpeedRows));
break;
}
}
return itemCount;
}
int MenuHandler::readMenuRows(const byte menuRows[], int arraySize) {
for (int i = 0; i < arraySize; i++) {
configuration->readScreenMessage(menuRows[i], currentMenuRows[i], LINE_LENGTH);
}
return arraySize;
}
void MenuHandler::updateMenuSlotList(void) {
for (int i = 0; i < CONFIG_SLOT_COUNT; i++) {
ModemConfigSlot slot = ModemConfigSlot();
slot.readMemory(i);
if (bitRead(slot.statusFlag, CONFIG_BIT_SLOT_USED_MASK) == 0) {
currentMenuRows[i][2] = '-';
}
}
}
void MenuHandler::showCurrentMenu(void) {
int itemCount = getMenuRows();
display->clearDisplay();
display->setTextSize(1);
display->setCursor(0, 0);
display->setTextColor(BLACK);
for (int i = 0; i < itemCount; i++) {
if (i == menuPoss[currentMenuCode]) {
display->setTextColor(WHITE, BLACK);
}
for (int j = 0; j < LINE_LENGTH; j++) {
display->print(currentMenuRows[i][j]);
}
if (i == menuPoss[currentMenuCode]) {
display->setTextColor(BLACK);
}
}
display->display();
}