Mercurial > public > ostc4
annotate Discovery/Src/tHome.c @ 187:485c5135cf7f cleanup-2
cleanup: forgotten cleanup from 9da7dd50e2ec
Simply cleanup something forgotten in 9da7dd50e2ec. There is so much
duplicate code, that things are very easy to forget when cleaning up.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Fri, 15 Mar 2019 12:53:14 +0100 |
parents | c659fda83e44 |
children | cdbdb4458520 |
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 "t9.h" | |
40 #include "tDebug.h" | |
41 #include "timer.h" // for timer_Stopwatch_Restart | |
42 #include "tMenu.h" | |
43 #include "tMenuEditGasOC.h" // for openEdit_DiveSelectBetterGas() | |
44 #include "tMenuEditSetpoint.h" // for openEdit_DiveSelectBetterSetpoint() | |
45 #include "simulation.h" | |
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 uint32_t cv_configuration = 0xFFFFFFFF; | |
61 const uint8_t cv_changelist[6] = {CVIEW_Compass, CVIEW_SummaryOfLeftCorner, CVIEW_Tissues, CVIEW_Profile, CVIEW_EADTime, CVIEW_Gaslist}; | |
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 switch_to_SimData_tHome(void) | |
77 { | |
78 set_stateUsedToSim(); | |
79 } | |
80 | |
81 | |
82 void switch_to_RealData_tHome(void) | |
83 { | |
84 set_stateUsedToReal(); | |
85 } | |
86 | |
87 | |
88 void tHome_init(void) | |
89 { | |
90 t7_init(); // standard + surface | |
91 t3_init(); // big font | |
92 t4_init(); // game | |
93 t5_init(); // gauge | |
94 t6_init(); // apnea | |
95 } | |
96 | |
97 | |
98 void tHome_init_compass(void) | |
99 { | |
100 init_t7_compass(); | |
101 } | |
102 | |
103 | |
104 void tHome_refresh(void) | |
105 { | |
106 SSettings* pSettings = settingsGetPointer(); | |
107 | |
108 warning_toogle_count++; | |
109 if(warning_toogle_count >= 2* pSettings->warning_blink_dsec) | |
110 warning_toogle_count = 0; | |
111 | |
112 if(warning_toogle_count >= pSettings->warning_blink_dsec) | |
113 warning_count_high_time = 1; | |
114 else | |
115 warning_count_high_time = 0; | |
116 | |
117 | |
118 display_toogle_count++; | |
119 if(display_toogle_count >= 2* pSettings->display_toogle_desc) | |
120 display_toogle_count = 0; | |
121 | |
122 if(display_toogle_count >= pSettings->display_toogle_desc) | |
123 display_count_high_time = 1; | |
124 else | |
125 display_count_high_time = 0; | |
126 | |
127 | |
128 if(pSettings->design == 6) | |
129 t6_refresh(); | |
130 else | |
131 if(pSettings->design == 5) | |
132 t5_refresh(); | |
133 else | |
134 if(pSettings->design == 4) | |
135 t4_refresh(); | |
136 else | |
137 if(pSettings->design == 3) | |
138 t3_refresh(); | |
139 else | |
140 if(pSettings->design == 7) | |
141 t7_refresh(); | |
142 else | |
143 { | |
144 pSettings->design = 7; | |
145 t7_refresh(); | |
146 } | |
147 } | |
148 | |
149 | |
150 void tHome_sleepmode_fun(void) | |
151 { | |
152 t7_refresh_sleepmode_fun(); | |
153 } | |
154 | |
155 | |
156 void tHomeDiveMenuControl(uint8_t sendAction) | |
157 { | |
158 if(sendAction == ACTION_BUTTON_NEXT) | |
159 { | |
160 if(settingsGetPointer()->design == 4) | |
161 return; | |
162 | |
163 if(settingsGetPointer()->design == 3) | |
164 settingsGetPointer()->design = 7; | |
165 | |
166 switch(get_globalState()) | |
167 { | |
168 case StD: | |
169 if(settingsGetPointer()->design == 6) | |
170 { | |
171 if(is_stateUsedSetToSim()) | |
172 set_globalState(StDSIM1); | |
173 else | |
174 set_globalState(StDQUIT); | |
175 break; | |
176 } | |
177 | |
178 if(settingsGetPointer()->design == 5) | |
179 { | |
180 if(t5_getCustomView() == CVIEW_Compass) | |
181 set_globalState(StDBEAR); | |
182 else | |
183 set_globalState(StDRAVG); | |
184 break; | |
185 } | |
186 | |
187 if(stateUsed->warnings.betterGas) | |
188 set_globalState(StDMGAS); | |
189 else | |
190 if(stateUsed->warnings.betterSetpoint) | |
191 set_globalState(StDMSPT); | |
192 else | |
193 set_globalState(StDMENU); | |
194 break; | |
195 | |
196 case StDMGAS: | |
197 if(stateUsed->warnings.betterSetpoint) | |
198 set_globalState(StDMSPT); | |
199 else | |
200 set_globalState(StDMENU); | |
201 break; | |
202 | |
203 case StDMSPT: | |
204 set_globalState(StDMENU); | |
205 break; | |
206 | |
207 case StDMENU: | |
208 if(is_stateUsedSetToSim()) | |
209 set_globalState(StDSIM1); | |
210 else | |
211 set_globalState(StD); | |
212 break; | |
213 | |
214 case StDSIM1: | |
215 set_globalState(StDSIM2); | |
216 break; | |
217 | |
218 case StDSIM2: | |
219 set_globalState(StDSIM3); | |
220 break; | |
221 | |
222 case StDSIM3: | |
223 set_globalState(StDSIM4); | |
224 break; | |
225 | |
226 case StDSIM4: | |
227 set_globalState(StD); | |
228 break; | |
229 | |
230 case StDBEAR: // t5_gauge | |
231 set_globalState(StDRAVG); | |
232 break; | |
233 | |
234 case StDRAVG: // t5_gauge | |
235 if(is_stateUsedSetToSim()) | |
236 set_globalState(StDSIM1); | |
237 else | |
238 set_globalState(StD); | |
239 break; | |
240 | |
241 case StDQUIT: // t6_apnea | |
242 set_globalState(StD); | |
243 break; | |
244 | |
245 default: | |
246 set_globalState(StD); | |
247 } | |
248 } | |
249 | |
250 if(sendAction == ACTION_BUTTON_ENTER) | |
251 { | |
252 if(settingsGetPointer()->design == 4) | |
253 return; | |
254 | |
255 if(settingsGetPointer()->design == 3) | |
256 settingsGetPointer()->design = 7; | |
257 | |
258 switch(get_globalState()) | |
259 { | |
260 case StDMGAS: | |
261 openEdit_DiveSelectBetterGas(); | |
262 set_globalState(StD); | |
263 break; | |
264 case StDMSPT: | |
265 openEdit_DiveSelectBetterSetpoint(); | |
266 set_globalState(StD); | |
267 break; | |
268 | |
269 case StDMENU: | |
270 openMenu_first_page_with_OC_gas_update(); | |
271 break; | |
272 | |
273 case StDSIM1: | |
274 Sim_Quit(); | |
275 break; | |
276 | |
277 case StDSIM2: | |
278 Sim_Ascend(); | |
279 break; | |
280 | |
281 case StDSIM3: | |
282 Sim_Descend(); | |
283 break; | |
284 | |
285 case StDSIM4: | |
286 Sim_Divetime(); | |
287 break; | |
288 | |
289 case StDBEAR: // t5_gauge | |
290 if(is_stateUsedSetToSim()) | |
291 stateSimGetPointerWrite()->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading; | |
292 else | |
293 stateRealGetPointerWrite()->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading; | |
294 set_globalState(StD); | |
295 break; | |
296 | |
297 case StDRAVG: // t5_gauge | |
298 timer_Stopwatch_Restart(); | |
299 set_globalState(StD); | |
300 break; | |
301 | |
302 case StDQUIT: // t6_apnea | |
303 set_globalState(StD); // used to end StDQUIT, is called before everything else because changes are made in the next lines | |
304 if(is_stateUsedSetToSim()) | |
305 Sim_Quit(); | |
306 else | |
307 dataOutGetPointer()->setEndDive = 1; | |
308 break; | |
309 | |
310 default: | |
311 break; | |
312 } | |
313 } | |
314 } | |
315 | |
316 | |
317 void tHome_findNextStop(const uint16_t *list, uint8_t *depthOutMeter, uint16_t *lengthOutSeconds) | |
318 { | |
319 uint8_t ptr = DECOINFO_STRUCT_MAX_STOPS - 1; | |
320 | |
321 while(ptr && !list[ptr]) | |
322 ptr--; | |
323 | |
324 *lengthOutSeconds = list[ptr]; | |
325 if(!(*lengthOutSeconds)) | |
326 { | |
327 *depthOutMeter = 0; | |
328 } | |
329 else | |
330 if(ptr == 0) | |
331 { | |
332 *depthOutMeter = (uint8_t)((stateUsed->diveSettings.last_stop_depth_bar*10.0f) + 0.1f); | |
333 } | |
334 else | |
335 { | |
336 ptr -= 1; | |
337 *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); | |
338 } | |
339 } | |
340 | |
341 | |
342 void tHome_change_field_button_pressed(void) | |
343 { | |
344 tHome_tick_count_field = 0; | |
345 if(settingsGetPointer()->design == 7) | |
346 t7_change_field(); | |
347 } | |
348 | |
349 | |
350 void tHome_change_customview_button_pressed(void) | |
351 { | |
352 tHome_tick_count_cview = 0; | |
353 if(settingsGetPointer()->design == 7) | |
354 t7_change_customview(); | |
355 else | |
356 if(settingsGetPointer()->design == 3) | |
357 t3_change_customview(); | |
358 else | |
359 if(settingsGetPointer()->design == 5) | |
360 t5_change_customview(); | |
361 else | |
362 if(settingsGetPointer()->design == 6) | |
363 t6_change_customview(); | |
364 } | |
365 | |
366 | |
367 void tHome_tick(void) | |
368 { | |
369 uint16_t field = settingsGetPointer()->tX_userselectedLeftLowerCornerTimeout; | |
370 uint16_t cview = settingsGetPointer()->tX_customViewTimeout; | |
371 | |
372 if(field) | |
373 { | |
374 tHome_tick_count_field++; | |
375 if(tHome_tick_count_field > (field * 10)) | |
376 { | |
377 tHome_tick_count_field = 0; | |
378 if(settingsGetPointer()->design == 7) | |
379 { | |
380 t7_set_field_to_primary(); | |
381 } | |
382 } | |
383 } | |
384 | |
385 if(cview) | |
386 { | |
387 tHome_tick_count_cview++; | |
388 if(tHome_tick_count_cview > (cview *10)) | |
389 { | |
390 tHome_tick_count_cview = 0; | |
391 if(settingsGetPointer()->design == 7) | |
392 { | |
393 t7_set_customview_to_primary(); | |
394 } | |
395 } | |
396 } | |
397 } | |
398 | |
399 | |
400 uint32_t tHome_DateCode(RTC_DateTypeDef *dateInput) | |
401 { | |
402 uint32_t answer = 0; | |
403 | |
404 answer = 0; | |
405 answer += (dateInput->Year & 0x7F)<< 9; | |
406 answer += (dateInput->Month & 0x0F)<< 5; | |
407 answer += (dateInput->Date & 0x1F); | |
408 | |
409 return answer; | |
410 } | |
411 | |
412 | |
413 uint8_t tHome_gas_writer(uint8_t oxygen_percentage, uint8_t helium_percentage, char *text) | |
414 { | |
415 if(oxygen_percentage == 100) | |
416 return (uint8_t) snprintf(text,10,"Oxy"); | |
417 else if((oxygen_percentage == 21) && (!helium_percentage)) | |
418 return (uint8_t) snprintf(text,10,"Air"); | |
419 else if(!helium_percentage) | |
420 return (uint8_t) snprintf(text,10,"NX%02i",oxygen_percentage); | |
421 else if((oxygen_percentage + helium_percentage) == 100) | |
422 return (uint8_t) snprintf(text,10,"HX%02i",oxygen_percentage); | |
423 else | |
424 return (uint8_t) snprintf(text,10,"%02i/%02i",oxygen_percentage,helium_percentage); | |
425 } | |
426 | |
427 uint8_t tHome_show_lost_connection_count(GFX_DrawCfgScreen *ScreenToWriteOn) | |
428 { | |
99 | 429 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
|
430 if(DataEX_lost_connection_count()>=SPI_MIN_ERROR_SHOW && SPI_SHOW_SYNC_STATS){ |
38 | 431 |
99 | 432 char text[64]; |
38 | 433 |
82 | 434 SDataExchangeSlaveToMaster* dataIn=get_dataInPointer(); |
435 | |
99 | 436 snprintf(text,32,"spi err:\002 %i/%i",DataEX_lost_connection_count(),get_num_SPI_CALLBACKS()); |
437 Gfx_write_label_var(ScreenToWriteOn, 100,300, 0,&FontT24,CLUT_ButtonSymbols,text); | |
82 | 438 |
104 | 439 // 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]); |
440 // Gfx_write_label_var(ScreenToWriteOn, 350,550, 0,&FontT24,CLUT_ButtonSymbols,text); | |
82 | 441 |
99 | 442 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]); |
443 Gfx_write_label_var(ScreenToWriteOn, 600,800, 0,&FontT24,CLUT_ButtonSymbols,text); | |
444 } | |
82 | 445 |
99 | 446 |
447 | |
448 // snprintf(text,32,"cpt:\002%i",get_num_SPI_CALLBACKS()); | |
449 // Gfx_write_label_var(ScreenToWriteOn, 600,800, 90,&FontT24,CLUT_ButtonSymbols,text); | |
82 | 450 |
451 // snprintf(text,10,"i2c:\002%i",get_DataEX_Error_place()); | |
452 // Gfx_write_label_var(ScreenToWriteOn, 600,800, 90,&FontT24,CLUT_ButtonSymbols,text); | |
38 | 453 |
454 return DataEX_lost_connection_count(); | |
455 } |