-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLCDML_display_menuFunction.ino
338 lines (278 loc) · 10.1 KB
/
LCDML_display_menuFunction.ino
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/* ===================================================================== *
* *
* Menu Callback Function *
* *
* ===================================================================== *
*
* EXAMPLE CODE:
// *********************************************************************
void your_function_name(uint8_t param)
// *********************************************************************
{
if(LCDML.FUNC_setup()) // ****** SETUP *********
{
// setup
// is called only if it is started
// starts a trigger event for the loop function every 100 milliseconds
LCDML.FUNC_setLoopInterval(100);
}
if(LCDML.FUNC_loop()) // ****** LOOP *********
{
// loop
// is called when it is triggered
// - with LCDML_DISP_triggerMenu( milliseconds )
// - with every button status change
// check if any button is pressed (enter, up, down, left, right)
if(LCDML.BT_checkAny()) {
LCDML.FUNC_goBackToMenu();
}
}
if(LCDML.FUNC_close()) // ****** STABLE END *********
{
// loop end
// you can here reset some global vars or delete it
}
}
* ===================================================================== *
*/
// *********************************************************************
void mFunc_information(uint8_t param)
// *********************************************************************
{
if(LCDML.FUNC_setup()) // ****** SETUP *********
{
// setup function
u8g2.setFont(_LCDML_DISP_font);
u8g2.firstPage();
do {
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 1), "To close this");
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 2), "function press");
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 3), "any button or use");
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 4), "back button");
} while( u8g2.nextPage() );
}
if(LCDML.FUNC_loop()) // ****** LOOP *********
{
// loop function, can be run in a loop when LCDML_DISP_triggerMenu(xx) is set
// the quit button works in every DISP function without any checks; it starts the loop_end function
if(LCDML.BT_checkAny()) // check if any button is pressed (enter, up, down, left, right)
{
// LCDML_goToMenu stops a running menu function and goes to the menu
LCDML.FUNC_goBackToMenu();
}
}
if(LCDML.FUNC_close()) // ****** STABLE END *********
{
// you can here reset some global vars or do nothing
}
}
// *********************************************************************
uint8_t g_func_timer_info = 0; // time counter (global variable)
unsigned long g_timer_1 = 0; // timer variable (global variable)
void mFunc_timer_info(uint8_t param)
// *********************************************************************
{
if(LCDML.FUNC_setup()) // ****** SETUP *********
{
g_func_timer_info = 20; // reset and set timer
char buf[20];
sprintf (buf, "wait %d seconds", g_func_timer_info);
u8g2.setFont(_LCDML_DISP_font);
u8g2.firstPage();
do {
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 1), buf);
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 2), "or press back button");
} while( u8g2.nextPage() );
LCDML.FUNC_setLoopInterval(100); // starts a trigger event for the loop function every 100 milliseconds
LCDML.TIMER_msReset(g_timer_1);
}
if(LCDML.FUNC_loop()) // ****** LOOP *********
{
// loop function, can be run in a loop when LCDML_DISP_triggerMenu(xx) is set
// the quit button works in every DISP function without any checks; it starts the loop_end function
// reset screensaver timer
LCDML.SCREEN_resetTimer();
// this function is called every 100 milliseconds
// this method checks every 1000 milliseconds if it is called
if(LCDML.TIMER_ms(g_timer_1, 1000))
{
g_timer_1 = millis();
g_func_timer_info--; // increment the value every second
char buf[20];
sprintf (buf, "wait %d seconds", g_func_timer_info);
u8g2.setFont(_LCDML_DISP_font);
u8g2.firstPage();
do {
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 1), buf);
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 2), "or press back button");
} while( u8g2.nextPage() );
}
// this function can only be ended when quit button is pressed or the time is over
// check if the function ends normally
if (g_func_timer_info <= 0)
{
// leave this function
LCDML.FUNC_goBackToMenu();
}
}
if(LCDML.FUNC_close()) // ****** STABLE END *********
{
// you can here reset some global vars or do nothing
}
}
// *********************************************************************
uint8_t g_button_value = 0; // button value counter (global variable)
void mFunc_p2(uint8_t param)
// *********************************************************************
{
if(LCDML.FUNC_setup()) // ****** SETUP *********
{
// setup function
// print LCD content
char buf[17];
sprintf (buf, "count: %d of 3", 0);
u8g2.setFont(_LCDML_DISP_font);
u8g2.firstPage();
do {
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 1), "press a or w button");
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 2), buf);
} while( u8g2.nextPage() );
// Reset Button Value
g_button_value = 0;
// Disable the screensaver for this function until it is closed
LCDML.FUNC_disableScreensaver();
}
if(LCDML.FUNC_loop()) // ****** LOOP *********
{
// loop function, can be run in a loop when LCDML_DISP_triggerMenu(xx) is set
// the quit button works in every DISP function without any checks; it starts the loop_end function
// the quit button works in every DISP function without any checks; it starts the loop_end function
if (LCDML.BT_checkAny()) // check if any button is pressed (enter, up, down, left, right)
{
if (LCDML.BT_checkLeft() || LCDML.BT_checkUp()) // check if button left is pressed
{
LCDML.BT_resetLeft(); // reset the left button
LCDML.BT_resetUp(); // reset the left button
g_button_value++;
// update LCD content
char buf[20];
sprintf (buf, "count: %d of 3", g_button_value);
u8g2.setFont(_LCDML_DISP_font);
u8g2.firstPage();
do {
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 1), "press a or w button");
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 2), buf);
} while( u8g2.nextPage() );
}
}
// check if button count is three
if (g_button_value >= 3) {
LCDML.FUNC_goBackToMenu(); // leave this function
}
}
if(LCDML.FUNC_close()) // ****** STABLE END *********
{
// you can here reset some global vars or do nothing
}
}
// *********************************************************************
void mFunc_screensaver(uint8_t param)
// *********************************************************************
{
if(LCDML.FUNC_setup()) // ****** SETUP *********
{
// setup function
u8g2.setFont(_LCDML_DISP_font);
u8g2.firstPage();
do {
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 1), "Telescope Status");
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 2), g_status);
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 3), "Press any button to go back");
} while( u8g2.nextPage() );
LCDML.FUNC_setLoopInterval(100); // starts a trigger event for the loop function every 100 milliseconds
}
if(LCDML.FUNC_loop()) // ****** LOOP *********
{
if (LCDML.BT_checkAny()) // check if any button is pressed (enter, up, down, left, right)
{
LCDML.FUNC_goBackToMenu(); // leave this function
}
}
if(LCDML.FUNC_close()) // ****** STABLE END *********
{
// The screensaver go to the root menu
LCDML.MENU_goRoot();
}
}
// *********************************************************************
void mFunc_back(uint8_t param)
// *********************************************************************
{
if(LCDML.FUNC_setup()) // ****** SETUP *********
{
// end function and go an layer back
LCDML.FUNC_goBackToMenu(1); // leave this function and go a layer back
}
}
// *********************************************************************
void mFunc_goToRootMenu(uint8_t param)
// *********************************************************************
{
if(LCDML.FUNC_setup()) // ****** SETUP *********
{
// go to root and display menu
LCDML.MENU_goRoot();
}
}
// *********************************************************************
void mFunc_jumpTo_timer_info(uint8_t param)
// *********************************************************************
{
if(LCDML.FUNC_setup()) // ****** SETUP *********
{
// Jump to main screen
LCDML.OTHER_jumpToFunc(mFunc_timer_info);
}
}
// *********************************************************************
void mFunc_para(uint8_t param)
// *********************************************************************
{
if(LCDML.FUNC_setup()) // ****** SETUP *********
{
char buf[20];
sprintf (buf, "parameter: %d", param);
// setup function
u8g2.setFont(_LCDML_DISP_font);
u8g2.firstPage();
do {
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 1), buf);
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 2), "press any key");
u8g2.drawStr( 0, (_LCDML_DISP_font_h * 3), "to leave it");
} while( u8g2.nextPage() );
LCDML.FUNC_setLoopInterval(100); // starts a trigger event for the loop function every 100 milliseconds
}
if(LCDML.FUNC_loop()) // ****** LOOP *********
{
// For example
switch(param)
{
case 10:
break;
case 20:
break;
case 30:
break;
default:
break;
}
if (LCDML.BT_checkAny()) // check if any button is pressed (enter, up, down, left, right)
{
LCDML.FUNC_goBackToMenu(); // leave this function
}
}
if(LCDML.FUNC_close()) // ****** STABLE END *********
{
// you can here reset some global vars or do nothing
}
}