# HG changeset patch # User Ideenmodellierer # Date 1602341958 -7200 # Node ID d784f281833a77df1c807a1a3deababec70066fc # Parent b1eee27cd02b5de06cae5e6a8b21b4844805797f 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 diff -r b1eee27cd02b -r d784f281833a Common/Inc/data_central.h --- a/Common/Inc/data_central.h Sat Oct 10 13:51:44 2020 +0200 +++ b/Common/Inc/data_central.h Sat Oct 10 16:59:18 2020 +0200 @@ -433,6 +433,8 @@ void setBatteryPercentage(uint8_t newChargePercentage); void setButtonResponsiveness(uint8_t *ButtonSensitivyList); void calibrateCompass(void); +void compass_Inertia(float newHeading); +float compass_getCompensated(); void clearDeco(void); void translateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate); void translateTime(uint32_t tmpreg, RTC_TimeTypeDef *sTime); diff -r b1eee27cd02b -r d784f281833a Common/Inc/settings.h --- a/Common/Inc/settings.h Sat Oct 10 13:51:44 2020 +0200 +++ b/Common/Inc/settings.h Sat Oct 10 16:59:18 2020 +0200 @@ -68,6 +68,8 @@ #define PRESSURE_OFFSET_LIMIT_MBAR 50 +#define MAX_COMPASS_COMP (2u) + /* 2015 Jan 30, hw, deco and travel added for MenuEditGas * can be used for buehlmann, vpm, etc. later but be carefull * with current implemenation */ @@ -223,6 +225,8 @@ uint8_t MotionDetection; /* new in 0xFFFF001B */ uint32_t cv_config_BigScreen; + /* new in 0xFFFF001C */ + uint8_t compassInertia; } SSettings; typedef struct diff -r b1eee27cd02b -r d784f281833a Discovery/Inc/tStructure.h --- a/Discovery/Inc/tStructure.h Sat Oct 10 13:51:44 2020 +0200 +++ b/Discovery/Inc/tStructure.h Sat Oct 10 16:59:18 2020 +0200 @@ -238,6 +238,7 @@ #define StMHARD2_Compass_SetCourse _MB(2,7,2,2,0) #define StMHARD2_Compass_ResetCourse _MB(2,7,2,3,0) #define StMHARD2_Compass_Calibrate _MB(2,7,2,4,0) +#define StMHARD2_Compass_Inertia _MB(2,7,2,5,0) //#define StMHARD2_Exit _MB(2,7,2,2,0) @@ -251,7 +252,7 @@ #define StMHARD4_BrightnessHigh _MB(2,7,4,3,0) #define StMHARD4_BrightnessMax _MB(2,7,4,4,0) -#define StMHARD5_Button1 _MB(2,7,5,1,0) +#define StMHARD5_Button1 _MB(2,7,5,1,0) #define StMHARD5_ButtonBalance1 _MB(2,7,5,2,0) #define StMHARD5_ButtonBalance2 _MB(2,7,5,3,0) #define StMHARD5_ButtonBalance3 _MB(2,7,5,4,0) diff -r b1eee27cd02b -r d784f281833a Discovery/Inc/text_multilanguage.h --- a/Discovery/Inc/text_multilanguage.h Sat Oct 10 13:51:44 2020 +0200 +++ b/Discovery/Inc/text_multilanguage.h Sat Oct 10 16:59:18 2020 +0200 @@ -195,6 +195,7 @@ TXT2BYTE_SpecialDiveGasMenu, TXT2BYTE_SpecialDiveGasMenuCCR, TXT2BYTE_CompassCalib, + TXT2BYTE_CompassInertia, TXT2BYTE_UseSensor, /* */ TXT2BYTE_WarnDecoMissed, diff -r b1eee27cd02b -r d784f281833a Discovery/Src/data_central.c --- a/Discovery/Src/data_central.c Sat Oct 10 13:51:44 2020 +0200 +++ b/Discovery/Src/data_central.c Sat Oct 10 16:59:18 2020 +0200 @@ -61,6 +61,7 @@ /* Includes ------------------------------------------------------------------*/ #include +#include #include "data_central.h" #include "calc_crush.h" #include "decom.h" @@ -103,6 +104,11 @@ const SDiveState *stateUsed = &stateReal; SDiveState *stateUsedWrite = &stateReal; + +#define COMPASS_FRACTION (4.0f) /* delay till value changes to new actual */ + +static float compass_compensated = 0; + void set_stateUsedToReal(void) { stateUsed = stateUsedWrite = &stateReal; @@ -770,3 +776,41 @@ else return false; } + +void compass_Inertia(float newHeading) +{ + float newTarget = newHeading; + + if(settingsGetPointer()->compassInertia == 0) + { + compass_compensated = newHeading; + } + else + { + if((compass_compensated > 270.0) && (newHeading < 90.0)) /* transition passing 0 clockwise */ + { + newTarget = newHeading + 360.0; + } + + if((compass_compensated < 90.0) && (newHeading > 270.0)) /* transition passing 0 counter clockwise */ + { + newTarget = newHeading - 360.0; + } + + compass_compensated = compass_compensated + ((newTarget - compass_compensated) / (COMPASS_FRACTION * (settingsGetPointer()->compassInertia))); + if(compass_compensated < 0.0) + { + compass_compensated += 360.0; + } + if(compass_compensated >= 360.0) + { + compass_compensated -= 360.0; + } + } +} + +float compass_getCompensated() +{ + return compass_compensated; +} + diff -r b1eee27cd02b -r d784f281833a Discovery/Src/data_exchange_main.c --- a/Discovery/Src/data_exchange_main.c Sat Oct 10 13:51:44 2020 +0200 +++ b/Discovery/Src/data_exchange_main.c Sat Oct 10 16:59:18 2020 +0200 @@ -970,6 +970,7 @@ pStateReal->compass_uTick_old = pStateReal->compass_uTick_new; pStateReal->compass_uTick_new = dataIn.data[dataIn.boolCompassData].compass_uTick; pStateReal->compass_uTick_local_new = HAL_GetTick(); + compass_Inertia(pStateReal->lifeData.compass_heading); memcpy(pStateReal->lifeData.tissue_nitrogen_bar, dataIn.data[dataIn.boolTisssueData].tissue_nitrogen_bar,sizeof(pStateReal->lifeData.tissue_nitrogen_bar)); memcpy(pStateReal->lifeData.tissue_helium_bar, dataIn.data[dataIn.boolTisssueData].tissue_helium_bar,sizeof(pStateReal->lifeData.tissue_helium_bar)); diff -r b1eee27cd02b -r d784f281833a Discovery/Src/settings.c --- a/Discovery/Src/settings.c Sat Oct 10 13:51:44 2020 +0200 +++ b/Discovery/Src/settings.c Sat Oct 10 16:59:18 2020 +0200 @@ -34,6 +34,7 @@ #include "tHome.h" // for CVIEW_END #include "motion.h" #include "t7.h" +#include "data_central.h" SSettings Settings; @@ -84,7 +85,7 @@ * There might even be entries with fixed values that have no range */ const SSettings SettingsStandard = { - .header = 0xFFFF001B, + .header = 0xFFFF001C, .warning_blink_dsec = 8 * 2, .lastDiveLogId = 0, .logFlashNextSampleStartAddress = 0, @@ -311,6 +312,7 @@ .cv_configuration = 0xFFFFFFFF, .MotionDetection = MOTION_DETECT_OFF, .cv_config_BigScreen = 0xFFFFFFFF, + .compassInertia = 0, }; /* Private function prototypes -----------------------------------------------*/ @@ -464,6 +466,9 @@ pSettings->cv_config_BigScreen &= pSettings->cv_configuration ^= 1 << CVIEW_T3_Navigation; pSettings->cv_config_BigScreen &= pSettings->cv_configuration ^= 1 << CVIEW_T3_DepthData; // no break + case 0xFFFF001B: + pSettings->compassInertia = 0; /* no inertia */ + // no break default: pSettings->header = pStandard->header; break; // no break before!! @@ -1377,6 +1382,12 @@ Settings.MotionDetection = MOTION_DETECT_OFF; #endif + if(Settings.compassInertia > MAX_COMPASS_COMP) + { + Settings.compassInertia = 0; + corrections++; + } + if(corrections > 255) return 255; else diff -r b1eee27cd02b -r d784f281833a Discovery/Src/t3.c --- a/Discovery/Src/t3.c Sat Oct 10 13:51:44 2020 +0200 +++ b/Discovery/Src/t3.c Sat Oct 10 16:59:18 2020 +0200 @@ -697,6 +697,7 @@ /* compass position */ point_t center; + uint16_t heading; // CVIEW_T3_StopWatch SDivetime Stopwatch = {0,0,0,0}; @@ -723,6 +724,15 @@ tempWinC2Y1 = tXc2->WindowY1; tempWinC2Tab = tXc2->WindowTab; + if(settingsGetPointer()->compassInertia) + { + heading = (uint16_t)compass_getCompensated(); + } + else + { + heading = (uint16_t)stateUsed->lifeData.compass_heading; + } + switch(tX_selection_customview) { case CVIEW_T3_ApnoeSurfaceInfo: @@ -905,9 +915,9 @@ center.y = 116; snprintf(text,TEXTSIZE,"\032\f%c%c",TXT_2BYTE, TXT2BYTE_Compass); GFX_write_string(&FontT42,tXc1,text,0); - snprintf(text,100,"\030\003%03i`",(uint16_t)stateUsed->lifeData.compass_heading); + snprintf(text,100,"\030\003%03i`",heading); GFX_write_string(&FontT105,tXc1,text,0); - t3_basics_compass(tXscreen, center, (uint16_t)stateUsed->lifeData.compass_heading, stateUsed->diveSettings.compassHeading); + t3_basics_compass(tXscreen, center, heading, stateUsed->diveSettings.compassHeading); break; case CVIEW_T3_Decostop: @@ -1103,10 +1113,9 @@ snprintf(text,TEXTSIZE,"\032\f%c%c",TXT_2BYTE, TXT2BYTE_Compass); GFX_write_string(&FontT42,tXc1,text,0); - //snprintf(text,100,"\030\003%03i`",(uint16_t)stateUsed->lifeData.compass_heading); - snprintf(text,100,"\030%03i`",(uint16_t)stateUsed->lifeData.compass_heading); + snprintf(text,100,"\030%03i`",heading); GFX_write_string(&FontT144,tXc1,text,0); - t3_basics_compass(tXscreen, center, (uint16_t)stateUsed->lifeData.compass_heading, stateUsed->diveSettings.compassHeading); + t3_basics_compass(tXscreen, center, heading, stateUsed->diveSettings.compassHeading); break; diff -r b1eee27cd02b -r d784f281833a Discovery/Src/t7.c --- a/Discovery/Src/t7.c Sat Oct 10 13:51:44 2020 +0200 +++ b/Discovery/Src/t7.c Sat Oct 10 16:59:18 2020 +0200 @@ -1634,6 +1634,7 @@ char text[256]; uint16_t textpointer = 0; + uint16_t heading = 0; int16_t start; uint8_t lineCountCustomtext = 0; int16_t shiftWindowY0; @@ -1677,15 +1678,6 @@ case CVIEW_CompassDebug: snprintf(text,100,"\032\f\001Compass raw"); GFX_write_string(&FontT42,&t7cH,text,0); -/* - pStateReal->lifeData.compass_heading = dataIn.data[dataIn.boolCompassData].compass_heading; - pStateReal->lifeData.compass_roll = dataIn.data[dataIn.boolCompassData].compass_roll; - pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch; - - pStateReal->lifeData.compass_DX_f = dataIn.data[dataIn.boolCompassData].compass_DX_f; - pStateReal->lifeData.compass_DY_f = dataIn.data[dataIn.boolCompassData].compass_DY_f; - pStateReal->lifeData.compass_DZ_f = dataIn.data[dataIn.boolCompassData].compass_DZ_f; -*/ snprintf(text,255,"%1.1f\n\r%1.1f\n\r%1.1f\n\r%i\n\r%i\n\r%i" ,stateUsed->lifeData.compass_heading ,stateUsed->lifeData.compass_roll @@ -1978,9 +1970,18 @@ case CVIEW_Compass: default: + + if(pSettings->compassInertia) + { + heading = (uint16_t)compass_getCompensated(); + } + else + { + heading = (uint16_t)stateUsed->lifeData.compass_heading; + } snprintf(text,100,"\032\f\001%c%c",TXT_2BYTE, TXT2BYTE_Compass); GFX_write_string(&FontT42,&t7cH,text,0); - t7_compass((uint16_t)stateUsed->lifeData.compass_heading, stateUsed->diveSettings.compassHeading); + t7_compass(heading, stateUsed->diveSettings.compassHeading); if(!pSettings->FlipDisplay) { @@ -1993,7 +1994,7 @@ t7cY0free.WindowY0 = 0; t7cY0free.WindowY1 = 250; } - snprintf(text,100,"\030\001%03i`",(uint16_t)stateUsed->lifeData.compass_heading); + snprintf(text,100,"\030\001%03i`",heading); GFX_write_string(&FontT54,&t7cY0free,text,0); if(!pSettings->FlipDisplay) { @@ -2747,6 +2748,7 @@ { uint8_t i, j, textptr, lineCount; char nextChar; + uint8_t alignmentChanged = 0; textptr = 0; lineCount = 0; @@ -2762,14 +2764,16 @@ do { nextChar = settingsGetPointer()->customtext[i+j]; - if(nextChar == '^') /* center */ + if((nextChar == '^') && (alignmentChanged == 0)) /* center */ { text[textptr++] = '\001'; + alignmentChanged = 1; i++; }else - if(nextChar == 180) /* '´' => Right */ + if((nextChar == 180) && (alignmentChanged == 0)) /* '�' => Right */ { text[textptr++] = '\002'; + alignmentChanged = 1; i++; }else { @@ -2798,6 +2802,7 @@ text[textptr++] = '\n'; text[textptr++] = '\r'; } + alignmentChanged = 0; lineCount++; for(uint8_t k=0;k<2;k++) { diff -r b1eee27cd02b -r d784f281833a Discovery/Src/tMenuEditHardware.c --- 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) { diff -r b1eee27cd02b -r d784f281833a Discovery/Src/text_multilanguage.c --- a/Discovery/Src/text_multilanguage.c Sat Oct 10 13:51:44 2020 +0200 +++ b/Discovery/Src/text_multilanguage.c Sat Oct 10 16:59:18 2020 +0200 @@ -177,6 +177,13 @@ static uint8_t text_IT_CompassCalib[] = "Calibrazione bussola"; static uint8_t text_ES_CompassCalib[] = "Calibrar brújula"; +static uint8_t text_EN_CompassInertia[] = "Compass inertia level"; +static uint8_t text_DE_CompassInertia[] = "Kompass Trägheitsfaktor"; +static uint8_t text_FR_CompassInertia[] = ""; +static uint8_t text_IT_CompassInertia[] = ""; +static uint8_t text_ES_CompassInertia[] = ""; + + // Menu SYS1 and Customview header static uint8_t text_EN_Compass[] = "Compass"; static uint8_t text_DE_Compass[] = "Kompass"; @@ -1577,7 +1584,7 @@ static uint8_t text_IT_SelectCustom[] = ""; static uint8_t text_ES_SelectCustom[] = ""; -static uint8_t text_EN_SelectBigFont[] = "Select bigfont data views"; +static uint8_t text_EN_SelectBigFont[] = "Select big font data views"; static uint8_t text_DE_SelectBigFont[] = "Auswahl Grosschrift Daten"; static uint8_t text_FR_SelectBigFont[] = ""; static uint8_t text_IT_SelectBigFont[] = ""; @@ -1724,7 +1731,8 @@ {(uint8_t)TXT2BYTE_SpecialDiveGasMenu,{text_EN_SpecialDiveGasMenu, text_DE_SpecialDiveGasMenu, text_FR_SpecialDiveGasMenu, text_IT_SpecialDiveGasMenu, text_ES_SpecialDiveGasMenu}}, {(uint8_t)TXT2BYTE_SpecialDiveGasMenuCCR,{text_EN_SpecialDiveGasMenuCCR, text_DE_SpecialDiveGasMenuCCR, text_FR_SpecialDiveGasMenuCCR, text_IT_SpecialDiveGasMenuCCR, text_ES_SpecialDiveGasMenuCCR}}, {(uint8_t)TXT2BYTE_CompassCalib, {text_EN_CompassCalib, text_DE_CompassCalib, text_FR_CompassCalib, text_IT_CompassCalib, text_ES_CompassCalib}}, - {(uint8_t)TXT2BYTE_UseSensor, {text_EN_UseSensor, text_DE_UseSensor, text_FR_UseSensor, text_IT_UseSensor, text_ES_UseSensor}}, + {(uint8_t)TXT2BYTE_CompassInertia, {text_EN_CompassInertia, text_DE_CompassInertia, text_FR_CompassInertia, text_IT_CompassInertia, text_ES_CompassInertia}}, + {(uint8_t)TXT2BYTE_UseSensor, {text_EN_UseSensor, text_DE_UseSensor, text_FR_UseSensor, text_IT_UseSensor, text_ES_UseSensor}}, {(uint8_t)TXT2BYTE_WarnDecoMissed, {text_EN_WarnDecoMissed, text_DE_WarnDecoMissed, text_FR_WarnDecoMissed, text_IT_WarnDecoMissed, text_ES_WarnDecoMissed}}, {(uint8_t)TXT2BYTE_WarnPPO2Low, {text_EN_WarnPPO2Low, text_DE_WarnPPO2Low, text_FR_WarnPPO2Low, text_IT_WarnPPO2Low, text_ES_WarnPPO2Low}}, {(uint8_t)TXT2BYTE_WarnPPO2High, {text_EN_WarnPPO2High, text_DE_WarnPPO2High, text_FR_WarnPPO2High, text_IT_WarnPPO2High, text_ES_WarnPPO2High}},