forked from DCC-EX/CommandStation-EX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenuTrainAddrRead.cpp
244 lines (213 loc) · 5.24 KB
/
menuTrainAddrRead.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
/*
* La Box Project
* menuTrainAddrRead Classes
*
* @Author : Cedric Bellec
* @Organization : Locoduino.org
*/
#include "defines.h"
#include "DCC.h"
#ifdef USE_HMI
#include "menuobject.h"
#include "menuTrainAddrRead.h"
#include "hmi.h"
#include "LaboxModes.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
int locoID = 0;
bool longAddress = false;
bool updatedDisplay;
char message[21];
enum StateReading
{
// Select Up Down
Reading, // Waiting for Read result... -- -- --
AddressRead, // Reading finished and ok. -- -- --
ReadingError, // Reading finished and failed. -- -- --
MenuRetry, // Select retry/quit retry -- option quit
MenuQuit, // Select retry/quit quit option retry --
};
StateReading state;
void locoIdCallback(int16_t inId)
{
if (inId >= LONG_ADDR_MARKER)
{
longAddress = true;
inId -= LONG_ADDR_MARKER;
}
locoID = inId;
if (locoID > 0) // loco address cannot be 0 !
{
state = StateReading::MenuQuit;
}
if (locoID <= 0)
{
state = StateReading::MenuRetry;
}
DIAG(F("locoIdCallback called %d !"), locoID);
updatedDisplay = false;
}
void menuTrainAddrRead::start()
{
_HMIDEBUG_FCT_PRINTLN("menuTrainAddrRead::start.. Begin");
if (!LaboxModes::progMode) {
LaboxModes::Restart(CV1ADDR);
}
state = StateReading::Reading;
locoID = 0;
longAddress = false;
void (*ptr)(int16_t) = &locoIdCallback;
DCC::getLocoId(ptr);
updatedDisplay = false;
_HMIDEBUG_FCT_PRINTLN("menuTrainAddrRead::start.. End");
}
/*!
@brief menuTrainAddrRead Constructor
@param Screen, an Adafruit_SSD1306 object to permit to display our menu
@param p, a parent object. All menu are chained between parent and sons
@param title, a menu has a title, a char[HMI_MenueMessageSize].
@param val, a integer which define the king of menu or the returned value after selection
@return None (void).
@note
*/
menuTrainAddrRead::menuTrainAddrRead(Adafruit_SSD1306* screen, menuObject* p, const char* title, int value): menuObject(screen, p, title, value)
{
resetMenu();
}
/*!
@brief eventUp, Notification of a button event
@param None
@return None (void).
@note
*/
void menuTrainAddrRead::eventUp()
{
_HMIDEBUG_FCT_PRINTLN("menuTrainAddrRead::eventUp.. Begin");
menuObject::eventUp();
if (state == StateReading::MenuQuit)
{
state = StateReading::MenuRetry;
updatedDisplay = false;
}
_HMIDEBUG_FCT_PRINTLN("menuTrainAddrRead::eventUp.. End");
}
/*!
@brief eventDown, Notification of a button event
@param None
@return None (void).
@note
*/
void menuTrainAddrRead::eventDown()
{
_HMIDEBUG_FCT_PRINTLN("menuTrainAddrRead::eventDown.. Begin");
menuObject::eventDown();
if (state == StateReading::MenuRetry)
{
state = StateReading::MenuQuit;
updatedDisplay = false;
}
_HMIDEBUG_FCT_PRINTLN("menuTrainAddrRead::eventDown.. End");
}
/*!
@brief eventSelect, Notification of a button event
@param None
@return None (void).
@note
*/
int menuTrainAddrRead::eventSelect()
{
_HMIDEBUG_FCT_PRINTLN("menuTrainAddrRead::eventSelect.. Begin");
if (state == StateReading::MenuQuit)
{
LaboxModes::Restart(SILENTRETURNTOMAIN);
}
if (state == StateReading::MenuRetry)
{
this->start();
}
_HMIDEBUG_FCT_PRINTLN("menuTrainAddrRead::eventSelect.. End");
return MENUEXIT;
}
/*!
@brief Setup HMI class and start HMI
@param None
@return None (void).
@note
*/
void menuTrainAddrRead::begin()
{
_HMIDEBUG_FCT_PRINTLN("menuTrainAddrRead::begin.. Begin");
_HMIDEBUG_FCT_PRINTLN("menuTrainAddrRead::begin.. End");
}
/*!
@brief update, call to refresh screen
@param None
@return None (void).
@note
*/
void menuTrainAddrRead::update()
{
_HMIDEBUG_FCT_PRINTLN(F("menuTrainAddrRead::update.. Begin"));
if(!updatedDisplay)
{
display->clearDisplay();
updatedDisplay = true;
}
display->setTextSize(1);
display->setTextColor(WHITE);
display->setCursor(5, 9);
display->println(TXT_MenuAddrRead);
display->setCursor(5, 53);
if (state == StateReading::MenuRetry)
{
sprintf(message,">%s<",TXT_MenuAddrRetry);
display->println(message);
display->setCursor(64, 53);
sprintf(message," %s ",TXT_MenuAddrQuit);
display->println(message);
}
else
if (state == StateReading::MenuQuit)
{
sprintf(message," %s ",TXT_MenuAddrRetry);
display->println(message);
display->setCursor(64, 53);
sprintf(message,">%s<",TXT_MenuAddrQuit);
display->println(message);
}
display->display();
if(locoID > 0)
{
if (longAddress)
sprintf(message,"%04d",locoID);
else
sprintf(message,"%03d", locoID);
}
else
if(locoID < 0)
{
sprintf(message," ERR");
}
else
sprintf(message,"----");
display->setTextColor(WHITE);
display->setTextSize(3);
display->setCursor(20, 25);
display->println(message);
display->display();
_HMIDEBUG_FCT_PRINTLN(F("menuTrainAddrRead::update.. End"));
}
/*!
@brief resetMenu,
@param None
@return None (void).
@note
*/
void menuTrainAddrRead::resetMenu()
{
_HMIDEBUG_FCT_PRINTLN("menuTrainAddrRead::resetMenu.. Begin");
menuObject::resetMenu();
updatedDisplay = false;
_HMIDEBUG_FCT_PRINTLN("menuTrainAddrRead::resetMenu.. End");
}
#endif