diff Discovery/Src/data_exchange_main.c @ 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 ea3fda8eb93e
line wrap: on
line diff
--- 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;
 }