Mercurial > public > ostc4
annotate Discovery/Src/tHome.c @ 417:54a480c43e97 v1.5.2.beta release
1.5.2 beta with RTE 2.02
author | heinrichsweikamp |
---|---|
date | Wed, 15 Jan 2020 13:41:01 +0100 |
parents | 39c147e47c1c |
children | b560e474e319 |
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}; |
38 | 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) | |
384
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
151 { |
38 | 152 settingsGetPointer()->design = 7; |
384
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
153 if(settingsGetPointer()->MotionDetection == MOTION_DETECT_SECTOR) |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
154 { |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
155 DefinePitchSectors(stateRealGetPointer()->lifeData.compass_pitch,CUSTOMER_DEFINED_VIEWS); |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
156 } |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
157 } |
38 | 158 switch(get_globalState()) |
159 { | |
160 case StD: | |
161 if(settingsGetPointer()->design == 6) | |
162 { | |
163 if(is_stateUsedSetToSim()) | |
164 set_globalState(StDSIM1); | |
165 else | |
166 set_globalState(StDQUIT); | |
167 break; | |
168 } | |
169 | |
170 if(settingsGetPointer()->design == 5) | |
171 { | |
172 if(t5_getCustomView() == CVIEW_Compass) | |
173 set_globalState(StDBEAR); | |
174 else | |
175 set_globalState(StDRAVG); | |
176 break; | |
177 } | |
178 | |
179 if(stateUsed->warnings.betterGas) | |
180 set_globalState(StDMGAS); | |
181 else | |
182 if(stateUsed->warnings.betterSetpoint) | |
183 set_globalState(StDMSPT); | |
184 else | |
185 set_globalState(StDMENU); | |
186 break; | |
187 | |
188 case StDMGAS: | |
189 if(stateUsed->warnings.betterSetpoint) | |
190 set_globalState(StDMSPT); | |
191 else | |
192 set_globalState(StDMENU); | |
193 break; | |
194 | |
195 case StDMSPT: | |
196 set_globalState(StDMENU); | |
197 break; | |
198 | |
199 case StDMENU: | |
200 if(is_stateUsedSetToSim()) | |
201 set_globalState(StDSIM1); | |
202 else | |
203 set_globalState(StD); | |
204 break; | |
205 | |
206 case StDSIM1: | |
207 set_globalState(StDSIM2); | |
208 break; | |
209 | |
210 case StDSIM2: | |
211 set_globalState(StDSIM3); | |
212 break; | |
213 | |
214 case StDSIM3: | |
215 set_globalState(StDSIM4); | |
216 break; | |
217 | |
218 case StDSIM4: | |
219 set_globalState(StD); | |
220 break; | |
221 | |
222 case StDBEAR: // t5_gauge | |
223 set_globalState(StDRAVG); | |
224 break; | |
225 | |
226 case StDRAVG: // t5_gauge | |
227 if(is_stateUsedSetToSim()) | |
228 set_globalState(StDSIM1); | |
229 else | |
230 set_globalState(StD); | |
231 break; | |
232 | |
233 case StDQUIT: // t6_apnea | |
234 set_globalState(StD); | |
235 break; | |
236 | |
237 default: | |
238 set_globalState(StD); | |
239 } | |
240 } | |
241 | |
242 if(sendAction == ACTION_BUTTON_ENTER) | |
243 { | |
244 if(settingsGetPointer()->design == 4) | |
245 return; | |
246 | |
384
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
247 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
|
248 { |
38 | 249 settingsGetPointer()->design = 7; |
384
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
250 if(settingsGetPointer()->MotionDetection == MOTION_DETECT_SECTOR) |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
251 { |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
252 DefinePitchSectors(stateRealGetPointer()->lifeData.compass_pitch,CUSTOMER_DEFINED_VIEWS); |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
253 } |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
379
diff
changeset
|
254 } |
38 | 255 |
256 switch(get_globalState()) | |
257 { | |
258 case StDMGAS: | |
259 openEdit_DiveSelectBetterGas(); | |
260 set_globalState(StD); | |
261 break; | |
262 case StDMSPT: | |
263 openEdit_DiveSelectBetterSetpoint(); | |
264 set_globalState(StD); | |
265 break; | |
266 | |
267 case StDMENU: | |
268 openMenu_first_page_with_OC_gas_update(); | |
269 break; | |
270 | |
271 case StDSIM1: | |
272 Sim_Quit(); | |
273 break; | |
274 | |
275 case StDSIM2: | |
276 Sim_Ascend(); | |
277 break; | |
278 | |
279 case StDSIM3: | |
280 Sim_Descend(); | |
281 break; | |
282 | |
283 case StDSIM4: | |
284 Sim_Divetime(); | |
285 break; | |
286 | |
287 case StDBEAR: // t5_gauge | |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
210
diff
changeset
|
288 stateUsedWrite->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading; |
38 | 289 set_globalState(StD); |
290 break; | |
291 | |
292 case StDRAVG: // t5_gauge | |
293 timer_Stopwatch_Restart(); | |
294 set_globalState(StD); | |
295 break; | |
296 | |
297 case StDQUIT: // t6_apnea | |
298 set_globalState(StD); // used to end StDQUIT, is called before everything else because changes are made in the next lines | |
299 if(is_stateUsedSetToSim()) | |
300 Sim_Quit(); | |
301 else | |
302 dataOutGetPointer()->setEndDive = 1; | |
303 break; | |
304 | |
305 default: | |
306 break; | |
307 } | |
308 } | |
309 } | |
310 | |
311 | |
312 void tHome_findNextStop(const uint16_t *list, uint8_t *depthOutMeter, uint16_t *lengthOutSeconds) | |
313 { | |
314 uint8_t ptr = DECOINFO_STRUCT_MAX_STOPS - 1; | |
315 | |
316 while(ptr && !list[ptr]) | |
317 ptr--; | |
318 | |
319 *lengthOutSeconds = list[ptr]; | |
320 if(!(*lengthOutSeconds)) | |
321 { | |
322 *depthOutMeter = 0; | |
323 } | |
324 else | |
325 if(ptr == 0) | |
326 { | |
327 *depthOutMeter = (uint8_t)((stateUsed->diveSettings.last_stop_depth_bar*10.0f) + 0.1f); | |
328 } | |
329 else | |
330 { | |
331 ptr -= 1; | |
332 *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); | |
333 } | |
334 } | |
335 | |
336 | |
337 void tHome_change_field_button_pressed(void) | |
338 { | |
339 tHome_tick_count_field = 0; | |
340 if(settingsGetPointer()->design == 7) | |
341 t7_change_field(); | |
342 } | |
343 | |
344 | |
361
b111fc4250e9
Pass action to customer vie update function.
Ideenmodellierer
parents:
289
diff
changeset
|
345 void tHome_change_customview_button_pressed(uint8_t action) |
38 | 346 { |
347 tHome_tick_count_cview = 0; | |
348 if(settingsGetPointer()->design == 7) | |
361
b111fc4250e9
Pass action to customer vie update function.
Ideenmodellierer
parents:
289
diff
changeset
|
349 t7_change_customview(action); |
38 | 350 else |
351 if(settingsGetPointer()->design == 3) | |
386
39c147e47c1c
Added key direction awarness to t3, t5 and t6 views:
ideenmodellierer
parents:
384
diff
changeset
|
352 t3_change_customview(action); |
38 | 353 else |
354 if(settingsGetPointer()->design == 5) | |
386
39c147e47c1c
Added key direction awarness to t3, t5 and t6 views:
ideenmodellierer
parents:
384
diff
changeset
|
355 t5_change_customview(action); |
38 | 356 else |
357 if(settingsGetPointer()->design == 6) | |
386
39c147e47c1c
Added key direction awarness to t3, t5 and t6 views:
ideenmodellierer
parents:
384
diff
changeset
|
358 t6_change_customview(action); |
38 | 359 } |
360 | |
361 | |
362 void tHome_tick(void) | |
363 { | |
364 uint16_t field = settingsGetPointer()->tX_userselectedLeftLowerCornerTimeout; | |
365 uint16_t cview = settingsGetPointer()->tX_customViewTimeout; | |
366 | |
367 if(field) | |
368 { | |
369 tHome_tick_count_field++; | |
370 if(tHome_tick_count_field > (field * 10)) | |
371 { | |
372 tHome_tick_count_field = 0; | |
373 if(settingsGetPointer()->design == 7) | |
374 { | |
375 t7_set_field_to_primary(); | |
376 } | |
377 } | |
378 } | |
379 | |
380 if(cview) | |
381 { | |
382 tHome_tick_count_cview++; | |
383 if(tHome_tick_count_cview > (cview *10)) | |
384 { | |
385 tHome_tick_count_cview = 0; | |
386 if(settingsGetPointer()->design == 7) | |
387 { | |
388 t7_set_customview_to_primary(); | |
389 } | |
390 } | |
391 } | |
392 } | |
393 | |
394 | |
395 uint32_t tHome_DateCode(RTC_DateTypeDef *dateInput) | |
396 { | |
397 uint32_t answer = 0; | |
398 | |
399 answer = 0; | |
400 answer += (dateInput->Year & 0x7F)<< 9; | |
401 answer += (dateInput->Month & 0x0F)<< 5; | |
402 answer += (dateInput->Date & 0x1F); | |
403 | |
404 return answer; | |
405 } | |
406 | |
407 | |
408 uint8_t tHome_gas_writer(uint8_t oxygen_percentage, uint8_t helium_percentage, char *text) | |
409 { | |
410 if(oxygen_percentage == 100) | |
411 return (uint8_t) snprintf(text,10,"Oxy"); | |
412 else if((oxygen_percentage == 21) && (!helium_percentage)) | |
413 return (uint8_t) snprintf(text,10,"Air"); | |
414 else if(!helium_percentage) | |
415 return (uint8_t) snprintf(text,10,"NX%02i",oxygen_percentage); | |
416 else if((oxygen_percentage + helium_percentage) == 100) | |
417 return (uint8_t) snprintf(text,10,"HX%02i",oxygen_percentage); | |
418 else | |
419 return (uint8_t) snprintf(text,10,"%02i/%02i",oxygen_percentage,helium_percentage); | |
420 } | |
421 | |
422 uint8_t tHome_show_lost_connection_count(GFX_DrawCfgScreen *ScreenToWriteOn) | |
423 { | |
208 | 424 static uint8_t LastKnowRTEState = SPI_RX_STATE_INVALID; |
425 | |
99 | 426 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
|
427 if(DataEX_lost_connection_count()>=SPI_MIN_ERROR_SHOW && SPI_SHOW_SYNC_STATS){ |
38 | 428 |
99 | 429 char text[64]; |
38 | 430 |
82 | 431 SDataExchangeSlaveToMaster* dataIn=get_dataInPointer(); |
208 | 432 SDataReceiveFromMaster* pDataOut = dataOutGetPointer(); |
82 | 433 |
99 | 434 snprintf(text,32,"spi err:\002 %i/%i",DataEX_lost_connection_count(),get_num_SPI_CALLBACKS()); |
435 Gfx_write_label_var(ScreenToWriteOn, 100,300, 0,&FontT24,CLUT_ButtonSymbols,text); | |
82 | 436 |
104 | 437 // 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]); |
438 // Gfx_write_label_var(ScreenToWriteOn, 350,550, 0,&FontT24,CLUT_ButtonSymbols,text); | |
82 | 439 |
208 | 440 //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]); |
441 | |
442 /* data shifted => ignore received data */ | |
443 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)) | |
444 { | |
445 dataIn->header.checkCode[SPI_HEADER_INDEX_RX_STATE] = LastKnowRTEState; | |
446 } | |
447 else | |
448 { | |
449 LastKnowRTEState =dataIn->header.checkCode[SPI_HEADER_INDEX_RX_STATE]; | |
450 } | |
451 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 | 452 Gfx_write_label_var(ScreenToWriteOn, 600,800, 0,&FontT24,CLUT_ButtonSymbols,text); |
453 } | |
82 | 454 |
99 | 455 |
456 | |
457 // snprintf(text,32,"cpt:\002%i",get_num_SPI_CALLBACKS()); | |
458 // Gfx_write_label_var(ScreenToWriteOn, 600,800, 90,&FontT24,CLUT_ButtonSymbols,text); | |
82 | 459 |
460 // snprintf(text,10,"i2c:\002%i",get_DataEX_Error_place()); | |
461 // Gfx_write_label_var(ScreenToWriteOn, 600,800, 90,&FontT24,CLUT_ButtonSymbols,text); | |
38 | 462 |
463 return DataEX_lost_connection_count(); | |
464 } |