comparison Discovery/Src/settings.c @ 696:cc542448fb28

Merge
author heinrichsweikamp
date Fri, 19 Aug 2022 11:30:24 +0200
parents 49b164022335
children 8adf9b8fc7fa
comparison
equal deleted inserted replaced
661:87bee7cc77b3 696:cc542448fb28
34 #include "tHome.h" // for CVIEW_END 34 #include "tHome.h" // for CVIEW_END
35 #include "motion.h" 35 #include "motion.h"
36 #include "t7.h" 36 #include "t7.h"
37 #include "data_central.h" 37 #include "data_central.h"
38 38
39 static uint8_t settingsWarning = 0; /* Active if setting values have been corrected */
40
39 SSettings Settings; 41 SSettings Settings;
40 42
41 const uint8_t RTErequiredHigh = 2; 43 const uint8_t RTErequiredHigh = 2;
42 const uint8_t RTErequiredLow = 7; 44 const uint8_t RTErequiredLow = 9;
43 45
44 const uint8_t FONTrequiredHigh = 1; 46 const uint8_t FONTrequiredHigh = 1;
45 const uint8_t FONTrequiredLow = 0; 47 const uint8_t FONTrequiredLow = 0;
46 48
47 uint8_t RTEactualHigh = 0; 49 uint8_t RTEactualHigh = 0;
55 // =============================================================================== 57 // ===============================================================================
56 58
57 const SFirmwareData firmware_FirmwareData __attribute__( (section(".firmware_firmware_data")) ) = 59 const SFirmwareData firmware_FirmwareData __attribute__( (section(".firmware_firmware_data")) ) =
58 { 60 {
59 .versionFirst = 1, 61 .versionFirst = 1,
60 .versionSecond = 5, 62 .versionSecond = 6,
61 .versionThird = 8, 63 .versionThird = 0,
62 .versionBeta = 1, 64 .versionBeta = 0,
63 65
64 /* 4 bytes with trailing 0 */ 66 /* 4 bytes with trailing 0 */
65 .signature = "mh", 67 .signature = "mh",
66 68
67 .release_year = 21, 69 .release_year = 22,
68 .release_month = 04, 70 .release_month = 8,
69 .release_day = 26, 71 .release_day = 19,
70 .release_sub = 0, 72 .release_sub = 0,
71 73
72 /* max 48 with trailing 0 */ 74 /* max 48 with trailing 0 */
73 //release_info ="12345678901234567890123456789012345678901" 75 //release_info ="12345678901234567890123456789012345678901"
74 .release_info ="gcc_2nd", 76 .release_info ="gcc_2nd",
83 85
84 /* always adjust check_and_correct_settings() accordingly 86 /* always adjust check_and_correct_settings() accordingly
85 * There might even be entries with fixed values that have no range 87 * There might even be entries with fixed values that have no range
86 */ 88 */
87 const SSettings SettingsStandard = { 89 const SSettings SettingsStandard = {
88 .header = 0xFFFF001F, 90 .header = 0xFFFF0022,
89 .warning_blink_dsec = 8 * 2, 91 .warning_blink_dsec = 8 * 2,
90 .lastDiveLogId = 0, 92 .lastDiveLogId = 0,
91 .logFlashNextSampleStartAddress = 0, 93 .logFlashNextSampleStartAddress = SAMPLESTART,
92 94
93 .gas[0].oxygen_percentage = 21, 95 .gas[0].oxygen_percentage = 21,
94 .gas[1].oxygen_percentage = 21, 96 .gas[1].oxygen_percentage = 21,
95 .gas[2].oxygen_percentage = 21, 97 .gas[2].oxygen_percentage = 21,
96 .gas[3].oxygen_percentage = 21, 98 .gas[3].oxygen_percentage = 21,
217 .ppO2_max_deco = 160, 219 .ppO2_max_deco = 160,
218 .ppO2_max_std = 140, 220 .ppO2_max_std = 140,
219 .ppO2_min = 15, 221 .ppO2_min = 15,
220 .CNS_max = 90, 222 .CNS_max = 90,
221 .ascent_MeterPerMinute_max = 30, 223 .ascent_MeterPerMinute_max = 30,
222 .ascent_MeterPerMinute_showGraph = 7, 224 .ascent_MeterPerMinute_showGraph = 30,
223 .future_TTS = 5, 225 .future_TTS = 5,
224 .GF_high = 85, 226 .GF_high = 85,
225 .GF_low = 30, 227 .GF_low = 30,
226 .aGF_high = 95, 228 .aGF_high = 95,
227 .aGF_low = 95, 229 .aGF_low = 95,
266 .nonMetricalSystem = 0, 268 .nonMetricalSystem = 0,
267 .fallbackToFixedSetpoint = 1, 269 .fallbackToFixedSetpoint = 1,
268 .bluetoothActive = 0, 270 .bluetoothActive = 0,
269 .safetystopDepth = 5, 271 .safetystopDepth = 5,
270 .updateSettingsAllowedFromHeader = 0xFFFF0002, 272 .updateSettingsAllowedFromHeader = 0xFFFF0002,
271 .scooterControl = 0, 273 .pscr_lung_ratio = 10,
272 .scooterDrag = 2, 274 .pscr_o2_drop = 4,
273 .scooterLoad = 2, 275 .co2_sensor_active = 0,
274 .scooterNumberOfBatteries = 1,
275 .scooterBattSize = 760,
276 .scooterSPARE1[0] = 0,
277 .scooterSPARE2[0] = 0,
278 .ppo2sensors_deactivated = 0, 276 .ppo2sensors_deactivated = 0,
279 .tX_colorscheme = 0, 277 .tX_colorscheme = 0,
280 .tX_userselectedLeftLowerCornerPrimary = LLC_Temperature, 278 .tX_userselectedLeftLowerCornerPrimary = LLC_Temperature,
281 .tX_userselectedLeftLowerCornerTimeout = 0, 279 .tX_userselectedLeftLowerCornerTimeout = 0,
282 .tX_customViewPrimary = 1, 280 .tX_customViewPrimary = 1,
368 settingsGetPointer()->firmwareVersion[2] = firmware_FirmwareData.versionThird; 366 settingsGetPointer()->firmwareVersion[2] = firmware_FirmwareData.versionThird;
369 settingsGetPointer()->firmwareVersion[3] = firmware_FirmwareData.versionBeta; 367 settingsGetPointer()->firmwareVersion[3] = firmware_FirmwareData.versionBeta;
370 368
371 SSettings* pSettings = settingsGetPointer(); 369 SSettings* pSettings = settingsGetPointer();
372 const SSettings* pStandard = settingsGetPointerStandard(); 370 const SSettings* pStandard = settingsGetPointerStandard();
373
374 pSettings->scooterControl = 0;
375 371
376 /* Pointing to the old header data => set new data depending on what had been added since last version */ 372 /* Pointing to the old header data => set new data depending on what had been added since last version */
377 switch(pSettings->header) 373 switch(pSettings->header)
378 { 374 {
379 case 0xFFFF0000: 375 case 0xFFFF0000:
431 pSettings->debugModeOnStart = 0; 427 pSettings->debugModeOnStart = 0;
432 // no break 428 // no break
433 case 0xFFFF000F: 429 case 0xFFFF000F:
434 pSettings->compassBearing = 0; 430 pSettings->compassBearing = 0;
435 // no break 431 // no break
436 case 0xFFFF0010:
437 pSettings->scooterDrag = 2;
438 pSettings->scooterLoad = 2;
439 pSettings->scooterSPARE1[0] = 0;
440 pSettings->scooterSPARE2[0] = 0;
441 // no break
442 case 0xFFFF0011: 432 case 0xFFFF0011:
443 pSettings->scooterNumberOfBatteries = 1;
444 pSettings->scooterBattSize = 760;
445 pSettings->lastKnownBatteryPercentage = 0; 433 pSettings->lastKnownBatteryPercentage = 0;
446 // no break 434 // no break
447 case 0xFFFF0012: 435 case 0xFFFF0012:
448 pSettings->buttonBalance[0] = 3; 436 pSettings->buttonBalance[0] = 3;
449 pSettings->buttonBalance[1] = 3; 437 pSettings->buttonBalance[1] = 3;
494 case 0xFFFF001D: 482 case 0xFFFF001D:
495 pSettings->ppo2sensors_source = O2_SENSOR_SOURCE_OPTIC; 483 pSettings->ppo2sensors_source = O2_SENSOR_SOURCE_OPTIC;
496 pSettings->ppo2sensors_calibCoeff[0] = 0.0; 484 pSettings->ppo2sensors_calibCoeff[0] = 0.0;
497 pSettings->ppo2sensors_calibCoeff[1] = 0.0; 485 pSettings->ppo2sensors_calibCoeff[1] = 0.0;
498 pSettings->ppo2sensors_calibCoeff[2] = 0.0; 486 pSettings->ppo2sensors_calibCoeff[2] = 0.0;
487 pSettings->amPMTime = 0;
499 // no break 488 // no break
489 case 0xFFFF001E:
490 pSettings->autoSetpoint = 0;
491 pSettings->scrubTimerMax = 0;
492 pSettings->scrubTimerCur = 0;
493 pSettings->scrubTimerMode = SCRUB_TIMER_OFF;
494 // no break
495 case 0xFFFF001F:
496 pSettings->pscr_lung_ratio = 10;
497 pSettings->pscr_o2_drop = 4;
498 // no break
499 case 0xFFFF0020:
500 pSettings->co2_sensor_active = 0;
501 // no break;
502 case 0xFFFF0021:
503 pSettings->ext_uart_protocol = 0;
504 // no break;
500 default: 505 default:
501 pSettings->header = pStandard->header; 506 pSettings->header = pStandard->header;
502 break; // no break before!! 507 break; // no break before!!
503 } 508 }
504 } 509 }
534 { 539 {
535 uint32_t corrections = 0; 540 uint32_t corrections = 0;
536 uint8_t firstGasFoundOC = 0; 541 uint8_t firstGasFoundOC = 0;
537 uint8_t firstGasFoundCCR = 0; 542 uint8_t firstGasFoundCCR = 0;
538 543
544
545 settingsWarning = 0; /* reset warning indicator */
546
539 /* uint32_t header; 547 /* uint32_t header;
540 */ 548 */
541 549
542 /* uint8_t warning_blink_dsec; 1/10 seconds 550 /* uint8_t warning_blink_dsec; 1/10 seconds
543 */ 551 */
562 /* uint8_t dive_mode; has to before the gases 570 /* uint8_t dive_mode; has to before the gases
563 */ 571 */
564 if( (Settings.dive_mode != DIVEMODE_OC) && 572 if( (Settings.dive_mode != DIVEMODE_OC) &&
565 (Settings.dive_mode != DIVEMODE_CCR) && 573 (Settings.dive_mode != DIVEMODE_CCR) &&
566 (Settings.dive_mode != DIVEMODE_Gauge) && 574 (Settings.dive_mode != DIVEMODE_Gauge) &&
567 (Settings.dive_mode != DIVEMODE_Apnea) ) 575 (Settings.dive_mode != DIVEMODE_Apnea) &&
576 (Settings.dive_mode != DIVEMODE_PSCR))
568 { 577 {
569 Settings.dive_mode = DIVEMODE_OC; 578 Settings.dive_mode = DIVEMODE_OC;
570 corrections++; 579 corrections++;
571 } 580 }
572 581
616 corrections++; 625 corrections++;
617 } 626 }
618 } 627 }
619 if(Settings.gas[i].note.ub.first) 628 if(Settings.gas[i].note.ub.first)
620 { 629 {
621 if(Settings.setpoint[i].note.ub.active != 1) 630 if(Settings.gas[i].note.ub.active != 1)
622 { 631 {
623 Settings.setpoint[i].note.ub.active = 1; 632 Settings.gas[i].note.ub.active = 1;
624 corrections++; 633 corrections++;
625 } 634 }
626 if(Settings.gas[i].note.ub.travel == 1) 635 if(Settings.gas[i].note.ub.travel == 1)
627 { 636 {
628 Settings.gas[i].note.ub.travel = 0; 637 Settings.gas[i].note.ub.travel = 0;
669 { 678 {
670 Settings.gas[1].note.ub.active = 1; 679 Settings.gas[1].note.ub.active = 1;
671 Settings.gas[1].note.ub.first = 1; 680 Settings.gas[1].note.ub.first = 1;
672 Settings.gas[1].note.ub.travel = 0; 681 Settings.gas[1].note.ub.travel = 0;
673 Settings.gas[1].note.ub.deco = 0; 682 Settings.gas[1].note.ub.deco = 0;
683 corrections++;
674 } 684 }
675 if(!firstGasFoundCCR) 685 if(!firstGasFoundCCR)
676 { 686 {
677 Settings.gas[1 + NUM_GASES].note.ub.active = 1; 687 Settings.gas[1 + NUM_GASES].note.ub.active = 1;
678 Settings.gas[1 + NUM_GASES].note.ub.first = 1; 688 Settings.gas[1 + NUM_GASES].note.ub.first = 1;
679 Settings.gas[1 + NUM_GASES].note.ub.travel = 0; 689 Settings.gas[1 + NUM_GASES].note.ub.travel = 0;
680 Settings.gas[1 + NUM_GASES].note.ub.deco = 0; 690 Settings.gas[1 + NUM_GASES].note.ub.deco = 0;
691 corrections++;
681 } 692 }
682 /* SSetpointLine setpoint[1 + NUM_GASES]; 693 /* SSetpointLine setpoint[1 + NUM_GASES];
683 */ 694 */
684 for(int i=1; i<=NUM_GASES;i++) 695 for(int i=1; i<=NUM_GASES;i++)
685 { 696 {
745 } // for(int i=1; i<=NUM_GASES;i++) 756 } // for(int i=1; i<=NUM_GASES;i++)
746 757
747 /* uint8_t CCR_Mode; 758 /* uint8_t CCR_Mode;
748 */ 759 */
749 if( (Settings.CCR_Mode != CCRMODE_Sensors) && 760 if( (Settings.CCR_Mode != CCRMODE_Sensors) &&
761 (Settings.CCR_Mode != CCRMODE_Simulation) &&
750 (Settings.CCR_Mode != CCRMODE_FixedSetpoint)) 762 (Settings.CCR_Mode != CCRMODE_FixedSetpoint))
751 { 763 {
752 Settings.CCR_Mode = CCRMODE_FixedSetpoint; 764 Settings.CCR_Mode = CCRMODE_FixedSetpoint;
753 corrections++; 765 corrections++;
754 } 766 }
1459 if(Settings.scrubTimerMode > SCRUB_TIMER_END) 1471 if(Settings.scrubTimerMode > SCRUB_TIMER_END)
1460 { 1472 {
1461 Settings.scrubTimerMode = SCRUB_TIMER_OFF; 1473 Settings.scrubTimerMode = SCRUB_TIMER_OFF;
1462 corrections++; 1474 corrections++;
1463 } 1475 }
1476
1477 if((Settings.pscr_lung_ratio > PSCR_MAX_LUNG_RATIO) || (Settings.pscr_lung_ratio < PSCR_MIN_LUNG_RATIO))
1478 {
1479 Settings.pscr_lung_ratio = 10;
1480 corrections++;
1481 }
1482 if(Settings.pscr_o2_drop > PSCR_MAX_O2_DROP)
1483 {
1484 Settings.pscr_o2_drop = 4;
1485 corrections++;
1486 }
1487
1488 if(Settings.co2_sensor_active > 1)
1489 {
1490 Settings.co2_sensor_active = 0;
1491 corrections++;
1492 }
1493 if(Settings.co2_sensor_active > UART_MAX_PROTOCOL)
1494 {
1495 Settings.ext_uart_protocol = 0;
1496 corrections++;
1497 }
1498
1499 if(corrections)
1500 {
1501 settingsWarning = 1;
1502 }
1503 else
1504
1464 if(corrections > 255) 1505 if(corrections > 255)
1465 return 255; 1506 {
1466 else 1507 corrections = 255;
1467 return (uint8_t)corrections; 1508 }
1509
1510 return (uint8_t)corrections;
1468 } 1511 }
1469 1512
1470 1513
1471 /* always at 0x8080000, do not move -> bootloader access */ 1514 /* always at 0x8080000, do not move -> bootloader access */
1472 const SFirmwareData* firmwareDataGetPointer(void) 1515 const SFirmwareData* firmwareDataGetPointer(void)
2919 { 2962 {
2920 return 110; 2963 return 110;
2921 } 2964 }
2922 } 2965 }
2923 } 2966 }
2967
2968 void reset_SettingWarning()
2969 {
2970 settingsWarning = 0;
2971 }
2972 inline uint8_t isSettingsWarning()
2973 {
2974 return settingsWarning;
2975 }
2976