diff Discovery/Src/data_central.c @ 271:1303747b5ba2 write-from-sim

cleanup: also write gas and setpoint changes in simulator mode This is related to the previous commit. There is all kinds of logic around that distinguishes real diving mode and simulator mode. This is valid in certain cases. For example, we do not want a simulator session to act as a repetitive dive for subsequent real dives. What is simply wrong, is skipping relevant logic, like gas switches to act differently in the simulator and in a real dive. The main advantage of this commit is code simplicity. Normal users will never see the difference, as simulator dives are not logged (unless compiled in by a developer). Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Sat, 27 Apr 2019 09:32:16 +0200
parents 2e58a4094770
children 54d14bc2083c
line wrap: on
line diff
--- a/Discovery/Src/data_central.c	Wed Apr 24 17:10:51 2019 +0200
+++ b/Discovery/Src/data_central.c	Sat Apr 27 09:32:16 2019 +0200
@@ -100,17 +100,17 @@
 	.is_data_from_RTE_CPU = 0,
 };
 
-const SDiveState * stateUsed = &stateReal;
-
+const SDiveState *stateUsed = &stateReal;
+SDiveState *stateUsedWrite = &stateReal;
 
 void set_stateUsedToReal(void)
 {
-	stateUsed = &stateReal;
+	stateUsed = stateUsedWrite = &stateReal;
 }
 
 void set_stateUsedToSim(void)
 {
-	stateUsed = &stateSim;
+	stateUsed = stateUsedWrite = &stateSim;
 }
 
 _Bool is_stateUsedSetToSim(void)
@@ -458,39 +458,25 @@
 
 void updateSetpointStateUsed(void)
 {
-	SLifeData *pLifeDataWrite;
-	
-	if(is_stateUsedSetToSim())
-		pLifeDataWrite = &stateSimGetPointerWrite()->lifeData;
-	else
-		pLifeDataWrite = &stateRealGetPointerWrite()->lifeData;
-
 	if(stateUsed->diveSettings.diveMode != DIVEMODE_CCR)
 	{
-		pLifeDataWrite->actualGas.setPoint_cbar = 0;
-		pLifeDataWrite->ppO2 = decom_calc_ppO2(stateUsed->lifeData.pressure_ambient_bar, &stateUsed->lifeData.actualGas);
+		stateUsedWrite->lifeData.actualGas.setPoint_cbar = 0;
+		stateUsedWrite->lifeData.ppO2 = decom_calc_ppO2(stateUsed->lifeData.pressure_ambient_bar, &stateUsed->lifeData.actualGas);
 	}
 	else
 	{
 		if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors)
 		{
-			pLifeDataWrite->actualGas.setPoint_cbar = get_ppO2SensorWeightedResult_cbar();
+			stateUsedWrite->lifeData.actualGas.setPoint_cbar = get_ppO2SensorWeightedResult_cbar();
 		}
 
 		if((stateUsed->lifeData.pressure_ambient_bar * 100) < stateUsed->lifeData.actualGas.setPoint_cbar)
-			pLifeDataWrite->ppO2 = stateUsed->lifeData.pressure_ambient_bar;
+			stateUsedWrite->lifeData.ppO2 = stateUsed->lifeData.pressure_ambient_bar;
 		else
-			pLifeDataWrite->ppO2 = ((float)stateUsed->lifeData.actualGas.setPoint_cbar) / 100;
+			stateUsedWrite->lifeData.ppO2 = ((float)stateUsed->lifeData.actualGas.setPoint_cbar) / 100;
 	}
 }
 
-/*
-void fallbackToFixedSetpoints(SLifeData *lifeData)
-{
-	
-}
-*/
-
 void setActualGasFirst(SLifeData *lifeData)
 {
 	SSettings* pSettings = settingsGetPointer();
@@ -555,37 +541,30 @@
 
 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar)
 {
-  //Real dive => Set events for logbook
-	if(stateUsed == stateRealGetPointer())
-  {
-    SDiveState * pStateUsed;
-		pStateUsed = stateRealGetPointerWrite();
-
     if(stateUsed->diveSettings.ccrOption && gasId < 6)
     {
       if(lifeData->actualGas.GasIdInSettings != gasId)
       {
         SSettings* pSettings = settingsGetPointer();
-        pStateUsed->events.bailout = 1;
-        pStateUsed->events.info_bailoutO2 = pSettings->gas[gasId].oxygen_percentage;
-        pStateUsed->events.info_bailoutHe = pSettings->gas[gasId].helium_percentage;
+        stateUsedWrite->events.bailout = 1;
+        stateUsedWrite->events.info_bailoutO2 = pSettings->gas[gasId].oxygen_percentage;
+        stateUsedWrite->events.info_bailoutHe = pSettings->gas[gasId].helium_percentage;
       }
     }
     else
     {
       if(lifeData->actualGas.GasIdInSettings != gasId)
       {
-          pStateUsed->events.gasChange = 1;
-          pStateUsed->events.info_GasChange = gasId;
+    	  stateUsedWrite->events.gasChange = 1;
+    	  stateUsedWrite->events.info_GasChange = gasId;
       }
       if(	lifeData->actualGas.setPoint_cbar != setpoint_cbar)
       {
 				// setPoint_cbar = 255 -> change to sensor mode
-        pStateUsed->events.setpointChange = 1;
-        pStateUsed->events.info_SetpointChange = setpoint_cbar;
+    	  stateUsedWrite->events.setpointChange = 1;
+    	  stateUsedWrite->events.info_SetpointChange = setpoint_cbar;
       }
     }
-  }
 	setActualGas(lifeData, gasId, setpoint_cbar);
 }
 
@@ -597,23 +576,17 @@
 	nitrogen -= oxygen;
 	nitrogen -= helium;
 
-  //Real dive => Set events for logbook
-	if(stateUsed == stateRealGetPointer())
-  {
-    SDiveState * pStateUsed;
-		pStateUsed = stateRealGetPointerWrite();
     if((lifeData->actualGas.nitrogen_percentage != nitrogen) || (lifeData->actualGas.helium_percentage != helium))
     {
-      pStateUsed->events.manuelGasSet = 1;
-      pStateUsed->events.info_manuelGasSetHe = helium;
-      pStateUsed->events.info_manuelGasSetO2 = oxygen;
+    	stateUsedWrite->events.manuelGasSet = 1;
+    	stateUsedWrite->events.info_manuelGasSetHe = helium;
+    	stateUsedWrite->events.info_manuelGasSetO2 = oxygen;
     }
     if(	lifeData->actualGas.setPoint_cbar != setpoint_cbar)
     {
-      pStateUsed->events.setpointChange = 1;
-      pStateUsed->events.info_SetpointChange = setpoint_cbar;
+    	stateUsedWrite->events.setpointChange = 1;
+    	stateUsedWrite->events.info_SetpointChange = setpoint_cbar;
     }
-  }
   lifeData->actualGas.GasIdInSettings = 0;
   lifeData->actualGas.nitrogen_percentage = nitrogen;
   lifeData->actualGas.helium_percentage = helium;