diff Discovery/Src/settings.c @ 776:45b8f3c2acce

Add support for a configurable compass declination in a range of -99 to 99 degrees. This allows the displayed compass reading to be configured to take into account the compass declination (difference between the measured magnetic North direction and the actual geographical North direction) that has different values for different locations around the globe. See https://magnetic-declination.com/ for more information. (mikeller)
author heinrichsweikamp
date Thu, 18 May 2023 09:49:17 +0200
parents dfdfea8897f3
children 4abfb8a2a435
line wrap: on
line diff
--- a/Discovery/Src/settings.c	Thu May 11 12:13:03 2023 +0200
+++ b/Discovery/Src/settings.c	Thu May 18 09:49:17 2023 +0200
@@ -89,7 +89,7 @@
  * There might even be entries with fixed values that have no range
  */
 const SSettings SettingsStandard = {
-    .header = 0xFFFF0025,
+    .header = 0xFFFF0026,
     .warning_blink_dsec = 8 * 2,
     .lastDiveLogId = 0,
     .logFlashNextSampleStartAddress = SAMPLESTART,
@@ -332,7 +332,8 @@
 	.ext_sensor_map[2] = SENSOR_OPTIC,
 	.ext_sensor_map[3] = SENSOR_NONE,
 	.ext_sensor_map[4] = SENSOR_NONE,
-	.buttonLockActive = 0
+	.buttonLockActive = 0,
+    .compassDeclinationDeg = 0,
 };
 
 /* Private function prototypes -----------------------------------------------*/
@@ -534,6 +535,10 @@
     	// no break;
     case 0xFFFF0024: pSettings->buttonLockActive = 0;
     	// no break;
+    case 0xFFFF0025:
+        pSettings->compassDeclinationDeg = pStandard->compassDeclinationDeg;
+
+    	// no break;
     default:
         pSettings->header = pStandard->header;
         break; // no break before!!
@@ -1578,6 +1583,16 @@
         corrections++;
     }
 
+    if (Settings.compassDeclinationDeg > 99) {
+        Settings.compassDeclinationDeg = 99;
+
+        corrections++;
+    } else if (Settings.compassDeclinationDeg < -99) {
+        Settings.compassDeclinationDeg = -99;
+
+        corrections++;
+    }
+
     if(corrections)
     {
     	settingsWarning = 1;