comparison Discovery/Src/settings.c @ 993:df052f0347fb GasConsumption

Add settings that have been missing in the bluetooth API: flip display compass declination (mikeller)
author heinrichsweikamp
date Fri, 25 Apr 2025 08:26:03 +0200
parents d63584d6428d
children bad5561c0c59
comparison
equal deleted inserted replaced
990:d63584d6428d 993:df052f0347fb
31 #include "settings.h" 31 #include "settings.h"
32 #include "firmwareEraseProgram.h" // for HARDWAREDATA_ADDRESS 32 #include "firmwareEraseProgram.h" // for HARDWAREDATA_ADDRESS
33 #include "externLogbookFlash.h" // for SAMPLESTART and SAMPLESTOP 33 #include "externLogbookFlash.h" // for SAMPLESTART and SAMPLESTOP
34 #include "text_multilanguage.h" // for LANGUAGE_END 34 #include "text_multilanguage.h" // for LANGUAGE_END
35 #include "tHome.h" // for CVIEW_END 35 #include "tHome.h" // for CVIEW_END
36 #include "tMenu.h"
37 #include "tMenuEdit.h"
38 #include "tInfo.h"
39 #include "tInfoLog.h"
36 #include "motion.h" 40 #include "motion.h"
37 #include "t7.h" 41 #include "t7.h"
38 #include "data_central.h" 42 #include "data_central.h"
39 43
40 static uint8_t settingsWarning = 0; /* Active if setting values have been corrected */ 44 static uint8_t settingsWarning = 0; /* Active if setting values have been corrected */
349 /* Private function prototypes -----------------------------------------------*/ 353 /* Private function prototypes -----------------------------------------------*/
350 uint8_t checkValue(uint8_t value,uint8_t from, uint8_t to); 354 uint8_t checkValue(uint8_t value,uint8_t from, uint8_t to);
351 355
352 /* Functions -----------------------------------------------------------------*/ 356 /* Functions -----------------------------------------------------------------*/
353 357
358 void setFlipDisplay(uint8_t flipDisplay)
359 {
360 bool settingChanged = flipDisplay != Settings.FlipDisplay;
361 Settings.FlipDisplay = flipDisplay;
362 if (settingChanged) {
363 // reinit all views
364 tHome_init();
365 tI_init();
366 tM_init();
367 tMenuEdit_init();
368 tInfoLog_init();
369 tM_build_pages();
370 GFX_build_logo_frame();
371 GFX_build_hw_background_frame();
372 }
373 }
374
354 375
355 // =============================================================================== 376 // ===============================================================================
356 // set_new_settings_missing_in_ext_flash 377 // set_new_settings_missing_in_ext_flash
357 /// @brief Add all the new setting variables of this version 378 /// @brief Add all the new setting variables of this version
358 /// or/and change what has changed in the meantime 379 /// or/and change what has changed in the meantime
474 pSettings->FactoryButtonBalance[0] = pStandard->FactoryButtonBalance[0]; 495 pSettings->FactoryButtonBalance[0] = pStandard->FactoryButtonBalance[0];
475 pSettings->FactoryButtonBalance[1] = pStandard->FactoryButtonBalance[1]; 496 pSettings->FactoryButtonBalance[1] = pStandard->FactoryButtonBalance[1];
476 pSettings->FactoryButtonBalance[2] = pStandard->FactoryButtonBalance[2]; 497 pSettings->FactoryButtonBalance[2] = pStandard->FactoryButtonBalance[2];
477 // no break 498 // no break
478 case 0xFFFF0017: 499 case 0xFFFF0017:
479 pSettings->FlipDisplay = 0; 500 setFlipDisplay(0);
480 // no break 501 // no break
481 case 0xFFFF0018: 502 case 0xFFFF0018:
482 pSettings->cv_configuration = 0xFFFFFFFF; 503 pSettings->cv_configuration = 0xFFFFFFFF;
483 // no break 504 // no break
484 case 0xFFFF0019: 505 case 0xFFFF0019:
485 pSettings->MotionDetection = MOTION_DETECT_OFF; 506 pSettings->MotionDetection = MOTION_DETECT_OFF;
1676 Settings.GF_model = BUEHLMANN_OSTC4; 1697 Settings.GF_model = BUEHLMANN_OSTC4;
1677 corrections++; 1698 corrections++;
1678 setFirstCorrection(parameterId); 1699 setFirstCorrection(parameterId);
1679 } 1700 }
1680 parameterId++; 1701 parameterId++;
1681 if(Settings.FlipDisplay > 1) /* only boolean values allowed */ 1702 if(Settings.FlipDisplay > 1) { /* only boolean values allowed */
1682 { 1703 setFlipDisplay(1);
1683 Settings.FlipDisplay = 0;
1684 corrections++; 1704 corrections++;
1685 setFirstCorrection(parameterId); 1705 setFirstCorrection(parameterId);
1686 } 1706 }
1687 parameterId++; 1707 parameterId++;
1688 #ifdef ENABLE_MOTION_CONTROL 1708 #ifdef ENABLE_MOTION_CONTROL
1689 if(Settings.MotionDetection >= MOTION_DETECT_END) 1709 if(Settings.MotionDetection >= MOTION_DETECT_END)
1690 { 1710 {
1691 Settings.MotionDetection = MOTION_DETECT_OFF; 1711 Settings.MotionDetection = MOTION_DETECT_OFF;
1829 Settings.buttonLockActive = 1; 1849 Settings.buttonLockActive = 1;
1830 corrections++; 1850 corrections++;
1831 setFirstCorrection(parameterId); 1851 setFirstCorrection(parameterId);
1832 } 1852 }
1833 parameterId++; 1853 parameterId++;
1834 if (Settings.compassDeclinationDeg > 99) { 1854 if (Settings.compassDeclinationDeg > MAX_COMPASS_DECLINATION_DEG) {
1835 Settings.compassDeclinationDeg = 99; 1855 Settings.compassDeclinationDeg = MAX_COMPASS_DECLINATION_DEG;
1836 1856
1837 corrections++; 1857 corrections++;
1838 setFirstCorrection(parameterId); 1858 setFirstCorrection(parameterId);
1839 } else if (Settings.compassDeclinationDeg < -99) { 1859 } else if (Settings.compassDeclinationDeg < -MAX_COMPASS_DECLINATION_DEG) {
1840 Settings.compassDeclinationDeg = -99; 1860 Settings.compassDeclinationDeg = -MAX_COMPASS_DECLINATION_DEG;
1841 1861
1842 corrections++; 1862 corrections++;
1843 setFirstCorrection(parameterId); 1863 setFirstCorrection(parameterId);
1844 } 1864 }
1845 parameterId++; 1865 parameterId++;
2116 uint8_t checkValue(uint8_t value,uint8_t from, uint8_t to) 2136 uint8_t checkValue(uint8_t value,uint8_t from, uint8_t to)
2117 { 2137 {
2118 if(value >= from && value <= to) 2138 if(value >= from && value <= to)
2119 return 1; 2139 return 1;
2120 return 0; 2140 return 0;
2141 }
2142
2143 bool checkValueSigned(int8_t value, int8_t from, int8_t to)
2144 {
2145 if(value >= from && value <= to)
2146 return true;
2147 return false;
2121 } 2148 }
2122 2149
2123 uint8_t writeData(uint8_t * data) 2150 uint8_t writeData(uint8_t * data)
2124 { 2151 {
2125 uint32_t newSensitivity; 2152 uint32_t newSensitivity;
2254 if(!checkValue(data[1],0,2)) 2281 if(!checkValue(data[1],0,2))
2255 return ERROR_; 2282 return ERROR_;
2256 Settings.date_format = data[1]; 2283 Settings.date_format = data[1];
2257 break; 2284 break;
2258 case 0x34: 2285 case 0x34:
2286 if (!checkValueSigned(data[1], -MAX_COMPASS_DECLINATION_DEG, MAX_COMPASS_DECLINATION_DEG))
2259 return ERROR_; 2287 return ERROR_;
2288 Settings.compassDeclinationDeg = (int8_t)data[1];
2289
2290 break;
2260 case 0x35: 2291 case 0x35:
2261 if(data[1] & 0x80) 2292 if(data[1] & 0x80)
2262 { 2293 {
2263 data[1] = ~(data[1]); 2294 data[1] = ~(data[1]);
2264 if(!checkValue(data[1],0,PRESSURE_OFFSET_LIMIT_MBAR)) 2295 if(!checkValue(data[1],0,PRESSURE_OFFSET_LIMIT_MBAR))
2286 if(!checkValue(data[1],0,1)) 2317 if(!checkValue(data[1],0,1))
2287 return ERROR_; 2318 return ERROR_;
2288 Settings.fallbackToFixedSetpoint = data[1]; 2319 Settings.fallbackToFixedSetpoint = data[1];
2289 break; 2320 break;
2290 case 0x39: 2321 case 0x39:
2322 if (!checkValue(data[1], 0, 1))
2291 return ERROR_; 2323 return ERROR_;
2324 setFlipDisplay(data[1]);
2325
2326 break;
2292 case 0x3A: 2327 case 0x3A:
2293 if(!checkValue(data[1],70,110)) 2328 if(!checkValue(data[1],70,110))
2294 return ERROR_; 2329 return ERROR_;
2295 newSensitivity = data[1]; 2330 newSensitivity = data[1];
2296 settingsHelperButtonSens_keepPercentageValues(newSensitivity, settingsGetPointer()->ButtonResponsiveness); 2331 settingsHelperButtonSens_keepPercentageValues(newSensitivity, settingsGetPointer()->ButtonResponsiveness);
2615 data[datacounter++] = settingsGetPointerStandard()->date_format; 2650 data[datacounter++] = settingsGetPointerStandard()->date_format;
2616 data[datacounter++] = 2; 2651 data[datacounter++] = 2;
2617 break; 2652 break;
2618 2653
2619 case 0x34: 2654 case 0x34:
2620 data[datacounter++] = PARAM_UNKNOWN ; 2655 data[datacounter++] = PARAM_SINT;
2621 data[datacounter++] = 0; 2656 data[datacounter++] = (uint8_t)-MAX_COMPASS_DECLINATION_DEG;
2622 data[datacounter++] = 0; // compass gain, is unknown,, settingsGetPointerStandard()->; 2657 data[datacounter++] = (uint8_t)settingsGetPointerStandard()->compassDeclinationDeg;
2623 data[datacounter++] = 0; 2658 data[datacounter++] = MAX_COMPASS_DECLINATION_DEG;
2624 break; 2659 break;
2625 2660
2626 case 0x35: 2661 case 0x35:
2627 data[datacounter++] = PARAM_SINT; 2662 data[datacounter++] = PARAM_SINT;
2628 data[datacounter++] = (uint8_t)(256 - PRESSURE_OFFSET_LIMIT_MBAR); // == -20 2663 data[datacounter++] = (uint8_t)(256 - PRESSURE_OFFSET_LIMIT_MBAR); // == -20
2658 break; 2693 break;
2659 2694
2660 case 0x39: 2695 case 0x39:
2661 data[datacounter++] = PARAM_BOOL; 2696 data[datacounter++] = PARAM_BOOL;
2662 data[datacounter++] = 0; 2697 data[datacounter++] = 0;
2663 data[datacounter++] = 0; // flipscreen, not yet :-) settingsGetPointerStandard()->; 2698 data[datacounter++] = settingsGetPointerStandard()->FlipDisplay;
2664 data[datacounter++] = 0; 2699 data[datacounter++] = 1;
2665 break; 2700 break;
2666 2701
2667 case 0x3A: 2702 case 0x3A:
2668 data[datacounter++] = PARAM_PERCENT; 2703 data[datacounter++] = PARAM_PERCENT;
2669 data[datacounter++] = 70; 2704 data[datacounter++] = 70;
2919 break; 2954 break;
2920 case 0x33: 2955 case 0x33:
2921 data[0] = Settings.date_format; 2956 data[0] = Settings.date_format;
2922 break; 2957 break;
2923 case 0x34: 2958 case 0x34:
2924 data[0] = 7; // gain should be always 7 as far as I understand the code in RTE 2959 data[0] = (uint8_t)Settings.compassDeclinationDeg;
2925 break; 2960 break;
2926 case 0x35: 2961 case 0x35:
2927 data[0] = Settings.offsetPressure_mbar; 2962 data[0] = Settings.offsetPressure_mbar;
2928 break; 2963 break;
2929 case 0x36: 2964 case 0x36:
2937 break; 2972 break;
2938 case 0x38: 2973 case 0x38:
2939 data[0] = Settings.fallbackToFixedSetpoint; 2974 data[0] = Settings.fallbackToFixedSetpoint;
2940 break; 2975 break;
2941 case 0x39: 2976 case 0x39:
2942 data[0] = 0; // flip screen 2977 data[0] = Settings.FlipDisplay;
2943 break; 2978 break;
2944 case 0x3A: 2979 case 0x3A:
2945 data[0] = Settings.ButtonResponsiveness[3]; 2980 data[0] = Settings.ButtonResponsiveness[3];
2946 break; 2981 break;
2947 case 0x3B: 2982 case 0x3B: