Mercurial > public > ostc4
annotate Discovery/Src/tHome.c @ 368:50ea68c7a153 MotionDetection
Added menu item for motion detection. There are several possibility to use motion detection for user action input. To select of the a new menu entry has been added to the Sys2 =>Custom View Menu (Variables in german)
author | ideenmodellierer |
---|---|
date | Tue, 13 Aug 2019 21:10:46 +0200 |
parents | b111fc4250e9 |
children | 0dbf550dc743 |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/tHome.c | |
5 /// \brief Control for Surface and Dive Templates | |
6 /// \author heinrichs weikamp gmbh | |
7 /// \date 10-November-2014 | |
8 /// | |
9 /// \details | |
10 /// | |
11 /// $Id$ | |
12 /////////////////////////////////////////////////////////////////////////////// | |
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
14 /// | |
15 /// This program is free software: you can redistribute it and/or modify | |
16 /// it under the terms of the GNU General Public License as published by | |
17 /// the Free Software Foundation, either version 3 of the License, or | |
18 /// (at your option) any later version. | |
19 /// | |
20 /// This program is distributed in the hope that it will be useful, | |
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 /// GNU General Public License for more details. | |
24 /// | |
25 /// You should have received a copy of the GNU General Public License | |
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 ////////////////////////////////////////////////////////////////////////////// | |
28 | |
29 /* Includes ------------------------------------------------------------------*/ | |
30 #include "tHome.h" | |
31 | |
32 #include "data_exchange_main.h" // for dataOutGetPointer() | |
33 #include "gfx_fonts.h" | |
34 #include "t3.h" | |
35 #include "t4_tetris.h" | |
36 #include "t5_gauge.h" | |
37 #include "t6_apnea.h" | |
38 #include "t7.h" | |
39 #include "tDebug.h" | |
40 #include "timer.h" // for timer_Stopwatch_Restart | |
41 #include "tMenu.h" | |
42 #include "tMenuEditGasOC.h" // for openEdit_DiveSelectBetterGas() | |
43 #include "tMenuEditSetpoint.h" // for openEdit_DiveSelectBetterSetpoint() | |
44 #include "simulation.h" | |
361
b111fc4250e9
Pass action to customer vie update function.
Ideenmodellierer
parents:
289
diff
changeset
|
45 #include "motion.h" |
38 | 46 |
47 /* Private types -------------------------------------------------------------*/ | |
48 | |
49 /* Exported variables --------------------------------------------------------*/ | |
50 _Bool warning_count_high_time = 0; | |
51 _Bool display_count_high_time = 0; | |
52 | |
53 uint8_t errorsInSettings = 0; | |
54 /* Private variables ---------------------------------------------------------*/ | |
55 static uint8_t warning_toogle_count; | |
56 static uint16_t display_toogle_count; | |
57 static uint16_t tHome_tick_count_cview; | |
58 static uint16_t tHome_tick_count_field; | |
59 | |
60 const uint8_t cv_changelist[6] = {CVIEW_Compass, CVIEW_SummaryOfLeftCorner, CVIEW_Tissues, CVIEW_Profile, CVIEW_EADTime, CVIEW_Gaslist}; | |
61 | |
62 /* Private function prototypes -----------------------------------------------*/ | |
63 | |
64 /* Exported functions --------------------------------------------------------*/ | |
65 | |
66 void set_globalState_tHome(void) | |
67 { | |
68 if(stateUsed->mode == MODE_DIVE) | |
69 set_globalState(StD); | |
70 else | |
71 set_globalState(StS); | |
72 } | |
73 | |
74 | |
75 void tHome_init(void) | |
76 { | |
77 t7_init(); // standard + surface | |
78 t3_init(); // big font | |
79 t4_init(); // game | |
80 t5_init(); // gauge | |
81 t6_init(); // apnea | |
82 } | |
83 | |
84 | |
85 void tHome_init_compass(void) | |
86 { | |
87 init_t7_compass(); | |
88 } | |
89 | |
90 | |
91 void tHome_refresh(void) | |
92 { | |
93 SSettings* pSettings = settingsGetPointer(); | |
94 | |
95 warning_toogle_count++; | |
96 if(warning_toogle_count >= 2* pSettings->warning_blink_dsec) | |
97 warning_toogle_count = 0; | |
98 | |
99 if(warning_toogle_count >= pSettings->warning_blink_dsec) | |
100 warning_count_high_time = 1; | |
101 else | |
102 warning_count_high_time = 0; | |
103 | |
104 | |
105 display_toogle_count++; | |
106 if(display_toogle_count >= 2* pSettings->display_toogle_desc) | |
107 display_toogle_count = 0; | |
108 | |
109 if(display_toogle_count >= pSettings->display_toogle_desc) | |
110 display_count_high_time = 1; | |
111 else | |
112 display_count_high_time = 0; | |
113 | |
114 | |
115 if(pSettings->design == 6) | |
116 t6_refresh(); | |
117 else | |
118 if(pSettings->design == 5) | |
119 t5_refresh(); | |
120 else | |
121 if(pSettings->design == 4) | |
122 t4_refresh(); | |
123 else | |
124 if(pSettings->design == 3) | |
125 t3_refresh(); | |
126 else | |
127 if(pSettings->design == 7) | |
128 t7_refresh(); | |
129 else | |
130 { | |
131 pSettings->design = 7; | |
132 t7_refresh(); | |
133 } | |
134 } | |
135 | |
136 | |
137 void tHome_sleepmode_fun(void) | |
138 { | |
139 t7_refresh_sleepmode_fun(); | |
140 } | |
141 | |
142 | |
143 void tHomeDiveMenuControl(uint8_t sendAction) | |
144 { | |
145 if(sendAction == ACTION_BUTTON_NEXT) | |
146 { | |
147 if(settingsGetPointer()->design == 4) | |
148 return; | |
149 | |
150 if(settingsGetPointer()->design == 3) | |
151 settingsGetPointer()->design = 7; | |
152 | |
153 switch(get_globalState()) | |
154 { | |
155 case StD: | |
156 if(settingsGetPointer()->design == 6) | |
157 { | |
158 if(is_stateUsedSetToSim()) | |
159 set_globalState(StDSIM1); | |
160 else | |
161 set_globalState(StDQUIT); | |
162 break; | |
163 } | |
164 | |
165 if(settingsGetPointer()->design == 5) | |
166 { | |
167 if(t5_getCustomView() == CVIEW_Compass) | |
168 set_globalState(StDBEAR); | |
169 else | |
170 set_globalState(StDRAVG); | |
171 break; | |
172 } | |
173 | |
174 if(stateUsed->warnings.betterGas) | |
175 set_globalState(StDMGAS); | |
176 else | |
177 if(stateUsed->warnings.betterSetpoint) | |
178 set_globalState(StDMSPT); | |
179 else | |
180 set_globalState(StDMENU); | |
181 break; | |
182 | |
183 case StDMGAS: | |
184 if(stateUsed->warnings.betterSetpoint) | |
185 set_globalState(StDMSPT); | |
186 else | |
187 set_globalState(StDMENU); | |
188 break; | |
189 | |
190 case StDMSPT: | |
191 set_globalState(StDMENU); | |
192 break; | |
193 | |
194 case StDMENU: | |
195 if(is_stateUsedSetToSim()) | |
196 set_globalState(StDSIM1); | |
197 else | |
198 set_globalState(StD); | |
199 break; | |
200 | |
201 case StDSIM1: | |
202 set_globalState(StDSIM2); | |
203 break; | |
204 | |
205 case StDSIM2: | |
206 set_globalState(StDSIM3); | |
207 break; | |
208 | |
209 case StDSIM3: | |
210 set_globalState(StDSIM4); | |
211 break; | |
212 | |
213 case StDSIM4: | |
214 set_globalState(StD); | |
215 break; | |
216 | |
217 case StDBEAR: // t5_gauge | |
218 set_globalState(StDRAVG); | |
219 break; | |
220 | |
221 case StDRAVG: // t5_gauge | |
222 if(is_stateUsedSetToSim()) | |
223 set_globalState(StDSIM1); | |
224 else | |
225 set_globalState(StD); | |
226 break; | |
227 | |
228 case StDQUIT: // t6_apnea | |
229 set_globalState(StD); | |
230 break; | |
231 | |
232 default: | |
233 set_globalState(StD); | |
234 } | |
235 } | |
236 | |
237 if(sendAction == ACTION_BUTTON_ENTER) | |
238 { | |
239 if(settingsGetPointer()->design == 4) | |
240 return; | |
241 | |
242 if(settingsGetPointer()->design == 3) | |
243 settingsGetPointer()->design = 7; | |
244 | |
245 switch(get_globalState()) | |
246 { | |
247 case StDMGAS: | |
248 openEdit_DiveSelectBetterGas(); | |
249 set_globalState(StD); | |
250 break; | |
251 case StDMSPT: | |
252 openEdit_DiveSelectBetterSetpoint(); | |
253 set_globalState(StD); | |
254 break; | |
255 | |
256 case StDMENU: | |
257 openMenu_first_page_with_OC_gas_update(); | |
258 break; | |
259 | |
260 case StDSIM1: | |
261 Sim_Quit(); | |
262 break; | |
263 | |
264 case StDSIM2: | |
265 Sim_Ascend(); | |
266 break; | |
267 | |
268 case StDSIM3: | |
269 Sim_Descend(); | |
270 break; | |
271 | |
272 case StDSIM4: | |
273 Sim_Divetime(); | |
274 break; | |
275 | |
276 case StDBEAR: // t5_gauge | |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
210
diff
changeset
|
277 stateUsedWrite->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading; |
38 | 278 set_globalState(StD); |
279 break; | |
280 | |
281 case StDRAVG: // t5_gauge | |
282 timer_Stopwatch_Restart(); | |
283 set_globalState(StD); | |
284 break; | |
285 | |
286 case StDQUIT: // t6_apnea | |
287 set_globalState(StD); // used to end StDQUIT, is called before everything else because changes are made in the next lines | |
288 if(is_stateUsedSetToSim()) | |
289 Sim_Quit(); | |
290 else | |
291 dataOutGetPointer()->setEndDive = 1; | |
292 break; | |
293 | |
294 default: | |
295 break; | |
296 } | |
297 } | |
298 } | |
299 | |
300 | |
301 void tHome_findNextStop(const uint16_t *list, uint8_t *depthOutMeter, uint16_t *lengthOutSeconds) | |
302 { | |
303 uint8_t ptr = DECOINFO_STRUCT_MAX_STOPS - 1; | |
304 | |
305 while(ptr && !list[ptr]) | |
306 ptr--; | |
307 | |
308 *lengthOutSeconds = list[ptr]; | |
309 if(!(*lengthOutSeconds)) | |
310 { | |
311 *depthOutMeter = 0; | |
312 } | |
313 else | |
314 if(ptr == 0) | |
315 { | |
316 *depthOutMeter = (uint8_t)((stateUsed->diveSettings.last_stop_depth_bar*10.0f) + 0.1f); | |
317 } | |
318 else | |
319 { | |
320 ptr -= 1; | |
321 *depthOutMeter = (uint8_t)(((stateUsed->diveSettings.input_second_to_last_stop_depth_bar + (stateUsed->diveSettings.input_next_stop_increment_depth_bar * ptr))*10.0f) + 0.1f); | |
322 } | |
323 } | |
324 | |
325 | |
326 void tHome_change_field_button_pressed(void) | |
327 { | |
328 tHome_tick_count_field = 0; | |
329 if(settingsGetPointer()->design == 7) | |
330 t7_change_field(); | |
331 } | |
332 | |
333 | |
361
b111fc4250e9
Pass action to customer vie update function.
Ideenmodellierer
parents:
289
diff
changeset
|
334 void tHome_change_customview_button_pressed(uint8_t action) |
38 | 335 { |
336 tHome_tick_count_cview = 0; | |
337 if(settingsGetPointer()->design == 7) | |
361
b111fc4250e9
Pass action to customer vie update function.
Ideenmodellierer
parents:
289
diff
changeset
|
338 t7_change_customview(action); |
38 | 339 else |
340 if(settingsGetPointer()->design == 3) | |
341 t3_change_customview(); | |
342 else | |
343 if(settingsGetPointer()->design == 5) | |
344 t5_change_customview(); | |
345 else | |
346 if(settingsGetPointer()->design == 6) | |
347 t6_change_customview(); | |
348 } | |
349 | |
350 | |
351 void tHome_tick(void) | |
352 { | |
353 uint16_t field = settingsGetPointer()->tX_userselectedLeftLowerCornerTimeout; | |
354 uint16_t cview = settingsGetPointer()->tX_customViewTimeout; | |
355 | |
356 if(field) | |
357 { | |
358 tHome_tick_count_field++; | |
359 if(tHome_tick_count_field > (field * 10)) | |
360 { | |
361 tHome_tick_count_field = 0; | |
362 if(settingsGetPointer()->design == 7) | |
363 { | |
364 t7_set_field_to_primary(); | |
365 } | |
366 } | |
367 } | |
368 | |
369 if(cview) | |
370 { | |
371 tHome_tick_count_cview++; | |
372 if(tHome_tick_count_cview > (cview *10)) | |
373 { | |
374 tHome_tick_count_cview = 0; | |
375 if(settingsGetPointer()->design == 7) | |
376 { | |
377 t7_set_customview_to_primary(); | |
378 } | |
379 } | |
380 } | |
381 } | |
382 | |
383 | |
384 uint32_t tHome_DateCode(RTC_DateTypeDef *dateInput) | |
385 { | |
386 uint32_t answer = 0; | |
387 | |
388 answer = 0; | |
389 answer += (dateInput->Year & 0x7F)<< 9; | |
390 answer += (dateInput->Month & 0x0F)<< 5; | |
391 answer += (dateInput->Date & 0x1F); | |
392 | |
393 return answer; | |
394 } | |
395 | |
396 | |
397 uint8_t tHome_gas_writer(uint8_t oxygen_percentage, uint8_t helium_percentage, char *text) | |
398 { | |
399 if(oxygen_percentage == 100) | |
400 return (uint8_t) snprintf(text,10,"Oxy"); | |
401 else if((oxygen_percentage == 21) && (!helium_percentage)) | |
402 return (uint8_t) snprintf(text,10,"Air"); | |
403 else if(!helium_percentage) | |
404 return (uint8_t) snprintf(text,10,"NX%02i",oxygen_percentage); | |
405 else if((oxygen_percentage + helium_percentage) == 100) | |
406 return (uint8_t) snprintf(text,10,"HX%02i",oxygen_percentage); | |
407 else | |
408 return (uint8_t) snprintf(text,10,"%02i/%02i",oxygen_percentage,helium_percentage); | |
409 } | |
410 | |
411 uint8_t tHome_show_lost_connection_count(GFX_DrawCfgScreen *ScreenToWriteOn) | |
412 { | |
208 | 413 static uint8_t LastKnowRTEState = SPI_RX_STATE_INVALID; |
414 | |
99 | 415 if(!SPI_MIN_ERROR_SHOW) return 0; |
172
c659fda83e44
Minor: Button defaults, release date adjusted, use SPI_SHOW_SYNC_STATS
heinrichsweikamp
parents:
138
diff
changeset
|
416 if(DataEX_lost_connection_count()>=SPI_MIN_ERROR_SHOW && SPI_SHOW_SYNC_STATS){ |
38 | 417 |
99 | 418 char text[64]; |
38 | 419 |
82 | 420 SDataExchangeSlaveToMaster* dataIn=get_dataInPointer(); |
208 | 421 SDataReceiveFromMaster* pDataOut = dataOutGetPointer(); |
82 | 422 |
99 | 423 snprintf(text,32,"spi err:\002 %i/%i",DataEX_lost_connection_count(),get_num_SPI_CALLBACKS()); |
424 Gfx_write_label_var(ScreenToWriteOn, 100,300, 0,&FontT24,CLUT_ButtonSymbols,text); | |
82 | 425 |
104 | 426 // snprintf(text,32,"header:\002%X%X%X%X",dataIn->header.checkCode[0],dataIn->header.checkCode[1],dataIn->header.checkCode[2],dataIn->header.checkCode[3]); |
427 // Gfx_write_label_var(ScreenToWriteOn, 350,550, 0,&FontT24,CLUT_ButtonSymbols,text); | |
82 | 428 |
208 | 429 //snprintf(text,32,"footer:\002%X%X%X%X",dataIn->footer.checkCode[0],dataIn->footer.checkCode[1],dataIn->footer.checkCode[2],dataIn->footer.checkCode[3]); |
430 | |
431 /* data shifted => ignore received data */ | |
432 if((pDataOut->header.checkCode[SPI_HEADER_INDEX_RX_STATE] == SPI_RX_STATE_SHIFTED) || (pDataOut->header.checkCode[SPI_HEADER_INDEX_RX_STATE] == SPI_RX_STATE_OFFLINE)) | |
433 { | |
434 dataIn->header.checkCode[SPI_HEADER_INDEX_RX_STATE] = LastKnowRTEState; | |
435 } | |
436 else | |
437 { | |
438 LastKnowRTEState =dataIn->header.checkCode[SPI_HEADER_INDEX_RX_STATE]; | |
439 } | |
440 snprintf(text,32,"RX State M|R:\002%X|%X",pDataOut->header.checkCode[SPI_HEADER_INDEX_RX_STATE], dataIn->header.checkCode[SPI_HEADER_INDEX_RX_STATE] ); | |
99 | 441 Gfx_write_label_var(ScreenToWriteOn, 600,800, 0,&FontT24,CLUT_ButtonSymbols,text); |
442 } | |
82 | 443 |
99 | 444 |
445 | |
446 // snprintf(text,32,"cpt:\002%i",get_num_SPI_CALLBACKS()); | |
447 // Gfx_write_label_var(ScreenToWriteOn, 600,800, 90,&FontT24,CLUT_ButtonSymbols,text); | |
82 | 448 |
449 // snprintf(text,10,"i2c:\002%i",get_DataEX_Error_place()); | |
450 // Gfx_write_label_var(ScreenToWriteOn, 600,800, 90,&FontT24,CLUT_ButtonSymbols,text); | |
38 | 451 |
452 return DataEX_lost_connection_count(); | |
453 } |