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