Add optional define LM75AD_SKIP_NULL_SENSOR

This commit is contained in:
Theo Arends 2026-01-05 12:07:01 +01:00
parent 9ac1d09bab
commit 9451cf1cfd

View File

@ -35,13 +35,15 @@
#define LM75AD_MAX_SENSORS 8
#endif
//#define LM75AD_SKIP_NULL_SENSOR // Skip sensor instead of reporting null value
#define LM75AD_ADDRESS 0x48 // Start address
#define LM75AD_COUNT 8 // Number of sequential addresses
#define LM75_TEMP_REGISTER 0x00
#define LM75_CONF_REGISTER 0x01
#define LM75_THYST_REGISTER 0x02
#define LM75_TOS_REGISTER 0x03
#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];
@ -76,7 +78,7 @@ float LM75ADGetTemp(uint32_t sensor) {
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()
@ -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;