Skip to content

Commit

Permalink
Fixed implementation of maximum number of sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-bs committed Jun 9, 2024
1 parent 675a286 commit 5452ad8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
13 changes: 5 additions & 8 deletions examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// -
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand All @@ -363,8 +364,6 @@ DecodeStatus WeatherSensor::getMessage(void)
return decode_res;
}



//
// Generate sample data for testing
//
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// -
Expand Down Expand Up @@ -172,7 +173,6 @@ class WeatherSensor {
Preferences cfgPrefs; //!< Preferences (stored in flash memory)
std::vector<uint32_t> sensor_ids_inc;
std::vector<uint32_t> sensor_ids_exc;
uint8_t maxSensorsDefault;

public:
/*!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 4 additions & 8 deletions src/WeatherSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// -
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand All @@ -363,8 +363,6 @@ DecodeStatus WeatherSensor::getMessage(void)
return decode_res;
}



//
// Generate sample data for testing
//
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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
//
Expand Down
2 changes: 1 addition & 1 deletion src/WeatherSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// -
Expand Down Expand Up @@ -172,7 +173,6 @@ class WeatherSensor {
Preferences cfgPrefs; //!< Preferences (stored in flash memory)
std::vector<uint32_t> sensor_ids_inc;
std::vector<uint32_t> sensor_ids_exc;
uint8_t maxSensorsDefault;

public:
/*!
Expand Down
3 changes: 2 additions & 1 deletion src/WeatherSensorConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 5452ad8

Please sign in to comment.