changeset 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 (8 days ago)
parents d63584d6428d
children bad5561c0c59
files Common/Inc/settings.h Discovery/Inc/tMenu.h Discovery/Src/settings.c Discovery/Src/tMenuEditHardware.c
diffstat 4 files changed, 64 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/settings.h	Sat Apr 12 12:21:49 2025 +0200
+++ b/Common/Inc/settings.h	Fri Apr 25 08:26:03 2025 +0200
@@ -76,6 +76,9 @@
 #define PRESSURE_OFFSET_LIMIT_MBAR	50
 
 #define MAX_COMPASS_COMP 		(2u)
+
+#define MAX_COMPASS_DECLINATION_DEG 99
+
 #define MAX_VIEWPORT_MODE 		(0x7F)
 
 #define MAX_SCRUBBER_TIME 		(999u)
@@ -382,6 +385,7 @@
 void setActualRTEversion(uint8_t high, uint8_t low);
 void getActualRTEandFONTversion(uint8_t *RTEhigh, uint8_t *RTElow, uint8_t *FONThigh, uint8_t *FONTlow);
 
+void setFlipDisplay(uint8_t flipDisplay);
 void set_new_settings_missing_in_ext_flash(void);
 uint8_t check_and_correct_settings(void);
 uint8_t newFirmwareVersionCheckViaSettings(void);
--- a/Discovery/Inc/tMenu.h	Sat Apr 12 12:21:49 2025 +0200
+++ b/Discovery/Inc/tMenu.h	Fri Apr 25 08:26:03 2025 +0200
@@ -68,6 +68,7 @@
 void nextline(char * text, uint8_t *textPointer);
 
 void tM_init(void);
+void tM_build_pages(void);
 void openMenu(uint8_t freshWithFlipPages);
 void openMenu_first_page_with_OC_gas_update(void);
 void updateMenu(void);
--- a/Discovery/Src/settings.c	Sat Apr 12 12:21:49 2025 +0200
+++ b/Discovery/Src/settings.c	Fri Apr 25 08:26:03 2025 +0200
@@ -33,6 +33,10 @@
 #include "externLogbookFlash.h" // for SAMPLESTART and SAMPLESTOP
 #include "text_multilanguage.h" // for LANGUAGE_END
 #include "tHome.h" // for CVIEW_END
+#include "tMenu.h"
+#include "tMenuEdit.h"
+#include "tInfo.h"
+#include "tInfoLog.h"
 #include "motion.h"
 #include "t7.h"
 #include "data_central.h"
@@ -351,6 +355,23 @@
 
 /* Functions -----------------------------------------------------------------*/
 
+void setFlipDisplay(uint8_t flipDisplay)
+{
+    bool settingChanged = flipDisplay != Settings.FlipDisplay;
+    Settings.FlipDisplay = flipDisplay;
+    if (settingChanged) {
+        // reinit all views
+        tHome_init();
+        tI_init();
+        tM_init();
+        tMenuEdit_init();
+        tInfoLog_init();
+        tM_build_pages();
+        GFX_build_logo_frame();
+        GFX_build_hw_background_frame();
+    }
+}
+
 
 //  ===============================================================================
 //	set_new_settings_missing_in_ext_flash
@@ -476,8 +497,8 @@
         pSettings->FactoryButtonBalance[2]          = pStandard->FactoryButtonBalance[2];
         // no break
     case 0xFFFF0017:
-    	pSettings->FlipDisplay = 0;
-    	// no break
+        setFlipDisplay(0);
+        // no break
     case 0xFFFF0018:
     	pSettings->cv_configuration = 0xFFFFFFFF;
     	// no break
@@ -1678,12 +1699,11 @@
         setFirstCorrection(parameterId);
     }
     parameterId++;
-    if(Settings.FlipDisplay > 1) /* only boolean values allowed */
-   	{
-    	Settings.FlipDisplay = 0;
+    if(Settings.FlipDisplay > 1) { /* only boolean values allowed */
+        setFlipDisplay(1);
 	    corrections++;
 	    setFirstCorrection(parameterId);
-   	}
+    }
     parameterId++;
 #ifdef ENABLE_MOTION_CONTROL
     if(Settings.MotionDetection >= MOTION_DETECT_END)
@@ -1831,13 +1851,13 @@
         setFirstCorrection(parameterId);
     }
     parameterId++;
-    if (Settings.compassDeclinationDeg > 99) {
-        Settings.compassDeclinationDeg = 99;
+    if (Settings.compassDeclinationDeg > MAX_COMPASS_DECLINATION_DEG) {
+        Settings.compassDeclinationDeg = MAX_COMPASS_DECLINATION_DEG;
 
         corrections++;
         setFirstCorrection(parameterId);
-    } else if (Settings.compassDeclinationDeg < -99) {
-        Settings.compassDeclinationDeg = -99;
+    } else if (Settings.compassDeclinationDeg < -MAX_COMPASS_DECLINATION_DEG) {
+        Settings.compassDeclinationDeg = -MAX_COMPASS_DECLINATION_DEG;
 
         corrections++;
         setFirstCorrection(parameterId);
@@ -2120,6 +2140,13 @@
     return 0;
 }
 
+bool checkValueSigned(int8_t value, int8_t from, int8_t to)
+{
+    if(value >= from && value <= to)
+        return true;
+    return false;
+}
+
 uint8_t writeData(uint8_t * data)
 {
         uint32_t newSensitivity;
@@ -2256,7 +2283,11 @@
         Settings.date_format = data[1];
         break;
         case 0x34:
+            if (!checkValueSigned(data[1], -MAX_COMPASS_DECLINATION_DEG, MAX_COMPASS_DECLINATION_DEG))
                 return ERROR_;
+            Settings.compassDeclinationDeg = (int8_t)data[1];
+
+            break;
         case 0x35:
                 if(data[1] & 0x80)
                 {
@@ -2288,7 +2319,11 @@
         Settings.fallbackToFixedSetpoint = data[1];
         break;
         case 0x39:
+            if (!checkValue(data[1], 0, 1))
                 return ERROR_;
+            setFlipDisplay(data[1]);
+
+            break;
         case 0x3A:
         if(!checkValue(data[1],70,110))
             return ERROR_;
@@ -2617,10 +2652,10 @@
         break;
 
     case 0x34:
-        data[datacounter++] = PARAM_UNKNOWN ;
-        data[datacounter++] = 0;
-        data[datacounter++] = 0; // compass gain, is unknown,, settingsGetPointerStandard()->;
-        data[datacounter++] = 0;
+        data[datacounter++] = PARAM_SINT;
+        data[datacounter++] = (uint8_t)-MAX_COMPASS_DECLINATION_DEG;
+        data[datacounter++] = (uint8_t)settingsGetPointerStandard()->compassDeclinationDeg;
+        data[datacounter++] = MAX_COMPASS_DECLINATION_DEG;
         break;
 
     case 0x35:
@@ -2660,8 +2695,8 @@
     case 0x39:
         data[datacounter++] = PARAM_BOOL;
         data[datacounter++] = 0;
-        data[datacounter++] = 0; // flipscreen, not yet :-) settingsGetPointerStandard()->;
-        data[datacounter++] = 0;
+        data[datacounter++] = settingsGetPointerStandard()->FlipDisplay;
+        data[datacounter++] = 1;
         break;
 
     case 0x3A:
@@ -2921,7 +2956,7 @@
         data[0] = Settings.date_format;
         break;
      case 0x34:
-        data[0] = 7; // gain should be always 7 as far as I understand the code in RTE
+        data[0] = (uint8_t)Settings.compassDeclinationDeg;
         break;
      case 0x35:
         data[0] = Settings.offsetPressure_mbar;
@@ -2939,7 +2974,7 @@
         data[0] = Settings.fallbackToFixedSetpoint;
         break;
      case 0x39:
-        data[0] = 0; // flip screen
+        data[0] = Settings.FlipDisplay;
         break;
      case 0x3A:
         data[0] = Settings.ButtonResponsiveness[3];
--- a/Discovery/Src/tMenuEditHardware.c	Sat Apr 12 12:21:49 2025 +0200
+++ b/Discovery/Src/tMenuEditHardware.c	Fri Apr 25 08:26:03 2025 +0200
@@ -34,17 +34,10 @@
 #include "gfx_fonts.h"
 #include "ostc.h"
 #include "tCCR.h"
-#include "tMenuEdit.h"
-#include "tHome.h"
-#include "tInfo.h"
-#include "tInfoLog.h"
-#include "tInfoSensor.h"
 #include "tComm.h"
 #include "data_exchange_main.h"
 
 
-extern void tM_build_pages(void);
-
 /* Private function prototypes -----------------------------------------------*/
 void openEdit_Bluetooth(void);
 void openEdit_Compass(void);
@@ -135,25 +128,9 @@
 {
 /* does not work like this	resetEnterPressedToStateBeforeButtonAction(); */
 
-    SSettings *pSettings = settingsGetPointer();
+    bool oldValue = settingsGetPointer()->FlipDisplay;
 
-    if(pSettings->FlipDisplay == 0)
-    {
-        pSettings->FlipDisplay = 1;
-    }
-    else
-    {
-        pSettings->FlipDisplay = 0;
-    }
-    /* reinit all views */
-    tHome_init();
-    tI_init();
-    tM_init();
-    tMenuEdit_init();
-    tInfoLog_init();
-    tM_build_pages();
-    GFX_build_logo_frame();
-    GFX_build_hw_background_frame();
+    setFlipDisplay(!oldValue);
 
     exitEditWithUpdate();
     exitMenuEdit_to_Home();
@@ -172,10 +149,10 @@
             int32_t compassDeclinationDeg;
             evaluateNewString(editId, (uint32_t *)&compassDeclinationDeg, NULL, NULL, NULL);
 
-            if (compassDeclinationDeg > 99) {
-                compassDeclinationDeg = 99;
-            } else if (compassDeclinationDeg < -99) {
-                compassDeclinationDeg = -99;
+            if (compassDeclinationDeg > MAX_COMPASS_DECLINATION_DEG) {
+                compassDeclinationDeg = MAX_COMPASS_DECLINATION_DEG;
+            } else if (compassDeclinationDeg < -MAX_COMPASS_DECLINATION_DEG) {
+                compassDeclinationDeg = -MAX_COMPASS_DECLINATION_DEG;
             }
 
             settings->compassDeclinationDeg = compassDeclinationDeg;