comparison Discovery/Src/data_exchange_main.c @ 308:1203255481e4 cleanup-4

cleanup: introduce function setAvgDepth The simulator and the realtime code shared a literally identical piece of code to compute a running depth average. This is simply poor coding style, so factor this out and create a function to do this work. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Fri, 24 May 2019 09:02:46 +0200
parents b6436edfb2c0
children b0045281cb2d
comparison
equal deleted inserted replaced
307:b6436edfb2c0 308:1203255481e4
992 pStateReal->lifeData.max_depth_meter = 0; 992 pStateReal->lifeData.max_depth_meter = 0;
993 pStateReal->lifeData.boolResetAverageDepth = 1; 993 pStateReal->lifeData.boolResetAverageDepth = 1;
994 } 994 }
995 } 995 }
996 996
997 /* average depth 997 setAvgDepth(pStateReal);
998 */ 998 }
999
1000 void setAvgDepth(SDiveState *pStateReal) {
1001
999 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter; 1002 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter;
1000 float DepthNow = pStateReal->lifeData.depth_meter; 1003 float DepthNow = pStateReal->lifeData.depth_meter;
1001 uint32_t *AvgDepthCount = &pStateReal->lifeData.internal.average_depth_meter_Count; 1004 uint32_t *AvgDepthCount = &pStateReal->lifeData.internal.average_depth_meter_Count;
1002 uint32_t *AvgDepthTimer = &pStateReal->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time; 1005 uint32_t *AvgDepthTimer = &pStateReal->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time;
1003 uint32_t AvgSecondsSinceLast; 1006 uint32_t AvgSecondsSinceLast;
1004 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time; 1007 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time;
1005 1008
1006 if(pStateReal->lifeData.boolResetAverageDepth) 1009 if(pStateReal->lifeData.boolResetAverageDepth)
1007 { 1010 {
1008 *AvgDepthValue = DepthNow; 1011 *AvgDepthValue = DepthNow;
1009 *AvgDepthCount = 1; 1012 *AvgDepthCount = 1;
1010 *AvgDepthTimer = DiveTime; 1013 *AvgDepthTimer = DiveTime;