forked from DCC-EX/CommandStation-EX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenumanagement.cpp
305 lines (279 loc) · 10.6 KB
/
menumanagement.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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*
* La Box Project
* MenuManagement Class
* The purpose of this class is to organize the operation menu.
* This is where the actions or choices selected by the user are executed.
*
* @Author : Cedric Bellec
* @Organization : Locoduino.org
*/
#include "defines.h"
#include "DCC.h"
#include "TrackManager.h"
#ifdef USE_HMI
#include "hmi.h"
#include "LaboxModes.h"
#include "menumanagement.h"
#include "menuobject.h"
#include "menuinformation.h"
#include "menuTrainAddrRead.h"
#include "menuTrainCvRead.h"
#include "menuTrainCvWrite.h"
#include "menuDecoderIdentification.h"
#include "menuShuttleSample.h"
#include "menuDcDccMode.h"
extern enumHMIState _HMIState ;
extern enumHMIState _HMIState_prev;
extern enumEvent _HMIEvent;
/*!
@brief Constructor
@param None
@return None (void).
@note
*/
MenuManagement::MenuManagement(hmi* screen)
{
display = (Adafruit_SSD1306*) screen;
baseMenu = new menuObject(display, NULL, TXT_MenuParams, MENUTYPELIST);
onOffLine = new menuObject(display, baseMenu, TXT_MenuDCCOffLine, MENUTYPELIST);
onOffLineOn = new menuObject(display, onOffLine, TXT_MenuOnLine, 0);
onOffLineOff= new menuObject(display, onOffLine, TXT_MenuOffLine, 1);
trainAddrRead = new menuTrainAddrRead(display, baseMenu, TXT_MenuAddrRead, MENUTRAINADDRREAD);
trainCVRead = new menuTrainCvRead(display, baseMenu, TXT_MenuCVRead, MENUTRAINCVREAD);
trainCVWrite = new menuTrainCvWrite(display, baseMenu, TXT_MenuCVWrite, MENUTRAINCVWRITE);
trainIdent = new menuDecoderIdentification(display, baseMenu, TXT_MenuIdent, MENUTRAINIDENT);
shuttle = new menuShuttleSample(display, baseMenu, TXT_MenuShuttle, MENUSHUTTLESAMPLE);
//dcMode = new menuDcDccMode(display, baseMenu, TXT_DcDccMode, MENUDCDCCMODE);
TrainView = new menuObject(display, baseMenu, TXT_TrainView, MENUTYPELIST);
V1Train = new menuObject(display, TrainView, TXT_V1Train, 1);
V2Trains = new menuObject(display, TrainView, TXT_V2Trains, 2);
V3Trains = new menuObject(display, TrainView, TXT_V3Trains, 3);
physicalMes = new menuInformation(display, baseMenu, TXT_PhysicalMes, MENUACTION); // Classe à définir
lstEvent = new menuObject(display, baseMenu, TXT_LstEvent, MENUACTION);
info = new menuObject(display, baseMenu, TXT_MenuInfos, MENUTYPELIST);
about = new menuInformation(display, info, TXT_MenuAbout, MENUINFORMATION_ABOUT);
wifiInfo = new menuInformation(display, info, TXT_MenuWifiInfo, MENUINFORMATION_WIFI);
#ifdef ENABLE_EXCOMM
exCommInfo = new menuInformation(display, info, TXT_MenuEXCOMMInfo, MENUINFORMATION_EXCOMM);
#endif
reset = new menuObject(display, baseMenu, TXT_MenuSoftReset, MENUTYPELIST);
resetConfirm= new menuObject(display, reset, TXT_MenuResetConfirm, MENUACTION);
}
/*!
@brief begin
i.e. Setup
@param None
@return None (void).
@note
*/
void MenuManagement::begin()
{
_HMIDEBUG_FCT_PRINTLN("MenuManagement::begin.. Begin");
baseMenu->begin(); // Recursive call, all sub menu will execute this fonction
resetMenu();
_HMIDEBUG_FCT_PRINTLN("MenuManagement::begin.. End");
}
/*!
@brief update
@param None
@return None (void).
@note
*/
void MenuManagement::update()
{
_HMIDEBUG_FCT_PRINTLN("MenuManagement::update.. Begin");
if(activeMenu == 0) activeMenu = baseMenu;
activeMenu->update();
_HMIDEBUG_FCT_PRINTLN("MenuManagement::update.. End");
}
/*!
@brief BtnUpPressed
@param None
@return None (void).
@note
*/
void MenuManagement::BtnUpPressed()
{
_HMIDEBUG_FCT_PRINTLN("MenuManagement::BtnUpPressed.. Begin");
activeMenu->eventUp();
// Return value is important to know witch action has been Selected
_HMIDEBUG_FCT_PRINTLN("MenuManagement::BtnUpPressed.. End");
}
/*!
@brief BtnDownPressed
@param None
@return None (void).
@note
*/
void MenuManagement::BtnDownPressed()
{
_HMIDEBUG_FCT_PRINTLN("MenuManagement::BtnDownPressed.. Begin");
activeMenu->eventDown();
_HMIDEBUG_FCT_PRINTLN("MenuManagement::BtnDownPressed.. End");
}
/*!
@brief BtnSelectPressed
@param None
@return None (void).
@note
*/
void MenuManagement::BtnSelectPressed()
{
_HMIDEBUG_FCT_PRINTLN("MenuManagement::BtnSelectPressed.. Begin");
int status = activeMenu->eventSelect();
if (LaboxModes::progMode)
{
return;
}
switch(status)
{
case MENUEXIT:
_HMIDEBUG_LEVEL1_PRINT("Exit menu ");_HMIDEBUG_LEVEL1_PRINTLN(activeMenu->caption);
if(activeMenu->parent)
{
activeMenu->resetMenu();
activeMenu = activeMenu->parent;
}else
{
_HMIState = StateExitMenu;
}
break;
case MENUCHANGETOCHILD:
_HMIDEBUG_LEVEL1_PRINT("Change menu from ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->caption);
_HMIDEBUG_LEVEL1_PRINT(" to ");_HMIDEBUG_LEVEL1_PRINTLN(activeMenu->subMenu[activeMenu->SelectListIndex]->caption);
activeMenu = activeMenu->subMenu[activeMenu->SelectListIndex];
activeMenu->parent->resetMenu();
break;
case MENUTRAINADDRREAD:
case MENUTRAINCVREAD:
case MENUTRAINCVWRITE:
case MENUTRAINIDENT:
case MENUSHUTTLESAMPLE:
case MENUDCDCCMODE:
_HMIDEBUG_LEVEL1_PRINT("Change menu from ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->caption);
_HMIDEBUG_LEVEL1_PRINT(" to ");_HMIDEBUG_LEVEL1_PRINTLN(activeMenu->subMenu[activeMenu->SelectListIndex]->caption);
activeMenu = activeMenu->subMenu[activeMenu->SelectListIndex];
activeMenu->start();
break;
case MENUCHOSEN :
_HMIDEBUG_LEVEL1_PRINT("Menu choice ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->caption);_HMIDEBUG_LEVEL1_PRINT(" has been made : ");
_HMIDEBUG_LEVEL1_PRINTLN(activeMenu->subMenu[activeMenu->SelectListIndex]->caption);
activeMenu = activeMenu->subMenu[activeMenu->SelectListIndex];
bool found = false;
switch(activeMenu->value)
{
case MENUINFORMATION_ABOUT:
case MENUINFORMATION_WIFI:
case MENUINFORMATION_EXCOMM:
_HMIDEBUG_LEVEL1_PRINT("Change sub menu to ");_HMIDEBUG_LEVEL1_PRINTLN(activeMenu->caption);
activeMenu->start();
found = true;
break;
}
if (found)
break;
if(activeMenu == onOffLine)
{
_HMIDEBUG_LEVEL1_PRINT("Choice menu found for ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->caption);
_HMIDEBUG_LEVEL1_PRINT(": Choice is ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->subMenu[activeMenu->SelectListIndex]->caption);
_HMIDEBUG_LEVEL1_PRINT(" (value : ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->subMenu[activeMenu->SelectListIndex]->value);_HMIDEBUG_LEVEL1_PRINTLN(")");
}else
if(activeMenu == onOffLineOn)
{
_HMIDEBUG_LEVEL1_PRINT("Choice menu Line ON");
if (LaboxModes::progMode == true)
TrackManager::setProgPower(POWERMODE::ON);
else
TrackManager::setMainPower(POWERMODE::ON);
_HMIState = StateExitMenu;
}else
if(activeMenu == onOffLineOff)
{
_HMIDEBUG_LEVEL1_PRINT("Choice menu Line OFF");
if (LaboxModes::progMode == true)
TrackManager::setProgPower(POWERMODE::OFF);
else
TrackManager::setMainPower(POWERMODE::OFF);
_HMIState = StateExitMenu;
}else
{
if(activeMenu == resetConfirm)
{
_HMIDEBUG_LEVEL1_PRINT("Choice menu found for ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->caption);
_HMIDEBUG_LEVEL1_PRINT(": Choice is ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->subMenu[activeMenu->SelectListIndex]->caption);
_HMIDEBUG_LEVEL1_PRINT(" (value : ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->subMenu[activeMenu->SelectListIndex]->value);_HMIDEBUG_LEVEL1_PRINTLN(")");
#ifdef ARDUINO_ARCH_ESP32
// !! Only for ESP !!
LaboxModes::Restart(MAIN);
#endif
}else
{
if(activeMenu == lstEvent)
{
_HMIDEBUG_LEVEL1_PRINT("Choice menu found for ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->caption);
//_HMIDEBUG_LEVEL1_PRINT(": Choice is ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->subMenu[activeMenu->SelectListIndex]->caption);
//_HMIDEBUG_LEVEL1_PRINT(" (value : ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->subMenu[activeMenu->SelectListIndex]->value);_HMIDEBUG_LEVEL1_PRINTLN(")");
// Restore default setting
_HMIState = StateBrowseEventLst ;
baseMenu->resetMenu();
}else
{
if(activeMenu == V1Train)
{
_HMIDEBUG_LEVEL1_PRINT("Choice menu found for ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->caption);
//_HMIDEBUG_LEVEL1_PRINT(": Choice is ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->subMenu[activeMenu->SelectListIndex]->caption);
//_HMIDEBUG_LEVEL1_PRINT(" (value : ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->subMenu[activeMenu->SelectListIndex]->value);_HMIDEBUG_LEVEL1_PRINTLN(")");
// Restore default setting
((hmi*) display)->nbTrainToView = 1 ;
_HMIState = StateExitMenu;
}else
{
if(activeMenu == V2Trains)
{
_HMIDEBUG_LEVEL1_PRINT("Choice menu found for ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->caption);
//_HMIDEBUG_LEVEL1_PRINT(": Choice is ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->subMenu[activeMenu->SelectListIndex]->caption);
//_HMIDEBUG_LEVEL1_PRINT(" (value : ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->subMenu[activeMenu->SelectListIndex]->value);_HMIDEBUG_LEVEL1_PRINTLN(")");
// Restore default setting
((hmi*) display)->nbTrainToView = 2 ;
_HMIState = StateExitMenu;
}else
{
if(activeMenu == V3Trains)
{
_HMIDEBUG_LEVEL1_PRINT("Choice menu found for ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->caption);
//_HMIDEBUG_LEVEL1_PRINT(": Choice is ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->subMenu[activeMenu->SelectListIndex]->caption);
//_HMIDEBUG_LEVEL1_PRINT(" (value : ");_HMIDEBUG_LEVEL1_PRINT(activeMenu->subMenu[activeMenu->SelectListIndex]->value);_HMIDEBUG_LEVEL1_PRINTLN(")");
// Restore default setting
((hmi*) display)->nbTrainToView = 3 ;
_HMIState = StateExitMenu;
}else
{
_HMIDEBUG_CRITICAL_PRINT("Critical error, no choice menu found for ");_HMIDEBUG_CRITICAL_PRINTLN(activeMenu->caption);
}
}
}
}
}
}
baseMenu->resetMenu();
activeMenu = activeMenu->parent;
_HMIEvent = noEvent;
break;
}
_HMIDEBUG_FCT_PRINTLN("MenuManagement::BtnSelectPressed.. End");
}
/*!
@brief resetMenu
@param None
@return None (void).
@note
*/
void MenuManagement::resetMenu()
{
_HMIDEBUG_FCT_PRINTLN("MenuManagement::resetMenu.. Begin");
_HMIDEBUG_LEVEL1_PRINTLN("Menu Reset");
baseMenu->resetMenu(); // Recursive call, all sub menu will execute this fonction
activeMenu = baseMenu;
_HMIDEBUG_FCT_PRINTLN("MenuManagement::resetMenu.. End");
}
#endif