From 75be1abc4c5bc74f53496d022693061c55486097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Wed, 25 Jan 2017 14:57:00 +0100 Subject: [PATCH] temperature_compensation: make sure to reset temperature when params change Makes sure that the offsets & scales are updated and published later on. --- src/modules/sensors/temperature_compensation.cpp | 7 +++++++ src/modules/sensors/temperature_compensation.h | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/modules/sensors/temperature_compensation.cpp b/src/modules/sensors/temperature_compensation.cpp index fc491cead8..e5c1f84e73 100644 --- a/src/modules/sensors/temperature_compensation.cpp +++ b/src/modules/sensors/temperature_compensation.cpp @@ -239,6 +239,13 @@ int TemperatureCompensation::parameters_update() } } + /* the offsets & scales might have changed, so make sure to report that change later when applying the + * next corrections + */ + _gyro_data.reset_temperature(); + _accel_data.reset_temperature(); + _baro_data.reset_temperature(); + return ret; } diff --git a/src/modules/sensors/temperature_compensation.h b/src/modules/sensors/temperature_compensation.h index b6005848e2..94980e7ba4 100644 --- a/src/modules/sensors/temperature_compensation.h +++ b/src/modules/sensors/temperature_compensation.h @@ -254,6 +254,10 @@ private: { for (int i = 0; i < SENSOR_COUNT_MAX; ++i) { device_mapping[i] = 255; last_temperature[i] = -100.0f; } } + void reset_temperature() + { + for (int i = 0; i < SENSOR_COUNT_MAX; ++i) { last_temperature[i] = -100.0f; } + } uint8_t device_mapping[SENSOR_COUNT_MAX]; /// map a topic instance to the parameters index float last_temperature[SENSOR_COUNT_MAX]; };