From 9451cf1cfd88c8a04e80d9cd255ecb1db10a7766 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 5 Jan 2026 12:07:01 +0100 Subject: [PATCH] Add optional define LM75AD_SKIP_NULL_SENSOR --- .../tasmota_xsns_sensor/xsns_26_lm75ad.ino | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tasmota/tasmota_xsns_sensor/xsns_26_lm75ad.ino b/tasmota/tasmota_xsns_sensor/xsns_26_lm75ad.ino index 8f818ec70..0877fdd14 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_26_lm75ad.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_26_lm75ad.ino @@ -28,20 +28,22 @@ * I2C Address: 0x48 - 0x4F \*********************************************************************************************/ -#define XSNS_26 26 -#define XI2C_20 20 // See I2CDEVICES.md +#define XSNS_26 26 +#define XI2C_20 20 // See I2CDEVICES.md #ifndef LM75AD_MAX_SENSORS -#define LM75AD_MAX_SENSORS 8 +#define LM75AD_MAX_SENSORS 8 #endif -#define LM75AD_ADDRESS 0x48 // Start address -#define LM75AD_COUNT 8 // Number of sequential addresses +//#define LM75AD_SKIP_NULL_SENSOR // Skip sensor instead of reporting null value -#define LM75_TEMP_REGISTER 0x00 -#define LM75_CONF_REGISTER 0x01 -#define LM75_THYST_REGISTER 0x02 -#define LM75_TOS_REGISTER 0x03 +#define LM75AD_ADDRESS 0x48 // Start address +#define LM75AD_COUNT 8 // Number of sequential addresses + +#define LM75_TEMP_REGISTER 0x00 +#define LM75_CONF_REGISTER 0x01 // Power On State is 0x00 +#define LM75_THYST_REGISTER 0x02 // Power On state is 0x4B00 = 75C - Used for I2C device detection +#define LM75_TOS_REGISTER 0x03 // Power On State is 0x5000 = 80C struct { uint8_t address[LM75AD_MAX_SENSORS]; @@ -53,7 +55,7 @@ void LM75ADDetect(void) { if ((LM75AD_MAX_SENSORS < 1) || (LM75AD_MAX_SENSORS > 16)) { return; } // Safeguard user changed LM75AD_MAX_SENSORS out of bounds for (uint32_t bus = 0; bus < 2; bus++) { for (uint32_t address = LM75AD_ADDRESS; address < LM75AD_ADDRESS + LM75AD_COUNT; address++) { - if (!I2cSetDevice(address, bus)) { continue; } // Do not make the next step without a confirmed device on the bus + if (!I2cSetDevice(address, bus)) { continue; } // Do not make the next step without a confirmed device on the bus uint16_t buffer; if (I2cValidRead16(&buffer, address, LM75_THYST_REGISTER, bus)) { if (buffer == 0x4B00) { @@ -72,14 +74,14 @@ float LM75ADGetTemp(uint32_t sensor) { uint16_t t; if (I2cValidRead16(&t, Lm75.address[sensor], LM75_TEMP_REGISTER, Lm75.bus[sensor])) { int16_t sign = 1; - if (t & 0x8000) { // We are getting a negative temperature value + if (t & 0x8000) { // We are getting a negative temperature value t = (~t) +0x20; sign = -1; } - t = t >> 5; // Shift value into place (5 LSB not used) + t = t >> 5; // Shift value into place (5 LSB not used, expect 11-bit resolution) return ConvertTemp(sign * t * 0.125f); } - return NAN; // Will be changed to "null" by ext_vsprintf_P() + return NAN; // Will be changed to "null" by ext_vsprintf_P() } void LM75ADShow(bool json) { @@ -87,6 +89,9 @@ void LM75ADShow(bool json) { for (uint32_t sensor = 0; sensor < Lm75.count; sensor++) { // Takes 2ms / LM75 float t = LM75ADGetTemp(sensor); +#ifdef LM75AD_SKIP_NULL_SENSOR + if (isnan(t)) { continue; } // Skip sensor instead of reporting null value +#endif // LM75AD_SKIP_NULL_SENSOR char name[16]; strlcpy(name, "LM75AD", sizeof(name)); // LM75AD @@ -118,8 +123,7 @@ void LM75ADShow(bool json) { * Interface \*********************************************************************************************/ -bool Xsns26(uint32_t function) -{ +bool Xsns26(uint32_t function) { if (!I2cEnabled(XI2C_20)) { return false; } bool result = false; @@ -132,11 +136,11 @@ bool Xsns26(uint32_t function) case FUNC_JSON_APPEND: LM75ADShow(1); break; - #ifdef USE_WEBSERVER +#ifdef USE_WEBSERVER case FUNC_WEB_SENSOR: LM75ADShow(0); break; - #endif // USE_WEBSERVER +#endif // USE_WEBSERVER } } return result;