comparison Discovery/Src/demo.c @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 /**
2 ******************************************************************************
3 * @copyright heinrichs weikamp gmbh
4 * @file demo.c
5 * @author heinrichs weikamp gmbh
6 * @date 26-Nov-2015
7 * @version 0.1
8 * @since 26-Nov-2015
9 * @brief f�r die Messe und die Vitrine
10 * @bug
11 * @warning
12 @verbatim
13 ==============================================================================
14
15
16 ==============================================================================
17 @endverbatim
18 ******************************************************************************
19 * @attention
20 *
21 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
22 *
23 ******************************************************************************
24 */
25
26 #include "demo.h"
27 #include "base.h" // for BUTTON_BACK, ...
28 #include "data_exchange_main.h" // for time_elapsed_ms()
29 #include "settings.h"
30 #include "ostc.h"
31
32 #ifndef DEMOMODE
33
34 /* Exported functions --------------------------------------------------------*/
35
36 uint8_t demoGetCommand(void) { return 0; }
37 uint8_t demoModeActive(void) { return 0; }
38 void demoSendCommand(uint8_t action) { return; }
39
40
41 #else
42
43 /* Private variables with external access ------------------------------------*/
44
45 uint8_t demoModeActiveStatus = 1;
46 uint32_t systickDemoMode;
47
48 uint16_t demoModeActual = 0;
49
50 #define BUTTON_BACK (BUTTON_BACK_PIN | 0x80)
51 #define BUTTON_NEXT (BUTTON_NEXT_PIN | 0x80)
52 #define BUTTON_ENTER (BUTTON_ENTER_PIN | 0x80)
53
54 /* Private typedef -----------------------------------------------------------*/
55
56 #define MAXCOMMANDS 200
57
58 #ifdef SHOWCCRMODE
59 const uint8_t commandlist[MAXCOMMANDS][3] =
60 {
61 /* Button, deci-seconds to wait */
62
63 // start for both
64 {0, 40},
65 // start OC, activate CC
66 {BUTTON_NEXT, 0},
67 {BUTTON_NEXT, 0},
68 {BUTTON_ENTER, 0},
69 {BUTTON_ENTER, 0},
70 {BUTTON_NEXT, 0},
71 {BUTTON_ENTER, 0}, // Change to CC
72 {BUTTON_ENTER, 0}, // Leave Edit
73 {BUTTON_BACK, 0}, // Cursor
74 {BUTTON_NEXT, 0},
75 {BUTTON_NEXT, 0},
76 {BUTTON_NEXT, 0},
77 {BUTTON_NEXT, 0},
78 {BUTTON_BACK, 0},
79 {0, 0},
80 {0, 0},
81 {0, 0},
82 {0, 0},
83 {0, 0},
84 {0, 0},
85 // start CC @ 20, set cursor to Sim Menu
86 {BUTTON_NEXT, 0},
87 {BUTTON_NEXT, 0},
88 {BUTTON_NEXT, 0},
89 {BUTTON_NEXT, 0},
90 {BUTTON_NEXT, 0},
91 {BUTTON_NEXT, 0},
92 {BUTTON_NEXT, 0},
93 {BUTTON_NEXT, 0},
94 {BUTTON_BACK, 50},
95 {0, 0},
96 // re-loop @ 30
97 {0, 3},
98 // Logbook
99 {BUTTON_BACK, 0},
100 {BUTTON_ENTER, 20},
101 {BUTTON_NEXT, 20},
102 {BUTTON_BACK, 0},
103 {BUTTON_BACK, 0},
104 {BUTTON_BACK, 0},
105 // surface screen
106 {0, 2},
107 // menu
108 {BUTTON_NEXT, 0},
109 {BUTTON_NEXT, 0},
110 {BUTTON_NEXT, 0},
111 {BUTTON_NEXT, 0},
112 {BUTTON_NEXT, 0},
113 {BUTTON_NEXT, 0},
114 {BUTTON_NEXT, 0},
115 {BUTTON_NEXT, 0},
116 {BUTTON_NEXT, 0},
117 {BUTTON_ENTER, 30},
118 {BUTTON_ENTER, 0},
119 // simulator
120 {0, 10},
121 {BUTTON_ENTER, 10},
122 {BUTTON_ENTER, 10},
123 {BUTTON_ENTER, 10},
124 {BUTTON_ENTER, 10},
125 {BUTTON_ENTER, 10},
126
127 {BUTTON_NEXT, 0},
128 {BUTTON_NEXT, 0},
129 {BUTTON_ENTER, 0},
130 {BUTTON_ENTER, 0},
131 // the end, repeat from start
132 {255, 0}
133 };
134 #else // OC Mode Demo
135 const uint8_t commandlist[MAXCOMMANDS][2] =
136 {
137 /* Button, seconds to wait */
138
139 // start for both
140 {0, 50}, // wait IS IMPORTANT
141 // start CC, activate OC
142 {BUTTON_NEXT, 0},
143 {BUTTON_NEXT, 0},
144 {BUTTON_NEXT, 0},
145 {BUTTON_NEXT, 0},
146 {BUTTON_ENTER, 0},
147 {BUTTON_ENTER, 0},
148 {BUTTON_ENTER, 0},
149 {BUTTON_ENTER, 0},
150 {BUTTON_BACK, 0}, // Leave Cursor Mode
151 {BUTTON_NEXT, 0},
152 {BUTTON_NEXT, 0},
153 {BUTTON_NEXT, 0},
154 {BUTTON_NEXT, 0},
155 {BUTTON_NEXT, 0}, // OC
156 {BUTTON_BACK, 0},
157 {0, 0},
158 {0, 0},
159 {0, 0},
160 {0, 0},
161 // start OC @ line 20
162 {BUTTON_NEXT, 0},
163 {BUTTON_NEXT, 0},
164 {BUTTON_NEXT, 0},
165 {BUTTON_NEXT, 0},
166 {BUTTON_NEXT, 0},
167 {BUTTON_NEXT, 0}, // OC -> SIM
168 {BUTTON_BACK, 0}, // Exit Menu
169 {0, 0},
170 {0, 0},
171 {0, 0},
172 // re-loop @ 30
173 {0, 10},
174 // Logbook
175 {BUTTON_BACK, 4},
176 {BUTTON_NEXT, 0},
177 {BUTTON_NEXT, 10},
178 {BUTTON_ENTER, 20},
179 {BUTTON_NEXT, 20},
180 {BUTTON_NEXT, 20},
181 {BUTTON_BACK, 0},
182 {BUTTON_BACK, 5},
183 {BUTTON_BACK, 0}, // Exit Logbook Mode
184 // surface screen
185 {0, 10},
186 {BUTTON_ENTER, 10},
187 {BUTTON_ENTER, 10},
188
189 // menu
190 // activate Configure Deco Gas
191 {BUTTON_NEXT, 0}, // Start Menu
192 {BUTTON_NEXT, 2}, // SIM -> OC
193 {BUTTON_ENTER, 2},
194 {BUTTON_NEXT, 1},
195 {BUTTON_ENTER, 0},
196 {BUTTON_ENTER, 0},
197 // Mix 30 -> 90
198 {BUTTON_NEXT, 0},
199 {BUTTON_NEXT, 0},
200 {BUTTON_NEXT, 0},
201 {BUTTON_NEXT, 0},
202 {BUTTON_NEXT, 0},
203 {BUTTON_NEXT, 0},
204 {BUTTON_ENTER, 0},
205 // Mix 90 -> 99
206 {BUTTON_BACK, 0},
207 {BUTTON_ENTER, 0},
208 {BUTTON_ENTER, 0},
209 {BUTTON_ENTER, 5},
210 // First -> Deco
211 {BUTTON_NEXT, 2},
212 {BUTTON_ENTER, 2},
213 {BUTTON_NEXT, 2},
214 {BUTTON_ENTER, 2},
215 {BUTTON_ENTER, 10},
216 {BUTTON_BACK, 0},
217 {BUTTON_BACK, 30},
218 /*
219 // OC -> SIM
220 {BUTTON_NEXT, 2},
221 {BUTTON_NEXT, 2},
222 {BUTTON_NEXT, 2},
223 {BUTTON_NEXT, 2},
224 {BUTTON_NEXT, 1},
225 {BUTTON_ENTER, 10},
226 */
227 // SYS2 Layout
228 {BUTTON_NEXT, 2},
229 {BUTTON_NEXT, 2},
230 {BUTTON_NEXT, 2},
231 {BUTTON_NEXT, 2},
232 {BUTTON_ENTER, 2},
233 {BUTTON_NEXT, 2},
234 {BUTTON_NEXT, 2},
235 {BUTTON_ENTER, 2},
236 {BUTTON_NEXT, 2},
237 {BUTTON_ENTER, 2},
238 {BUTTON_BACK, 2},
239 {BUTTON_BACK, 10},
240 // SYS2 -> SIM
241 {BUTTON_NEXT, 2},
242 {BUTTON_ENTER, 10},
243 // simulator
244 {BUTTON_ENTER, 40}, // Start Simulator
245 {BUTTON_ENTER, 10},
246 {BUTTON_ENTER, 10},
247 {BUTTON_ENTER, 10},
248 {BUTTON_ENTER, 10},
249 {BUTTON_ENTER, 10},
250 {BUTTON_ENTER, 10},
251 {BUTTON_ENTER, 90},
252
253 {BUTTON_NEXT, 5}, // Quit
254 {BUTTON_NEXT, 5},
255 {BUTTON_ENTER, 5},
256 {BUTTON_ENTER, 50},
257 // surface screen
258 {0, 10},
259 // Logbook
260 {BUTTON_BACK, 20},
261 {BUTTON_ENTER, 20},
262 {BUTTON_NEXT, 20},
263 {BUTTON_NEXT, 20},
264 {BUTTON_BACK, 0},
265 {BUTTON_BACK, 5},
266 {BUTTON_BACK, 0}, // Exit Logbook Mode
267 // surface screen
268 {0, 10},
269 // activate Configure Deco Gas, go to Gas 2
270 {BUTTON_NEXT, 0}, // Start Menu
271 {BUTTON_NEXT, 2}, // SIM -> OC
272 {BUTTON_ENTER, 2},
273 {BUTTON_NEXT, 1},
274 {BUTTON_ENTER, 0},
275 {BUTTON_ENTER, 0},
276 // Mix Decogas 99 -> EAN30 First
277 {BUTTON_BACK, 0},
278 {BUTTON_BACK, 0},
279 {BUTTON_BACK, 0},
280 {BUTTON_BACK, 0},
281 {BUTTON_BACK, 0},
282 {BUTTON_BACK, 0},
283 {BUTTON_ENTER, 0},
284 {BUTTON_NEXT, 0},
285 {BUTTON_ENTER, 0},
286 {BUTTON_ENTER, 0},
287 {BUTTON_ENTER, 2},
288 {BUTTON_NEXT, 2},
289 {BUTTON_ENTER, 5},
290 {BUTTON_ENTER, 5},
291 {BUTTON_ENTER, 10}, // Now EAN 30 First
292 {BUTTON_BACK, 0}, // Exit Edit Mode
293 {BUTTON_BACK, 30}, // Exit Cursor Mode
294 /*
295 // OC -> SIM
296 {BUTTON_NEXT, 2},
297 {BUTTON_NEXT, 2},
298 {BUTTON_NEXT, 2},
299 {BUTTON_NEXT, 2},
300 {BUTTON_NEXT, 1},
301 {BUTTON_ENTER, 10},
302 */
303 // SYS2 Layout
304 {BUTTON_NEXT, 2},
305 {BUTTON_NEXT, 2},
306 {BUTTON_NEXT, 2},
307 {BUTTON_NEXT, 2},
308 {BUTTON_ENTER, 2},
309 {BUTTON_NEXT, 2},
310 {BUTTON_NEXT, 2},
311 {BUTTON_ENTER, 2},
312 {BUTTON_NEXT, 2},
313 {BUTTON_ENTER, 2},
314 {BUTTON_BACK, 2},
315 {BUTTON_BACK, 10},
316 // SYS -> SIM
317 {BUTTON_NEXT, 2},
318 {BUTTON_ENTER, 10},
319 // simulator
320 {BUTTON_ENTER, 40}, // Start Simulator
321 {BUTTON_ENTER, 5},
322 {BUTTON_ENTER, 10},
323 {BUTTON_ENTER, 10},
324 {BUTTON_ENTER, 10},
325 {BUTTON_ENTER, 10},
326 {BUTTON_ENTER, 10},
327 {BUTTON_ENTER, 90},
328 {BUTTON_NEXT, 5}, // Menu?
329 {BUTTON_NEXT, 5}, // Quit?
330 {BUTTON_ENTER, 10},
331 {BUTTON_ENTER, 50},
332 // the end, repeat from start
333 {255, 0}
334 };
335 #endif
336
337
338 /* Exported functions --------------------------------------------------------*/
339
340 uint8_t demoModeActive(void)
341 {
342 return demoModeActiveStatus;
343 }
344
345 uint8_t demoGetCommand(void)
346 {
347 if(!demoModeActiveStatus)
348 return 0;
349
350 uint32_t milliSecondsSinceLast;
351 uint32_t systick_now;
352
353
354 systick_now = HAL_GetTick();
355 milliSecondsSinceLast = time_elapsed_ms(systickDemoMode, systick_now);
356
357 #ifdef SHOWCCRMODE
358 if((demoModeActual == 1) && (settingsGetPointer()->dive_mode == DIVEMODE_CCR))
359 demoModeActual = 20;
360 #else
361 if((demoModeActual == 1) && (settingsGetPointer()->dive_mode == DIVEMODE_OC))
362 demoModeActual = 20;
363 #endif
364
365 if(demoModeActual > MAXCOMMANDS - 2)
366 demoModeActual = 30;
367
368
369 uint32_t actualDelay = ((commandlist[demoModeActual][1]) * 100) + 15;
370
371 if(milliSecondsSinceLast < actualDelay)
372 return 0;
373
374 systickDemoMode = systick_now;
375
376 if(commandlist[demoModeActual][0] == 255)
377 demoModeActual = 30;
378 else
379 demoModeActual++;
380
381 return commandlist[demoModeActual][0];
382 }
383
384
385 void demoSendCommand(uint8_t action)
386 {
387 demoModeActiveStatus = 0;
388
389 }
390
391 void demoConfigureSettings(void)
392 {
393 settingsGetPointer()->gas[1].oxygen_percentage = 21;
394 settingsGetPointer()->gas[1].helium_percentage = 0;
395 settingsGetPointer()->gas[1].depth_meter = 0;
396 settingsGetPointer()->gas[1].note.ub.first = 0;
397 settingsGetPointer()->gas[1].note.ub.active = 0;
398 settingsGetPointer()->gas[1].note.ub.deco = 0;
399 settingsGetPointer()->gas[1].note.ub.travel = 0;
400
401 settingsGetPointer()->gas[2].oxygen_percentage = 30;
402 settingsGetPointer()->gas[2].helium_percentage = 0;
403 settingsGetPointer()->gas[2].depth_meter = 0;
404 settingsGetPointer()->gas[2].note.ub.first = 1;
405 settingsGetPointer()->gas[2].note.ub.active = 1;
406 settingsGetPointer()->gas[2].note.ub.deco = 0;
407 settingsGetPointer()->gas[2].note.ub.travel = 0;
408
409 settingsGetPointer()->ButtonResponsiveness[0] = 90;
410 settingsGetPointer()->ButtonResponsiveness[1] = 90;
411 settingsGetPointer()->ButtonResponsiveness[2] = 90;
412 settingsGetPointer()->ButtonResponsiveness[3] = 90;
413 }
414
415 /* Includes ------------------------------------------------------------------*/
416
417 /* Private function prototypes -----------------------------------------------*/
418
419 /* Private variables with external access ------------------------------------*/
420
421 /* Exported functions --------------------------------------------------------*/
422
423 /* Private functions ---------------------------------------------------------*/
424
425
426 #endif // DEMO
427
428
429 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/