comparison 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
comparison
equal deleted inserted replaced
308:1203255481e4 309:b0045281cb2d
999 999
1000 void setAvgDepth(SDiveState *pStateReal) { 1000 void setAvgDepth(SDiveState *pStateReal) {
1001 1001
1002 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter; 1002 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter;
1003 float DepthNow = pStateReal->lifeData.depth_meter; 1003 float DepthNow = pStateReal->lifeData.depth_meter;
1004 uint32_t *AvgDepthCount = &pStateReal->lifeData.internal.average_depth_meter_Count; 1004 static uint32_t AvgDepthCount = 0;
1005 uint32_t *AvgDepthTimer = &pStateReal->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time; 1005 static uint32_t AvgDepthTimer = 0;
1006 uint32_t AvgSecondsSinceLast; 1006 uint32_t AvgSecondsSinceLast;
1007 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time; 1007 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time;
1008 1008
1009 if(pStateReal->lifeData.boolResetAverageDepth) 1009 if(pStateReal->lifeData.boolResetAverageDepth)
1010 { 1010 {
1011 *AvgDepthValue = DepthNow; 1011 *AvgDepthValue = DepthNow;
1012 *AvgDepthCount = 1; 1012 AvgDepthCount = 0;
1013 *AvgDepthTimer = DiveTime; 1013 AvgDepthTimer = DiveTime;
1014 pStateReal->lifeData.boolResetAverageDepth = 0; 1014 pStateReal->lifeData.boolResetAverageDepth = 0;
1015 } 1015 }
1016 else if (DiveTime > *AvgDepthTimer) 1016 else if (DiveTime > AvgDepthTimer)
1017 { 1017 {
1018 AvgSecondsSinceLast = DiveTime - *AvgDepthTimer; 1018 AvgSecondsSinceLast = DiveTime - AvgDepthTimer;
1019 for(int i=0;i<AvgSecondsSinceLast;i++) 1019 for(int i=0;i<AvgSecondsSinceLast;i++)
1020 { 1020 {
1021 *AvgDepthValue = (*AvgDepthValue * *AvgDepthCount + DepthNow) / (*AvgDepthCount + 1); 1021 *AvgDepthValue = (*AvgDepthValue * AvgDepthCount + DepthNow) / (AvgDepthCount + 1);
1022 *AvgDepthCount += 1; 1022 AvgDepthCount += 1;
1023 } 1023 }
1024 *AvgDepthTimer = DiveTime; 1024 AvgDepthTimer = DiveTime;
1025 } 1025 }
1026 if(*AvgDepthCount == 0) 1026 if(AvgDepthCount == 0)
1027 *AvgDepthValue = 0; 1027 *AvgDepthValue = DepthNow;
1028 } 1028 }
1029 1029
1030 1030
1031 uint8_t DataEX_check_RTE_version__needs_update(void) 1031 uint8_t DataEX_check_RTE_version__needs_update(void)
1032 { 1032 {