changeset 272:74a8296a2318 write-from-sim

cleanup: simplify stateUsed usage Get rid of some local stateUsed pointers used to differentiate between normal dive and simulator mode. Simply use the (properly set) global data for this. Its rather useless to do this test on countless locations. Trivial cleanup. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Sat, 27 Apr 2019 12:27:46 +0200
parents 1303747b5ba2
children 5fe136480a47
files Discovery/Src/base.c Discovery/Src/check_warning.c Discovery/Src/t3.c Discovery/Src/tCCR.c Discovery/Src/tHome.c Discovery/Src/tMenuEditXtra.c
diffstat 6 files changed, 11 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Src/base.c	Sat Apr 27 09:32:16 2019 +0200
+++ b/Discovery/Src/base.c	Sat Apr 27 12:27:46 2019 +0200
@@ -511,13 +511,10 @@
 // Enable this to make the simulator write a logbook entry
 // #define SIM_WRITES_LOGBOOK 1
 
+#ifdef SIM_WRITES_LOGBOOK
         if(stateUsed == stateSimGetPointer())
-        {
-#ifdef SIM_WRITES_LOGBOOK
             logbook_InitAndWrite(stateUsed);
 #endif
-        }
-
         	if(stateUsed == stateRealGetPointer())	/* Handle log entries while in dive mode*/
                 logbook_InitAndWrite(stateUsed);
         }
--- a/Discovery/Src/check_warning.c	Sat Apr 27 09:32:16 2019 +0200
+++ b/Discovery/Src/check_warning.c	Sat Apr 27 12:27:46 2019 +0200
@@ -61,14 +61,7 @@
 
 void check_warning(void)
 {
-	SDiveState * pDiveState;
-
-	if(stateUsed == stateRealGetPointer())
-		pDiveState = stateRealGetPointerWrite();
-	else
-		pDiveState = stateSimGetPointerWrite();
-
-  check_warning2(pDiveState);
+  check_warning2(stateUsedWrite);
 }
 
 
--- a/Discovery/Src/t3.c	Sat Apr 27 09:32:16 2019 +0200
+++ b/Discovery/Src/t3.c	Sat Apr 27 12:27:46 2019 +0200
@@ -487,14 +487,7 @@
     if((t3_selection_customview == CVIEW_sensors) &&(stateUsed->diveSettings.ccrOption == 0))
         t3_change_customview();
 
-    SDiveState * pDiveState;
-
-    if(stateUsed == stateRealGetPointer())
-        pDiveState = stateRealGetPointerWrite();
-    else
-        pDiveState = stateSimGetPointerWrite();
-
-    t3_basics_refresh_customview(depth, t3_selection_customview, &t3screen, &t3c1, &t3c2, pDiveState->diveSettings.diveMode);
+    t3_basics_refresh_customview(depth, t3_selection_customview, &t3screen, &t3c1, &t3c2, stateUsedWrite->diveSettings.diveMode);
 }
 
 
--- a/Discovery/Src/tCCR.c	Sat Apr 27 09:32:16 2019 +0200
+++ b/Discovery/Src/tCCR.c	Sat Apr 27 12:27:46 2019 +0200
@@ -59,7 +59,7 @@
 /* Private variables with external access via get_xxx() function -------------*/
 
 /* Private function prototypes -----------------------------------------------*/
-void tCCR_fallbackToFixedSetpoint(void);
+static void tCCR_fallbackToFixedSetpoint(void);
 
 #ifndef USART_IR_HUD
 
@@ -343,23 +343,17 @@
 #endif
 /* Private functions ---------------------------------------------------------*/
 
-void tCCR_fallbackToFixedSetpoint(void)
+static void tCCR_fallbackToFixedSetpoint(void)
 {
     if((stateUsed->mode == MODE_DIVE) && (stateUsed->diveSettings.diveMode == DIVEMODE_CCR) && (stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) && (stateUsed->diveSettings.fallbackOption))
     {
         uint8_t setpointCbar, actualGasID;
-        SDiveState *pState;
 
-        if(stateUsed == stateRealGetPointer())
-            pState = stateRealGetPointerWrite();
-        else
-            pState = stateSimGetPointerWrite();
+        setpointCbar = stateUsed->diveSettings.setpoint[1].setpoint_cbar;
+        stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint;
 
-        setpointCbar = pState->diveSettings.setpoint[1].setpoint_cbar;
-        pState->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint;
-
-        actualGasID = pState->lifeData.actualGas.GasIdInSettings;
-        setActualGas_DM(&pState->lifeData,actualGasID,setpointCbar);
+        actualGasID = stateUsed->lifeData.actualGas.GasIdInSettings;
+        setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar);
 
         set_warning_fallback();
     }
--- a/Discovery/Src/tHome.c	Sat Apr 27 09:32:16 2019 +0200
+++ b/Discovery/Src/tHome.c	Sat Apr 27 12:27:46 2019 +0200
@@ -285,10 +285,7 @@
             break;
 
         case StDBEAR: // t5_gauge
-            if(is_stateUsedSetToSim())
-                stateSimGetPointerWrite()->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading;
-            else
-                stateRealGetPointerWrite()->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading;
+        	stateUsedWrite->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading;
             set_globalState(StD);
             break;
 
--- a/Discovery/Src/tMenuEditXtra.c	Sat Apr 27 09:32:16 2019 +0200
+++ b/Discovery/Src/tMenuEditXtra.c	Sat Apr 27 12:27:46 2019 +0200
@@ -121,56 +121,7 @@
 
 uint8_t OnAction_CompassHeading	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
-    if(is_stateUsedSetToSim())
-        stateSimGetPointerWrite()->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading;
-    else
-        stateRealGetPointerWrite()->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading;
+	stateUsedWrite->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading;
     exitMenuEdit_to_Home_with_Menu_Update();
     return EXIT_TO_HOME;
 }
-
-
-/*
-    uint8_t digitContentNew;
-    uint32_t newHeading;
-
-    if(action == ACTION_BUTTON_ENTER)
-    {
-        return digitContent;
-    }
-    if(action == ACTION_BUTTON_ENTER_FINAL)
-    {
-        evaluateNewString(editId, &newHeading, 0, 0, 0);
-        if(newHeading > 359)
-            newHeading = 0;
-
-        if(is_stateUsedSetToSim())
-            stateSimGetPointerWrite()->diveSettings.compassHeading = newHeading;
-        else
-            stateRealGetPointerWrite()->diveSettings.compassHeading = newHeading;
-        exitMenuEdit_to_Home_with_Menu_Update();
-        return EXIT_TO_HOME;
-    }
-    if(action == ACTION_BUTTON_NEXT)
-    {
-        digitContentNew = digitContent + 1;
-        if((digitNumber == 0) && (digitContentNew > '3'))
-            digitContentNew = '0';
-        else
-        if(digitContentNew > '9')
-            digitContentNew = '0';
-        return digitContentNew;
-    }
-    if(action == ACTION_BUTTON_BACK)
-    {
-        digitContentNew = digitContent - 1;
-        if((digitNumber == 0) && (digitContentNew < '0'))
-            digitContentNew = '3';
-        else
-        if(digitContentNew < '0')
-            digitContentNew = '9';
-        return digitContentNew;
-    }
-
-    return EXIT_TO_MENU;
-*/