From 5452ad88a0c547edce1c3631aaf0236b4f1e1eaf Mon Sep 17 00:00:00 2001 From: Matthias Prinke Date: Sun, 9 Jun 2024 19:33:17 +0200 Subject: [PATCH] Fixed implementation of maximum number of sensors --- .../src/WeatherSensor.cpp | 13 +++++-------- .../src/WeatherSensor.h | 2 +- .../src/WeatherSensorConfig.cpp | 3 ++- src/WeatherSensor.cpp | 12 ++++-------- src/WeatherSensor.h | 2 +- src/WeatherSensorConfig.cpp | 3 ++- 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.cpp b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.cpp index 70e9949..0a30dc9 100644 --- a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.cpp +++ b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.cpp @@ -100,6 +100,7 @@ // - Run-time configuration functions (WeatherSensorConfig.cpp) // 20240528 Fixed channel comparison in findType() // 20240608 Modified implementation of maximum number of sensors +// 20240609 Fixed implementation of maximum number of sensors // // ToDo: // - @@ -136,8 +137,8 @@ void int16_t WeatherSensor::begin(uint8_t max_sensors_default) { - uint8_t maxSensorsDefault = max_sensors_default; - uint8_t maxSensors; + uint8_t maxSensors = max_sensors_default; + getSensorsCfg(maxSensors, rxFlags, enDecoders); log_d("max_sensors: %u", maxSensors); log_d("rx_flags: %u", rxFlags); @@ -309,7 +310,7 @@ bool WeatherSensor::getData(uint32_t timeout, uint8_t flags, uint8_t type, void } } // if (decode_status == DECODE_OK) - } // while ((millis() - timestamp) < timeout) + } // while ((millis() - timestamp) < timeout) // Timeout radio.standby(); @@ -348,7 +349,7 @@ DecodeStatus WeatherSensor::getMessage(void) decode_res = decodeMessage(&recvData[1], sizeof(recvData) - 1); } // if (recvData[0] == 0xD4) - } // if (state == RADIOLIB_ERR_NONE) + } // if (state == RADIOLIB_ERR_NONE) else if (state == RADIOLIB_ERR_RX_TIMEOUT) { log_v("T"); @@ -363,8 +364,6 @@ DecodeStatus WeatherSensor::getMessage(void) return decode_res; } - - // // Generate sample data for testing // @@ -422,7 +421,6 @@ bool WeatherSensor::genMessage(int i, uint32_t id, uint8_t s_type, uint8_t chann return true; } - // // Find required sensor data by ID // @@ -450,7 +448,6 @@ int WeatherSensor::findType(uint8_t type, uint8_t ch) return -1; } - // // From from rtl_433 project - https://github.com/merbanan/rtl_433/blob/master/src/util.c // diff --git a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h index 1e7ae82..bf59785 100644 --- a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h +++ b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h @@ -80,6 +80,7 @@ // 20240506 Changed sensor from array to std::vector, added getSensorCfg() / setSensorCfg() // 20240507 Added configuration of enabled decoders at run time // 20240608 Modified implementation of maximum number of sensors +// 20240609 Fixed implementation of maximum number of sensors // // ToDo: // - @@ -172,7 +173,6 @@ class WeatherSensor { Preferences cfgPrefs; //!< Preferences (stored in flash memory) std::vector sensor_ids_inc; std::vector sensor_ids_exc; - uint8_t maxSensorsDefault; public: /*! diff --git a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorConfig.cpp b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorConfig.cpp index 5c00d55..0a546be 100644 --- a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorConfig.cpp +++ b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorConfig.cpp @@ -38,6 +38,7 @@ // // 20240513 Created from WeatherSensor.cpp // 20240608 Modified implementation of maximum number of sensors +// 20240609 Fixed implementation of maximum number of sensors // // // ToDo: @@ -180,7 +181,7 @@ void WeatherSensor::setSensorsCfg(uint8_t max_sensors, uint8_t rx_flags, uint8_t void WeatherSensor::getSensorsCfg(uint8_t &max_sensors, uint8_t &rx_flags, uint8_t &en_decoders) { cfgPrefs.begin("BWS-CFG", false); - max_sensors = cfgPrefs.getUChar("maxsensors", maxSensorsDefault); + max_sensors = cfgPrefs.getUChar("maxsensors", max_sensors); rx_flags = cfgPrefs.getUChar("rxflags", DATA_COMPLETE); en_decoders = cfgPrefs.getUChar("endec", 0xFF); cfgPrefs.end(); diff --git a/src/WeatherSensor.cpp b/src/WeatherSensor.cpp index 70e9949..e2ac686 100644 --- a/src/WeatherSensor.cpp +++ b/src/WeatherSensor.cpp @@ -100,6 +100,7 @@ // - Run-time configuration functions (WeatherSensorConfig.cpp) // 20240528 Fixed channel comparison in findType() // 20240608 Modified implementation of maximum number of sensors +// 20240609 Fixed implementation of maximum number of sensors // // ToDo: // - @@ -136,8 +137,7 @@ void int16_t WeatherSensor::begin(uint8_t max_sensors_default) { - uint8_t maxSensorsDefault = max_sensors_default; - uint8_t maxSensors; + uint8_t maxSensors = max_sensors_default; getSensorsCfg(maxSensors, rxFlags, enDecoders); log_d("max_sensors: %u", maxSensors); log_d("rx_flags: %u", rxFlags); @@ -309,7 +309,7 @@ bool WeatherSensor::getData(uint32_t timeout, uint8_t flags, uint8_t type, void } } // if (decode_status == DECODE_OK) - } // while ((millis() - timestamp) < timeout) + } // while ((millis() - timestamp) < timeout) // Timeout radio.standby(); @@ -348,7 +348,7 @@ DecodeStatus WeatherSensor::getMessage(void) decode_res = decodeMessage(&recvData[1], sizeof(recvData) - 1); } // if (recvData[0] == 0xD4) - } // if (state == RADIOLIB_ERR_NONE) + } // if (state == RADIOLIB_ERR_NONE) else if (state == RADIOLIB_ERR_RX_TIMEOUT) { log_v("T"); @@ -363,8 +363,6 @@ DecodeStatus WeatherSensor::getMessage(void) return decode_res; } - - // // Generate sample data for testing // @@ -422,7 +420,6 @@ bool WeatherSensor::genMessage(int i, uint32_t id, uint8_t s_type, uint8_t chann return true; } - // // Find required sensor data by ID // @@ -450,7 +447,6 @@ int WeatherSensor::findType(uint8_t type, uint8_t ch) return -1; } - // // From from rtl_433 project - https://github.com/merbanan/rtl_433/blob/master/src/util.c // diff --git a/src/WeatherSensor.h b/src/WeatherSensor.h index 1e7ae82..bf59785 100644 --- a/src/WeatherSensor.h +++ b/src/WeatherSensor.h @@ -80,6 +80,7 @@ // 20240506 Changed sensor from array to std::vector, added getSensorCfg() / setSensorCfg() // 20240507 Added configuration of enabled decoders at run time // 20240608 Modified implementation of maximum number of sensors +// 20240609 Fixed implementation of maximum number of sensors // // ToDo: // - @@ -172,7 +173,6 @@ class WeatherSensor { Preferences cfgPrefs; //!< Preferences (stored in flash memory) std::vector sensor_ids_inc; std::vector sensor_ids_exc; - uint8_t maxSensorsDefault; public: /*! diff --git a/src/WeatherSensorConfig.cpp b/src/WeatherSensorConfig.cpp index 5c00d55..0a546be 100644 --- a/src/WeatherSensorConfig.cpp +++ b/src/WeatherSensorConfig.cpp @@ -38,6 +38,7 @@ // // 20240513 Created from WeatherSensor.cpp // 20240608 Modified implementation of maximum number of sensors +// 20240609 Fixed implementation of maximum number of sensors // // // ToDo: @@ -180,7 +181,7 @@ void WeatherSensor::setSensorsCfg(uint8_t max_sensors, uint8_t rx_flags, uint8_t void WeatherSensor::getSensorsCfg(uint8_t &max_sensors, uint8_t &rx_flags, uint8_t &en_decoders) { cfgPrefs.begin("BWS-CFG", false); - max_sensors = cfgPrefs.getUChar("maxsensors", maxSensorsDefault); + max_sensors = cfgPrefs.getUChar("maxsensors", max_sensors); rx_flags = cfgPrefs.getUChar("rxflags", DATA_COMPLETE); en_decoders = cfgPrefs.getUChar("endec", 0xFF); cfgPrefs.end();