Mercurial > public > ostc4
annotate Discovery/Src/tHome.c @ 94:c6d284ea265b kittz
reduce i2c speed and dutycycle for compass stability
author | Dmitry Romanov <kitt@bk.ru> |
---|---|
date | Mon, 26 Nov 2018 12:20:31 +0300 |
parents | e6abbef57475 |
children | 6a2308b9a3d4 |
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 t9_init(); // bonex | |
96 } | |
97 | |
98 | |
99 void tHome_init_compass(void) | |
100 { | |
101 init_t7_compass(); | |
102 init_t9_compass(); | |
103 } | |
104 | |
105 | |
106 void tHome_refresh(void) | |
107 { | |
108 SSettings* pSettings = settingsGetPointer(); | |
109 | |
110 warning_toogle_count++; | |
111 if(warning_toogle_count >= 2* pSettings->warning_blink_dsec) | |
112 warning_toogle_count = 0; | |
113 | |
114 if(warning_toogle_count >= pSettings->warning_blink_dsec) | |
115 warning_count_high_time = 1; | |
116 else | |
117 warning_count_high_time = 0; | |
118 | |
119 | |
120 display_toogle_count++; | |
121 if(display_toogle_count >= 2* pSettings->display_toogle_desc) | |
122 display_toogle_count = 0; | |
123 | |
124 if(display_toogle_count >= pSettings->display_toogle_desc) | |
125 display_count_high_time = 1; | |
126 else | |
127 display_count_high_time = 0; | |
128 | |
129 | |
130 if(pSettings->design == 6) | |
131 t6_refresh(); | |
132 else | |
133 if(pSettings->design == 5) | |
134 t5_refresh(); | |
135 else | |
136 if(pSettings->design == 4) | |
137 t4_refresh(); | |
138 else | |
139 if(pSettings->design == 3) | |
140 t3_refresh(); | |
141 else | |
142 if(pSettings->design == 7) | |
143 t7_refresh(); | |
144 else | |
145 if(pSettings->design == 9) | |
146 t9_refresh(); | |
147 else | |
148 { | |
149 pSettings->design = 7; | |
150 t7_refresh(); | |
151 } | |
152 } | |
153 | |
154 | |
155 void tHome_sleepmode_fun(void) | |
156 { | |
157 t7_refresh_sleepmode_fun(); | |
158 } | |
159 | |
160 | |
161 void tHomeDiveMenuControl(uint8_t sendAction) | |
162 { | |
163 if(sendAction == ACTION_BUTTON_NEXT) | |
164 { | |
165 if(settingsGetPointer()->design == 4) | |
166 return; | |
167 | |
168 if(settingsGetPointer()->design == 3) | |
169 settingsGetPointer()->design = 7; | |
170 | |
171 switch(get_globalState()) | |
172 { | |
173 case StD: | |
174 if(settingsGetPointer()->design == 6) | |
175 { | |
176 if(is_stateUsedSetToSim()) | |
177 set_globalState(StDSIM1); | |
178 else | |
179 set_globalState(StDQUIT); | |
180 break; | |
181 } | |
182 | |
183 if(settingsGetPointer()->design == 5) | |
184 { | |
185 if(t5_getCustomView() == CVIEW_Compass) | |
186 set_globalState(StDBEAR); | |
187 else | |
188 set_globalState(StDRAVG); | |
189 break; | |
190 } | |
191 | |
192 if(stateUsed->warnings.betterGas) | |
193 set_globalState(StDMGAS); | |
194 else | |
195 if(stateUsed->warnings.betterSetpoint) | |
196 set_globalState(StDMSPT); | |
197 else | |
198 set_globalState(StDMENU); | |
199 break; | |
200 | |
201 case StDMGAS: | |
202 if(stateUsed->warnings.betterSetpoint) | |
203 set_globalState(StDMSPT); | |
204 else | |
205 set_globalState(StDMENU); | |
206 break; | |
207 | |
208 case StDMSPT: | |
209 set_globalState(StDMENU); | |
210 break; | |
211 | |
212 case StDMENU: | |
213 if(is_stateUsedSetToSim()) | |
214 set_globalState(StDSIM1); | |
215 else | |
216 set_globalState(StD); | |
217 break; | |
218 | |
219 case StDSIM1: | |
220 set_globalState(StDSIM2); | |
221 break; | |
222 | |
223 case StDSIM2: | |
224 set_globalState(StDSIM3); | |
225 break; | |
226 | |
227 case StDSIM3: | |
228 set_globalState(StDSIM4); | |
229 break; | |
230 | |
231 case StDSIM4: | |
232 set_globalState(StD); | |
233 break; | |
234 | |
235 case StDBEAR: // t5_gauge | |
236 set_globalState(StDRAVG); | |
237 break; | |
238 | |
239 case StDRAVG: // t5_gauge | |
240 if(is_stateUsedSetToSim()) | |
241 set_globalState(StDSIM1); | |
242 else | |
243 set_globalState(StD); | |
244 break; | |
245 | |
246 case StDQUIT: // t6_apnea | |
247 set_globalState(StD); | |
248 break; | |
249 | |
250 default: | |
251 set_globalState(StD); | |
252 } | |
253 } | |
254 | |
255 if(sendAction == ACTION_BUTTON_ENTER) | |
256 { | |
257 if(settingsGetPointer()->design == 4) | |
258 return; | |
259 | |
260 if(settingsGetPointer()->design == 3) | |
261 settingsGetPointer()->design = 7; | |
262 | |
263 switch(get_globalState()) | |
264 { | |
265 case StDMGAS: | |
266 openEdit_DiveSelectBetterGas(); | |
267 set_globalState(StD); | |
268 break; | |
269 case StDMSPT: | |
270 openEdit_DiveSelectBetterSetpoint(); | |
271 set_globalState(StD); | |
272 break; | |
273 | |
274 case StDMENU: | |
275 openMenu_first_page_with_OC_gas_update(); | |
276 break; | |
277 | |
278 case StDSIM1: | |
279 Sim_Quit(); | |
280 break; | |
281 | |
282 case StDSIM2: | |
283 Sim_Ascend(); | |
284 break; | |
285 | |
286 case StDSIM3: | |
287 Sim_Descend(); | |
288 break; | |
289 | |
290 case StDSIM4: | |
291 Sim_Divetime(); | |
292 break; | |
293 | |
294 case StDBEAR: // t5_gauge | |
295 if(is_stateUsedSetToSim()) | |
296 stateSimGetPointerWrite()->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading; | |
297 else | |
298 stateRealGetPointerWrite()->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading; | |
299 set_globalState(StD); | |
300 break; | |
301 | |
302 case StDRAVG: // t5_gauge | |
303 timer_Stopwatch_Restart(); | |
304 set_globalState(StD); | |
305 break; | |
306 | |
307 case StDQUIT: // t6_apnea | |
308 set_globalState(StD); // used to end StDQUIT, is called before everything else because changes are made in the next lines | |
309 if(is_stateUsedSetToSim()) | |
310 Sim_Quit(); | |
311 else | |
312 dataOutGetPointer()->setEndDive = 1; | |
313 break; | |
314 | |
315 default: | |
316 break; | |
317 } | |
318 } | |
319 } | |
320 | |
321 | |
322 void tHome_findNextStop(const uint16_t *list, uint8_t *depthOutMeter, uint16_t *lengthOutSeconds) | |
323 { | |
324 uint8_t ptr = DECOINFO_STRUCT_MAX_STOPS - 1; | |
325 | |
326 while(ptr && !list[ptr]) | |
327 ptr--; | |
328 | |
329 *lengthOutSeconds = list[ptr]; | |
330 if(!(*lengthOutSeconds)) | |
331 { | |
332 *depthOutMeter = 0; | |
333 } | |
334 else | |
335 if(ptr == 0) | |
336 { | |
337 *depthOutMeter = (uint8_t)((stateUsed->diveSettings.last_stop_depth_bar*10.0f) + 0.1f); | |
338 } | |
339 else | |
340 { | |
341 ptr -= 1; | |
342 *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); | |
343 } | |
344 } | |
345 | |
346 | |
347 void tHome_change_field_button_pressed(void) | |
348 { | |
349 tHome_tick_count_field = 0; | |
350 if(settingsGetPointer()->design == 7) | |
351 t7_change_field(); | |
352 if(settingsGetPointer()->design == 9) | |
353 t9_change_field(); | |
354 } | |
355 | |
356 | |
357 void tHome_change_customview_button_pressed(void) | |
358 { | |
359 tHome_tick_count_cview = 0; | |
360 if(settingsGetPointer()->design == 7) | |
361 t7_change_customview(); | |
362 else | |
363 if(settingsGetPointer()->design == 9) | |
364 t9_change_customview(); | |
365 else | |
366 if(settingsGetPointer()->design == 3) | |
367 t3_change_customview(); | |
368 else | |
369 if(settingsGetPointer()->design == 5) | |
370 t5_change_customview(); | |
371 else | |
372 if(settingsGetPointer()->design == 6) | |
373 t6_change_customview(); | |
374 } | |
375 | |
376 | |
377 void tHome_tick(void) | |
378 { | |
379 uint16_t field = settingsGetPointer()->tX_userselectedLeftLowerCornerTimeout; | |
380 uint16_t cview = settingsGetPointer()->tX_customViewTimeout; | |
381 | |
382 if(field) | |
383 { | |
384 tHome_tick_count_field++; | |
385 if(tHome_tick_count_field > (field * 10)) | |
386 { | |
387 tHome_tick_count_field = 0; | |
388 if(settingsGetPointer()->design == 7) | |
389 { | |
390 t7_set_field_to_primary(); | |
391 } | |
392 } | |
393 } | |
394 | |
395 if(cview) | |
396 { | |
397 tHome_tick_count_cview++; | |
398 if(tHome_tick_count_cview > (cview *10)) | |
399 { | |
400 tHome_tick_count_cview = 0; | |
401 if(settingsGetPointer()->design == 7) | |
402 { | |
403 t7_set_customview_to_primary(); | |
404 } | |
405 } | |
406 } | |
407 } | |
408 | |
409 | |
410 uint32_t tHome_DateCode(RTC_DateTypeDef *dateInput) | |
411 { | |
412 uint32_t answer = 0; | |
413 | |
414 answer = 0; | |
415 answer += (dateInput->Year & 0x7F)<< 9; | |
416 answer += (dateInput->Month & 0x0F)<< 5; | |
417 answer += (dateInput->Date & 0x1F); | |
418 | |
419 return answer; | |
420 } | |
421 | |
422 | |
423 uint8_t tHome_gas_writer(uint8_t oxygen_percentage, uint8_t helium_percentage, char *text) | |
424 { | |
425 if(oxygen_percentage == 100) | |
426 return (uint8_t) snprintf(text,10,"Oxy"); | |
427 else if((oxygen_percentage == 21) && (!helium_percentage)) | |
428 return (uint8_t) snprintf(text,10,"Air"); | |
429 else if(!helium_percentage) | |
430 return (uint8_t) snprintf(text,10,"NX%02i",oxygen_percentage); | |
431 else if((oxygen_percentage + helium_percentage) == 100) | |
432 return (uint8_t) snprintf(text,10,"HX%02i",oxygen_percentage); | |
433 else | |
434 return (uint8_t) snprintf(text,10,"%02i/%02i",oxygen_percentage,helium_percentage); | |
435 } | |
436 | |
437 uint8_t tHome_show_lost_connection_count(GFX_DrawCfgScreen *ScreenToWriteOn) | |
438 { | |
82 | 439 // return 0; |
38 | 440 |
82 | 441 // if(!DataEX_lost_connection_count()) return 0; |
38 | 442 |
443 char text[10]; | |
82 | 444 // if(get_DataEX_Error_place()) last_place=get_DataEX_Error_place(); |
38 | 445 |
82 | 446 // if(get_DataEX_Error_Handler()) last_err=get_DataEX_Error_Handler(); |
447 SDataExchangeSlaveToMaster* dataIn=get_dataInPointer(); | |
448 | |
449 snprintf(text,10,"spi:\002%i",DataEX_lost_connection_count()); | |
450 Gfx_write_label_var(ScreenToWriteOn, 600,800, 0,&FontT24,CLUT_ButtonSymbols,text); | |
451 | |
452 snprintf(text,10,"\002%X%X%X%X",dataIn->header.checkCode[0],dataIn->header.checkCode[1],dataIn->header.checkCode[2],dataIn->header.checkCode[3]); | |
453 Gfx_write_label_var(ScreenToWriteOn, 600,800, 30,&FontT24,CLUT_ButtonSymbols,text); | |
454 | |
455 snprintf(text,10,"\002%X%X%X%X",dataIn->footer.checkCode[0],dataIn->footer.checkCode[1],dataIn->footer.checkCode[2],dataIn->footer.checkCode[3]); | |
456 Gfx_write_label_var(ScreenToWriteOn, 600,800, 60,&FontT24,CLUT_ButtonSymbols,text); | |
457 | |
84
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
458 snprintf(text,10,"cpt:\002%i",get_num_SPI_CALLBACKS()); |
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
459 Gfx_write_label_var(ScreenToWriteOn, 600,800, 90,&FontT24,CLUT_ButtonSymbols,text); |
82 | 460 |
461 // snprintf(text,10,"i2c:\002%i",get_DataEX_Error_place()); | |
462 // Gfx_write_label_var(ScreenToWriteOn, 600,800, 90,&FontT24,CLUT_ButtonSymbols,text); | |
38 | 463 |
464 return DataEX_lost_connection_count(); | |
465 } |