diff Discovery/Src/data_exchange_main.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 aa6006975e76
children e40790a67165
line wrap: on
line diff
--- a/Discovery/Src/data_exchange_main.c	Thu May 11 12:13:03 2023 +0200
+++ b/Discovery/Src/data_exchange_main.c	Thu May 18 09:49:17 2023 +0200
@@ -1096,11 +1096,19 @@
 		pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds;
 
 		pStateReal->lifeData.compass_heading = dataIn.data[dataIn.boolCompassData].compass_heading;
-		if(settingsGetPointer()->FlipDisplay) /* consider that diver is targeting into the opposite direction */
-		{
-			pStateReal->lifeData.compass_heading -= 180.0;
-			if (pStateReal->lifeData.compass_heading < 0) pStateReal->lifeData.compass_heading +=360.0;
-		}
+        if (pStateReal->lifeData.compass_heading != -1) {
+            if (pSettings->FlipDisplay) { /* consider that diver is targeting into the opposite direction */
+                pStateReal->lifeData.compass_heading -= 180.0;
+            }
+
+            if (pSettings->compassDeclinationDeg != 0) {
+                pStateReal->lifeData.compass_heading = pStateReal->lifeData.compass_heading + pSettings->compassDeclinationDeg - 360.0;
+            }
+
+            while (pStateReal->lifeData.compass_heading < 0) {
+                pStateReal->lifeData.compass_heading += 360.0;
+            }
+        }
 
 		pStateReal->lifeData.compass_roll = dataIn.data[dataIn.boolCompassData].compass_roll;
 		pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch;