Mercurial > public > ostc4
annotate Discovery/Src/tHome.c @ 515:218ac999e96b
Added missing display of button labels in refresh function:
Back, select and next were not shown on screen => added write call
author | Ideenmodellierer |
---|---|
date | Sun, 06 Sep 2020 21:09:37 +0200 |
parents | 06b21f1e47a5 |
children | bd66f4910993 |
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 | |
379 | 60 const uint8_t cv_changelist[] = {CVIEW_Compass, CVIEW_SummaryOfLeftCorner, CVIEW_Tissues, CVIEW_Profile, CVIEW_EADTime, CVIEW_Gaslist, CVIEW_noneOrDebug, CVIEW_Decolist,CVIEW_sensors,CVIEW_sensors_mV, CVIEW_END}; |
505 | 61 const uint8_t cv_changelist_BS[] = {CVIEW_T3_Decostop, CVIEW_sensors, CVIEW_Compass, CVIEW_T3_MaxDepth,CVIEW_T3_StopWatch, CVIEW_T3_TTS, CVIEW_T3_ppO2andGas, CVIEW_noneOrDebug, CVIEW_T3_Navigation, CVIEW_T3_DepthData, CVIEW_T3_END}; |
38 | 62 |
63 /* Private function prototypes -----------------------------------------------*/ | |
64 | |
65 /* Exported functions --------------------------------------------------------*/ | |
66 | |
67 void set_globalState_tHome(void) | |
68 { | |
69 if(stateUsed->mode == MODE_DIVE) | |
70 set_globalState(StD); | |
71 else | |
72 set_globalState(StS); | |
73 } | |
74 | |
75 | |
76 void tHome_init(void) | |
77 { | |
78 t7_init(); // standard + surface | |
79 t3_init(); // big font | |
80 t4_init(); // game | |
81 t5_init(); // gauge | |
82 t6_init(); // apnea | |
83 } | |
84 | |
85 | |
86 void tHome_init_compass(void) | |
87 { | |
88 init_t7_compass(); | |
89 } | |
90 | |
91 | |
92 void tHome_refresh(void) | |
93 { | |
94 SSettings* pSettings = settingsGetPointer(); | |
95 | |
96 warning_toogle_count++; | |
97 if(warning_toogle_count >= 2* pSettings->warning_blink_dsec) | |
98 warning_toogle_count = 0; | |
99 | |
100 if(warning_toogle_count >= pSettings->warning_blink_dsec) | |
101 warning_count_high_time = 1; | |
102 else | |
103 warning_count_high_time = 0; | |
104 | |
105 | |
106 display_toogle_count++; | |
107 if(display_toogle_count >= 2* pSettings->display_toogle_desc) | |
108 display_toogle_count = 0; | |
109 | |
110 if(display_toogle_count >= pSettings->display_toogle_desc) | |
111 display_count_high_time = 1; | |
112 else | |
113 display_count_high_time = 0; | |
114 | |
115 | |
116 if(pSettings->design == 6) | |
117 t6_refresh(); | |
118 else | |
119 if(pSettings->design == 5) | |
120 t5_refresh(); | |
121 else | |
122 if(pSettings->design == 4) | |
123 t4_refresh(); | |
124 else | |
125 if(pSettings->design == 3) | |
126 t3_refresh(); | |
127 else | |
128 if(pSettings->design == 7) | |
129 t7_refresh(); | |
130 else | |
131 { | |
132 pSettings->design = 7; | |
133 t7_refresh(); | |
134 } | |
135 } | |
136 | |
137 | |
138 void tHome_sleepmode_fun(void) | |
139 { | |
140 t7_refresh_sleepmode_fun(); | |
141 } | |
142 | |
143 | |
144 void tHomeDiveMenuControl(uint8_t sendAction) | |
145 { | |
146 if(sendAction == ACTION_BUTTON_NEXT) | |
147 { | |
148 if(settingsGetPointer()->design == 4) | |
149 return; | |
150 | |
151 if(settingsGetPointer()->design == 3) | |
384
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
152 { |
38 | 153 settingsGetPointer()->design = 7; |
384
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
154 if(settingsGetPointer()->MotionDetection == MOTION_DETECT_SECTOR) |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
155 { |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
156 DefinePitchSectors(stateRealGetPointer()->lifeData.compass_pitch,CUSTOMER_DEFINED_VIEWS); |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
157 } |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
158 } |
38 | 159 switch(get_globalState()) |
160 { | |
161 case StD: | |
162 if(settingsGetPointer()->design == 6) | |
163 { | |
164 if(is_stateUsedSetToSim()) | |
165 set_globalState(StDSIM1); | |
166 else | |
167 set_globalState(StDQUIT); | |
168 break; | |
169 } | |
170 | |
171 if(settingsGetPointer()->design == 5) | |
172 { | |
173 if(t5_getCustomView() == CVIEW_Compass) | |
174 set_globalState(StDBEAR); | |
175 else | |
176 set_globalState(StDRAVG); | |
177 break; | |
178 } | |
179 | |
180 if(stateUsed->warnings.betterGas) | |
181 set_globalState(StDMGAS); | |
182 else | |
183 if(stateUsed->warnings.betterSetpoint) | |
184 set_globalState(StDMSPT); | |
185 else | |
186 set_globalState(StDMENU); | |
187 break; | |
188 | |
189 case StDMGAS: | |
190 if(stateUsed->warnings.betterSetpoint) | |
191 set_globalState(StDMSPT); | |
192 else | |
193 set_globalState(StDMENU); | |
194 break; | |
195 | |
196 case StDMSPT: | |
197 set_globalState(StDMENU); | |
198 break; | |
199 | |
200 case StDMENU: | |
201 if(is_stateUsedSetToSim()) | |
202 set_globalState(StDSIM1); | |
203 else | |
204 set_globalState(StD); | |
205 break; | |
206 | |
207 case StDSIM1: | |
208 set_globalState(StDSIM2); | |
209 break; | |
210 | |
211 case StDSIM2: | |
212 set_globalState(StDSIM3); | |
213 break; | |
214 | |
215 case StDSIM3: | |
216 set_globalState(StDSIM4); | |
217 break; | |
218 | |
219 case StDSIM4: | |
220 set_globalState(StD); | |
221 break; | |
222 | |
223 case StDBEAR: // t5_gauge | |
224 set_globalState(StDRAVG); | |
225 break; | |
226 | |
227 case StDRAVG: // t5_gauge | |
228 if(is_stateUsedSetToSim()) | |
229 set_globalState(StDSIM1); | |
230 else | |
231 set_globalState(StD); | |
232 break; | |
233 | |
234 case StDQUIT: // t6_apnea | |
235 set_globalState(StD); | |
236 break; | |
237 | |
238 default: | |
239 set_globalState(StD); | |
240 } | |
241 } | |
242 | |
243 if(sendAction == ACTION_BUTTON_ENTER) | |
244 { | |
245 if(settingsGetPointer()->design == 4) | |
246 return; | |
247 | |
384
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
248 if(settingsGetPointer()->design == 3) /* switch back to t7 (standard) view */ |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
249 { |
38 | 250 settingsGetPointer()->design = 7; |
384
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
251 if(settingsGetPointer()->MotionDetection == MOTION_DETECT_SECTOR) |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
252 { |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
253 DefinePitchSectors(stateRealGetPointer()->lifeData.compass_pitch,CUSTOMER_DEFINED_VIEWS); |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
254 } |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
255 } |
38 | 256 |
257 switch(get_globalState()) | |
258 { | |
259 case StDMGAS: | |
260 openEdit_DiveSelectBetterGas(); | |
261 set_globalState(StD); | |
262 break; | |
263 case StDMSPT: | |
264 openEdit_DiveSelectBetterSetpoint(); | |
265 set_globalState(StD); | |
266 break; | |
267 | |
268 case StDMENU: | |
269 openMenu_first_page_with_OC_gas_update(); | |
270 break; | |
271 | |
272 case StDSIM1: | |
273 Sim_Quit(); | |
274 break; | |
275 | |
276 case StDSIM2: | |
277 Sim_Ascend(); | |
278 break; | |
279 | |
280 case StDSIM3: | |
281 Sim_Descend(); | |
282 break; | |
283 | |
284 case StDSIM4: | |
285 Sim_Divetime(); | |
286 break; | |
287 | |
288 case StDBEAR: // t5_gauge | |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
210
diff
changeset
|
289 stateUsedWrite->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading; |
38 | 290 set_globalState(StD); |
291 break; | |
292 | |
293 case StDRAVG: // t5_gauge | |
294 timer_Stopwatch_Restart(); | |
295 set_globalState(StD); | |
296 break; | |
297 | |
298 case StDQUIT: // t6_apnea | |
299 set_globalState(StD); // used to end StDQUIT, is called before everything else because changes are made in the next lines | |
300 if(is_stateUsedSetToSim()) | |
301 Sim_Quit(); | |
302 else | |
303 dataOutGetPointer()->setEndDive = 1; | |
304 break; | |
305 | |
306 default: | |
307 break; | |
308 } | |
309 } | |
310 } | |
311 | |
312 | |
313 void tHome_findNextStop(const uint16_t *list, uint8_t *depthOutMeter, uint16_t *lengthOutSeconds) | |
314 { | |
315 uint8_t ptr = DECOINFO_STRUCT_MAX_STOPS - 1; | |
316 | |
317 while(ptr && !list[ptr]) | |
318 ptr--; | |
319 | |
320 *lengthOutSeconds = list[ptr]; | |
321 if(!(*lengthOutSeconds)) | |
322 { | |
323 *depthOutMeter = 0; | |
324 } | |
325 else | |
326 if(ptr == 0) | |
327 { | |
328 *depthOutMeter = (uint8_t)((stateUsed->diveSettings.last_stop_depth_bar*10.0f) + 0.1f); | |
329 } | |
330 else | |
331 { | |
332 ptr -= 1; | |
333 *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); | |
334 } | |
335 } | |
336 | |
337 | |
338 void tHome_change_field_button_pressed(void) | |
339 { | |
340 tHome_tick_count_field = 0; | |
341 if(settingsGetPointer()->design == 7) | |
342 t7_change_field(); | |
343 } | |
344 | |
345 | |
361
b111fc4250e9
Pass action to customer vie update function.
Ideenmodellierer
parents:
289
diff
changeset
|
346 void tHome_change_customview_button_pressed(uint8_t action) |
38 | 347 { |
348 tHome_tick_count_cview = 0; | |
349 if(settingsGetPointer()->design == 7) | |
361
b111fc4250e9
Pass action to customer vie update function.
Ideenmodellierer
parents:
289
diff
changeset
|
350 t7_change_customview(action); |
38 | 351 else |
352 if(settingsGetPointer()->design == 3) | |
386
39c147e47c1c
Added key direction awarness to t3, t5 and t6 views:
ideenmodellierer
parents:
384
diff
changeset
|
353 t3_change_customview(action); |
38 | 354 else |
355 if(settingsGetPointer()->design == 5) | |
386
39c147e47c1c
Added key direction awarness to t3, t5 and t6 views:
ideenmodellierer
parents:
384
diff
changeset
|
356 t5_change_customview(action); |
38 | 357 else |
358 if(settingsGetPointer()->design == 6) | |
386
39c147e47c1c
Added key direction awarness to t3, t5 and t6 views:
ideenmodellierer
parents:
384
diff
changeset
|
359 t6_change_customview(action); |
38 | 360 } |
361 | |
505 | 362 uint8_t tHome_getNumberOfAvailableCVs(const uint8_t* pcv_list) |
363 { | |
364 uint8_t cnt = 0; | |
365 | |
366 while((pcv_list[cnt] != CVIEW_END) && (pcv_list[cnt] != CVIEW_T3_END)) | |
367 { | |
368 cnt++; | |
369 if (cnt > 100) /* just in case an invalid list has been provided... */ | |
370 { | |
371 break; | |
372 } | |
373 } | |
374 cnt--; /* do not count end token */ | |
375 return cnt; | |
376 } | |
38 | 377 |
378 void tHome_tick(void) | |
379 { | |
380 uint16_t field = settingsGetPointer()->tX_userselectedLeftLowerCornerTimeout; | |
381 uint16_t cview = settingsGetPointer()->tX_customViewTimeout; | |
382 | |
383 if(field) | |
384 { | |
385 tHome_tick_count_field++; | |
386 if(tHome_tick_count_field > (field * 10)) | |
387 { | |
388 tHome_tick_count_field = 0; | |
389 if(settingsGetPointer()->design == 7) | |
390 { | |
391 t7_set_field_to_primary(); | |
392 } | |
393 } | |
394 } | |
395 | |
396 if(cview) | |
397 { | |
398 tHome_tick_count_cview++; | |
399 if(tHome_tick_count_cview > (cview *10)) | |
400 { | |
401 tHome_tick_count_cview = 0; | |
402 if(settingsGetPointer()->design == 7) | |
403 { | |
404 t7_set_customview_to_primary(); | |
405 } | |
406 } | |
407 } | |
408 } | |
409 | |
410 | |
411 uint32_t tHome_DateCode(RTC_DateTypeDef *dateInput) | |
412 { | |
413 uint32_t answer = 0; | |
414 | |
415 answer = 0; | |
416 answer += (dateInput->Year & 0x7F)<< 9; | |
417 answer += (dateInput->Month & 0x0F)<< 5; | |
418 answer += (dateInput->Date & 0x1F); | |
419 | |
420 return answer; | |
421 } | |
422 | |
423 | |
424 uint8_t tHome_gas_writer(uint8_t oxygen_percentage, uint8_t helium_percentage, char *text) | |
425 { | |
426 if(oxygen_percentage == 100) | |
427 return (uint8_t) snprintf(text,10,"Oxy"); | |
428 else if((oxygen_percentage == 21) && (!helium_percentage)) | |
429 return (uint8_t) snprintf(text,10,"Air"); | |
430 else if(!helium_percentage) | |
431 return (uint8_t) snprintf(text,10,"NX%02i",oxygen_percentage); | |
432 else if((oxygen_percentage + helium_percentage) == 100) | |
433 return (uint8_t) snprintf(text,10,"HX%02i",oxygen_percentage); | |
434 else | |
435 return (uint8_t) snprintf(text,10,"%02i/%02i",oxygen_percentage,helium_percentage); | |
436 } | |
437 | |
438 uint8_t tHome_show_lost_connection_count(GFX_DrawCfgScreen *ScreenToWriteOn) | |
439 { | |
208 | 440 static uint8_t LastKnowRTEState = SPI_RX_STATE_INVALID; |
441 | |
99 | 442 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
|
443 if(DataEX_lost_connection_count()>=SPI_MIN_ERROR_SHOW && SPI_SHOW_SYNC_STATS){ |
38 | 444 |
99 | 445 char text[64]; |
38 | 446 |
82 | 447 SDataExchangeSlaveToMaster* dataIn=get_dataInPointer(); |
208 | 448 SDataReceiveFromMaster* pDataOut = dataOutGetPointer(); |
82 | 449 |
500
0d2449e9d659
Added possibility to switch between "classic" bigfont views and a selection with a new information combination
Ideenmodellierer
parents:
386
diff
changeset
|
450 snprintf(text,32,"spi err:\002 %ld/%ld",DataEX_lost_connection_count(),get_num_SPI_CALLBACKS()); |
99 | 451 Gfx_write_label_var(ScreenToWriteOn, 100,300, 0,&FontT24,CLUT_ButtonSymbols,text); |
82 | 452 |
104 | 453 // 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]); |
454 // Gfx_write_label_var(ScreenToWriteOn, 350,550, 0,&FontT24,CLUT_ButtonSymbols,text); | |
82 | 455 |
208 | 456 //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]); |
457 | |
458 /* data shifted => ignore received data */ | |
459 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)) | |
460 { | |
461 dataIn->header.checkCode[SPI_HEADER_INDEX_RX_STATE] = LastKnowRTEState; | |
462 } | |
463 else | |
464 { | |
465 LastKnowRTEState =dataIn->header.checkCode[SPI_HEADER_INDEX_RX_STATE]; | |
466 } | |
467 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 | 468 Gfx_write_label_var(ScreenToWriteOn, 600,800, 0,&FontT24,CLUT_ButtonSymbols,text); |
469 } | |
82 | 470 |
99 | 471 |
472 | |
473 // snprintf(text,32,"cpt:\002%i",get_num_SPI_CALLBACKS()); | |
474 // Gfx_write_label_var(ScreenToWriteOn, 600,800, 90,&FontT24,CLUT_ButtonSymbols,text); | |
82 | 475 |
476 // snprintf(text,10,"i2c:\002%i",get_DataEX_Error_place()); | |
477 // Gfx_write_label_var(ScreenToWriteOn, 600,800, 90,&FontT24,CLUT_ButtonSymbols,text); | |
38 | 478 |
479 return DataEX_lost_connection_count(); | |
480 } |