From ae1ff88401ba0fe103989221a18ff6107f670354 Mon Sep 17 00:00:00 2001 From: Firat17aze <187820330+Firat17aze@users.noreply.github.com> Date: Fri, 9 Oct 2026 17:08:03 -0400 Subject: [PATCH] Only mark HDC10xx values invalid on read errors Avoid provisional NAN writes on valid reads because setFloat dispatches formulas. Use the invalid-value handler only after a failed register selection or short response. Add the requested GitHub changelog attribution. OpenAI Codex automation prepared and validated this follow-up. The submitted plugin fails four new setter-order regression scenarios; all 12 revised host scenarios pass with ASan/UBSan. Both complete climate-A ESP8266/ESP32 firmware builds pass, retaining existing warnings in unchanged sources. No physical ESP board or HDC10xx sensor was tested. --- src/_P072_HDC1080.ino | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/_P072_HDC1080.ino b/src/_P072_HDC1080.ino index c0863e9e8..3681bac07 100644 --- a/src/_P072_HDC1080.ino +++ b/src/_P072_HDC1080.ino @@ -6,7 +6,7 @@ // ###################################################################################################### /** Changelog: - * 2026-10-09: Reject failed or short I2C reads instead of reporting maximum sensor values + * 2026-10-09 Firat17aze: Reject failed or short I2C reads instead of reporting maximum sensor values * 2025-01-04 tonhuisman: Send initialization (resolution setting) only once during INIT, small code optimizations * 2023-02-09 tonhuisman: Fix typo in temperature calculation (was 65526.0f instead of 65536.0f (2^16)) * 2023-02-08 tonhuisman: Add PLUGIN_I2C_GET_ADDRESS support @@ -90,22 +90,25 @@ boolean Plugin_072(uint8_t function, struct EventStruct *event, String& string) uint16_t hdc1080_rawtemp, hdc1080_rawhum; float hdc1080_temp, hdc1080_hum; - UserVar.setFloat(event->TaskIndex, 0, NAN); - UserVar.setFloat(event->TaskIndex, 1, NAN); + const auto readError = [event]() { + UserVar.setFloat(event->TaskIndex, 0, NAN); + UserVar.setFloat(event->TaskIndex, 1, NAN); + return false; + }; Wire.beginTransmission(HDC1080_I2C_ADDRESS); // start transmission to device Wire.write(0x00); // sends HDC1080_TEMPERATURE - if (Wire.endTransmission() != 0) { break; } // end transmission + if (Wire.endTransmission() != 0) { return readError(); } // end transmission delay(9); - if (Wire.requestFrom(HDC1080_I2C_ADDRESS, 2) != 2) { break; } // read 2 bytes for temperature + if (Wire.requestFrom(HDC1080_I2C_ADDRESS, 2) != 2) { return readError(); } // read 2 bytes for temperature hdc1080_rawtemp = Wire.read() << 8 | Wire.read(); hdc1080_temp = (static_cast(hdc1080_rawtemp) / 65536.0f) * 165.0f - 40.0f; Wire.beginTransmission(HDC1080_I2C_ADDRESS); // start transmission to device Wire.write(0x01); // sends HDC1080_HUMIDITY - if (Wire.endTransmission() != 0) { break; } // end transmission + if (Wire.endTransmission() != 0) { return readError(); } // end transmission delay(9); - if (Wire.requestFrom(HDC1080_I2C_ADDRESS, 2) != 2) { break; } // read 2 bytes for humidity + if (Wire.requestFrom(HDC1080_I2C_ADDRESS, 2) != 2) { return readError(); } // read 2 bytes for humidity hdc1080_rawhum = Wire.read() << 8 | Wire.read(); hdc1080_hum = (static_cast(hdc1080_rawhum) / 65536.0f) * 100.0f;