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

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children bf43851a678b
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 ///////////////////////////////////////////////////////////////////////////////
2 /// -*- coding: UTF-8 -*-
3 ///
4 /// \file Discovery/Src/settings.c
5 /// \brief settingsHelperButtonSens_translate_hwOS_values_to_percentage.
6 /// \author Heinrichs Weikamp gmbh
7 /// \date 6-March-2017
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 #include <string.h>
30 #include "settings.h"
31 #include "firmwareEraseProgram.h" // for HARDWAREDATA_ADDRESS
32 #include "externLogbookFlash.h" // for SAMPLESTART and SAMPLESTOP
33 #include "text_multilanguage.h" // for LANGUAGE_END
34 #include "tHome.h" // for CVIEW_END
35
36 SSettings Settings;
37
38 const uint8_t RTErequiredHigh = 1;
39 const uint8_t RTErequiredLow = 1;
40
41 const uint8_t FONTrequiredHigh = 0;
42 const uint8_t FONTrequiredLow = 9;
43
44 uint8_t RTEactualHigh = 0;
45 uint8_t RTEactualLow = 0;
46
47 // ===============================================================================
48 // SFirmwareData FirmwareData
49 /// @brief internal counter is for changes after last release
50 /// use date and info as well for this purpose
51 ///
52 // ===============================================================================
53
54 const SFirmwareData firmware_FirmwareData __attribute__( (section(".firmware_firmware_data")) ) =
55 {
56 .versionFirst = 1,
57 .versionSecond = 3,
58 .versionThird = 2,
59 .versionBeta = 1,
60
61 /* 4 bytes with trailing 0 */
62 .signature = "cw",
63
64 .release_year = 17,
65 .release_month = 7,
66 .release_day = 4,
67 .release_sub = 0,
68
69 /* max 48 with trailing 0 */
70 //release_info ="12345678901234567890123456789012345678901"
71 .release_info ="going on",
72
73 /* for safety reasons and coming functions */
74 .magic[0] = FIRMWARE_MAGIC_FIRST,
75 .magic[1] = FIRMWARE_MAGIC_SECOND,
76 .magic[2] = FIRMWARE_MAGIC_FIRMWARE, /* the magic byte */
77 .magic[3] = FIRMWARE_MAGIC_END
78 };
79
80
81 /* always adjust check_and_correct_settings() accordingly
82 * There might even be entries with fixed values that have no range
83 */
84 const SSettings SettingsStandard = {
85 .header = 0xFFFF0017,
86 .warning_blink_dsec = 8 * 2,
87 .lastDiveLogId = 0,
88 .logFlashNextSampleStartAddress = 0,
89
90 .gas[0].oxygen_percentage = 21,
91 .gas[1].oxygen_percentage = 21,
92 .gas[2].oxygen_percentage = 21,
93 .gas[3].oxygen_percentage = 21,
94 .gas[4].oxygen_percentage = 21,
95 .gas[5].oxygen_percentage = 21,
96 .gas[6].oxygen_percentage = 21,
97 .gas[7].oxygen_percentage = 21,
98 .gas[8].oxygen_percentage = 21,
99 .gas[9].oxygen_percentage = 21,
100 .gas[10].oxygen_percentage = 21,
101 .gas[0].helium_percentage = 0,
102 .gas[1].helium_percentage = 0,
103 .gas[2].helium_percentage = 0,
104 .gas[3].helium_percentage = 0,
105 .gas[4].helium_percentage = 0,
106 .gas[5].helium_percentage = 0,
107 .gas[6].helium_percentage = 0,
108 .gas[7].helium_percentage = 0,
109 .gas[8].helium_percentage = 0,
110 .gas[9].helium_percentage = 0,
111 .gas[10].helium_percentage = 0,
112 .gas[0].depth_meter = 0,
113 .gas[1].depth_meter = 0,
114 .gas[2].depth_meter = 0,
115 .gas[3].depth_meter = 0,
116 .gas[4].depth_meter = 0,
117 .gas[5].depth_meter = 0,
118 .gas[6].depth_meter = 0,
119 .gas[7].depth_meter = 0,
120 .gas[8].depth_meter = 0,
121 .gas[9].depth_meter = 0,
122 .gas[10].depth_meter = 0,
123 .gas[0].depth_meter_travel = 0,
124 .gas[1].depth_meter_travel = 0,
125 .gas[2].depth_meter_travel = 0,
126 .gas[3].depth_meter_travel = 0,
127 .gas[4].depth_meter_travel = 0,
128 .gas[5].depth_meter_travel = 0,
129 .gas[6].depth_meter_travel = 0,
130 .gas[7].depth_meter_travel = 0,
131 .gas[8].depth_meter_travel = 0,
132 .gas[9].depth_meter_travel = 0,
133 .gas[10].depth_meter_travel = 0,
134 .gas[0].note.uw = 0,
135 .gas[1].note.ub.first = 1,
136 .gas[1].note.ub.active = 1,
137 .gas[1].note.ub.deco = 0,
138 .gas[1].note.ub.travel = 0,
139 .gas[2].note.uw = 0,
140 .gas[3].note.uw = 0,
141 .gas[4].note.uw = 0,
142 .gas[5].note.uw = 0,
143 .gas[6].note.ub.first = 1,
144 .gas[6].note.ub.active = 1,
145 .gas[6].note.ub.deco = 0,
146 .gas[6].note.ub.travel = 0,
147 .gas[7].note.uw = 0,
148 .gas[8].note.uw = 0,
149 .gas[9].note.uw = 0,
150 .gas[10].note.uw = 0,
151 .gas[0].bottle_size_liter = 0,
152 .gas[1].bottle_size_liter = 0,
153 .gas[2].bottle_size_liter = 0,
154 .gas[3].bottle_size_liter = 0,
155 .gas[4].bottle_size_liter = 0,
156 .gas[5].bottle_size_liter = 0,
157 .gas[6].bottle_size_liter = 0,
158 .gas[7].bottle_size_liter = 0,
159 .gas[8].bottle_size_liter = 0,
160 .gas[9].bottle_size_liter = 0,
161 .gas[10].bottle_size_liter = 0,
162 /*
163 .gas[0].bottle_wireless_status = 0,
164 .gas[1].bottle_wireless_status = 0,
165 .gas[2].bottle_wireless_status = 0,
166 .gas[3].bottle_wireless_status = 0,
167 .gas[4].bottle_wireless_status = 0,
168 .gas[5].bottle_wireless_status = 0,
169 .gas[6].bottle_wireless_status = 0,
170 .gas[7].bottle_wireless_status = 0,
171 .gas[8].bottle_wireless_status = 0,
172 .gas[9].bottle_wireless_status = 0,
173 .gas[10].bottle_wireless_status = 0,
174 */
175 .gas[0].bottle_wireless_id = 0,
176 .gas[1].bottle_wireless_id = 0,
177 .gas[2].bottle_wireless_id = 0,
178 .gas[3].bottle_wireless_id = 0,
179 .gas[4].bottle_wireless_id = 0,
180 .gas[5].bottle_wireless_id = 0,
181 .gas[6].bottle_wireless_id = 0,
182 .gas[7].bottle_wireless_id = 0,
183 .gas[8].bottle_wireless_id = 0,
184 .gas[9].bottle_wireless_id = 0,
185 .gas[10].bottle_wireless_id = 0,
186 .setpoint[0].setpoint_cbar = 100,
187 .setpoint[1].setpoint_cbar = 70,
188 .setpoint[2].setpoint_cbar = 90,
189 .setpoint[3].setpoint_cbar = 100,
190 .setpoint[4].setpoint_cbar = 120,
191 .setpoint[5].setpoint_cbar = 140,
192 .setpoint[0].depth_meter = 0,
193 .setpoint[1].depth_meter = 0,
194 .setpoint[2].depth_meter = 0,
195 .setpoint[3].depth_meter = 0,
196 .setpoint[4].depth_meter = 0,
197 .setpoint[5].depth_meter = 0,
198 .setpoint[0].note.uw = 0,
199 .setpoint[1].note.ub.active = 1,
200 .setpoint[1].note.ub.first = 1,
201 .setpoint[2].note.ub.active = 1,
202 .setpoint[2].note.ub.first = 0,
203 .setpoint[3].note.ub.active = 1,
204 .setpoint[3].note.ub.first = 0,
205 .setpoint[4].note.ub.active = 1,
206 .setpoint[4].note.ub.first = 0,
207 .setpoint[5].note.ub.active = 1,
208 .setpoint[5].note.ub.first = 0,
209
210 .CCR_Mode = CCRMODE_Sensors,
211 .dive_mode = DIVEMODE_OC,
212 .deco_type.ub.standard = GF_MODE,
213 .deco_type.ub.alternative = GF_MODE,
214 .ppO2_max_deco = 160,
215 .ppO2_max_std = 140,
216 .ppO2_min = 15,
217 .CNS_max = 90,
218 .ascent_MeterPerMinute_max = 30,
219 .ascent_MeterPerMinute_showGraph = 7,
220 .future_TTS = 5,
221 .GF_high = 85,
222 .GF_low = 30,
223 .aGF_high = 95,
224 .aGF_low = 95,
225 .VPM_conservatism.ub.standard = 2,
226 .VPM_conservatism.ub.alternative = 0,
227 .safetystopDuration = 1,
228 .AtemMinutenVolumenLiter = 25,
229 .ReserveFractionDenominator = 4,
230 .salinity = 0,
231 .last_stop_depth_meter = 3,
232 .stop_increment_depth_meter = 3,
233 .brightness = 1,
234 .date_format = DDMMYY,
235 .selected_language = 0, /* 0 = LANGUAGE_English */
236 .customtext = " <your name>\n" " <address>",
237 .timeoutSurfacemode = 120,
238 .timeoutMenuSurface = 120,//240,
239 .timeoutMenuDive = 120,//20,
240 .timeoutMenuEdit = 120,//40,
241 .timeoutInfo = 120,//60,
242 .timeoutInfoCompass = 60,
243 .design = 7,
244 .timeoutDiveReachedZeroDepth = 300,
245 .divetimeToCreateLogbook = 60,
246 .serialHigh = 0,
247 .serialLow = 2,
248 /*
249 .firmwareVersion16to32bit.ub.first = 0,
250 .firmwareVersion16to32bit.ub.second = 6,
251 .firmwareVersion16to32bit.ub.third = 0,
252 .firmwareVersion16to32bit.ub.betaFlag = 0,
253 */
254 .backup_localtime_rtc_tr = 0,
255 .backup_localtime_rtc_dr = 0,
256 .totalDiveCounter = 0,
257 .personalDiveCount = 0,
258 .showDebugInfo = 0,
259 .ButtonResponsiveness[0] = 90, // new hw 170306
260 .ButtonResponsiveness[1] = 90, // new hw 170306
261 .ButtonResponsiveness[2] = 90, // new hw 170306
262 .ButtonResponsiveness[3] = 90, // new hw 170306
263 .nonMetricalSystem = 0,
264 .fallbackToFixedSetpoint = 1,
265 .bluetoothActive = 0,
266 .safetystopDepth = 5,
267 .updateSettingsAllowedFromHeader = 0xFFFF0002,
268 .scooterControl = 0,
269 .scooterDrag = 2,
270 .scooterLoad = 2,
271 .scooterNumberOfBatteries = 1,
272 .scooterBattSize = 760,
273 .scooterSPARE1[0] = 0,
274 .scooterSPARE2[0] = 0,
275 .ppo2sensors_deactivated = 0,
276 .tX_colorscheme = 0,
277 .tX_userselectedLeftLowerCornerPrimary = 1,
278 .tX_userselectedLeftLowerCornerTimeout = 0,
279 .tX_customViewPrimary = 1,
280 .tX_customViewTimeout = 0,
281 .timeoutEnterButtonSelectDive = 10,
282 .logbookOffset = 0,
283 .alwaysShowPPO2 = 0,
284 .extraDisplay = EXTRADISPLAY_BIGFONT,
285 .display_toogle_desc = 200,
286 .offsetPressure_mbar = 0,
287 .offsetTemperature_centigrad = 0,
288 .gasConsumption_travel_l_min = 30,
289 .gasConsumption_bottom_l_min = 30,
290 .gasConsumption_deco_l_min = 20,
291 .debugModeOnStart = 0,
292 .compassBearing = 0,
293 .lastKnownBatteryPercentage = 0,
294 .buttonBalance[0] = 3,
295 .buttonBalance[1] = 3,
296 .buttonBalance[2] = 3,
297 .firmwareVersion[0] = 0,//FirmwareData.firmwareVersion16to32bit.ub.first,
298 .firmwareVersion[1] = 0,//FirmwareData.firmwareVersion16to32bit.ub.second,
299 .firmwareVersion[2] = 0,//FirmwareData.firmwareVersion16to32bit.ub.third,
300 .firmwareVersion[3] = 0,//FirmwareData.firmwareVersion16to32bit.ub.betaFlag,
301 .timeoutSurfacemodeWithSensors = 600,
302 .VPM_model = 0,
303 .GF_model = 0,
304 .FactoryButtonBase = 90,
305 .FactoryButtonBalance[0] = 3,
306 .FactoryButtonBalance[1] = 3,
307 .FactoryButtonBalance[2] = 3,
308 };
309
310 /* Private function prototypes -----------------------------------------------*/
311 uint8_t checkValue(uint8_t value,uint8_t from, uint8_t to);
312
313 /* Functions -----------------------------------------------------------------*/
314
315
316 // ===============================================================================
317 // set_new_settings_missing_in_ext_flash
318 /// @brief Add all the new setting variables of this version
319 /// or/and change what has changed in the meantime
320 ///
321 /// Additionally update the serial number if written via bluetooth
322 ///
323 // ===============================================================================
324 void set_new_settings_missing_in_ext_flash(void)
325 {
326 // never delete this part setting the serial
327 if(hardwareDataGetPointer()->secondarySerial != 0xFFFF)
328 {
329 settingsGetPointer()->serialHigh = (hardwareDataGetPointer()->secondarySerial / 256);
330 settingsGetPointer()->serialLow = (hardwareDataGetPointer()->secondarySerial & 0xFF);
331 }
332 else
333 if(hardwareDataGetPointer()->primarySerial != 0xFFFF)
334 {
335 settingsGetPointer()->serialHigh = (hardwareDataGetPointer()->primarySerial / 256);
336 settingsGetPointer()->serialLow = (hardwareDataGetPointer()->primarySerial & 0xFF);
337 }
338 else
339 {
340 settingsGetPointer()->serialHigh = 0;
341 settingsGetPointer()->serialLow = 0;
342 }
343
344 settingsGetPointer()->firmwareVersion[0] = firmware_FirmwareData.versionFirst;
345 settingsGetPointer()->firmwareVersion[1] = firmware_FirmwareData.versionSecond;
346 settingsGetPointer()->firmwareVersion[2] = firmware_FirmwareData.versionThird;
347 settingsGetPointer()->firmwareVersion[3] = firmware_FirmwareData.versionBeta;
348
349 SSettings* pSettings = settingsGetPointer();
350 const SSettings* pStandard = settingsGetPointerStandard();
351
352 pSettings->scooterControl = 0;
353
354 if((pSettings->serialHigh == 0) && (pSettings->serialLow == 25))
355 {
356 memcpy(pSettings->customtext, " Salom�\n\r" " Wiedmer\n\r", 60);
357 }
358
359 switch(pSettings->header)
360 {
361 case 0xFFFF0000:
362 case 0xFFFF0001:
363 case 0xFFFF0002:
364 case 0xFFFF0003:
365 case 0xFFFF0004:
366 case 0xFFFF0005:
367 pSettings->ppo2sensors_deactivated = pStandard->ppo2sensors_deactivated;
368 pSettings->tX_colorscheme = pStandard->tX_colorscheme;
369 pSettings->tX_userselectedLeftLowerCornerPrimary = pStandard->tX_userselectedLeftLowerCornerPrimary;
370 pSettings->tX_userselectedLeftLowerCornerTimeout = pStandard->tX_userselectedLeftLowerCornerTimeout;
371 pSettings->tX_customViewPrimary = pStandard->tX_customViewPrimary;
372 pSettings->tX_customViewTimeout = pStandard->tX_customViewTimeout;
373 // no break
374 case 0xFFFF0006:
375 pSettings->timeoutEnterButtonSelectDive = pStandard->timeoutEnterButtonSelectDive;
376 pSettings->ButtonResponsiveness[0] = pStandard->ButtonResponsiveness[0];
377 pSettings->ButtonResponsiveness[1] = pStandard->ButtonResponsiveness[1];
378 pSettings->ButtonResponsiveness[2] = pStandard->ButtonResponsiveness[2];
379 pSettings->ButtonResponsiveness[3] = pStandard->ButtonResponsiveness[3];
380 pSettings->timeoutSurfacemode = pStandard->timeoutSurfacemode;
381 pSettings->timeoutMenuSurface = pStandard->timeoutMenuSurface;
382 pSettings->timeoutMenuDive = pStandard->timeoutMenuDive;
383 pSettings->timeoutMenuEdit = pStandard->timeoutMenuEdit;
384 pSettings->timeoutInfo = pStandard->timeoutInfo;
385 pSettings->timeoutInfoCompass = pStandard->timeoutInfoCompass;
386 pSettings->timeoutDiveReachedZeroDepth = pStandard->timeoutDiveReachedZeroDepth;
387 pSettings->divetimeToCreateLogbook = pStandard->divetimeToCreateLogbook;
388 pSettings->safetystopDuration = pStandard->safetystopDuration; // change from on/off to minutes
389 // no break
390 case 0xFFFF0007:
391 case 0xFFFF0008:
392 pSettings->alwaysShowPPO2 = pStandard->alwaysShowPPO2;
393 pSettings->logbookOffset = pStandard->logbookOffset;
394 // no break
395 case 0xFFFF0009:
396 pSettings->extraDisplay = pStandard->extraDisplay;
397 // no break
398 case 0xFFFF000A:
399 pSettings->display_toogle_desc = pStandard->display_toogle_desc;
400 // no break
401 case 0xFFFF000B:
402 pSettings->offsetPressure_mbar = pStandard->offsetPressure_mbar;
403 pSettings->offsetTemperature_centigrad = pStandard->offsetTemperature_centigrad;
404 pSettings->gasConsumption_travel_l_min = pStandard->gasConsumption_travel_l_min;
405 pSettings->gasConsumption_bottom_l_min = pStandard->gasConsumption_bottom_l_min;
406 pSettings->gasConsumption_deco_l_min = pStandard->gasConsumption_deco_l_min;
407 // no break
408 case 0xFFFF000C:
409 memcpy(pSettings->customtext, " hwOS 4\n\r" " welcome\n\r", 60);
410 // no break
411 case 0xFFFF000D: // nothing to do from 0xFFFF000D to 0xFFFF000E, just about header :-)
412 case 0xFFFF000E:
413 pSettings->debugModeOnStart = 0;
414 // no break
415 case 0xFFFF000F:
416 pSettings->compassBearing = 0;
417 // no break
418 case 0xFFFF0010:
419 pSettings->scooterDrag = 2;
420 pSettings->scooterLoad = 2;
421 pSettings->scooterSPARE1[0] = 0;
422 pSettings->scooterSPARE2[0] = 0;
423 // no break
424 case 0xFFFF0011:
425 pSettings->scooterNumberOfBatteries = 1;
426 pSettings->scooterBattSize = 760;
427 pSettings->lastKnownBatteryPercentage = 0;
428 // no break
429 case 0xFFFF0012:
430 pSettings->buttonBalance[0] = 3;
431 pSettings->buttonBalance[1] = 3;
432 pSettings->buttonBalance[2] = 3;
433 // no break
434 case 0xFFFF0013:
435 case 0xFFFF0014:
436 pSettings->timeoutSurfacemodeWithSensors = pStandard->timeoutSurfacemodeWithSensors;
437 // no break
438 case 0xFFFF0015:
439 pSettings->ButtonResponsiveness[3] = pStandard->ButtonResponsiveness[3];
440 settingsHelperButtonSens_keepPercentageValues(settingsHelperButtonSens_translate_hwOS_values_to_percentage(pSettings->ButtonResponsiveness[3]), pSettings->ButtonResponsiveness);
441 pSettings->VPM_model = 0;
442 pSettings->GF_model = 0;
443 // no break
444 case 0xFFFF0016:
445 pSettings->FactoryButtonBase = pStandard->FactoryButtonBase;
446 pSettings->FactoryButtonBalance[0] = pStandard->FactoryButtonBalance[0];
447 pSettings->FactoryButtonBalance[1] = pStandard->FactoryButtonBalance[1];
448 pSettings->FactoryButtonBalance[2] = pStandard->FactoryButtonBalance[2];
449 // no break
450 default:
451 pSettings->header = pStandard->header;
452 break; // no break before!!
453 }
454 }
455
456
457 uint8_t newFirmwareVersionCheckViaSettings(void)
458 {
459 SSettings* pSettings = settingsGetPointer();
460
461 if(pSettings->header < 0xFFFF0014) // for the versions without firmwareVersion[]
462 return 1;
463
464 if(pSettings->firmwareVersion[0] != firmware_FirmwareData.versionFirst)
465 return 1;
466 if(pSettings->firmwareVersion[1] != firmware_FirmwareData.versionSecond)
467 return 1;
468 if(pSettings->firmwareVersion[2] != firmware_FirmwareData.versionThird)
469 return 1;
470 if(pSettings->firmwareVersion[3] != firmware_FirmwareData.versionBeta)
471 return 1;
472
473 return 0;
474 }
475
476
477 void set_settings_button_to_standard_with_individual_buttonBalance(void)
478 {
479 settingsHelperButtonSens_keepPercentageValues(SettingsStandard.ButtonResponsiveness[3], settingsGetPointer()->ButtonResponsiveness);
480 }
481
482
483 uint8_t check_and_correct_settings(void)
484 {
485 uint32_t corrections = 0;
486 uint8_t firstGasFoundOC = 0;
487 uint8_t firstGasFoundCCR = 0;
488
489 /* uint32_t header;
490 */
491
492 /* uint8_t warning_blink_dsec; 1/10 seconds
493 */
494 if((Settings.warning_blink_dsec < 1) || (Settings.warning_blink_dsec > 100))
495 {
496 Settings.warning_blink_dsec = SettingsStandard.warning_blink_dsec;
497 corrections++;
498 }
499
500 /* uint8_t lastDiveLogId;
501 */
502
503 /* uint32_t logFlashNextSampleStartAddress;
504 */
505 if((Settings.logFlashNextSampleStartAddress < SAMPLESTART) || (Settings.logFlashNextSampleStartAddress > SAMPLESTOP))
506 {
507 Settings.logFlashNextSampleStartAddress = SAMPLESTART;
508 corrections++;
509 }
510
511
512 /* uint8_t dive_mode; has to before the gases
513 */
514 if( (Settings.dive_mode != DIVEMODE_OC) &&
515 (Settings.dive_mode != DIVEMODE_CCR) &&
516 (Settings.dive_mode != DIVEMODE_Gauge) &&
517 (Settings.dive_mode != DIVEMODE_Apnea) )
518 {
519 Settings.dive_mode = DIVEMODE_OC;
520 corrections++;
521 }
522
523
524 /* SGasLine gas[1 + (2*NUM_GASES)];
525 */
526 for(int i=1; i<=2*NUM_GASES;i++)
527 {
528 if(Settings.gas[i].oxygen_percentage < 4)
529 {
530 Settings.gas[i].oxygen_percentage = 4;
531 corrections++;
532 }
533 if(Settings.gas[i].oxygen_percentage > 100)
534 {
535 Settings.gas[i].oxygen_percentage = 100;
536 corrections++;
537 }
538 if((Settings.gas[i].oxygen_percentage + Settings.gas[i].helium_percentage) > 100)
539 {
540 Settings.gas[i].helium_percentage = 100 - Settings.gas[i].oxygen_percentage;
541 corrections++;
542 }
543 if(Settings.gas[i].note.ub.deco)
544 {
545 if(Settings.gas[i].note.ub.active != 1)
546 {
547 Settings.gas[i].note.ub.active = 1;
548 corrections++;
549 }
550 if(Settings.gas[i].note.ub.travel == 1)
551 {
552 Settings.gas[i].note.ub.travel = 0;
553 corrections++;
554 }
555 }
556 if(Settings.gas[i].note.ub.travel)
557 {
558 if(Settings.gas[i].note.ub.active != 1)
559 {
560 Settings.gas[i].note.ub.active = 1;
561 corrections++;
562 }
563 if(Settings.gas[i].note.ub.deco == 1)
564 {
565 Settings.gas[i].note.ub.deco = 0;
566 corrections++;
567 }
568 }
569 if(Settings.gas[i].note.ub.first)
570 {
571 if(Settings.setpoint[i].note.ub.active != 1)
572 {
573 Settings.setpoint[i].note.ub.active = 1;
574 corrections++;
575 }
576 if(Settings.gas[i].note.ub.travel == 1)
577 {
578 Settings.gas[i].note.ub.travel = 0;
579 corrections++;
580 }
581 if(Settings.gas[i].note.ub.deco == 1)
582 {
583 Settings.gas[i].note.ub.deco = 0;
584 corrections++;
585 }
586 if((i<=NUM_GASES) && (!firstGasFoundOC))
587 firstGasFoundOC = 1;
588 else
589 if((i>NUM_GASES) && (!firstGasFoundCCR))
590 firstGasFoundCCR = 1;
591 else
592 Settings.gas[i].note.ub.first = 0;
593 }
594 if(Settings.gas[i].bottle_size_liter > 40)
595 {
596 Settings.gas[i].bottle_size_liter = 40;
597 corrections++;
598 }
599 if(Settings.gas[i].depth_meter > 250)
600 {
601 Settings.gas[i].depth_meter = 250;
602 corrections++;
603 }
604 if(Settings.gas[i].depth_meter_travel > 250)
605 {
606 Settings.gas[i].depth_meter_travel = 250;
607 corrections++;
608 }
609 /*if(Settings.gas[i].note.ub.senderCode)
610 {
611 }
612 if(Settings.gas[i].bottle_wireless_id)
613 {
614 }
615 */
616 } // for(int i=1; i<=2*NUM_GASES;i++)
617
618 if(!firstGasFoundOC)
619 {
620 Settings.gas[1].note.ub.active = 1;
621 Settings.gas[1].note.ub.first = 1;
622 Settings.gas[1].note.ub.travel = 0;
623 Settings.gas[1].note.ub.deco = 0;
624 }
625 if(!firstGasFoundCCR)
626 {
627 Settings.gas[1 + NUM_GASES].note.ub.active = 1;
628 Settings.gas[1 + NUM_GASES].note.ub.first = 1;
629 Settings.gas[1 + NUM_GASES].note.ub.travel = 0;
630 Settings.gas[1 + NUM_GASES].note.ub.deco = 0;
631 }
632 /* SSetpointLine setpoint[1 + NUM_GASES];
633 */
634 for(int i=1; i<=NUM_GASES;i++)
635 {
636 if(Settings.setpoint[i].setpoint_cbar < 50)
637 {
638 Settings.setpoint[i].setpoint_cbar = 50;
639 corrections++;
640 }
641 if(Settings.setpoint[i].setpoint_cbar > 160)
642 {
643 Settings.setpoint[i].setpoint_cbar = 160;
644 corrections++;
645 }
646 if(Settings.setpoint[i].depth_meter > 250)
647 {
648 Settings.setpoint[i].depth_meter = 250;
649 corrections++;
650 }
651 if(Settings.setpoint[i].note.ub.deco)
652 {
653 if(Settings.setpoint[i].note.ub.active != 1)
654 {
655 Settings.setpoint[i].note.ub.active = 1;
656 corrections++;
657 }
658 if(Settings.setpoint[i].note.ub.travel == 1)
659 {
660 Settings.setpoint[i].note.ub.travel = 0;
661 corrections++;
662 }
663 }
664 if(Settings.setpoint[i].note.ub.travel)
665 {
666 if(Settings.setpoint[i].note.ub.active != 1)
667 {
668 Settings.setpoint[i].note.ub.active = 1;
669 corrections++;
670 }
671 if(Settings.setpoint[i].note.ub.deco == 1)
672 {
673 Settings.setpoint[i].note.ub.deco = 0;
674 corrections++;
675 }
676 }
677 if(Settings.setpoint[i].note.ub.first)
678 {
679 if(Settings.setpoint[i].note.ub.active != 1)
680 {
681 Settings.setpoint[i].note.ub.active = 1;
682 corrections++;
683 }
684 if(Settings.setpoint[i].note.ub.travel == 1)
685 {
686 Settings.setpoint[i].note.ub.travel = 0;
687 corrections++;
688 }
689 if(Settings.setpoint[i].note.ub.deco == 1)
690 {
691 Settings.setpoint[i].note.ub.deco = 0;
692 corrections++;
693 }
694 }
695 } // for(int i=1; i<=NUM_GASES;i++)
696
697 /* uint8_t CCR_Mode;
698 */
699 if( (Settings.CCR_Mode != CCRMODE_Sensors) &&
700 (Settings.CCR_Mode != CCRMODE_FixedSetpoint))
701 {
702 Settings.CCR_Mode = CCRMODE_FixedSetpoint;
703 corrections++;
704 }
705
706 /* split2x4_Type deco_type;
707 */
708 if( (Settings.deco_type.ub.standard != GF_MODE) &&
709 (Settings.deco_type.ub.standard != VPM_MODE))
710 {
711 Settings.deco_type.ub.standard = VPM_MODE;
712 corrections++;
713 }
714 if(Settings.deco_type.ub.alternative != GF_MODE)
715 {
716 Settings.deco_type.ub.alternative = GF_MODE;
717 corrections++;
718 }
719
720 /* uint8_t ppO2_max_deco;
721 */
722 if(Settings.ppO2_max_deco > 190)
723 {
724 Settings.ppO2_max_deco = 190;
725 corrections++;
726 }
727 if(Settings.ppO2_max_deco < 100)
728 {
729 Settings.ppO2_max_deco = 100;
730 corrections++;
731 }
732
733 /* uint8_t ppO2_max_std;
734 */
735 if(Settings.ppO2_max_std > 190)
736 {
737 Settings.ppO2_max_std = 190;
738 corrections++;
739 }
740 if(Settings.ppO2_max_std < 100)
741 {
742 Settings.ppO2_max_std = 100;
743 corrections++;
744 }
745
746 /* uint8_t ppO2_min;
747 */
748 if(Settings.ppO2_min != 15)
749 {
750 Settings.ppO2_min = 15;
751 corrections++;
752 }
753
754 /* uint8_t CNS_max;
755 */
756 if(Settings.CNS_max != 90)
757 {
758 Settings.CNS_max = 90;
759 corrections++;
760 }
761
762 /* uint8_t ascent_MeterPerMinute_max;
763 */
764 if(Settings.ascent_MeterPerMinute_max != 30)
765 {
766 Settings.ascent_MeterPerMinute_max = 30;
767 corrections++;
768 }
769
770 /* uint8_t ascent_MeterPerMinute_showGraph;
771 */
772 if(Settings.ascent_MeterPerMinute_showGraph != 30)
773 {
774 Settings.ascent_MeterPerMinute_showGraph = 30;
775 corrections++;
776 }
777
778 /* uint8_t future_TTS;
779 */
780 if(Settings.future_TTS > 15)
781 {
782 Settings.future_TTS = 15;
783 corrections++;
784 }
785
786 /* uint8_t GF_high;
787 */
788 if(Settings.GF_high > 99)
789 {
790 Settings.GF_high = 99;
791 corrections++;
792 }
793 if(Settings.GF_high < 45)
794 {
795 Settings.GF_high = 45;
796 corrections++;
797 }
798
799 /* uint8_t GF_low;
800 */
801 if(Settings.GF_low > 99)
802 {
803 Settings.GF_low = 99;
804 corrections++;
805 }
806 if(Settings.GF_low < 10)
807 {
808 Settings.GF_low = 10;
809 corrections++;
810 }
811 if(Settings.GF_low > Settings.GF_high)
812 {
813 Settings.GF_low = Settings.GF_high;
814 corrections++;
815 }
816
817 /* uint8_t aGF_high;
818 */
819 if(Settings.aGF_high > 99)
820 {
821 Settings.aGF_high = 99;
822 corrections++;
823 }
824 if(Settings.aGF_high < 45)
825 {
826 Settings.aGF_high = 45;
827 corrections++;
828 }
829
830 /* uint8_t aGF_low;
831 */
832 if(Settings.aGF_low > 99)
833 {
834 Settings.aGF_low = 99;
835 corrections++;
836 }
837 if(Settings.aGF_low < 10)
838 {
839 Settings.aGF_low = 10;
840 corrections++;
841 }
842 if(Settings.aGF_low > Settings.aGF_high)
843 {
844 Settings.aGF_low = Settings.aGF_high;
845 corrections++;
846 }
847
848 /* split2x4_Type VPM_conservatism;
849 */
850 if(Settings.VPM_conservatism.ub.standard > 5)
851 {
852 Settings.VPM_conservatism.ub.standard = 5;
853 corrections++;
854 }
855 if(Settings.VPM_conservatism.ub.alternative > 5)
856 {
857 Settings.VPM_conservatism.ub.alternative = 5;
858 corrections++;
859 }
860
861 /* uint8_t safetystopDuration;
862 */
863 if(Settings.safetystopDuration > 5)
864 {
865 Settings.safetystopDuration = 5;
866 corrections++;
867 }
868
869 /* uint8_t AtemMinutenVolumenLiter;
870 */
871 if(Settings.AtemMinutenVolumenLiter != 25)
872 {
873 Settings.AtemMinutenVolumenLiter = 25;
874 corrections++;
875 }
876
877 /* uint8_t ReserveFractionDenominator;
878 */
879 if(Settings.ReserveFractionDenominator != 4)
880 {
881 Settings.ReserveFractionDenominator = 4;
882 corrections++;
883 }
884
885 /* uint8_t salinity;
886 */
887 if(Settings.salinity > 4)
888 {
889 Settings.salinity = 4;
890 corrections++;
891 }
892
893 /* uint8_t last_stop_depth_meter;
894 */
895 if(Settings.last_stop_depth_meter > 9)
896 {
897 Settings.last_stop_depth_meter = 9;
898 corrections++;
899 }
900 if(Settings.last_stop_depth_meter < 3)
901 {
902 Settings.last_stop_depth_meter = 3;
903 corrections++;
904 }
905
906 /* uint8_t stop_increment_depth_meter;
907 */
908 if(Settings.stop_increment_depth_meter != 3)
909 {
910 Settings.stop_increment_depth_meter = 3;
911 corrections++;
912 }
913
914 /* uint8_t brightness;
915 */
916 if(Settings.brightness > 4)
917 {
918 Settings.brightness = 4;
919 corrections++;
920 }
921
922 /* uint8_t date_format;
923 */
924 if( (Settings.date_format != DDMMYY) &&
925 (Settings.date_format != MMDDYY) &&
926 (Settings.date_format != YYMMDD))
927 {
928 Settings.date_format = DDMMYY;
929 corrections++;
930 }
931
932 /* uint8_t selected_language;
933 */
934 if(Settings.selected_language >= LANGUAGE_END)
935 {
936 Settings.selected_language = LANGUAGE_English;
937 corrections++;
938 }
939
940 /* char customtext[60];
941 */
942 if(Settings.customtext[59] != 0)
943 {
944 Settings.customtext[59] = 0;
945 corrections++;
946 }
947
948 /* uint16_t timeoutSurfacemode;
949 */
950 if( (Settings.timeoutSurfacemode != 20) && // Quick Sleep Option
951 (Settings.timeoutSurfacemode != 120))
952 {
953 Settings.timeoutSurfacemode = 120;
954 corrections++;
955 }
956
957 /* uint8_t timeoutMenuSurface;
958 */
959 if(Settings.timeoutMenuSurface != 120)
960 {
961 Settings.timeoutMenuSurface = 120;
962 corrections++;
963 }
964
965 /* uint8_t timeoutMenuDive;
966 */
967 if(Settings.timeoutMenuDive != 120)
968 {
969 Settings.timeoutMenuDive = 120;
970 corrections++;
971 }
972
973 /* uint8_t timeoutMenuEdit;
974 */
975 if(Settings.timeoutMenuEdit != 120)
976 {
977 Settings.timeoutMenuEdit = 120;
978 corrections++;
979 }
980
981 /* uint8_t timeoutInfo;
982 */
983 if(Settings.timeoutInfo != 120)
984 {
985 Settings.timeoutInfo = 120;
986 corrections++;
987 }
988
989 /* uint8_t timeoutInfoCompass;
990 */
991 if(Settings.timeoutInfoCompass != 60)
992 {
993 Settings.timeoutInfoCompass = 60;
994 corrections++;
995 }
996
997 /* uint8_t design;
998 */
999 if(Settings.design != 7)
1000 {
1001 Settings.design = 7;
1002 corrections++;
1003 }
1004
1005 /* uint16_t timeoutDiveReachedZeroDepth;
1006 */
1007 if(Settings.timeoutDiveReachedZeroDepth != 300)
1008 {
1009 Settings.timeoutDiveReachedZeroDepth = 300;
1010 corrections++;
1011 }
1012
1013 /* uint16_t divetimeToCreateLogbook;
1014 */
1015 if(Settings.divetimeToCreateLogbook != 60)
1016 {
1017 Settings.divetimeToCreateLogbook = 60;
1018 corrections++;
1019 }
1020
1021 /* uint8_t serialHigh;
1022 */
1023
1024 /* uint8_t serialLow;
1025 */
1026
1027 /* SUFirmware firmwareVersion16to32bit;
1028 */
1029
1030 /* uint32_t backup_localtime_rtc_tr;
1031 */
1032
1033 /* uint32_t backup_localtime_rtc_dr;
1034 */
1035
1036 /* uint16_t totalDiveCounter;
1037 */
1038
1039 /* uint16_t personalDiveCount;
1040 */
1041
1042 /* uint8_t showDebugInfo;
1043 */
1044 if(Settings.showDebugInfo > 1)
1045 {
1046 Settings.showDebugInfo = 0;
1047 corrections++;
1048 }
1049
1050 /* uint8_t ButtonResponsiveness[4];
1051 */
1052 // Base value, index 3
1053 if(Settings.ButtonResponsiveness[3] < 70)
1054 {
1055 Settings.ButtonResponsiveness[3] = 70;
1056 corrections++;
1057 }
1058 else
1059 if(Settings.ButtonResponsiveness[3] > 110)
1060 {
1061 Settings.ButtonResponsiveness[3] = 130;
1062 corrections++;
1063 }
1064 // flex values 0, 1, 2
1065 for(int i=0; i<3;i++)
1066 {
1067 if(Settings.ButtonResponsiveness[i] < 60) // 70-10
1068 {
1069 Settings.ButtonResponsiveness[i] = 70;
1070 corrections++;
1071 }
1072 else
1073 if(Settings.ButtonResponsiveness[i] > 130) // 110+20
1074 {
1075 Settings.ButtonResponsiveness[i] = 130;
1076 corrections++;
1077 }
1078 }
1079
1080 /* uint8_t buttonBalance[3];
1081 */
1082 for(int i=0; i<3;i++)
1083 {
1084 if(Settings.buttonBalance[i] < 2) // 2 = -10
1085 {
1086 Settings.buttonBalance[i] = 2;
1087 corrections++;
1088 }
1089 else
1090 if(Settings.buttonBalance[i] > 5) // 3 = 0, 4 = +10, 5 = +20
1091 {
1092 Settings.buttonBalance[i] = 5;
1093 corrections++;
1094 }
1095 }
1096
1097 /* uint8_t nonMetricalSystem;
1098 */
1099 if(Settings.nonMetricalSystem > 1)
1100 {
1101 Settings.nonMetricalSystem = 1;
1102 corrections++;
1103 }
1104
1105 /* uint8_t fallbackToFixedSetpoint;
1106 */
1107 if(Settings.fallbackToFixedSetpoint > 1)
1108 {
1109 Settings.fallbackToFixedSetpoint = 1;
1110 corrections++;
1111 }
1112
1113 /* uint8_t bluetoothActive;
1114 */
1115 if(Settings.bluetoothActive > 1)
1116 {
1117 Settings.bluetoothActive = 1;
1118 corrections++;
1119 }
1120
1121 /* uint8_t safetystopDepth;
1122 */
1123 if(Settings.safetystopDepth > 6)
1124 {
1125 Settings.safetystopDepth = 6;
1126 corrections++;
1127 }
1128 if(Settings.safetystopDepth < 3)
1129 {
1130 Settings.safetystopDepth = 3;
1131 corrections++;
1132 }
1133
1134 /* uint32_t updateSettingsAllowedFromHeader;
1135 */
1136
1137 /* uint8_t scooterControl;
1138 */
1139 if(Settings.scooterControl > 1)
1140 {
1141 Settings.scooterControl = 1;
1142 corrections++;
1143 }
1144
1145 /* char scooterDeviceAddress[12];
1146 */
1147
1148 /* char scooterDeviceName[19];
1149 */
1150
1151 /* uint8_t ppo2sensors_deactivated;
1152 */
1153 if(Settings.ppo2sensors_deactivated > (1+2+4))
1154 {
1155 Settings.ppo2sensors_deactivated = 0;
1156 corrections++;
1157 }
1158
1159 /* uint8_t tX_colorscheme;
1160 */
1161 if(Settings.tX_colorscheme > 3)
1162 {
1163 Settings.tX_colorscheme = 0;
1164 corrections++;
1165 }
1166
1167 /* uint8_t tX_userselectedLeftLowerCornerPrimary;
1168 */
1169 if(Settings.tX_userselectedLeftLowerCornerPrimary > 7)
1170 {
1171 Settings.tX_userselectedLeftLowerCornerPrimary = 1;
1172 corrections++;
1173 }
1174
1175 /* uint8_t tX_userselectedLeftLowerCornerTimeout;
1176 */
1177 if(Settings.tX_userselectedLeftLowerCornerTimeout > 60)
1178 {
1179 Settings.tX_userselectedLeftLowerCornerTimeout = 0;
1180 corrections++;
1181 }
1182
1183 /* uint8_t tX_customViewPrimary;
1184 */
1185 if(Settings.tX_customViewPrimary >= CVIEW_END)
1186 {
1187 Settings.tX_customViewPrimary = 1;
1188 corrections++;
1189 }
1190
1191 /* uint8_t tX_customViewTimeout;
1192 */
1193 if(Settings.tX_customViewTimeout > 60)
1194 {
1195 Settings.tX_customViewTimeout = 0;
1196 corrections++;
1197 }
1198
1199 /* uint8_t timeoutEnterButtonSelectDive;
1200 */
1201 if(Settings.timeoutEnterButtonSelectDive != 10)
1202 {
1203 Settings.timeoutEnterButtonSelectDive = 10;
1204 corrections++;
1205 }
1206
1207 /* uint8_t logbookOffset;
1208 */
1209 if(Settings.logbookOffset > 9000)
1210 {
1211 Settings.logbookOffset = 0;
1212 corrections++;
1213 }
1214
1215 /* uint8_t alwaysShowPPO2;
1216 */
1217 if(Settings.alwaysShowPPO2 > 1)
1218 {
1219 Settings.alwaysShowPPO2 = 0;
1220 corrections++;
1221 }
1222
1223 /* uint8_t extraDisplay;
1224 */
1225 if(Settings.extraDisplay >= EXTRADISPLAY_END)
1226 {
1227 Settings.extraDisplay = EXTRADISPLAY_BIGFONT;
1228 corrections++;
1229 }
1230
1231 /* int8_t offsetPressure_mbar;
1232 */
1233 if((Settings.offsetPressure_mbar > 20) ||
1234 (Settings.offsetPressure_mbar < -20))
1235 {
1236 Settings.offsetPressure_mbar = 0;
1237 corrections++;
1238 }
1239
1240 /* int8_t offsetTemperature_centigrad;
1241 */
1242 if((Settings.offsetTemperature_centigrad > 20) ||
1243 (Settings.offsetTemperature_centigrad < -20))
1244 {
1245 Settings.offsetTemperature_centigrad = 0;
1246 corrections++;
1247 }
1248
1249 /* uint8_t gasConsumption_travel_l_min;
1250 */
1251 if((Settings.gasConsumption_travel_l_min < 5) ||
1252 (Settings.gasConsumption_travel_l_min > 50))
1253 {
1254 Settings.gasConsumption_travel_l_min = 20;
1255 corrections++;
1256 }
1257
1258 /* uint8_t gasConsumption_bottom_l_min;
1259 */
1260 if((Settings.gasConsumption_bottom_l_min < 5) ||
1261 (Settings.gasConsumption_bottom_l_min > 50))
1262 {
1263 Settings.gasConsumption_bottom_l_min = 20;
1264 corrections++;
1265 }
1266
1267 /* uint8_t gasConsumption_deco_l_min;
1268 */
1269 if((Settings.gasConsumption_deco_l_min < 5) ||
1270 (Settings.gasConsumption_deco_l_min > 50))
1271 {
1272 Settings.gasConsumption_deco_l_min = 20;
1273 corrections++;
1274 }
1275
1276 /* uint8_t showDebugInfo;
1277 */
1278 #ifdef BOOT16
1279 Settings.showDebugInfo = 0;
1280 #else
1281 if(Settings.showDebugInfo > 1)
1282 Settings.showDebugInfo = 0;
1283
1284 #endif
1285
1286 /* uint8_t selected_language;
1287 */
1288 #ifdef BOOT16
1289 if(Settings.selected_language > 1)
1290 Settings.selected_language = 0;
1291 #else
1292 if(Settings.selected_language > 4)
1293 Settings.selected_language = 0;
1294 #endif
1295
1296
1297 /* uint8_t display_toogle_desc; 1/10 seconds
1298 */
1299 if((Settings.display_toogle_desc < 20) || (Settings.display_toogle_desc > 600))
1300 {
1301 Settings.display_toogle_desc = SettingsStandard.display_toogle_desc;
1302 corrections++;
1303 }
1304
1305 /* uint8_t debugModeOnStart;
1306 */
1307 if(Settings.debugModeOnStart > 1)
1308 {
1309 Settings.debugModeOnStart = 0;
1310 corrections++;
1311 }
1312
1313
1314 /* uint8_t IAmStolenPleaseKillMe;
1315 */
1316
1317 if(hardwareDataGetPointer()->primarySerial == 90)
1318 Settings.IAmStolenPleaseKillMe++;
1319 else
1320 Settings.IAmStolenPleaseKillMe = 0;
1321
1322
1323 /* uint8_t debugModeOnStart;
1324 */
1325 if(Settings.compassBearing > 360)
1326 {
1327 Settings.compassBearing = 0;
1328 corrections++;
1329 }
1330
1331 /* uint8_t scooterDrag;
1332 */
1333 if(Settings.scooterDrag > 3)
1334 {
1335 Settings.scooterDrag = 3;
1336 corrections++;
1337 }
1338
1339 /* uint8_t scooterLoad;
1340 */
1341 if(Settings.scooterLoad > 4)
1342 {
1343 Settings.scooterLoad = 4;
1344 corrections++;
1345 }
1346
1347 /* uint8_t scooterNumberOfBatteries;
1348 */
1349 if(Settings.scooterNumberOfBatteries > 3)
1350 {
1351 Settings.scooterNumberOfBatteries = 3;
1352 corrections++;
1353 }
1354
1355 /* uint16_t scooterBattSize;
1356 */
1357 if((Settings.scooterBattSize < 300) ||
1358 (Settings.scooterBattSize > 5000))
1359 {
1360 Settings.scooterBattSize = 700;
1361 corrections++;
1362 }
1363
1364
1365 /* uint8_t lastKnownBatteryPercentage;
1366 */
1367 if(Settings.lastKnownBatteryPercentage > 100)
1368 {
1369 Settings.lastKnownBatteryPercentage = 100;
1370 corrections++;
1371 }
1372
1373 /* uint8_t VPM_model
1374 */
1375 if((Settings.VPM_model != VPM_FROM_FORTRAN) && (Settings.VPM_model != VPM_BACHELORWORK))
1376 {
1377 Settings.VPM_model = VPM_FROM_FORTRAN;
1378 corrections++;
1379 }
1380
1381 /* uint8_t Buehlmann_model
1382 */
1383 if((Settings.GF_model != BUEHLMANN_OSTC4) && (Settings.GF_model != BUEHLMANN_hwOS))
1384 {
1385 Settings.GF_model = BUEHLMANN_OSTC4;
1386 corrections++;
1387 }
1388
1389
1390 if(corrections > 255)
1391 return 255;
1392 else
1393 return (uint8_t)corrections;
1394 }
1395
1396
1397 /* always at 0x8080000, do not move -> bootloader access */
1398 const SFirmwareData* firmwareDataGetPointer(void)
1399 {
1400 return &firmware_FirmwareData;
1401 }
1402
1403
1404 #ifndef SPECIALPROGRAMM
1405 const SHardwareData* hardwareDataGetPointer(void)
1406 {
1407 return (SHardwareData *)HARDWAREDATA_ADDRESS;
1408 }
1409 #endif
1410
1411 const SSettings* settingsGetPointerStandard(void)
1412 {
1413 return &SettingsStandard;
1414 }
1415
1416
1417 void hardwareBatchCode(uint8_t *high, uint8_t *low)
1418 {
1419 if(high)
1420 {
1421 *high = (uint8_t)((hardwareDataGetPointer()->production_year - 16) * 16);
1422 *high += hardwareDataGetPointer()->production_month;
1423 if(low)
1424 {
1425 *low = (uint8_t)(hardwareDataGetPointer()->production_day * 8);
1426 }
1427 }
1428 }
1429
1430
1431 uint8_t firmwareVersion_16bit_high(void)
1432 {
1433 return ((firmware_FirmwareData.versionFirst & 0x1F) << 3) + ((firmware_FirmwareData.versionSecond & 0x1C) >> 5);
1434 }
1435
1436 uint8_t firmwareVersion_16bit_low(void)
1437 {
1438 return ((firmware_FirmwareData.versionSecond & 0x03) << 6) + ((firmware_FirmwareData.versionThird & 0x1F) << 1) + (firmware_FirmwareData.versionBeta & 0x01);
1439 }
1440
1441 SSettings* settingsGetPointer(void)
1442 {
1443 return &Settings;
1444 }
1445
1446
1447 // ===============================================================================
1448 // set_settings_to_Standard
1449 /// @brief This function overwrites the current settings of the system
1450 /// with the EXCEPTION of the personalDiveCount
1451 ///
1452 /// It additionally calls set_new_settings_missing_in_ext_flash() and
1453 /// check_and_correct_settings(), even so this shouldn't be necessary.
1454 /// It is called on every start and from Reset All.
1455 ///
1456 /// 160622 added lastDiveLogIdBackup
1457 ///
1458 // ===============================================================================
1459 void set_settings_to_Standard(void)
1460 {
1461 SSettings *pSettings;
1462 const SSettings *pSettingsStandard;
1463 uint16_t personalDiveCountBackup;
1464 uint8_t lastDiveLogIdBackup;
1465 pSettings = settingsGetPointer();
1466 pSettingsStandard = settingsGetPointerStandard();
1467
1468 personalDiveCountBackup = pSettings->personalDiveCount;
1469 lastDiveLogIdBackup = pSettings->lastDiveLogId;
1470 memcpy(pSettings,pSettingsStandard,sizeof(*pSettings));
1471 pSettings->personalDiveCount = personalDiveCountBackup;
1472 pSettings->lastDiveLogId = lastDiveLogIdBackup;
1473
1474 pSettings->firmwareVersion[0] = firmware_FirmwareData.versionFirst;
1475 pSettings->firmwareVersion[1] = firmware_FirmwareData.versionSecond;
1476 pSettings->firmwareVersion[2] = firmware_FirmwareData.versionThird;
1477 pSettings->firmwareVersion[3] = firmware_FirmwareData.versionBeta;
1478
1479 set_new_settings_missing_in_ext_flash();
1480 check_and_correct_settings();
1481 // has to be called too: createDiveSettings();
1482 }
1483
1484
1485 // ===============================================================================
1486 // mod_settings_for_first_start_with_empty_ext_flash
1487 /// @brief This function overwrites some settings of the system
1488 /// It is called on every start.
1489 /// Those settings will be overwriten by ext_flash_read_settings()
1490 /// Will be kept if ext_flash_read_settings() is invalid because
1491 /// it is still empty.
1492 ///
1493 // ===============================================================================
1494 void mod_settings_for_first_start_with_empty_ext_flash(void)
1495 {
1496 settingsGetPointer()->debugModeOnStart = 1; //
1497 }
1498
1499
1500
1501 // ===============================================================================
1502 // hwOS4_to_hwOS_GasType
1503 /// @brief Helper for get gas / diluent
1504 ///
1505 // ===============================================================================
1506 uint8_t hwOS4_to_hwOS_GasType(uint8_t inOSTC4style)
1507 {
1508 switch(inOSTC4style)
1509 {
1510 case (1+2): // first
1511 case (2): // first
1512 return 1; // hwOS style first
1513 case (1+4): // deco
1514 case (4): // deco
1515 return 3; // hwOS style deco
1516 case (1+8): // travel
1517 case (8): // travel
1518 return 2; // hwOS style travel
1519 default:
1520 return 0; // hwOS style Disabled
1521 }
1522 }
1523
1524
1525 // ===============================================================================
1526 // hwOS_to_hwOS4_GasType
1527 /// @brief Helper for set gas / diluent
1528 ///
1529 // ===============================================================================
1530 uint8_t hwOS_to_hwOS4_GasType(uint8_t inOSTC4style)
1531 {
1532 switch(inOSTC4style)
1533 {
1534 case (1): // first
1535 return 1+2; // hwOS4 style first
1536 case (2): // travel (normal for diluent)
1537 return 1+8; // hwOS4 style travel
1538 case (3): // deco
1539 return 1+4; // hwOS4 style deco
1540 default:
1541 return 0; // hwOS4 style inactive
1542 }
1543 }
1544
1545
1546
1547 // ===============================================================================
1548 // setGas
1549 /// @brief This function overwrites one gas, including mode and deco depth,
1550 /// it returns 0x4D prompt which is not used by writeData() that calls it.
1551 ///
1552 /// @param i the gas id from 1 to 5 for OC and 6 to 10 for CCR, 0 is the extra gas
1553 /// @param *data 5 bytes with the first the command to call setGas and the four
1554 /// following bytes to define oxygen, helium, mode and deco depth
1555 ///
1556 /// @return 0x4D (prompt that is not used)
1557 // ===============================================================================
1558 uint8_t setGas(int i,uint8_t * data)
1559 {
1560 if(!checkValue(data[1],4,100))
1561 return ERROR_;
1562 if(!checkValue(data[4],0,250))
1563 return ERROR_;
1564
1565 Settings.gas[i].oxygen_percentage = data[1];
1566 Settings.gas[i].helium_percentage = data[2];
1567 Settings.gas[i].note.uw = hwOS_to_hwOS4_GasType(data[3]);
1568 Settings.gas[i].depth_meter = data[4];
1569 return 0x4d;
1570 }
1571
1572
1573 uint8_t getGas(int i,uint8_t * data)
1574 {
1575 data[0] = Settings.gas[i].oxygen_percentage;
1576 data[1] = Settings.gas[i].helium_percentage;
1577 data[2] = hwOS4_to_hwOS_GasType(Settings.gas[i].note.uw);
1578 data[3] = Settings.gas[i].depth_meter;
1579 return 0x4d;
1580 }
1581
1582 uint8_t setDiluent(int i,uint8_t * data)
1583 {
1584 if(!checkValue(data[1],4,100))
1585 return ERROR_;
1586 if(!checkValue(data[4],0,250))
1587 return ERROR_;
1588
1589 Settings.gas[NUM_OFFSET_DILUENT + i].oxygen_percentage = data[1];
1590 Settings.gas[NUM_OFFSET_DILUENT + i].helium_percentage = data[2];
1591 Settings.gas[NUM_OFFSET_DILUENT + i].note.uw = hwOS_to_hwOS4_GasType(data[3]);
1592 Settings.gas[NUM_OFFSET_DILUENT + i].depth_meter = data[4];
1593 return 0x4d;
1594 }
1595
1596 uint8_t getDiluent(int i,uint8_t * data)
1597 {
1598 data[0] = Settings.gas[NUM_OFFSET_DILUENT + i].oxygen_percentage;
1599 data[1] = Settings.gas[NUM_OFFSET_DILUENT + i].helium_percentage;
1600 data[2] = hwOS4_to_hwOS_GasType(Settings.gas[NUM_OFFSET_DILUENT + i].note.uw);
1601 data[3] = Settings.gas[NUM_OFFSET_DILUENT + i].depth_meter;
1602 return 0x4d;
1603 }
1604
1605 uint8_t setSetpoint(int i,uint8_t * data)
1606 {
1607 if(!checkValue(data[1],50,160))
1608 return ERROR_;
1609 if(!checkValue(data[2],0,250))
1610 return ERROR_;
1611
1612 Settings.setpoint[i].setpoint_cbar = data[1];
1613 Settings.setpoint[i].depth_meter = data[2];
1614 return 0x4d;
1615 }
1616
1617 uint8_t getSetpoint(int i,uint8_t * data)
1618 {
1619 data[0] = Settings.setpoint[i].setpoint_cbar;
1620 data[1] = Settings.setpoint[i].depth_meter;
1621 return 0x4d;
1622 }
1623
1624 uint8_t checkValue(uint8_t value,uint8_t from, uint8_t to)
1625 {
1626 if(value >= from && value <= to)
1627 return 1;
1628 return 0;
1629 }
1630
1631 uint8_t writeData(uint8_t * data)
1632 {
1633 uint32_t newSensitivity;
1634 uint16_t newDuration, newOffset;
1635 uint8_t newStopDepth;
1636
1637 switch(data[0])
1638 {
1639 case 0x10:
1640 return setGas(1,data);
1641 case 0x11:
1642 return setGas(2,data);
1643 case 0x12:
1644 return setGas(3,data);
1645 case 0x13:
1646 return setGas(4,data);
1647 case 0x14:
1648 return setGas(5,data);
1649 case 0x15:
1650 return setDiluent(1,data);
1651 case 0x16:
1652 return setDiluent(2,data);
1653 case 0x17:
1654 return setDiluent(3,data);
1655 case 0x18:
1656 return setDiluent(4,data);
1657 case 0x19:
1658 return setDiluent(5,data);
1659 case 0x1A:
1660 return setSetpoint(1,data);
1661 case 0x1B:
1662 return setSetpoint(2,data);
1663 case 0x1C:
1664 return setSetpoint(3,data);
1665 case 0x1D:
1666 return setSetpoint(4,data);
1667 case 0x1E:
1668 return setSetpoint(5,data);
1669 case 0x1F:
1670 if(!checkValue(data[2],0,1))
1671 return ERROR_;
1672 Settings.CCR_Mode = data[1];
1673 break;
1674 case 0x20:
1675 if(!checkValue(data[1],0,3))
1676 return ERROR_;
1677 Settings.dive_mode = data[1];
1678 break;
1679 case 0x21:
1680 if(!checkValue(data[1],1,2))
1681 return ERROR_;
1682 Settings.deco_type.ub.standard = data[1] & 0x0F;
1683 //Settings.deco_type.ub.alternative = (data[1] & 0xF0) >> 4;
1684 break;
1685 case 0x22:
1686 if(!checkValue(data[1],100,190))
1687 return ERROR_;
1688 Settings.ppO2_max_std = data[1];
1689 break;
1690 case 0x23:
1691 if(!checkValue(data[1],15,15))
1692 return ERROR_;
1693 Settings.ppO2_min = data[1];
1694 break;
1695 case 0x24:
1696 if(!checkValue(data[1],0,15))
1697 return ERROR_;
1698 Settings.future_TTS = data[1];
1699 break;
1700 case 0x25:
1701 if(!checkValue(data[1],10,99))
1702 return ERROR_;
1703 Settings.GF_low = data[1];
1704 break;
1705 case 0x26:
1706 if(!checkValue(data[1],45,99))
1707 return ERROR_;
1708 Settings.GF_high = data[1];
1709 break;
1710 case 0x27:
1711 if(!checkValue(data[1],10,99))
1712 return ERROR_;
1713 Settings.aGF_low = data[1];
1714 break;
1715 case 0x28:
1716 if(!checkValue(data[1],45,99))
1717 return ERROR_;
1718 Settings.aGF_high = data[1];
1719 break;
1720 case 0x29:
1721 if(!checkValue(data[1],0,5))
1722 return ERROR_;
1723 Settings.VPM_conservatism.ub.standard = data[1];
1724 break;
1725 case 0x2A:
1726 case 0x2B:
1727 return ERROR_;
1728 case 0x2C:
1729 if(!checkValue(data[1],3,9))
1730 return ERROR_;
1731 Settings.last_stop_depth_meter = data[1];
1732 break;
1733 case 0x2D:
1734 if(!checkValue(data[1],0,4))
1735 return ERROR_;
1736 Settings.brightness = data[1];
1737 break;
1738 case 0x2E:
1739 if(!checkValue(data[1],0,1))
1740 return ERROR_;
1741 Settings.nonMetricalSystem = data[1];
1742 break;
1743 case 0x2F:
1744 return ERROR_;
1745 case 0x30:
1746 if(!checkValue(data[1],0,4))
1747 return ERROR_;
1748 Settings.salinity = data[1];
1749 break;
1750 case 0x31:
1751 if(!checkValue(data[1],0,3))
1752 return ERROR_;
1753 Settings.tX_colorscheme = data[1];
1754 GFX_use_colorscheme(Settings.tX_colorscheme);
1755 break;
1756 case 0x32:
1757 if(!checkValue(data[1],0,4))
1758 return ERROR_;
1759 Settings.selected_language = data[1];
1760 break;
1761 case 0x33:
1762 if(!checkValue(data[1],0,2))
1763 return ERROR_;
1764 Settings.date_format = data[1];
1765 break;
1766 case 0x34:
1767 return ERROR_;
1768 case 0x35:
1769 if(data[1] & 0x80)
1770 {
1771 data[1] = ~(data[1]);
1772 if(!checkValue(data[1],0,20))
1773 return ERROR_;
1774 Settings.offsetPressure_mbar = 0 - data[1];
1775 }
1776 else
1777 {
1778 if(!checkValue(data[1],0,20))
1779 return ERROR_;
1780 Settings.offsetPressure_mbar = data[1];
1781 }
1782 break;
1783 case 0x36:
1784 if(!checkValue(data[1],0,1))
1785 return ERROR_;
1786 if(data[1])
1787 Settings.safetystopDuration = settingsGetPointerStandard()->safetystopDuration;
1788 else
1789 Settings.safetystopDuration = 0;
1790 break;
1791 case 0x37:
1792 return ERROR_;
1793 case 0x38:
1794 if(!checkValue(data[1],0,1))
1795 return ERROR_;
1796 Settings.fallbackToFixedSetpoint = data[1];
1797 break;
1798 case 0x39:
1799 return ERROR_;
1800 case 0x3A:
1801 if(!checkValue(data[1],70,110))
1802 return ERROR_;
1803 newSensitivity = data[1];
1804 settingsHelperButtonSens_keepPercentageValues(newSensitivity, settingsGetPointer()->ButtonResponsiveness);
1805 setButtonResponsiveness(Settings.ButtonResponsiveness);
1806 break;
1807 case 0x3B:
1808 // value between 0 and 127
1809 if(buttonBalanceTranslatorHexToArray(data[1], settingsGetPointer()->buttonBalance))
1810 {
1811 settingsHelperButtonSens_keepPercentageValues(settingsGetPointer()->ButtonResponsiveness[3], settingsGetPointer()->ButtonResponsiveness);
1812 }
1813 else // value >= 128 (bit 7 set) factory reset
1814 {
1815 getButtonFactorDefaults(&settingsGetPointer()->ButtonResponsiveness[3], settingsGetPointer()->buttonBalance);
1816 settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settingsGetPointer()->ButtonResponsiveness);
1817 }
1818 // valid for both:
1819 setButtonResponsiveness(Settings.ButtonResponsiveness);
1820 break;
1821 case 0x3C:
1822 if(!checkValue(data[1],5,50))
1823 return ERROR_;
1824 Settings.gasConsumption_bottom_l_min = data[1];
1825 break;
1826 case 0x3D:
1827 if(!checkValue(data[1],5,50))
1828 return ERROR_;
1829 Settings.gasConsumption_deco_l_min = data[1];
1830 break;
1831 case 0x3E:
1832 if(!checkValue(data[1],5,50))
1833 return ERROR_;
1834 Settings.gasConsumption_travel_l_min = data[1];
1835 break;
1836 case 0x3F:
1837 case 0x40:
1838 return ERROR_;
1839 case 0x41:
1840 if(!checkValue(data[1],0,1))
1841 return ERROR_;
1842 Settings.alwaysShowPPO2 = data[1];
1843 break;
1844 case 0x42:
1845 if(data[1] & 0x80)
1846 {
1847 data[1] = ~(data[1]);
1848 if(!checkValue(data[1],0,20))
1849 return ERROR_;
1850 Settings.offsetTemperature_centigrad = 0 - data[1];
1851 }
1852 else
1853 {
1854 if(!checkValue(data[1],0,20))
1855 return ERROR_;
1856 Settings.offsetTemperature_centigrad = data[1];
1857 }
1858 break;
1859 case 0x43:
1860 if(!checkValue(data[1],60,255))
1861 return ERROR_;
1862 newDuration = (uint16_t)data[1] + 59;
1863 newDuration /= 60;
1864 Settings.safetystopDuration = (uint8_t)newDuration;
1865 break;
1866 case 0x44:
1867 if(!checkValue(data[1],21,61))
1868 return ERROR_;
1869 newStopDepth = data[1] + 9;
1870 if(newStopDepth > 60)
1871 newStopDepth = 60;
1872 newStopDepth /= 10;
1873 Settings.safetystopDepth = newStopDepth;
1874 break;
1875 case 0x45:
1876 case 0x46:
1877 return ERROR_;
1878 case 0x47:
1879 newOffset = data[2] * 256;
1880 newOffset += data[1];
1881 if(newOffset > 9000)
1882 return ERROR_;
1883 Settings.logbookOffset = newOffset;
1884 break;
1885 case 0x70:
1886 if(!checkValue(data[1],0,1))
1887 return ERROR_;
1888 Settings.showDebugInfo = data[1];
1889 break;
1890 case 0x71:
1891 if(!checkValue(data[1],0,(EXTRADISPLAY_END - 1)))
1892 return ERROR_;
1893 Settings.extraDisplay = data[1];
1894 break;
1895 case 0x72:
1896 if(!checkValue(data[1],0,8))
1897 return ERROR_;
1898 Settings.tX_customViewPrimary = data[1];
1899 break;
1900 case 0x73:
1901 if(!checkValue(data[1],0,20))
1902 return ERROR_;
1903 Settings.tX_customViewTimeout = data[1];
1904 break;
1905 case 0x74:
1906 if(!checkValue(data[1],1,7))
1907 return ERROR_;
1908 Settings.tX_userselectedLeftLowerCornerPrimary = data[1];
1909 break;
1910 case 0x75:
1911 if(!checkValue(data[1],0,20))
1912 return ERROR_;
1913 Settings.tX_userselectedLeftLowerCornerTimeout = data[1];
1914 break;
1915 }
1916 return 0;
1917 }
1918
1919
1920 uint8_t readDataLimits__8and16BitValues_4and7BytesOutput(uint8_t what, uint8_t * data)
1921 {
1922 enum JeanDoParameterType {
1923 PARAM_UNKNOWN = 0,
1924 PARAM_INT15 = 1,
1925 PARAM_INT8,
1926 PARAM_DECI,
1927 PARAM_CENTI,
1928 PARAM_MILI,
1929 PARAM_PERCENT,
1930 PARAM_SEC,
1931 PARAM_COLOR,
1932 PARAM_BOOL,
1933 PARAM_ENUM,
1934 PARAM_SIGNED = 128,
1935 PARAM_SDECI = PARAM_SIGNED|PARAM_DECI,
1936 PARAM_SSEC = PARAM_SIGNED|PARAM_SEC,
1937 PARAM_SINT = PARAM_SIGNED|PARAM_INT8
1938 };
1939
1940 // uint32_t buttonSensitivity;
1941 uint16_t newDuration;
1942
1943 uint8_t datacounter = 0;
1944
1945 data[0] = 0;
1946 data[1] = 0;
1947 data[2] = 0;
1948 data[3] = 0;
1949 datacounter = 0;
1950
1951 switch(what)
1952 {
1953 case 0x10:
1954 case 0x11:
1955 case 0x12:
1956 case 0x13:
1957 case 0x14:
1958 data[datacounter++] = PARAM_INT8;
1959 data[datacounter++] = 4;
1960 data[datacounter++] = settingsGetPointerStandard()->gas[1].oxygen_percentage;
1961 data[datacounter++] = 100;
1962 break;
1963
1964 case 0x15:
1965 case 0x16:
1966 case 0x17:
1967 case 0x18:
1968 case 0x19:
1969 data[datacounter++] = PARAM_INT8;
1970 data[datacounter++] = 4;
1971 data[datacounter++] = settingsGetPointerStandard()->gas[1].oxygen_percentage;
1972 data[datacounter++] = 100;
1973 break;
1974
1975 case 0x1A:
1976 case 0x1B:
1977 case 0x1C:
1978 case 0x1D:
1979 case 0x1E:
1980 data[datacounter++] = PARAM_CENTI;
1981 data[datacounter++] = 50;
1982 data[datacounter++] = settingsGetPointerStandard()->setpoint[1].setpoint_cbar;
1983 data[datacounter++] = 160;
1984 break;
1985
1986 case 0x1F:
1987 data[datacounter++] = PARAM_ENUM;
1988 data[datacounter++] = 0;
1989 data[datacounter++] = settingsGetPointerStandard()->CCR_Mode;
1990 data[datacounter++] = 1;
1991 break;
1992
1993 case 0x20:
1994 data[datacounter++] = PARAM_ENUM;
1995 data[datacounter++] = 0;
1996 data[datacounter++] = settingsGetPointerStandard()->dive_mode;
1997 data[datacounter++] = 3;
1998 break;
1999
2000 case 0x21:
2001 data[datacounter++] = PARAM_ENUM;
2002 data[datacounter++] = 1;
2003 data[datacounter++] = settingsGetPointerStandard()->deco_type.ub.standard;
2004 data[datacounter++] = 2;
2005 break;
2006
2007 case 0x22:
2008 data[datacounter++] = PARAM_CENTI;
2009 data[datacounter++] = 100;
2010 data[datacounter++] = settingsGetPointerStandard()->ppO2_max_std;
2011 data[datacounter++] = 190;
2012 break;
2013
2014 case 0x23:
2015 data[datacounter++] = PARAM_CENTI;
2016 data[datacounter++] = 15;
2017 data[datacounter++] = settingsGetPointerStandard()->ppO2_min;
2018 data[datacounter++] = 15;
2019 break;
2020
2021 case 0x24:
2022 data[datacounter++] = PARAM_INT8; // minutes
2023 data[datacounter++] = 0;
2024 data[datacounter++] = settingsGetPointerStandard()->future_TTS;
2025 data[datacounter++] = 15;
2026 break;
2027
2028 case 0x25:
2029 data[datacounter++] = PARAM_PERCENT;
2030 data[datacounter++] = 10;
2031 data[datacounter++] = settingsGetPointerStandard()->GF_low;
2032 data[datacounter++] = 99;
2033 break;
2034
2035 case 0x26:
2036 data[datacounter++] = PARAM_PERCENT;
2037 data[datacounter++] = 45;
2038 data[datacounter++] = settingsGetPointerStandard()->GF_high;
2039 data[datacounter++] = 99;
2040 break;
2041
2042 case 0x27:
2043 data[datacounter++] = PARAM_PERCENT;
2044 data[datacounter++] = 10;
2045 data[datacounter++] = settingsGetPointerStandard()->aGF_low;
2046 data[datacounter++] = 99;
2047 break;
2048
2049 case 0x28:
2050 data[datacounter++] = PARAM_PERCENT;
2051 data[datacounter++] = 45;
2052 data[datacounter++] = settingsGetPointerStandard()->aGF_high;
2053 data[datacounter++] = 99;
2054 break;
2055
2056 case 0x29:
2057 data[datacounter++] = PARAM_INT8; // conservatism +0 .. +5
2058 data[datacounter++] = 0;
2059 data[datacounter++] = settingsGetPointerStandard()->VPM_conservatism.ub.standard;
2060 data[datacounter++] = 5;
2061 break;
2062
2063 case 0x2A:
2064 case 0x2B:
2065 data[datacounter++] = PARAM_PERCENT;
2066 data[datacounter++] = 100;
2067 data[datacounter++] = 100;// saturation, desaturation, settingsGetPointerStandard()->;
2068 data[datacounter++] = 100;
2069 break;
2070
2071 case 0x2C:
2072 data[datacounter++] = PARAM_INT8;
2073 data[datacounter++] = 3;
2074 data[datacounter++] = settingsGetPointerStandard()->last_stop_depth_meter;
2075 data[datacounter++] = 9;
2076 break;
2077
2078 case 0x2D:
2079 data[datacounter++] = PARAM_ENUM;
2080 data[datacounter++] = 0;
2081 data[datacounter++] = settingsGetPointerStandard()->brightness;
2082 data[datacounter++] = 4;
2083 break;
2084
2085 case 0x2E:
2086 data[datacounter++] = PARAM_ENUM;
2087 data[datacounter++] = 0;
2088 data[datacounter++] = settingsGetPointerStandard()->nonMetricalSystem;
2089 data[datacounter++] = 1;
2090 break;
2091
2092 case 0x2F:
2093 data[datacounter++] = PARAM_INT8; // Sampling rate logbook
2094 data[datacounter++] = 2;
2095 data[datacounter++] = 2;
2096 data[datacounter++] = 2;
2097 break;
2098
2099 case 0x30:
2100 data[datacounter++] = PARAM_PERCENT;
2101 data[datacounter++] = 0;
2102 data[datacounter++] = settingsGetPointerStandard()->salinity;
2103 data[datacounter++] = 4;
2104 break;
2105
2106 case 0x31:
2107 data[datacounter++] = PARAM_INT8;
2108 data[datacounter++] = 0;
2109 data[datacounter++] = settingsGetPointerStandard()->tX_colorscheme;
2110 data[datacounter++] = 3;
2111 break;
2112
2113 case 0x32:
2114 data[datacounter++] = PARAM_ENUM;
2115 data[datacounter++] = 0;
2116 data[datacounter++] = settingsGetPointerStandard()->selected_language;
2117 data[datacounter++] = 1;
2118 break;
2119
2120 case 0x33:
2121 data[datacounter++] = PARAM_ENUM;
2122 data[datacounter++] = 0;
2123 data[datacounter++] = settingsGetPointerStandard()->date_format;
2124 data[datacounter++] = 2;
2125 break;
2126
2127 case 0x34:
2128 data[datacounter++] = PARAM_UNKNOWN ;
2129 data[datacounter++] = 0;
2130 data[datacounter++] = 0; // compass gain, is unknown,, settingsGetPointerStandard()->;
2131 data[datacounter++] = 0;
2132 break;
2133
2134 case 0x35:
2135 data[datacounter++] = PARAM_SINT;
2136 data[datacounter++] = (uint8_t)(256 - 20); // == -20
2137 if(settingsGetPointerStandard()->offsetPressure_mbar < 0)
2138 data[datacounter++] = (uint8_t)(127 - settingsGetPointerStandard()->offsetPressure_mbar);
2139 else
2140 data[datacounter++] = settingsGetPointerStandard()->offsetPressure_mbar;
2141 data[datacounter++] = 20;
2142 break;
2143
2144 case 0x36:
2145 data[datacounter++] = PARAM_BOOL;
2146 data[datacounter++] = 0;
2147 if(settingsGetPointerStandard()->safetystopDuration)
2148 data[datacounter++] = 1;
2149 else
2150 data[datacounter++] = 0;
2151 data[datacounter++] = 1;
2152 break;
2153
2154 case 0x37:
2155 data[datacounter++] = PARAM_UNKNOWN ;
2156 data[datacounter++] = 0;
2157 data[datacounter++] = 0; // Set calibration gas, not possible with optical
2158 data[datacounter++] = 0;
2159 break;
2160
2161 case 0x38:
2162 data[datacounter++] = PARAM_BOOL;
2163 data[datacounter++] = 0;
2164 data[datacounter++] = settingsGetPointerStandard()->fallbackToFixedSetpoint;
2165 data[datacounter++] = 1;
2166 break;
2167
2168 case 0x39:
2169 data[datacounter++] = PARAM_BOOL;
2170 data[datacounter++] = 0;
2171 data[datacounter++] = 0; // flipscreen, not yet :-) settingsGetPointerStandard()->;
2172 data[datacounter++] = 0;
2173 break;
2174
2175 case 0x3A:
2176 data[datacounter++] = PARAM_PERCENT;
2177 data[datacounter++] = 70;
2178 data[datacounter++] = settingsGetPointerStandard()->ButtonResponsiveness[3];
2179 data[datacounter++] = 110;
2180 break;
2181
2182 case 0x3B:
2183 data[datacounter++] = PARAM_UNKNOWN;
2184 data[datacounter++] = 0;
2185 data[datacounter++] = buttonBalanceTranslateArrayOutHex(settingsGetPointerStandard()->buttonBalance);
2186 data[datacounter++] = 128;
2187 break;
2188
2189 case 0x3C:
2190 data[datacounter++] = PARAM_INT8;
2191 data[datacounter++] = 5;
2192 data[datacounter++] = settingsGetPointerStandard()->gasConsumption_bottom_l_min;
2193 data[datacounter++] = 50;
2194 break;
2195
2196 case 0x3D:
2197 data[datacounter++] = PARAM_INT8;
2198 data[datacounter++] = 5;
2199 data[datacounter++] = settingsGetPointerStandard()->gasConsumption_deco_l_min;
2200 data[datacounter++] = 50;
2201 break;
2202
2203 case 0x3E:
2204 data[datacounter++] = PARAM_INT8;
2205 data[datacounter++] = 5;
2206 data[datacounter++] = settingsGetPointerStandard()->gasConsumption_travel_l_min;
2207 data[datacounter++] = 50;
2208 break;
2209
2210 case 0x3F:
2211 data[datacounter++] = PARAM_UNKNOWN;
2212 data[datacounter++] = 0;
2213 data[datacounter++] = 0; // Dynamic ascend rate, not yet :-) settingsGetPointerStandard()->;
2214 data[datacounter++] = 0;
2215 break;
2216
2217 case 0x40:
2218 data[datacounter++] = PARAM_BOOL;
2219 data[datacounter++] = 1;
2220 data[datacounter++] = 1; // Graphical speed indicator;
2221 data[datacounter++] = 1;
2222 break;
2223
2224 case 0x41:
2225 data[datacounter++] = PARAM_BOOL;
2226 data[datacounter++] = 0;
2227 data[datacounter++] = settingsGetPointerStandard()->alwaysShowPPO2;
2228 data[datacounter++] = 1;
2229 break;
2230
2231 case 0x42:
2232 data[datacounter++] = PARAM_SIGNED|PARAM_CENTI;
2233 data[datacounter++] = (uint8_t)(256 - 20); // == -20
2234 if(settingsGetPointerStandard()->offsetTemperature_centigrad < 0)
2235 data[datacounter++] = (uint8_t)(127 - settingsGetPointerStandard()->offsetTemperature_centigrad);
2236 else
2237 data[datacounter++] = settingsGetPointerStandard()->offsetTemperature_centigrad;
2238 data[datacounter++] = 20;
2239 break;
2240
2241 case 0x43:
2242 newDuration = settingsGetPointerStandard()->safetystopDuration;
2243 newDuration *= 60;
2244 if(newDuration > 255)
2245 newDuration = 255;
2246 data[datacounter++] = PARAM_INT8;
2247 data[datacounter++] = 60; // coud be 1 minute instead
2248 data[datacounter++] = (uint8_t)newDuration;
2249 data[datacounter++] = 255; // could be 5 minutes instead
2250 break;
2251
2252 case 0x44:
2253 data[datacounter++] = PARAM_INT8;
2254 data[datacounter++] = 30; // coud be 3 meter instead
2255 data[datacounter++] = settingsGetPointerStandard()->safetystopDepth * 10;
2256 data[datacounter++] = 60; // could be 6 meter instead
2257 break;
2258
2259 case 0x45:
2260 case 0x46:
2261 data[datacounter++] = PARAM_UNKNOWN;
2262 data[datacounter++] = 0;
2263 data[datacounter++] = 0; // SafetyStop End Depth and SafetyStop Reset Depth
2264 data[datacounter++] = 0;
2265 break;
2266
2267 case 0x47:
2268 data[datacounter++] = PARAM_INT15;
2269 data[datacounter++] = 0;
2270 data[datacounter++] = 0;
2271 data[datacounter++] = settingsGetPointerStandard()->logbookOffset & 0xFF;
2272 data[datacounter++] = settingsGetPointerStandard()->logbookOffset / 0xFF;
2273 data[datacounter++] = 9000 & 0xFF;
2274 data[datacounter++] = 9000 / 0xFF;
2275 break;
2276
2277 case 0x70:
2278 data[datacounter++] = PARAM_BOOL;
2279 data[datacounter++] = 0;
2280 data[datacounter++] = settingsGetPointerStandard()->showDebugInfo;
2281 data[datacounter++] = 1;
2282 break;
2283
2284 case 0x71:
2285 data[datacounter++] = PARAM_ENUM;
2286 data[datacounter++] = 0;
2287 data[datacounter++] = settingsGetPointerStandard()->extraDisplay;
2288 data[datacounter++] = (EXTRADISPLAY_END - 1);
2289 break;
2290
2291 case 0x72:
2292 data[datacounter++] = PARAM_ENUM;
2293 data[datacounter++] = 0;
2294 data[datacounter++] = settingsGetPointerStandard()->tX_customViewPrimary;
2295 data[datacounter++] = 8;
2296 break;
2297
2298 case 0x73:
2299 data[datacounter++] = PARAM_INT8;
2300 data[datacounter++] = 0;
2301 data[datacounter++] = settingsGetPointerStandard()->tX_customViewTimeout;
2302 data[datacounter++] = 60;
2303 break;
2304
2305 case 0x74:
2306 data[datacounter++] = PARAM_ENUM;
2307 data[datacounter++] = 1;
2308 data[datacounter++] = settingsGetPointerStandard()->tX_userselectedLeftLowerCornerPrimary;
2309 data[datacounter++] = 7;
2310 break;
2311
2312 case 0x75:
2313 data[datacounter++] = PARAM_INT8;
2314 data[datacounter++] = 0;
2315 data[datacounter++] = settingsGetPointerStandard()->tX_userselectedLeftLowerCornerTimeout;
2316 data[datacounter++] = 60;
2317 break;
2318 }
2319
2320 if(datacounter == 0)
2321 {
2322 data[datacounter++] = PARAM_UNKNOWN;
2323 data[datacounter++] = 0;
2324 data[datacounter++] = 0; // SafetyStop End Depth and SafetyStop Reset Depth
2325 data[datacounter++] = 0;
2326 }
2327
2328 return datacounter;
2329 }
2330
2331
2332 uint8_t readData(uint8_t what, uint8_t * data)
2333 {
2334 data[0] = 0;
2335 data[1] = 0;
2336 data[2] = 0;
2337 data[3] = 0;
2338 switch(what)
2339 {
2340 case 0x10:
2341 return getGas(1,data);
2342 case 0x11:
2343 return getGas(2,data);
2344 case 0x12:
2345 return getGas(3,data);
2346 case 0x13:
2347 return getGas(4,data);
2348 case 0x14:
2349 return getGas(5,data);
2350 case 0x15:
2351 return getDiluent(1,data);
2352 case 0x16:
2353 return getDiluent(2,data);
2354 case 0x17:
2355 return getDiluent(3,data);
2356 case 0x18:
2357 return getDiluent(4,data);
2358 case 0x19:
2359 return getDiluent(5,data);
2360 case 0x1A:
2361 return getSetpoint(1,data);
2362 case 0x1B:
2363 return getSetpoint(2,data);
2364 case 0x1C:
2365 return getSetpoint(3,data);
2366 case 0x1D:
2367 return getSetpoint(4,data);
2368 case 0x1E:
2369 return getSetpoint(5,data);
2370 case 0x1F:
2371 data[0] = Settings.CCR_Mode;
2372 break;
2373 case 0x20:
2374 data[0] = Settings.dive_mode;
2375 break;
2376 case 0x21:
2377 data[0] = Settings.deco_type.ub.standard;
2378 break;
2379 case 0x22:
2380 data[0] = Settings.ppO2_max_std;
2381 break;
2382 case 0x23:
2383 data[0] = Settings.ppO2_min;
2384 break;
2385 case 0x24:
2386 data[0] = Settings.future_TTS;
2387 break;
2388 case 0x25:
2389 data[0] = Settings.GF_low;
2390 break;
2391 case 0x26:
2392 data[0] = Settings.GF_high;
2393 break;
2394 case 0x27:
2395 data[0] = Settings.aGF_low;
2396 break;
2397 case 0x28:
2398 data[0] = Settings.aGF_high;
2399 break;
2400 case 0x29:
2401 data[0] = Settings.VPM_conservatism.ub.standard;
2402 break;
2403 case 0x2A:
2404 case 0x2B:
2405 data[0] = 100;
2406 break;
2407 case 0x2C:
2408 data[0] = Settings.last_stop_depth_meter;
2409 break;
2410 case 0x2D:
2411 data[0] = Settings.brightness;
2412 break;
2413 case 0x2E:
2414 data[0] = Settings.nonMetricalSystem;
2415 break;
2416 case 0x2F:
2417 data[0] = 0; // 0 == 2 sec sampling rate
2418 break;
2419 case 0x30:
2420 data[0] = Settings.salinity;
2421 break;
2422 case 0x31:
2423 data[0] = Settings.tX_colorscheme;
2424 break;
2425 case 0x32:
2426 data[0] = Settings.selected_language;
2427 break;
2428 case 0x33:
2429 data[0] = Settings.date_format;
2430 break;
2431 case 0x34:
2432 data[0] = 7; // gain should be always 7 as far as I understand the code in RTE
2433 break;
2434 case 0x35:
2435 data[0] = Settings.offsetPressure_mbar;
2436 break;
2437 case 0x36:
2438 if(Settings.safetystopDepth)
2439 data[0] = 1;
2440 else
2441 data[0] = 0;
2442 break;
2443 case 0x37:
2444 data[0] = 0; // calibration gas %O2 -> 0 no gas :-)
2445 break;
2446 case 0x38:
2447 data[0] = Settings.fallbackToFixedSetpoint;
2448 break;
2449 case 0x39:
2450 data[0] = 0; // flip screen
2451 break;
2452 case 0x3A:
2453 data[0] = Settings.ButtonResponsiveness[3];
2454 break;
2455 case 0x3B:
2456 data[0] = buttonBalanceTranslateArrayOutHex(settingsGetPointer()->buttonBalance);
2457 break;
2458 case 0x3C:
2459 data[0] = Settings.gasConsumption_bottom_l_min;
2460 break;
2461 case 0x3D:
2462 data[0] = Settings.gasConsumption_deco_l_min;
2463 break;
2464 case 0x3E:
2465 data[0] = Settings.gasConsumption_travel_l_min;
2466 break;
2467 case 0x3F:
2468 data[0] = 0; // fixed ascend rate 10 m/min
2469 break;
2470 case 0x40:
2471 data[0] = 1; // graphical speed indicator
2472 break;
2473 case 0x41:
2474 data[0] = Settings.alwaysShowPPO2;
2475 break;
2476 case 0x42:
2477 data[0] = Settings.offsetTemperature_centigrad;
2478 break;
2479 case 0x43:
2480 if(Settings.safetystopDuration > 4)
2481 data[0] = 255; // seconds
2482 else
2483 data[0] = 60 * Settings.safetystopDuration;
2484 break;
2485 case 0x44:
2486 data[0] = Settings.safetystopDepth * 10; // cbar instead of meter
2487 break;
2488 case 0x45:
2489 if(Settings.safetystopDepth == 3)
2490 data[0] = 20; // cbar
2491 else
2492 data[0] = 30; // cbar
2493 break;
2494 case 0x46:
2495 data[0] = 10; // reset at 10 meter as far as I understood
2496 break;
2497 case 0x47:
2498 data[0] = Settings.logbookOffset & 0xFF;
2499 data[1] = Settings.logbookOffset / 0xFF;
2500 break;
2501 case 0x70:
2502 data[0] = Settings.showDebugInfo;
2503 break;
2504 case 0x71:
2505 data[0] = Settings.extraDisplay;
2506 break;
2507 case 0x72:
2508 data[0] = Settings.tX_customViewPrimary;
2509 break;
2510 case 0x73:
2511 data[0] = Settings.tX_customViewTimeout;
2512 break;
2513 case 0x74:
2514 data[0] = Settings.tX_userselectedLeftLowerCornerPrimary;
2515 break;
2516 case 0x75:
2517 data[0] = Settings.tX_userselectedLeftLowerCornerTimeout;
2518 break;
2519 }
2520 return 0x4D;
2521 }
2522
2523
2524 uint8_t RTEminimum_required_high(void)
2525 {
2526 return RTErequiredHigh;
2527 }
2528 uint8_t RTEminimum_required_low(void)
2529 {
2530 return RTErequiredLow;
2531 }
2532
2533 uint8_t FONTminimum_required_high(void)
2534 {
2535 return FONTrequiredHigh;
2536 }
2537 uint8_t FONTminimum_required_low(void)
2538 {
2539 return FONTrequiredLow;
2540 }
2541
2542
2543 void setActualRTEversion(uint8_t high, uint8_t low)
2544 {
2545 RTEactualHigh = high;
2546 RTEactualLow = low;
2547 }
2548
2549
2550 void getActualRTEandFONTversion(uint8_t *RTEhigh, uint8_t *RTElow, uint8_t *FONThigh, uint8_t *FONTlow)
2551 {
2552 if(RTEhigh && RTElow)
2553 {
2554 *RTEhigh = RTEactualHigh;
2555 *RTElow = RTEactualLow;
2556 }
2557 if(FONThigh && FONTlow)
2558 {
2559 *FONThigh = *(uint8_t *)0x08132000;
2560 *FONTlow = *(uint8_t *)0x08132001;
2561 }
2562 }
2563
2564
2565 uint8_t getLicence(void)
2566 {
2567 //return 0xFF;
2568 //return LICENCEBONEX;
2569 return hardwareDataGetPointer()->primaryLicence;
2570 }
2571
2572
2573 void firmwareGetDate(RTC_DateTypeDef *SdateOutput)
2574 {
2575 SdateOutput->Year = firmwareDataGetPointer()->release_year;
2576 SdateOutput->Month = firmwareDataGetPointer()->release_month;
2577 SdateOutput->Date = firmwareDataGetPointer()->release_day;
2578 }
2579
2580
2581 // this should use device specific values stored in OTPROG ROM soon
2582 void getButtonFactorDefaults(uint8_t* basePercentage, uint8_t* buttonBalanceArray)
2583 {
2584 *basePercentage = settingsGetPointerStandard()->ButtonResponsiveness[3];
2585
2586 for(int i=0;i<3;i++)
2587 {
2588 buttonBalanceArray[i] = settingsGetPointerStandard()->buttonBalance[i];
2589 }
2590 }
2591
2592
2593 uint8_t buttonBalanceTranslatorHexToArray(uint8_t hexValue, uint8_t* outputArray)
2594 {
2595 if(hexValue > 127)
2596 return 0;
2597 // internal order: 0 = right, 1 = center, 2 = left
2598 // external order: Factory,left,center,right
2599 outputArray[0] = 2 + (hexValue & 0x03);
2600 hexValue /= 4;
2601 outputArray[1] = 2 + (hexValue & 0x03);
2602 hexValue /= 4;
2603 outputArray[2] = 2 + (hexValue & 0x03);
2604
2605 return 1;
2606 }
2607
2608
2609 uint8_t buttonBalanceTranslateArrayOutHex(const uint8_t* inputArray)
2610 {
2611 uint8_t hexValue = 0;
2612
2613 if(inputArray[2] > 2)
2614 {
2615 hexValue += inputArray[2] - 2;
2616 }
2617 hexValue *= 4;
2618
2619 if(inputArray[1] > 2)
2620 {
2621 hexValue += inputArray[1] - 2;
2622 }
2623 hexValue *= 4;
2624 if(inputArray[0] > 2)
2625 {
2626 hexValue += inputArray[0] - 2;
2627 }
2628 return hexValue;
2629 }
2630
2631 void settingsWriteFactoryDefaults(uint8_t inputValueRaw, uint8_t *inputBalanceArray)
2632 {
2633 if((inputValueRaw >= 70) && (inputValueRaw <= 110))
2634 {
2635 Settings.FactoryButtonBase = inputValueRaw;
2636 }
2637 for(int i=0;i<3;i++)
2638 {
2639 if((inputBalanceArray[i] >= 2) && (inputBalanceArray[i] <= 5))
2640 {
2641 Settings.FactoryButtonBalance[i] = inputBalanceArray[i];
2642 }
2643 }
2644 }
2645
2646
2647 /**
2648 ******************************************************************************
2649 * @brief settingsHelperButtonSens. / make 32 bit input to three buttons + storage value in [3]
2650 * @author heinrichs weikamp gmbh
2651 * @version V 01
2652 * @date 19-Sept-2016
2653 ******************************************************************************
2654 *
2655 * @param inputValueRaw:
2656 * @param outArray4Values: [0] is right, [1] is center, [2] is left, [3] is original value with zero balance
2657 * @retval None
2658 */
2659 void settingsHelperButtonSens_keepPercentageValues(uint32_t inputValueRaw, uint8_t *outArray4Values)
2660 {
2661 uint32_t newSensitivity;
2662
2663 if(inputValueRaw > 110)
2664 {
2665 inputValueRaw = 110;
2666 }
2667 else
2668 if(inputValueRaw < 70)
2669 {
2670 inputValueRaw = 70;
2671 }
2672
2673 // the unbalanced value
2674 outArray4Values[3] = inputValueRaw;
2675
2676 // the balanced values
2677 for(int i=0;i<3;i++)
2678 {
2679 newSensitivity = inputValueRaw;
2680 switch(settingsGetPointer()->buttonBalance[i])
2681 {
2682 case 1: // should not be an option hw 170508
2683 newSensitivity -= 20;
2684 break;
2685 case 2:
2686 newSensitivity -= 10;
2687 break;
2688 default:
2689 break;
2690 case 4:
2691 newSensitivity += 10;
2692 break;
2693 case 5:
2694 newSensitivity += 20;
2695 break;
2696 }
2697
2698 if(newSensitivity > 110)
2699 {
2700 newSensitivity = 110;
2701 }
2702 outArray4Values[i] = newSensitivity;
2703 }
2704 }
2705
2706
2707 /**
2708 ******************************************************************************
2709 * @brief settingsHelperButtonSens_translate_to_hwOS_values. / make 32 bit input to three buttons + storage value in [3]
2710 * @author heinrichs weikamp gmbh
2711 * @version V 01
2712 * @date 19-Sept-2016
2713 ******************************************************************************
2714 *
2715 * @param inputValueRaw:
2716 * @param outArray4Values: [0] is right, [1] is center, [2] is left, [3] is original value with zero balance
2717 * @retval None
2718 */
2719 void settingsHelperButtonSens_original_translate_to_hwOS_values(const uint32_t inputValueRaw, uint8_t *outArray4Values)
2720 {
2721 uint32_t newSensitivity;
2722
2723 for(int i=0;i<3;i++)
2724 {
2725 newSensitivity = inputValueRaw;
2726 switch(settingsGetPointer()->buttonBalance[i])
2727 {
2728 case 1:
2729 newSensitivity -= 20;
2730 break;
2731 case 2:
2732 newSensitivity -= 10;
2733 break;
2734 default:
2735 break;
2736 case 4:
2737 newSensitivity += 10;
2738 break;
2739 case 5:
2740 newSensitivity += 20;
2741 break;
2742 }
2743
2744 if(newSensitivity > 100)
2745 {
2746 if(newSensitivity <= 105)
2747 newSensitivity = 10;
2748 else
2749 newSensitivity = 7;
2750 }
2751 else
2752 {
2753 newSensitivity *= 24;
2754 newSensitivity = 2400 - newSensitivity;
2755 newSensitivity /= 10;
2756
2757 newSensitivity += 15;
2758 if(newSensitivity > 255)
2759 newSensitivity = 255;
2760 }
2761 outArray4Values[i] = newSensitivity;
2762 }
2763
2764 // the unbalanced value
2765 newSensitivity = inputValueRaw;
2766 if(newSensitivity > 100)
2767 {
2768 if(newSensitivity <= 105)
2769 newSensitivity = 10;
2770 else
2771 newSensitivity = 7;
2772 }
2773 else
2774 {
2775 newSensitivity *= 24;
2776 newSensitivity = 2400 - newSensitivity;
2777 newSensitivity /= 10;
2778
2779 newSensitivity += 15;
2780 if(newSensitivity > 255)
2781 newSensitivity = 255;
2782 }
2783 outArray4Values[3] = newSensitivity;
2784 }
2785
2786
2787 /**
2788 ******************************************************************************
2789 * @brief settingsHelperButtonSens_translate_percentage_to_hwOS_values.
2790 * @author heinrichs weikamp gmbh
2791 * @version V 01
2792 * @date 6-March-2017
2793 ******************************************************************************
2794 *
2795 * @param inputValuePercentage with buttonBalance included
2796 * @retval PIC compatible value
2797 */
2798 uint8_t settingsHelperButtonSens_translate_percentage_to_hwOS_values(uint8_t inputValuePercentage)
2799 {
2800 uint32_t newSensitivity = inputValuePercentage;
2801
2802 if(newSensitivity > 100)
2803 {
2804 if(newSensitivity <= 105)
2805 newSensitivity = 10;
2806 else
2807 newSensitivity = 7;
2808 }
2809 else
2810 {
2811 newSensitivity *= 24;
2812 newSensitivity = 2400 - newSensitivity;
2813 newSensitivity /= 10;
2814
2815 newSensitivity += 15;
2816 if(newSensitivity > 255)
2817 newSensitivity = 255;
2818 }
2819 return (uint8_t)newSensitivity;
2820 }
2821
2822
2823 /**
2824 ******************************************************************************
2825 * @brief settingsHelperButtonSens_translate_hwOS_values_to_percentage.
2826 * @author heinrichs weikamp gmbh
2827 * @version V 01
2828 * @date 6-March-2017
2829 ******************************************************************************
2830 *
2831 * @param PIC compatible value
2832 * @retval Percentage
2833 */
2834 uint8_t settingsHelperButtonSens_translate_hwOS_values_to_percentage(uint8_t inputValuePIC)
2835 {
2836 if(inputValuePIC >= 15)
2837 {
2838 return(uint8_t)((25500 - (inputValuePIC)*100) / 240);
2839 }
2840 else
2841 {
2842 if(inputValuePIC >= 10)
2843 {
2844 return 105;
2845 }
2846 else
2847 {
2848 return 110;
2849 }
2850 }
2851 }