changeset 309:b0045281cb2d cleanup-4

cleanup: factor out SHelper typedef (and more) It is totally useless to carry some data around in the SLifeData global data, that is never used in a significant way. All data in the SHelper typedef can trivially be changed to static data in the new setAvgDepth code. Further, cleanup the setAvgDepth code. Reset to 0 instead of 1, adapt the references to the new local and static data instead of pointers to the external data. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Fri, 24 May 2019 09:29:29 +0200
parents 1203255481e4
children 95928ef3986f
files Common/Inc/data_central.h Discovery/Src/data_exchange_main.c
diffstat 2 files changed, 11 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/data_central.h	Fri May 24 09:02:46 2019 +0200
+++ b/Common/Inc/data_central.h	Fri May 24 09:29:29 2019 +0200
@@ -152,12 +152,6 @@
 }		SDeviceState;
 */
 
-typedef struct
-{
-	uint32_t average_depth_meter_Count;
-	uint32_t average_depth_last_update_dive_time_seconds_without_surface_time;
-} 	SHelper;
-
 /* struct SLifeData
  * contains data all actual data (pressure, stuturation, etc. as received from second ship
  * and has actualGas to be send to Small CPU (second chip)
@@ -227,10 +221,6 @@
 	 float ppO2Sensor_bar[3];
 	 float sensorVoltage_mV[3];
 	 float HUD_battery_voltage_V;
-
-	/* used by DataEX_copy_to_LifeData()
-	 */
-	SHelper internal;
 } 	SLifeData;
 
 
--- a/Discovery/Src/data_exchange_main.c	Fri May 24 09:02:46 2019 +0200
+++ b/Discovery/Src/data_exchange_main.c	Fri May 24 09:29:29 2019 +0200
@@ -1001,30 +1001,30 @@
 
 	float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter;
 	float	DepthNow = pStateReal->lifeData.depth_meter; 
-	uint32_t *AvgDepthCount = &pStateReal->lifeData.internal.average_depth_meter_Count;
-	uint32_t *AvgDepthTimer = &pStateReal->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time;
+	static uint32_t AvgDepthCount = 0;
+	static uint32_t AvgDepthTimer = 0;
 	uint32_t AvgSecondsSinceLast;
 	uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time;
 
 	if(pStateReal->lifeData.boolResetAverageDepth)
 	{
 		*AvgDepthValue = DepthNow;
-		*AvgDepthCount = 1;
-		*AvgDepthTimer = DiveTime;
+		AvgDepthCount = 0;
+		AvgDepthTimer = DiveTime;
 		pStateReal->lifeData.boolResetAverageDepth = 0;
 	}
-	else if (DiveTime > *AvgDepthTimer)
+	else if (DiveTime > AvgDepthTimer)
 	{
-		AvgSecondsSinceLast = DiveTime - *AvgDepthTimer;
+		AvgSecondsSinceLast = DiveTime - AvgDepthTimer;
 		for(int i=0;i<AvgSecondsSinceLast;i++)
 		{
-			*AvgDepthValue = (*AvgDepthValue * *AvgDepthCount + DepthNow) / (*AvgDepthCount + 1);
-			*AvgDepthCount += 1;
+			*AvgDepthValue = (*AvgDepthValue * AvgDepthCount + DepthNow) / (AvgDepthCount + 1);
+			AvgDepthCount += 1;
 		}
-		*AvgDepthTimer = DiveTime;
+		AvgDepthTimer = DiveTime;
 	}
-	if(*AvgDepthCount == 0)
-		*AvgDepthValue = 0;
+	if(AvgDepthCount == 0)
+		*AvgDepthValue = DepthNow;
 }