diff Discovery/Src/tMenuEditHardware.c @ 539:d784f281833a

Added inertia simulation for compass heading: In previous version calculated compass values were directly used for visualization of the compass. This causes a fast changing (jumping) of values. With the inertia introduction the compass behalfs more like an analog compass. The final value is reached slowly and the displayed values are more stable. For configuration a new menu item has been added to the compass menu allowing to switch inertia off (default), small and large inertia simulation
author Ideenmodellierer
date Sat, 10 Oct 2020 16:59:18 +0200
parents 1f557e5f4b5a
children ec76fa85009e
line wrap: on
line diff
--- a/Discovery/Src/tMenuEditHardware.c	Sat Oct 10 13:51:44 2020 +0200
+++ b/Discovery/Src/tMenuEditHardware.c	Sat Oct 10 16:59:18 2020 +0200
@@ -54,6 +54,7 @@
 uint8_t OnAction_Compass		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_Bearing		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_BearingClear	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+uint8_t OnAction_InertiaLevel	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 //uint8_t OnAction_ExitHardw	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_Sensor1		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_Sensor2		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
@@ -147,6 +148,7 @@
 {
     uint16_t heading;
     char text[32];
+    uint8_t textIndex = 0;
 
     text[0] = '\001';
     text[1] = TXT_2BYTE;
@@ -154,13 +156,27 @@
     text[3] = 0;
     write_topline(text);
 
-    heading = (uint16_t)stateUsed->lifeData.compass_heading;
+    if(settingsGetPointer()->compassInertia)
+    {
+    	heading = (uint16_t)compass_getCompensated();
+    }
+    else
+    {
+    	heading = (uint16_t)stateUsed->lifeData.compass_heading;
+    }
     snprintf(text,32,"\001%03i`",heading);
     write_label_var(   0, 800, ME_Y_LINE1, &FontT54, text);
 
     tMenuEdit_refresh_field(StMHARD2_Compass_SetCourse);
     tMenuEdit_refresh_field(StMHARD2_Compass_Calibrate);
     tMenuEdit_refresh_field(StMHARD2_Compass_ResetCourse);
+    text[textIndex++] = TXT_2BYTE;
+    text[textIndex++] = TXT2BYTE_CompassInertia;
+    text[textIndex++] = ':';
+    text[textIndex++] = ' ';
+    text[textIndex++] = '0' + settingsGetPointer()->compassInertia;
+
+    write_label_var(30, 800, ME_Y_LINE5,  &FontT48, text);
 
     write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
 }
@@ -168,12 +184,13 @@
 
 void openEdit_Compass(void)
 {
-    char text[4];
+    char text[10];
+    uint8_t textIndex = 0;
 
-    text[0] = '\001';
-    text[1] = TXT_2BYTE;
-    text[2] = TXT2BYTE_Compass;
-    text[3] = 0;
+    text[textIndex++] = '\001';
+    text[textIndex++] = TXT_2BYTE;
+    text[textIndex++] = TXT2BYTE_Compass;
+    text[textIndex++] = 0;
     write_topline(text);
 
     text[0] = TXT_2BYTE;
@@ -188,9 +205,18 @@
     text[1] = TXT2BYTE_ResetBearing;
     write_field_button(StMHARD2_Compass_ResetCourse, 30, 800, ME_Y_LINE4,  &FontT48, text);
 
+    text[1] = TXT2BYTE_CompassInertia;
+    textIndex = 2;
+    text[textIndex++] = ':';
+    text[textIndex++] = ' ';
+    text[textIndex++] = '0' + settingsGetPointer()->compassInertia;
+
+    write_field_button(StMHARD2_Compass_Inertia, 30, 800, ME_Y_LINE5,  &FontT48, text);
+
     setEvent(StMHARD2_Compass_SetCourse,		(uint32_t)OnAction_Bearing);
     setEvent(StMHARD2_Compass_Calibrate,		(uint32_t)OnAction_Compass);
     setEvent(StMHARD2_Compass_ResetCourse,	(uint32_t)OnAction_BearingClear);
+    setEvent(StMHARD2_Compass_Inertia,	(uint32_t)OnAction_InertiaLevel);
 
     write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
 }
@@ -218,6 +244,20 @@
     return UPDATE_AND_EXIT_TO_MENU;
 }
 
+
+uint8_t OnAction_InertiaLevel	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+{
+	uint8_t newLevel = 0;
+
+	newLevel = settingsGetPointer()->compassInertia + 1;
+	if(newLevel > MAX_COMPASS_COMP)
+	{
+		newLevel = 0;
+	}
+	settingsGetPointer()->compassInertia = newLevel;
+    return UPDATE_DIVESETTINGS;
+}
+
 /*
 uint8_t OnAction_ExitHardw (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {