diff --git a/tasmota/xdrv_15_pca9685.ino b/tasmota/xdrv_15_pca9685.ino index 254103d0a..48eae7f1f 100644 --- a/tasmota/xdrv_15_pca9685.ino +++ b/tasmota/xdrv_15_pca9685.ino @@ -45,7 +45,7 @@ uint16_t pca9685_pin_pwm_value[16]; void PCA9685_Detect(void) { - if (I2cActive(USE_PCA9685_ADDR)) { return; } + if (!I2cSetDevice(USE_PCA9685_ADDR)) { return; } uint8_t buffer; if (I2cValidRead8(&buffer, USE_PCA9685_ADDR, PCA9685_REG_MODE1)) { diff --git a/tasmota/xsns_09_bmp.ino b/tasmota/xsns_09_bmp.ino index c8ccba8c1..a4cc85149 100644 --- a/tasmota/xsns_09_bmp.ino +++ b/tasmota/xsns_09_bmp.ino @@ -459,7 +459,7 @@ void BmpDetect(void) memset(bmp_sensors, 0, bmp_sensor_size); // Init defaults to 0 for (uint32_t i = 0; i < BMP_MAX_SENSORS; i++) { - if (I2cActive(bmp_addresses[i])) { continue; } + if (!I2cSetDevice(bmp_addresses[i])) { continue; } uint8_t bmp_type = I2cRead8(bmp_addresses[i], BMP_REGISTER_CHIPID); if (bmp_type) { bmp_sensors[bmp_count].bmp_address = bmp_addresses[i]; diff --git a/tasmota/xsns_10_bh1750.ino b/tasmota/xsns_10_bh1750.ino index 26a53689d..b8be7a04e 100644 --- a/tasmota/xsns_10_bh1750.ino +++ b/tasmota/xsns_10_bh1750.ino @@ -115,7 +115,7 @@ bool Bh1750Read(uint32_t sensor_index) { void Bh1750Detect(void) { for (uint32_t i = 0; i < sizeof(Bh1750.addresses); i++) { - if (I2cActive(Bh1750.addresses[i])) { continue; } + if (!I2cSetDevice(Bh1750.addresses[i])) { continue; } Bh1750_sensors[Bh1750.count].address = Bh1750.addresses[i]; if (Bh1750SetMTreg(Bh1750.count)) { diff --git a/tasmota/xsns_11_veml6070.ino b/tasmota/xsns_11_veml6070.ino index 83f889b09..cb24554ad 100644 --- a/tasmota/xsns_11_veml6070.ino +++ b/tasmota/xsns_11_veml6070.ino @@ -128,7 +128,7 @@ char str_uvrisk_text[10]; void Veml6070Detect(void) { - if (I2cActive(VEML6070_ADDR_L)) { return; } + if (!I2cSetDevice(VEML6070_ADDR_L)) { return; } // init the UV sensor Wire.beginTransmission(VEML6070_ADDR_L); diff --git a/tasmota/xsns_12_ads1115.ino b/tasmota/xsns_12_ads1115.ino index f489ad26d..b0249a465 100644 --- a/tasmota/xsns_12_ads1115.ino +++ b/tasmota/xsns_12_ads1115.ino @@ -167,7 +167,7 @@ void Ads1115Detect(void) for (uint32_t i = 0; i < sizeof(Ads1115.addresses); i++) { if (!Ads1115.found[i]) { Ads1115.address = Ads1115.addresses[i]; - if (I2cActive(Ads1115.address)) { continue; } + if (!I2cSetDevice(Ads1115.address)) { continue; } uint16_t buffer; if (I2cValidRead16(&buffer, Ads1115.address, ADS1115_REG_POINTER_CONVERT) && I2cValidRead16(&buffer, Ads1115.address, ADS1115_REG_POINTER_CONFIG)) { diff --git a/tasmota/xsns_13_ina219.ino b/tasmota/xsns_13_ina219.ino index c7bd2fc8e..738c9aabe 100644 --- a/tasmota/xsns_13_ina219.ino +++ b/tasmota/xsns_13_ina219.ino @@ -246,7 +246,7 @@ void Ina219Detect(void) { for (uint32_t i = 0; i < sizeof(ina219_type); i++) { uint16_t addr = ina219_addresses[i]; - if (I2cActive(addr)) { continue; } + if (!I2cSetDevice(addr)) { continue; } if (Ina219SetCalibration(Settings->ina219_mode, addr)) { I2cSetActiveFound(addr, ina219_types); ina219_type[i] = 1; diff --git a/tasmota/xsns_14_sht3x.ino b/tasmota/xsns_14_sht3x.ino index 0f791f78a..438ee601a 100644 --- a/tasmota/xsns_14_sht3x.ino +++ b/tasmota/xsns_14_sht3x.ino @@ -80,7 +80,7 @@ bool Sht3xRead(float &t, float &h, uint8_t sht3x_address) void Sht3xDetect(void) { for (uint32_t i = 0; i < SHT3X_MAX_SENSORS; i++) { - if (I2cActive(sht3x_addresses[i])) { continue; } + if (!I2cSetDevice(sht3x_addresses[i])) { continue; } float t; float h; if (Sht3xRead(t, h, sht3x_addresses[i])) { diff --git a/tasmota/xsns_19_mgs.ino b/tasmota/xsns_19_mgs.ino index 8e62dcff9..5334c5c48 100644 --- a/tasmota/xsns_19_mgs.ino +++ b/tasmota/xsns_19_mgs.ino @@ -37,13 +37,9 @@ bool mgs_detected = false; -void MGSInit(void) { - gas.begin(MGS_SENSOR_ADDR); -} - void MGSPrepare(void) { - if (I2cActive(MGS_SENSOR_ADDR)) { return; } + if (!I2cSetDevice(MGS_SENSOR_ADDR)) { return; } gas.begin(MGS_SENSOR_ADDR); if (!gas.isError()) { diff --git a/tasmota/xsns_21_sgp30.ino b/tasmota/xsns_21_sgp30.ino index 73b6e2d78..ff5445455 100644 --- a/tasmota/xsns_21_sgp30.ino +++ b/tasmota/xsns_21_sgp30.ino @@ -43,7 +43,7 @@ float sgp30_abshum; void sgp30_Init(void) { - if (I2cActive(SGP30_ADDRESS)) { return; } + if (!I2cSetDevice(SGP30_ADDRESS)) { return; } if (sgp.begin()) { sgp30_type = true; diff --git a/tasmota/xsns_24_si1145.ino b/tasmota/xsns_24_si1145.ino index c054ab834..393211a9b 100644 --- a/tasmota/xsns_24_si1145.ino +++ b/tasmota/xsns_24_si1145.ino @@ -326,7 +326,7 @@ bool Si1145Read(void) void Si1145Detect(void) { - if (I2cActive(SI114X_ADDR)) { return; } + if (!I2cSetDevice(SI114X_ADDR)) { return; } if (Si1145Begin()) { si1145_type = true; diff --git a/tasmota/xsns_26_lm75ad.ino b/tasmota/xsns_26_lm75ad.ino index 22e42800e..9e038dd4a 100644 --- a/tasmota/xsns_26_lm75ad.ino +++ b/tasmota/xsns_26_lm75ad.ino @@ -53,8 +53,6 @@ void LM75ADDetect(void) { for (uint32_t i = 0; i < sizeof(lm75ad_addresses); i++) { lm75ad_address = lm75ad_addresses[i]; - if (I2cActive(lm75ad_address)) { - continue; } if (!I2cSetDevice(lm75ad_address)) { continue; // do not make the next step without a confirmed device on the bus } diff --git a/tasmota/xsns_27_apds9960.ino b/tasmota/xsns_27_apds9960.ino index 2182d923c..6c868a4be 100644 --- a/tasmota/xsns_27_apds9960.ino +++ b/tasmota/xsns_27_apds9960.ino @@ -1806,7 +1806,7 @@ void APDS9960_loop(void) { #endif // USE_APDS9960_GESTURE void APDS9960_detect(void) { - if (APDS9960_type || I2cActive(APDS9960_I2C_ADDR)) { return; } + if (APDS9960_type || !I2cSetDevice(APDS9960_I2C_ADDR)) { return; } APDS9960_type = I2cRead8(APDS9960_I2C_ADDR, APDS9960_ID); diff --git a/tasmota/xsns_29_mcp230xx.ino b/tasmota/xsns_29_mcp230xx.ino index a51d8d5e1..34f11c27d 100644 --- a/tasmota/xsns_29_mcp230xx.ino +++ b/tasmota/xsns_29_mcp230xx.ino @@ -251,7 +251,7 @@ void MCP230xx_ApplySettings(void) void MCP230xx_Detect(void) { - if (I2cActive(USE_MCP230xx_ADDR)) { return; } + if (!I2cSetDevice(USE_MCP230xx_ADDR)) { return; } uint8_t buffer; diff --git a/tasmota/xsns_30_mpr121.ino b/tasmota/xsns_30_mpr121.ino index 447b3c24d..24a0cbdd7 100644 --- a/tasmota/xsns_30_mpr121.ino +++ b/tasmota/xsns_30_mpr121.ino @@ -219,7 +219,7 @@ void Mpr121Init(struct mpr121 *pS, bool initial) // Loop through I2C addresses for (uint32_t i = 0; i < sizeof(pS->i2c_addr[i]); i++) { - if (initial && I2cActive(pS->i2c_addr[i])) { continue; } + if (initial && !I2cSetDevice(pS->i2c_addr[i])) { continue; } // Soft reset sensor and check if connected at I2C address pS->connected[i] = (I2cWrite8(pS->i2c_addr[i], MPR121_SRST_REG, MPR121_SRST_VAL) diff --git a/tasmota/xsns_31_ccs811.ino b/tasmota/xsns_31_ccs811.ino index a388c4b82..c0525a909 100644 --- a/tasmota/xsns_31_ccs811.ino +++ b/tasmota/xsns_31_ccs811.ino @@ -46,7 +46,7 @@ uint8_t ecnt = 0; void CCS811Detect(void) { - if (I2cActive(CCS811_ADDRESS)) { return; } + if (!I2cSetDevice(CCS811_ADDRESS)) { return; } if (!ccs.begin(CCS811_ADDRESS)) { CCS811_type = 1; diff --git a/tasmota/xsns_31_ccs811_v2.ino b/tasmota/xsns_31_ccs811_v2.ino index 5a3d65e19..735ebdbf9 100644 --- a/tasmota/xsns_31_ccs811_v2.ino +++ b/tasmota/xsns_31_ccs811_v2.ino @@ -89,7 +89,7 @@ void CCS811Detect(void) int active_index = 1; for (i = 0, pccsd = ccsd; i < MAXDEVICECOUNT; i++, pccsd++) { pccsd->address = CCS811_addresses[ i]; - if (I2cActive( pccsd->address)) { continue; } + if (!I2cSetDevice( pccsd->address)) { continue; } if (!pccsd->ccsinstance.begin(pccsd->address)) { pccsd->device_found = 1; CCS811_devices_found += 1; diff --git a/tasmota/xsns_33_ds3231.ino b/tasmota/xsns_33_ds3231.ino index 34e952ab4..6082bbe49 100644 --- a/tasmota/xsns_33_ds3231.ino +++ b/tasmota/xsns_33_ds3231.ino @@ -72,7 +72,7 @@ bool DS3231chipDetected = false; ----------------------------------------------------------------------*/ void DS3231Detect(void) { - if (I2cActive(USE_RTC_ADDR)) { return; } + if (!I2cSetDevice(USE_RTC_ADDR)) { return; } if (I2cValidRead(USE_RTC_ADDR, RTC_STATUS, 1)) { I2cSetActiveFound(USE_RTC_ADDR, "DS3231"); diff --git a/tasmota/xsns_36_mgc3130.ino b/tasmota/xsns_36_mgc3130.ino index 1c50b412f..73961c753 100644 --- a/tasmota/xsns_36_mgc3130.ino +++ b/tasmota/xsns_36_mgc3130.ino @@ -483,7 +483,7 @@ void MGC3130_loop() void MGC3130_detect(void) { - if (MGC3130_type || I2cActive(MGC3130_I2C_ADDR)) { return; } + if (MGC3130_type || !I2cSetDevice(MGC3130_I2C_ADDR)) { return; } MGC3130_xfer = Pin(GPIO_MGC3130_XFER); MGC3130_reset = Pin(GPIO_MGC3130_RESET); diff --git a/tasmota/xsns_41_max44009.ino b/tasmota/xsns_41_max44009.ino index 7eaf1322d..45cb91354 100644 --- a/tasmota/xsns_41_max44009.ino +++ b/tasmota/xsns_41_max44009.ino @@ -71,7 +71,7 @@ void Max4409Detect(void) for (uint32_t i = 0; 0 != max44009_addresses[i]; i++) { max44009_address = max44009_addresses[i]; - if (I2cActive(max44009_address)) { continue; } + if (!I2cSetDevice(max44009_address)) { continue; } if ((I2cValidRead8(&buffer1, max44009_address, REG_LOWER_THRESHOLD)) && (I2cValidRead8(&buffer2, max44009_address, REG_THRESHOLD_TIMER))) { diff --git a/tasmota/xsns_42_scd30.ino b/tasmota/xsns_42_scd30.ino index 081503ad1..062e1d841 100644 --- a/tasmota/xsns_42_scd30.ino +++ b/tasmota/xsns_42_scd30.ino @@ -79,7 +79,7 @@ float scd30_Temp = 0.0; void Scd30Detect(void) { - if (I2cActive(SCD30_ADDRESS)) { return; } + if (!I2cSetDevice(SCD30_ADDRESS)) { return; } scd30.begin(); diff --git a/tasmota/xsns_50_paj7620.ino b/tasmota/xsns_50_paj7620.ino index 9df5d152e..8a8db26c5 100644 --- a/tasmota/xsns_50_paj7620.ino +++ b/tasmota/xsns_50_paj7620.ino @@ -309,7 +309,7 @@ void PAJ7620ReadGesture(void) void PAJ7620Detect(void) { - if (I2cActive(PAJ7620_ADDR)) { return; } + if (!I2cSetDevice(PAJ7620_ADDR)) { return; } PAJ7620SelectBank(0); PAJ7620SelectBank(0); // do it twice diff --git a/tasmota/xsns_54_ina226.ino b/tasmota/xsns_54_ina226.ino index e2e27d89a..177051139 100644 --- a/tasmota/xsns_54_ina226.ino +++ b/tasmota/xsns_54_ina226.ino @@ -223,7 +223,7 @@ void Ina226Init() for (i = 0; i < INA226_MAX_ADDRESSES; i++){ uint8_t addr = pgm_read_byte(probeAddresses + i); - if (I2cActive(addr)) { continue; } + if (!I2cSetDevice(addr)) { continue; } // Skip device probing if the full scale current is zero diff --git a/tasmota/xsns_55_hih_series.ino b/tasmota/xsns_55_hih_series.ino index d42ec8a4b..b0c8765eb 100644 --- a/tasmota/xsns_55_hih_series.ino +++ b/tasmota/xsns_55_hih_series.ino @@ -74,7 +74,7 @@ bool Hih6Read(void) void Hih6Detect(void) { - if (I2cActive(HIH6_ADDR)) { return; } + if (!I2cSetDevice(HIH6_ADDR)) { return; } if (TasmotaGlobal.uptime < 2) { delay(20); } // Skip entering power on comand mode Hih6.type = Hih6Read(); diff --git a/tasmota/xsns_58_dht12.ino b/tasmota/xsns_58_dht12.ino index 0a04f29cf..559d9931b 100644 --- a/tasmota/xsns_58_dht12.ino +++ b/tasmota/xsns_58_dht12.ino @@ -69,7 +69,7 @@ bool Dht12Read(void) void Dht12Detect(void) { - if (I2cActive(DHT12_ADDR)) { return; } + if (!I2cSetDevice(DHT12_ADDR)) { return; } if (Dht12Read()) { I2cSetActiveFound(DHT12_ADDR, Dht12.name); diff --git a/tasmota/xsns_59_ds1624.ino b/tasmota/xsns_59_ds1624.ino index f6879e46d..1640cc801 100644 --- a/tasmota/xsns_59_ds1624.ino +++ b/tasmota/xsns_59_ds1624.ino @@ -78,7 +78,6 @@ void DS1624_HotPlugUp(uint32_t idx) { uint32_t addr = DS1624_Idx2Addr(idx); - if (I2cActive(addr)) { return; } if (!I2cSetDevice(addr)) { return; } uint8_t config; diff --git a/tasmota/xsns_65_hdc1080.ino b/tasmota/xsns_65_hdc1080.ino index 5fadf8268..cdeb6eaae 100644 --- a/tasmota/xsns_65_hdc1080.ino +++ b/tasmota/xsns_65_hdc1080.ino @@ -236,11 +236,7 @@ bool HdcRead(void) { */ void HdcDetect(void) { - if (I2cActive(HDC1080_ADDR)) { -// AddLog(LOG_LEVEL_DEBUG, PSTR("HdcDetect: Address = 0x%02X already in use."), HDC1080_ADDR); - - return; - } + if (!I2cSetDevice(HDC1080_ADDR)) { return; } hdc_manufacturer_id = HdcReadManufacturerId(); hdc_device_id = HdcReadDeviceId(); diff --git a/tasmota/xsns_70_veml6075.ino b/tasmota/xsns_70_veml6075.ino index 449ec89ec..69fd074f5 100644 --- a/tasmota/xsns_70_veml6075.ino +++ b/tasmota/xsns_70_veml6075.ino @@ -200,7 +200,7 @@ bool VEML6075init(void) } void VEML6075Detect(void) { - if (I2cActive(veml6075_sensor.address)) return; + if (!I2cSetDevice(veml6075_sensor.address)) return; if (VEML6075init()) { I2cSetActiveFound(veml6075_sensor.address, veml6075_sensor.types); diff --git a/tasmota/xsns_89_t67xx.ino b/tasmota/xsns_89_t67xx.ino index 0abeb4f98..8b018f88c 100644 --- a/tasmota/xsns_89_t67xx.ino +++ b/tasmota/xsns_89_t67xx.ino @@ -137,7 +137,7 @@ uint16_t T67XX::getFirmwareVersion(void) void T67XX::detect(void) { - if (I2cActive(T67XX_I2C_ADDR)) + if (!I2cSetDevice(T67XX_I2C_ADDR)) { return; } diff --git a/tasmota/xsns_92_scd40.ino b/tasmota/xsns_92_scd40.ino index 99b43f817..d0e8a5e18 100644 --- a/tasmota/xsns_92_scd40.ino +++ b/tasmota/xsns_92_scd40.ino @@ -115,10 +115,7 @@ float scd40_Temp = 0.0; void Scd40Detect(void) { - if (I2cActive(SCD40_ADDRESS)) { - AddLog(LOG_LEVEL_DEBUG, PSTR("SCD40 I2c already active in Scd40Detect()") ); - return; - } + if (!I2cSetDevice(SCD40_ADDRESS)) { return; } scd40.begin(); diff --git a/tasmota/xsns_93_hm330x.ino b/tasmota/xsns_93_hm330x.ino index 3ddc51ccb..a64141507 100644 --- a/tasmota/xsns_93_hm330x.ino +++ b/tasmota/xsns_93_hm330x.ino @@ -181,7 +181,9 @@ int HM330XSendI2CCommand(uint8_t cmd) { return ret; } -int HM330XInit() { +void HM330XInit(void) { + if (!I2cSetDevice(HM330X_DEFAULT_ADDRESS)) { return; } + int8_t set_pin = Pin(GPIO_HM330X_SET); if (set_pin >= 0) { pinMode(set_pin, OUTPUT); @@ -189,20 +191,15 @@ int HM330XInit() { delay(5); } - if (I2cActive(HM330X_DEFAULT_ADDRESS)) { - AddLog(LOG_LEVEL_DEBUG, PSTR("HM3: Address 0x%02X already in use"), HM330X_DEFAULT_ADDRESS); - return HM330X_ERROR_PARAM; - } - if (HM330X_NO_ERROR != HM330XSendI2CCommand(HM330X_SELECT_COMM_CMD)) { AddLog(LOG_LEVEL_DEBUG, PSTR("HM3: no response from address 0x%02X"), HM330X_DEFAULT_ADDRESS); - return HM330X_ERROR_COMM; + return; } HM330Xdata = (HM330XDATA*)calloc(1,sizeof(HM330XDATA)); if (!HM330Xdata) { AddLog(LOG_LEVEL_DEBUG, PSTR("HM3: out of memory")); - return HM330X_ERROR_MEMALLOC; + return; } HM330Xdata->valid = false; @@ -211,8 +208,6 @@ int HM330XInit() { HM330Xdata->warmup_counter = HM330X_WARMUP_DELAY; I2cSetActiveFound(HM330X_DEFAULT_ADDRESS, "HM330X"); - - return HM330X_NO_ERROR; } void HM330XEverySecond() {