comparison Discovery/Src/tMenuEditHardware.c @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children be35821a4974 cc8e24374b83
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 ///////////////////////////////////////////////////////////////////////////////
2 /// -*- coding: UTF-8 -*-
3 ///
4 /// \file Discovery/Src/tMenuEditHardware.c
5 /// \brief BUTTONS
6 /// \author heinrichs weikamp gmbh
7 /// \date 15-Sept-2016
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 "tMenuEditHardware.h"
31
32 //#include "bonex4.h"
33 #include "externCPU2bootloader.h"
34 #include "gfx_fonts.h"
35 #include "ostc.h"
36 #include "tCCR.h"
37 #include "tMenuEdit.h"
38
39 /* Private function prototypes -----------------------------------------------*/
40 void openEdit_Bluetooth(void);
41 void openEdit_Compass(void);
42 void openEdit_O2Sensors(void);
43 void openEdit_Brightness(void);
44 //void openEdit_Luftintegration(void);
45 void openEdit_ButtonSens(void);
46 void openEdit_ScooterControl(void);
47
48 /* Announced function prototypes -----------------------------------------------*/
49 uint8_t OnAction_Compass (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
50 uint8_t OnAction_Bearing (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
51 uint8_t OnAction_BearingClear (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
52 //uint8_t OnAction_ExitHardw (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
53 uint8_t OnAction_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
54 uint8_t OnAction_Sensor2 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
55 uint8_t OnAction_Sensor3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
56 uint8_t OnAction_O2_Fallback (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
57 uint8_t OnAction_Button (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
58 uint8_t OnAction_ButtonBalance (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
59 uint8_t OnAction_ScooterDrag (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
60 uint8_t OnAction_ScooterLoad (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
61 uint8_t OnAction_ScooterBatt (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
62 // nicht notwending uint8_t OnAction_Bluetooth (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
63 // nicht notwending uint8_t OnAction_ScooterControl (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
64
65 /* Exported functions --------------------------------------------------------*/
66
67 void openEdit_Hardware(uint8_t line)
68 {
69 set_globalState_Menu_Line(line);
70 resetMenuEdit(CLUT_MenuPageHardware);
71
72 switch(line)
73 {
74 case 1:
75 default:
76 openEdit_Bluetooth();
77 break;
78 case 2:
79 openEdit_Compass();
80 break;
81 case 3:
82 openEdit_O2Sensors();
83 break;
84 case 4:
85 openEdit_Brightness();
86 break;
87 case 5:
88 openEdit_ButtonSens();
89 break;
90 case 6:
91 openEdit_ScooterControl();
92 break;
93 }
94 }
95
96 /* Private functions ---------------------------------------------------------*/
97 void openEdit_Bluetooth(void)
98 {
99 /* does not work like this resetEnterPressedToStateBeforeButtonAction(); */
100
101 SSettings *pSettings = settingsGetPointer();
102
103 if(pSettings->bluetoothActive == 0)
104 {
105 pSettings->bluetoothActive = 1;
106 MX_Bluetooth_PowerOn();
107 }
108 else
109 {
110 pSettings->bluetoothActive = 0;
111 MX_Bluetooth_PowerOff();
112 }
113 exitMenuEdit_to_Menu_with_Menu_Update_do_not_write_settings_for_this_only();
114 }
115
116 /*
117 void refresh_ScooterControl(void)
118 {
119 char text[256];
120
121 text[0] = '\001';
122 text[1] = TXT_2BYTE;
123 text[2] = TXT2BYTE_ScooterSetup;
124 text[3] = 0;
125 write_topline(text);
126
127 // drag
128 text[0] = TXT_2BYTE;
129 text[1] = TXT2BYTE_ScooterDrag;
130 text[2] = 0;
131 write_label_var( 30, 180, ME_Y_LINE1, &FontT48, text);
132 // load
133 text[0] = TXT_2BYTE;
134 text[1] = TXT2BYTE_ScooterLoad;
135 text[2] = 0;
136 write_label_var( 30, 180, ME_Y_LINE2, &FontT48, text);
137 // batt type
138 text[0] = TXT_2BYTE;
139 text[1] = TXT2BYTE_ScooterBattTyp;
140 text[2] = 0;
141 write_label_var( 30, 180, ME_Y_LINE3, &FontT48, text);
142
143 // drag
144 text[0] = TXT_2BYTE;
145 text[1] = 0;
146 text[2] = 0;
147 switch(settingsGetPointer()->scooterDrag)
148 {
149 case 0:
150 text[1] = TXT2BYTE_ScooterD0Apnoe;
151 break;
152 case 1:
153 text[1] = TXT2BYTE_ScooterD1Scuba;
154 break;
155 case 2:
156 text[1] = TXT2BYTE_ScooterD2Tech;
157 break;
158 case 3:
159 text[1] = TXT2BYTE_ScooterD3Heavy;
160 break;
161 default:
162 snprintf(&text[4],3,"%02u",settingsGetPointer()->scooterDrag);
163 break;
164 }
165 write_label_var( 200, 700, ME_Y_LINE1, &FontT48, text);
166
167 // load
168 text[0] = TXT_2BYTE;
169 text[1] = 0;
170 text[2] = 0;
171 switch(settingsGetPointer()->scooterLoad)
172 {
173 case 0:
174 text[1] = TXT2BYTE_ScooterL0None;
175 break;
176 case 1:
177 text[1] = TXT2BYTE_ScooterL1Small;
178 break;
179 case 2:
180 text[1] = TXT2BYTE_ScooterL2Stages;
181 break;
182 case 3:
183 text[1] = TXT2BYTE_ScooterL3Full;
184 break;
185 case 4:
186 text[1] = TXT2BYTE_ScooterL4Towing;
187 break;
188 default:
189 snprintf(&text[4],3,"%02u",settingsGetPointer()->scooterLoad);
190 break;
191 }
192 write_label_var( 200, 700, ME_Y_LINE2, &FontT48, text);
193
194 //batt type
195
196 // txtptr = 0;
197 // txtptr += bo4GetBatteryName(text,settingsGetPointer()->scooterBattType);
198 // txtptr += snprintf(&text[txtptr],10," (%0.1f V)",bo4GetBatteryVoltage(settingsGetPointer()->scooterBattType));
199 // write_label_var( 200, 700, ME_Y_LINE3, &FontT48, text);
200 }
201 */
202
203 void getButtonText_ScooterControl(char *text, uint8_t * pointer)
204 {
205
206 if((pointer != &settingsGetPointer()->scooterLoad) && (pointer != &settingsGetPointer()->scooterDrag))
207 return;
208
209 text[0] = TXT_2BYTE;
210 text[1] = 0;
211 text[2] = 0;
212
213 // drag
214 if(pointer == &settingsGetPointer()->scooterDrag)
215 {
216 switch(settingsGetPointer()->scooterDrag)
217 {
218 case 0:
219 text[1] = TXT2BYTE_ScooterD0Apnoe;
220 break;
221 case 1:
222 text[1] = TXT2BYTE_ScooterD1Scuba;
223 break;
224 case 2:
225 text[1] = TXT2BYTE_ScooterD2Tech;
226 break;
227 case 3:
228 text[1] = TXT2BYTE_ScooterD3Heavy;
229 break;
230 default:
231 snprintf(&text[4],3,"%02u",settingsGetPointer()->scooterDrag);
232 break;
233 }
234 }
235 else // load
236 if(pointer == &settingsGetPointer()->scooterLoad)
237 {
238
239 switch(settingsGetPointer()->scooterLoad)
240 {
241 case 0:
242 text[1] = TXT2BYTE_ScooterL0None;
243 break;
244 case 1:
245 text[1] = TXT2BYTE_ScooterL1Small;
246 break;
247 case 2:
248 text[1] = TXT2BYTE_ScooterL2Stages;
249 break;
250 case 3:
251 text[1] = TXT2BYTE_ScooterL3Full;
252 break;
253 case 4:
254 text[1] = TXT2BYTE_ScooterL4Towing;
255 break;
256 default:
257 snprintf(&text[4],3,"%02u",settingsGetPointer()->scooterLoad);
258 break;
259 }
260 }
261 }
262
263
264 void openEdit_ScooterControl(void)
265 {
266 char text[256];
267 uint16_t battWh;
268
269 text[0] = '\001';
270 text[1] = TXT_2BYTE;
271 text[2] = TXT2BYTE_ScooterSetup;
272 text[3] = 0;
273 write_topline(text);
274
275 // drag
276 text[0] = TXT_2BYTE;
277 text[1] = TXT2BYTE_ScooterDrag;
278 text[2] = 0;
279 write_label_var( 30, 180, ME_Y_LINE1, &FontT48, text);
280 // load
281 text[0] = TXT_2BYTE;
282 text[1] = TXT2BYTE_ScooterLoad;
283 text[2] = 0;
284 write_label_var( 30, 180, ME_Y_LINE2, &FontT48, text);
285 // batt type
286 text[0] = TXT_2BYTE;
287 text[1] = TXT2BYTE_ScooterBattTyp;
288 text[2] = 0;
289 write_label_var( 30, 180, ME_Y_LINE3, &FontT48, text);
290
291 getButtonText_ScooterControl(text,&settingsGetPointer()->scooterDrag);
292 write_field_button(StMHARD6_ScooterDrag, 200, 770, ME_Y_LINE1, &FontT48, text);
293
294 getButtonText_ScooterControl(text,&settingsGetPointer()->scooterLoad);
295 write_field_button(StMHARD6_ScooterLoad, 200, 770, ME_Y_LINE2, &FontT48, text);
296
297 battWh = settingsGetPointer()->scooterBattSize;
298 write_field_udigit(StMHARD6_ScooterBatt, 200, 770, ME_Y_LINE3, &FontT48, "####\016\016 Wh\017", battWh, 0, 0, 0);
299
300 setEvent(StMHARD6_ScooterDrag, (uint32_t)OnAction_ScooterDrag);
301 setEvent(StMHARD6_ScooterLoad, (uint32_t)OnAction_ScooterLoad);
302 setEvent(StMHARD6_ScooterBatt, (uint32_t)OnAction_ScooterBatt);
303
304 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
305 }
306
307
308 uint8_t OnAction_ScooterDrag(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
309 {
310 char text[256];
311
312 settingsGetPointer()->scooterDrag = settingsGetPointer()->scooterDrag + 1;
313 if(settingsGetPointer()->scooterDrag > 3)
314 settingsGetPointer()->scooterDrag = 0;
315
316 getButtonText_ScooterControl(text,&settingsGetPointer()->scooterDrag);
317 tMenuEdit_newButtonText(editId, text);
318
319 return UPDATE_DIVESETTINGS;
320 }
321
322
323 uint8_t OnAction_ScooterLoad(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
324 {
325 char text[256];
326
327 settingsGetPointer()->scooterLoad = settingsGetPointer()->scooterLoad + 1;
328 if(settingsGetPointer()->scooterLoad > 4)
329 settingsGetPointer()->scooterLoad = 0;
330
331 getButtonText_ScooterControl(text,&settingsGetPointer()->scooterLoad);
332 tMenuEdit_newButtonText(editId, text);
333
334 return UPDATE_DIVESETTINGS;
335 }
336
337
338 uint8_t OnAction_ScooterBatt(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
339 {
340 uint8_t digitContentNew;
341 uint32_t newWh;
342
343 if(action == ACTION_BUTTON_ENTER)
344 {
345 return digitContent;
346 }
347 if(action == ACTION_BUTTON_ENTER_FINAL)
348 {
349 evaluateNewString(editId, &newWh, 0, 0, 0);
350
351 if(newWh < 300)
352 newWh = 300;
353 if(newWh > 5000)
354 newWh = 5000;
355
356 tMenuEdit_newInput(editId, newWh, 0, 0, 0);
357 settingsGetPointer()->scooterBattSize = newWh;
358 return UPDATE_DIVESETTINGS;
359 }
360 if(action == ACTION_BUTTON_NEXT)
361 {
362 digitContentNew = digitContent + 1;
363 if(digitNumber == 0)
364 {
365 if(digitContentNew > '5')
366 digitContentNew = '0';
367 }
368 else if(digitContentNew > '9')
369 digitContentNew = '0';
370 return digitContentNew;
371 }
372 if(action == ACTION_BUTTON_BACK)
373 {
374 digitContentNew = digitContent - 1;
375 if(digitNumber == 0)
376 {
377 if(digitContentNew < '0')
378 digitContentNew = '5';
379 }
380 else if(digitContentNew < '0')
381 digitContentNew = '9';
382 return digitContentNew;
383 }
384 return UNSPECIFIC_RETURN;
385 }
386
387
388 void refresh_CompassEdit(void)
389 {
390 uint16_t heading;
391 char text[32];
392
393 text[0] = '\001';
394 text[1] = TXT_2BYTE;
395 text[2] = TXT2BYTE_Compass;
396 text[3] = 0;
397 write_topline(text);
398
399 heading = (uint16_t)stateUsed->lifeData.compass_heading;
400 snprintf(text,32,"\001%03i`",heading);
401 write_label_var( 0, 800, ME_Y_LINE1, &FontT54, text);
402
403 tMenuEdit_refresh_field(StMHARD2_Compass_SetCourse);
404 tMenuEdit_refresh_field(StMHARD2_Compass_Calibrate);
405 tMenuEdit_refresh_field(StMHARD2_Compass_ResetCourse);
406
407 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
408 }
409
410
411 void openEdit_Compass(void)
412 {
413 char text[4];
414
415 text[0] = '\001';
416 text[1] = TXT_2BYTE;
417 text[2] = TXT2BYTE_Compass;
418 text[3] = 0;
419 write_topline(text);
420
421 text[0] = TXT_2BYTE;
422 text[2] = 0;
423
424 text[1] = TXT2BYTE_SetBearing;
425 write_field_button(StMHARD2_Compass_SetCourse, 30, 800, ME_Y_LINE2, &FontT48, text);
426
427 text[1] = TXT2BYTE_CompassCalib;
428 write_field_button(StMHARD2_Compass_Calibrate, 30, 800, ME_Y_LINE3, &FontT48, text);
429
430 text[1] = TXT2BYTE_ResetBearing;
431 write_field_button(StMHARD2_Compass_ResetCourse, 30, 800, ME_Y_LINE4, &FontT48, text);
432
433 setEvent(StMHARD2_Compass_SetCourse, (uint32_t)OnAction_Bearing);
434 setEvent(StMHARD2_Compass_Calibrate, (uint32_t)OnAction_Compass);
435 setEvent(StMHARD2_Compass_ResetCourse, (uint32_t)OnAction_BearingClear);
436
437 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
438 }
439
440
441 uint8_t OnAction_Compass (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
442 {
443 calibrateCompass();
444 return EXIT_TO_INFO_COMPASS;
445 }
446
447
448 uint8_t OnAction_Bearing (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
449 {
450 settingsGetPointer()->compassBearing = (int16_t)stateUsed->lifeData.compass_heading;
451 if(settingsGetPointer()->compassBearing == 0)
452 settingsGetPointer()->compassBearing = 360;
453 return UPDATE_AND_EXIT_TO_MENU;
454 }
455
456
457 uint8_t OnAction_BearingClear (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
458 {
459 settingsGetPointer()->compassBearing = 0;
460 return UPDATE_AND_EXIT_TO_MENU;
461 }
462
463 /*
464 uint8_t OnAction_ExitHardw (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
465 {
466 return EXIT_TO_MENU;
467 }
468 */
469
470 void refresh_O2Sensors(void)
471 {
472 char text[10];
473 uint16_t y_line;
474
475 text[0] = '\001';
476 text[1] = TXT_o2Sensors;
477 text[2] = 0;
478 write_topline(text);
479
480
481 text[0] = TXT_2BYTE;
482 text[1] = TXT2BYTE_Sensor;
483 text[2] = ' ';
484 text[3] = '1';
485 text[4] = 0;
486 write_label_var( 96, 340, ME_Y_LINE1, &FontT48, text);
487 text[3] = '2';
488 write_label_var( 96, 340, ME_Y_LINE2, &FontT48, text);
489 text[3] = '3';
490 write_label_var( 96, 340, ME_Y_LINE3, &FontT48, text);
491
492 text[0] = TXT_2BYTE;
493 text[1] = TXT2BYTE_HUDbattery;
494 text[2] = 0;
495 write_label_var( 30, 340, ME_Y_LINE4, &FontT48, text);
496 // write_label_var( 30, 340, ME_Y_LINE4, &FontT48, "HUD Battery");
497
498 for(int i=0;i<3;i++)
499 {
500 snprintf(text, 20,"%01.2f, %01.1fmV",get_ppO2Sensor_bar(i),get_sensorVoltage_mV(i));
501 y_line = ME_Y_LINE1 + (i * ME_Y_LINE_STEP);
502 write_label_var( 400, 800, y_line, &FontT48, text);
503 }
504
505 snprintf(text, 20,"%01.3fV", get_HUD_battery_voltage_V());
506 write_label_var( 400, 800, ME_Y_LINE4, &FontT48, text);
507
508 tMenuEdit_refresh_field(StMHARD3_O2_Sensor1);
509 tMenuEdit_refresh_field(StMHARD3_O2_Sensor2);
510 tMenuEdit_refresh_field(StMHARD3_O2_Sensor3);
511 tMenuEdit_refresh_field(StMHARD3_O2_Fallback);
512
513 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
514 }
515
516
517 void openEdit_O2Sensors(void)
518 {
519 char text[2];
520 uint8_t sensorActive[3];
521
522 sensorActive[0] = 1;
523 sensorActive[1] = 1;
524 sensorActive[2] = 1;
525 if(settingsGetPointer()->ppo2sensors_deactivated & 1)
526 sensorActive[0] = 0;
527 if(settingsGetPointer()->ppo2sensors_deactivated & 2)
528 sensorActive[1] = 0;
529 if(settingsGetPointer()->ppo2sensors_deactivated & 4)
530 sensorActive[2] = 0;
531
532 write_field_on_off(StMHARD3_O2_Sensor1, 30, 95, ME_Y_LINE1, &FontT48, "", sensorActive[0]);
533 write_field_on_off(StMHARD3_O2_Sensor2, 30, 95, ME_Y_LINE2, &FontT48, "", sensorActive[1]);
534 write_field_on_off(StMHARD3_O2_Sensor3, 30, 95, ME_Y_LINE3, &FontT48, "", sensorActive[2]);
535
536 text[0] = TXT_Fallback;
537 text[1] = 1;
538 write_field_on_off(StMHARD3_O2_Fallback, 30, 500, ME_Y_LINE5, &FontT48, text, settingsGetPointer()->fallbackToFixedSetpoint);
539
540 setEvent(StMHARD3_O2_Sensor1, (uint32_t)OnAction_Sensor1);
541 setEvent(StMHARD3_O2_Sensor2, (uint32_t)OnAction_Sensor2);
542 setEvent(StMHARD3_O2_Sensor3, (uint32_t)OnAction_Sensor3);
543 setEvent(StMHARD3_O2_Fallback, (uint32_t)OnAction_O2_Fallback);
544
545 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
546 }
547
548
549 uint8_t OnAction_Sensor1(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
550 {
551 if(settingsGetPointer()->ppo2sensors_deactivated & 1)
552 {
553 settingsGetPointer()->ppo2sensors_deactivated &= 4+2;
554 tMenuEdit_set_on_off(editId, 1);
555 }
556 else
557 {
558 settingsGetPointer()->ppo2sensors_deactivated |= 1;
559 tMenuEdit_set_on_off(editId, 0);
560 }
561
562 return UPDATE_DIVESETTINGS;
563 }
564
565
566 uint8_t OnAction_Sensor2(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
567 {
568 if(settingsGetPointer()->ppo2sensors_deactivated & 2)
569 {
570 settingsGetPointer()->ppo2sensors_deactivated &= 4+1;
571 tMenuEdit_set_on_off(editId, 1);
572 }
573 else
574 {
575 settingsGetPointer()->ppo2sensors_deactivated |= 2;
576 tMenuEdit_set_on_off(editId, 0);
577 }
578
579 return UPDATE_DIVESETTINGS;
580 }
581
582
583 uint8_t OnAction_Sensor3(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
584 {
585 if(settingsGetPointer()->ppo2sensors_deactivated & 4)
586 {
587 settingsGetPointer()->ppo2sensors_deactivated &= 2+1;
588 tMenuEdit_set_on_off(editId, 1);
589 }
590 else
591 {
592 settingsGetPointer()->ppo2sensors_deactivated |= 4;
593 tMenuEdit_set_on_off(editId, 0);
594 }
595
596 return UPDATE_DIVESETTINGS;
597 }
598
599
600 uint8_t OnAction_O2_Fallback (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
601 {
602 uint8_t fallback = settingsGetPointer()->fallbackToFixedSetpoint;
603
604 if(fallback)
605 fallback = 0;
606 else
607 fallback = 1;
608
609 settingsGetPointer()->fallbackToFixedSetpoint = fallback;
610 tMenuEdit_set_on_off(editId, fallback);
611 return UPDATE_DIVESETTINGS;
612 }
613
614
615 void openEdit_Brightness(void)
616 {
617 uint8_t actualBrightness;
618 SSettings *pSettings = settingsGetPointer();
619
620 actualBrightness = pSettings->brightness;
621 actualBrightness++;
622 if(actualBrightness > 4)
623 actualBrightness = 0;
624 pSettings->brightness = actualBrightness;
625 exitEditWithUpdate();
626 }
627
628
629 void buttonBalanceText_helper(uint8_t idOfButton, char *textOutput)
630 {
631 uint8_t txtcount = 0;
632
633 if(idOfButton < 3)
634 {
635 textOutput[txtcount++] = '@' + settingsGetPointer()->buttonBalance[idOfButton];
636 textOutput[txtcount++] = ' ';
637 textOutput[txtcount++] = ' ';
638 textOutput[txtcount++] = '(';
639
640 switch(settingsGetPointer()->buttonBalance[idOfButton])
641 {
642 case 1:
643 textOutput[txtcount++] = '-';
644 textOutput[txtcount++] = '2';
645 textOutput[txtcount++] = '0';
646 break;
647 case 2:
648 textOutput[txtcount++] = '-';
649 textOutput[txtcount++] = '1';
650 textOutput[txtcount++] = '0';
651 break;
652 case 3:
653 default:
654 textOutput[txtcount++] = '0';
655 break;
656 case 4:
657 textOutput[txtcount++] = '+';
658 textOutput[txtcount++] = '1';
659 textOutput[txtcount++] = '0';
660 break;
661 case 5:
662 textOutput[txtcount++] = '+';
663 textOutput[txtcount++] = '2';
664 textOutput[txtcount++] = '0';
665 break;
666 }
667 textOutput[txtcount++] = ')';
668 }
669 textOutput[txtcount++] = 0;
670 }
671
672 /**#
673 ******************************************************************************
674 * @brief BUTTONS
675 * @author heinrichs weikamp gmbh
676 * @version V 01
677 * @date 15-Sept-2016
678 ******************************************************************************
679 * Button 0 is right, Button 1 is middle, Button 2 is left !!!!
680 * 2 1 0 (base value 3)
681 * Button 3 is used to store the base value, all others are balanced around this one!
682 *
683 */
684
685 void openEdit_ButtonSens(void)
686 {
687 char text[32];
688 uint8_t sens;
689 const uint32_t eventListButtonBalance[3] = {StMHARD5_ButtonBalance1,StMHARD5_ButtonBalance2,StMHARD5_ButtonBalance3};
690
691 sens = (uint8_t)settingsGetPointer()->ButtonResponsiveness[3];
692 write_field_3digit(StMHARD5_Button1, 360, 780, ME_Y_LINE1, &FontT48, "###", sens, 0, 0, 0);
693
694 for(int i=2;i>=0;i--)
695 {
696 buttonBalanceText_helper(i,text);
697 write_field_button(eventListButtonBalance[i],360,500,ME_Y_LINE4-(i*ME_Y_LINE_STEP),&FontT48,text);
698 }
699
700
701 setEvent(StMHARD5_Button1, (uint32_t)OnAction_Button);
702
703 for(int i=2;i>=0;i--)
704 {
705 setEvent(eventListButtonBalance[i], (uint32_t)OnAction_ButtonBalance);
706 }
707
708 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
709 }
710
711
712 void refresh_ButtonValuesFromPIC(void)
713 {
714 uint8_t sens[3];
715 char text[64];
716
717 text[0] = '\001';
718 text[1] = TXT_2BYTE;
719 text[2] = TXT2BYTE_ButtonSensitivity;
720 text[3] = 0;
721 write_topline(text);
722
723 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
724
725 text[0] = '\020'; // '\021';
726 text[1] = TXT_2BYTE;
727 text[2] = TXT2BYTE_LowerIsLess;
728 text[3] = 0;
729 write_label_var( 20, 780, ME_Y_LINE5, &FontT42, text);
730
731 for(int i=0;i<3;i++)
732 {
733 text[0] = TXT_2BYTE;
734 text[1] = TXT2BYTE_ButtonLeft+i;
735 text[2] = 0;
736 write_label_var( 20, 300, ME_Y_LINE2+(i*ME_Y_LINE_STEP), &FontT48, text);
737 }
738
739 for(int i=0;i<3;i++)
740 {
741 sens[i] = settingsHelperButtonSens_translate_hwOS_values_to_percentage(stateRealGetPointer()->lifeData.buttonPICdata[i]);
742 }
743 snprintf(text,64,"(%03u %03u %03u)",sens[2],sens[1],sens[0]);
744 write_label_var( 20, 340, ME_Y_LINE6, &FontT42, text);
745
746 tMenuEdit_refresh_field(StMHARD5_Button1);
747 tMenuEdit_refresh_field(StMHARD5_ButtonBalance1);
748 tMenuEdit_refresh_field(StMHARD5_ButtonBalance2);
749 tMenuEdit_refresh_field(StMHARD5_ButtonBalance3);
750 }
751
752
753 uint8_t OnAction_Button(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
754 {
755 uint8_t digitContentNew, remainder;
756 uint32_t newSensitivityGlobal;
757
758 if(action == ACTION_BUTTON_NEXT)
759 {
760 digitContentNew = digitContent - '0';
761 if(digitContentNew >= 110)
762 {
763 digitContentNew = 70;
764 }
765 else
766 {
767 remainder = digitContentNew%5;
768 digitContentNew += 5 - remainder;
769 if(digitContentNew >= 110)
770 digitContentNew = 110;
771 }
772 return '0' + digitContentNew;
773 }
774
775 if(action == ACTION_BUTTON_BACK)
776 {
777 digitContentNew = digitContent - '0';
778 if(digitContentNew <= 70)
779 digitContentNew = 110;
780 else
781 {
782 remainder = digitContentNew%5;
783 if(remainder)
784 digitContentNew -= remainder;
785 else
786 digitContentNew -= 5;
787 }
788 return '0' + digitContentNew;
789 }
790
791 if(action == ACTION_BUTTON_ENTER_FINAL)
792 {
793 evaluateNewString(editId, &newSensitivityGlobal, 0, 0, 0);
794 settingsHelperButtonSens_keepPercentageValues(newSensitivityGlobal, settingsGetPointer()->ButtonResponsiveness);
795 setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness);
796 return UNSPECIFIC_RETURN;
797 }
798 return digitContent;
799 }
800
801
802 uint8_t OnAction_ButtonBalance(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
803 {
804 int8_t idBalance = -1;
805 uint8_t *ptrSetting;
806 char text[32];
807
808 const uint32_t eventListButtonBalance[3] = {StMHARD5_ButtonBalance1,StMHARD5_ButtonBalance2,StMHARD5_ButtonBalance3};
809
810 idBalance = -1;
811 for(int i=0;i<3;i++)
812 {
813 if(editId == eventListButtonBalance[i])
814 {
815 idBalance = i;
816 break;
817 }
818 }
819
820 if((idBalance >= 0) && (idBalance < 3))
821 {
822 ptrSetting = &settingsGetPointer()->buttonBalance[idBalance];
823
824 *ptrSetting += 1;
825
826 if(*ptrSetting > 5)
827 *ptrSetting = 2;
828
829 buttonBalanceText_helper(idBalance,text);
830 tMenuEdit_newButtonText(eventListButtonBalance[idBalance],text);
831 }
832
833 return UNSPECIFIC_RETURN;
834 }