comparison Discovery/Src/data_exchange_main.c @ 189:8b8074080d7b avg-temp

Bugfix: average temperature on arrival from RTE instead of display time This commit is heavily inspired by commits 05c770dc2911 and ecb71521d004. Reading the code, it was clear that a display time averaging process for measured temperature was implemented as was fixed for current depth display in the two mentioned commits. The bug for the late averaging of the temperature is, obviously, not as prominent as the current depth fault. The bug fixed here was nothing more than a visual glitch when first selecting the temperature display in the lower left corner (by default at the start of the dive, or by manually selecting it during the dive using the left button). So, to summarize. A small visual glitch fix, but more important, more consistent data handling and code. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Fri, 15 Mar 2019 15:04:57 +0100
parents 05c770dc2911
children c853f5d23bb7
comparison
equal deleted inserted replaced
188:ddc21166d25b 189:8b8074080d7b
769 if (c == AVERAGE_COUNT) c = 0; 769 if (c == AVERAGE_COUNT) c = 0;
770 770
771 return (depth[0] + depth[1] + depth[2] + depth[3])/4.0f; 771 return (depth[0] + depth[1] + depth[2] + depth[3])/4.0f;
772 } 772 }
773 773
774 #define TEMP_AVERAGE_COUNT 3
775 static float getTemperature(SDataExchangeSlaveToMaster *d)
776 {
777 static uint8_t c = 0;
778 static float temp[TEMP_AVERAGE_COUNT] = {0};
779
780 temp[c] = d->data[d->boolPressureData].temperature;
781
782 c++;
783 if (c == TEMP_AVERAGE_COUNT) c = 0;
784
785 return (temp[0] + temp[1] + temp[2])/3.0f;
786 }
787
774 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag) 788 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag)
775 { 789 {
776 SDiveState *pStateReal = stateRealGetPointerWrite(); 790 SDiveState *pStateReal = stateRealGetPointerWrite();
777 static uint16_t getDeviceDataAfterStartOfMainCPU = 20; 791 static uint16_t getDeviceDataAfterStartOfMainCPU = 20;
778 792
935 else 949 else
936 { 950 {
937 pStateReal->lifeData.depth_meter = meter; 951 pStateReal->lifeData.depth_meter = meter;
938 } 952 }
939 953
940 pStateReal->lifeData.temperature_celsius = dataIn.data[dataIn.boolPressureData].temperature; 954 pStateReal->lifeData.temperature_celsius = getTemperature(&dataIn);
941 pStateReal->lifeData.ascent_rate_meter_per_min = dataIn.data[dataIn.boolPressureData].ascent_rate_meter_per_min; 955 pStateReal->lifeData.ascent_rate_meter_per_min = dataIn.data[dataIn.boolPressureData].ascent_rate_meter_per_min;
942 if(pStateReal->mode != MODE_DIVE) 956 if(pStateReal->mode != MODE_DIVE)
943 pStateReal->lifeData.max_depth_meter = 0; 957 pStateReal->lifeData.max_depth_meter = 0;
944 else 958 else
945 { 959 {