comparison Discovery/Src/data_exchange_main.c @ 190:cca59de24fe0

Merged in janlmulder/ostc4/avg-temp (pull request #6) Bugfix: average temperature on arrival from RTE instead of display time
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Fri, 15 Mar 2019 15:48:53 +0000
parents 8b8074080d7b
children c853f5d23bb7
comparison
equal deleted inserted replaced
188:ddc21166d25b 190:cca59de24fe0
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 {