From 521b0f9d850ae8dc6b33c9042d809a19a2b0fbd1 Mon Sep 17 00:00:00 2001 From: Tom Pittenger Date: Tue, 23 May 2023 11:27:06 -0700 Subject: [PATCH] AP_Temperature: slow down temp driver thread and cleanup --- libraries/AP_TemperatureSensor/AP_TemperatureSensor.cpp | 2 +- libraries/AP_TemperatureSensor/AP_TemperatureSensor.h | 1 - .../AP_TemperatureSensor/AP_TemperatureSensor_MAX31865.cpp | 4 ++-- .../AP_TemperatureSensor/AP_TemperatureSensor_MCP9600.cpp | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libraries/AP_TemperatureSensor/AP_TemperatureSensor.cpp b/libraries/AP_TemperatureSensor/AP_TemperatureSensor.cpp index 857bed4f84..fce79c1a3b 100644 --- a/libraries/AP_TemperatureSensor/AP_TemperatureSensor.cpp +++ b/libraries/AP_TemperatureSensor/AP_TemperatureSensor.cpp @@ -124,6 +124,7 @@ void AP_TemperatureSensor::init() // create each instance for (uint8_t instance = 0; instance < AP_TEMPERATURE_SENSOR_MAX_INSTANCES; instance++) { + _state[instance].instance = instance; switch (get_type(instance)) { #if AP_TEMPERATURE_SENSOR_TSYS01_ENABLED @@ -148,7 +149,6 @@ void AP_TemperatureSensor::init() // call init function for each backend if (drivers[instance] != nullptr) { - _state[instance].instance = instance; drivers[instance]->init(); // _num_instances is actually the index for looping over instances // the user may have TEMP_TYPE=0 and TEMP2_TYPE=7, in which case diff --git a/libraries/AP_TemperatureSensor/AP_TemperatureSensor.h b/libraries/AP_TemperatureSensor/AP_TemperatureSensor.h index 14c02b3e6b..cf5cdc84c1 100644 --- a/libraries/AP_TemperatureSensor/AP_TemperatureSensor.h +++ b/libraries/AP_TemperatureSensor/AP_TemperatureSensor.h @@ -71,7 +71,6 @@ private: // The TemperatureSensor_State structure is filled in by the backend driver struct TemperatureSensor_State { - const struct AP_Param::GroupInfo *var_info; uint32_t last_time_ms; // time when the sensor was last read in milliseconds float temperature; // temperature (deg C) uint8_t instance; // instance number diff --git a/libraries/AP_TemperatureSensor/AP_TemperatureSensor_MAX31865.cpp b/libraries/AP_TemperatureSensor/AP_TemperatureSensor_MAX31865.cpp index f85ec04ebe..e17a858f62 100644 --- a/libraries/AP_TemperatureSensor/AP_TemperatureSensor_MAX31865.cpp +++ b/libraries/AP_TemperatureSensor/AP_TemperatureSensor_MAX31865.cpp @@ -93,8 +93,8 @@ void AP_TemperatureSensor_MAX31865::init() _dev->set_speed(AP_HAL::Device::SPEED_HIGH); - /* Request 10Hz update */ - _dev->register_periodic_callback(100 * AP_USEC_PER_MSEC, + /* Request 5Hz update */ + _dev->register_periodic_callback(200 * AP_USEC_PER_MSEC, FUNCTOR_BIND_MEMBER(&AP_TemperatureSensor_MAX31865::thread_tick, void)); } diff --git a/libraries/AP_TemperatureSensor/AP_TemperatureSensor_MCP9600.cpp b/libraries/AP_TemperatureSensor/AP_TemperatureSensor_MCP9600.cpp index 8d11a56a2a..a9e2d8eb3c 100644 --- a/libraries/AP_TemperatureSensor/AP_TemperatureSensor_MCP9600.cpp +++ b/libraries/AP_TemperatureSensor/AP_TemperatureSensor_MCP9600.cpp @@ -105,8 +105,8 @@ void AP_TemperatureSensor_MCP9600::init() // lower retries for run _dev->set_retries(3); - /* Request 10Hz update */ - _dev->register_periodic_callback(100 * AP_USEC_PER_MSEC, + /* Request 5Hz update */ + _dev->register_periodic_callback(200 * AP_USEC_PER_MSEC, FUNCTOR_BIND_MEMBER(&AP_TemperatureSensor_MCP9600::_timer, void)); }