Fix bug with temperature measurement

This commit is contained in:
Christoph Hagen 2023-06-07 16:38:59 +02:00
parent 36db04036c
commit 675fb4f771

View File

@ -20,7 +20,6 @@ RTC_DATA_ATTR bool didConfigureTemperatureSensors = false;
OneWireNg_CurrentPlatform ow(TEMPERATURE_SENSOR_PIN, TEMPERATURE_SENSOR_PARASITE_POWER); OneWireNg_CurrentPlatform ow(TEMPERATURE_SENSOR_PIN, TEMPERATURE_SENSOR_PARASITE_POWER);
DSTherm sensorInterface = DSTherm(ow); DSTherm sensorInterface = DSTherm(ow);
ALLOC_ALIGNED uint8_t scratchpadBuffer[sizeof(DSTherm::Scratchpad)]; ALLOC_ALIGNED uint8_t scratchpadBuffer[sizeof(DSTherm::Scratchpad)];
DSTherm::Scratchpad *scratchpad;
struct Sensor { struct Sensor {
@ -116,13 +115,17 @@ void clearFoundIndicatorForAllSensors() {
} }
} }
DSTherm::Scratchpad* getScratchpad() {
return reinterpret_cast<DSTherm::Scratchpad*>(&scratchpadBuffer[0]);
}
void temperatureConfigure() { void temperatureConfigure() {
if (didConfigureTemperatureSensors) { if (didConfigureTemperatureSensors) {
// Only determine and configure sensors once per power cycle // Only determine and configure sensors once per power cycle
return; return;
} }
scratchpad = reinterpret_cast<DSTherm::Scratchpad*>(&scratchpadBuffer[0]); DSTherm::Scratchpad* scratchpad = getScratchpad();
// Clear discovery flags // Clear discovery flags
clearFoundIndicatorForAllSensors(); clearFoundIndicatorForAllSensors();
@ -182,6 +185,8 @@ void temperaturePerformUpdate(Temperature* temperatures) {
// Convert temperature on all sensors connected // Convert temperature on all sensors connected
sensorInterface.convertTempAll(DSTherm::SCAN_BUS, TEMPERATURE_SENSOR_PARASITE_POWER); sensorInterface.convertTempAll(DSTherm::SCAN_BUS, TEMPERATURE_SENSOR_PARASITE_POWER);
DSTherm::Scratchpad* scratchpad = getScratchpad();
// Read sensors one by one // Read sensors one by one
for (const auto& id: (OneWireNg&) ow) { for (const auto& id: (OneWireNg&) ow) {
uint8_t sensorIndex = getSensorIndex(id); uint8_t sensorIndex = getSensorIndex(id);