Refactor dual bus detection

This commit is contained in:
Theo Arends 2026-01-05 11:35:56 +01:00
parent 4ccab9b05d
commit 9ac1d09bab
3 changed files with 29 additions and 47 deletions

View File

@ -200,15 +200,10 @@ void Ads1115Label(char* label, uint32_t maxsize, uint32_t device) {
// "ADS1115-48":{"A0":3240,"A1":3235,"A2":3269,"A3":3269},"ADS1115-49":{"A0":3240,"A1":3235,"A2":3269,"A3":3269} // "ADS1115-48":{"A0":3240,"A1":3235,"A2":3269,"A3":3269},"ADS1115-49":{"A0":3240,"A1":3235,"A2":3269,"A3":3269}
snprintf_P(label, maxsize, PSTR("%s%c%02X"), label, IndexSeparator(), Ads1115[device].address); snprintf_P(label, maxsize, PSTR("%s%c%02X"), label, IndexSeparator(), Ads1115[device].address);
#ifdef USE_I2C_BUS2 #ifdef USE_I2C_BUS2
if (TasmotaGlobal.i2c_enabled[1]) { // Second bus enabled if (TasmotaGlobal.i2c_enabled[1] && // Second bus enabled
uint8_t bus = Ads1115[0].bus; (Ads1115[0].bus != Ads1115[ads1115_count -1].bus)) { // Different busses
for (uint32_t i = 1; i < ads1115_count; i++) { // "ADS1115-48-1":{"A0":3240,"A1":3235,"A2":3269,"A3":3269},"ADS1115-48-2":{"A0":3240,"A1":3235,"A2":3269,"A3":3269}
if (bus != Ads1115[i].bus) { // Different busses snprintf_P(label, maxsize, PSTR("%s%c%d"), label, IndexSeparator(), Ads1115[device].bus +1);
// "ADS1115-48-1":{"A0":3240,"A1":3235,"A2":3269,"A3":3269},"ADS1115-48-2":{"A0":3240,"A1":3235,"A2":3269,"A3":3269}
snprintf_P(label, maxsize, PSTR("%s%c%d"), label, IndexSeparator(), Ads1115[device].bus +1);
break;
}
}
} }
#endif // USE_I2C_BUS2 #endif // USE_I2C_BUS2
} }

View File

@ -185,20 +185,15 @@ void Sht3xUpdate(void) {
void Sht3xShow(bool json) { void Sht3xShow(bool json) {
char types[11]; char types[11];
bool dual_bus_use = (sht3x_sensors[0].bus != sht3x_sensors[sht3x_count -1].bus);
for (uint32_t idx = 0; idx < sht3x_count; idx++) { for (uint32_t idx = 0; idx < sht3x_count; idx++) {
if (sht3x_sensors[idx].valid) { if (sht3x_sensors[idx].valid) {
strlcpy(types, sht3x_sensors[idx].types, sizeof(types)); strlcpy(types, sht3x_sensors[idx].types, sizeof(types));
if (sht3x_count > 1) { if (sht3x_count > 1) {
snprintf_P(types, sizeof(types), PSTR("%s%c%02X"), types, IndexSeparator(), sht3x_sensors[idx].address); // "SHT3X-0xXX" snprintf_P(types, sizeof(types), PSTR("%s%c%02X"), types, IndexSeparator(), sht3x_sensors[idx].address); // "SHT3X-XX"
#ifdef USE_I2C_BUS2 #ifdef USE_I2C_BUS2
if (TasmotaGlobal.i2c_enabled[1]) { if (TasmotaGlobal.i2c_enabled[1] && dual_bus_use) { // Different busses
for (uint32_t i = 1; i < sht3x_count; i++) { snprintf_P(types, sizeof(types), PSTR("%s%c%d"), types, IndexSeparator(), sht3x_sensors[idx].bus + 1); // "SHT3X-XX-X"
if (sht3x_sensors[0].bus != sht3x_sensors[i].bus) {
snprintf_P(types, sizeof(types), PSTR("%s%c%d"), types, IndexSeparator(), sht3x_sensors[idx].bus + 1); // "SHT3X-0xXX-X"
break;
}
}
} }
#endif // USE_I2C_BUS2 #endif // USE_I2C_BUS2
} }

View File

@ -83,42 +83,34 @@ float LM75ADGetTemp(uint32_t sensor) {
} }
void LM75ADShow(bool json) { void LM75ADShow(bool json) {
bool dual_bus_use = (Lm75.bus[0] != Lm75.bus[Lm75.count -1]);
for (uint32_t sensor = 0; sensor < Lm75.count; sensor++) { for (uint32_t sensor = 0; sensor < Lm75.count; sensor++) {
// Takes 2ms / LM75
float t = LM75ADGetTemp(sensor); float t = LM75ADGetTemp(sensor);
// if (!isnan(t)) {
char name[16];
// LM75AD
strlcpy(name, "LM75AD", sizeof(name));
if (Lm75.count > 1) {
// LM75AD-49
snprintf_P(name, sizeof(name), PSTR("%s%c%02X"), name, IndexSeparator(), Lm75.address[sensor]);
#ifdef USE_I2C_BUS2
if (TasmotaGlobal.i2c_enabled[1]) { // Second bus enabled
uint8_t bus = Lm75.bus[0];
for (uint32_t i = 1; i < Lm75.count; i++) {
if (bus != Lm75.bus[i]) { // Different busses
// LM75AD-49-1
snprintf_P(name, sizeof(name), PSTR("%s%c%d"), name, IndexSeparator(), Lm75.bus[sensor] +1);
break;
}
}
}
#endif // USE_I2C_BUS2
}
if (json) { char name[16];
ResponseAppend_P(JSON_SNS_F_TEMP, name, Settings->flag2.temperature_resolution, &t); strlcpy(name, "LM75AD", sizeof(name)); // LM75AD
if (Lm75.count > 1) {
snprintf_P(name, sizeof(name), PSTR("%s%c%02X"), name, IndexSeparator(), Lm75.address[sensor]); // LM75AD-49
#ifdef USE_I2C_BUS2
if (TasmotaGlobal.i2c_enabled[1] && dual_bus_use) { // Different busses
snprintf_P(name, sizeof(name), PSTR("%s%c%d"), name, IndexSeparator(), Lm75.bus[sensor] +1); // LM75AD-49-1
}
#endif // USE_I2C_BUS2
}
if (json) {
ResponseAppend_P(JSON_SNS_F_TEMP, name, Settings->flag2.temperature_resolution, &t);
#ifdef USE_DOMOTICZ #ifdef USE_DOMOTICZ
if ((0 == TasmotaGlobal.tele_period) && (0 == sensor)) { if ((0 == TasmotaGlobal.tele_period) && (0 == sensor)) {
DomoticzFloatSensor(DZ_TEMP, t); DomoticzFloatSensor(DZ_TEMP, t);
} }
#endif // USE_DOMOTICZ #endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
} else { } else {
WSContentSend_Temp(name, t); WSContentSend_Temp(name, t);
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
} }
// }
} }
} }