Mercurial > public > ostc4
diff 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 |
line wrap: on
line diff
--- a/Discovery/Src/data_exchange_main.c Fri Mar 15 12:55:58 2019 +0000 +++ b/Discovery/Src/data_exchange_main.c Fri Mar 15 15:48:53 2019 +0000 @@ -771,6 +771,20 @@ return (depth[0] + depth[1] + depth[2] + depth[3])/4.0f; } +#define TEMP_AVERAGE_COUNT 3 +static float getTemperature(SDataExchangeSlaveToMaster *d) +{ + static uint8_t c = 0; + static float temp[TEMP_AVERAGE_COUNT] = {0}; + + temp[c] = d->data[d->boolPressureData].temperature; + + c++; + if (c == TEMP_AVERAGE_COUNT) c = 0; + + return (temp[0] + temp[1] + temp[2])/3.0f; +} + void DataEX_copy_to_LifeData(_Bool *modeChangeFlag) { SDiveState *pStateReal = stateRealGetPointerWrite(); @@ -937,7 +951,7 @@ pStateReal->lifeData.depth_meter = meter; } - pStateReal->lifeData.temperature_celsius = dataIn.data[dataIn.boolPressureData].temperature; + pStateReal->lifeData.temperature_celsius = getTemperature(&dataIn); pStateReal->lifeData.ascent_rate_meter_per_min = dataIn.data[dataIn.boolPressureData].ascent_rate_meter_per_min; if(pStateReal->mode != MODE_DIVE) pStateReal->lifeData.max_depth_meter = 0;