From b46c6ef3e512caa1ecf235fa0c0e29f82bf908a0 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 4 Nov 2019 10:38:05 +0100 Subject: [PATCH] Refactor I2c drivers --- tasmota/support_command.ino | 2 +- tasmota/xdrv_15_pca9685.ino | 30 +++++------- tasmota/xdrv_28_pcf8574.ino | 30 ++++++------ tasmota/xdsp_01_lcd.ino | 56 +++++++++++----------- tasmota/xdsp_02_ssd1306.ino | 26 +++++----- tasmota/xdsp_03_matrix.ino | 44 +++++++++-------- tasmota/xdsp_07_sh1106.ino | 26 +++++----- tasmota/xnrg_07_ade7953.ino | 2 +- tasmota/xsns_07_sht1x.ino | 30 ++++++------ tasmota/xsns_08_htu21.ino | 30 ++++++------ tasmota/xsns_09_bmp.ino | 30 ++++++------ tasmota/xsns_10_bh1750.ino | 30 ++++++------ tasmota/xsns_11_veml6070.ino | 33 +++++++------ tasmota/xsns_12_ads1115.ino | 24 +++++----- tasmota/xsns_12_ads1115_i2cdev.ino | 24 +++++----- tasmota/xsns_13_ina219.ino | 40 ++++++++-------- tasmota/xsns_14_sht3x.ino | 24 +++++----- tasmota/xsns_16_tsl2561.ino | 30 ++++++------ tasmota/xsns_19_mgs.ino | 28 +++++------ tasmota/xsns_21_sgp30.ino | 30 ++++++------ tasmota/xsns_24_si1145.ino | 24 +++++----- tasmota/xsns_26_lm75ad.ino | 24 +++++----- tasmota/xsns_27_apds9960.ino | 40 ++++++++-------- tasmota/xsns_29_mcp230xx.ino | 76 ++++++++++++++---------------- tasmota/xsns_30_mpr121.ino | 38 +++++++-------- tasmota/xsns_31_ccs811.ino | 24 +++++----- tasmota/xsns_32_mpu6050.ino | 36 +++++++------- tasmota/xsns_33_ds3231.ino | 66 +++++++++++++------------- tasmota/xsns_36_mgc3130.ino | 42 ++++++++--------- tasmota/xsns_41_max44009.ino | 30 ++++++------ tasmota/xsns_42_scd30.ino | 30 ++++++------ tasmota/xsns_44_sps30.ino | 40 ++++++++-------- tasmota/xsns_45_vl53l0x.ino | 30 ++++++------ tasmota/xsns_46_MLX90614.ino | 28 +++++------ tasmota/xsns_48_chirp.ino | 42 ++++++++--------- tasmota/xsns_50_paj7620.ino | 44 +++++++++-------- tasmota/xsns_54_ina226.ino | 46 +++++++++--------- tasmota/xsns_55_hih_series.ino | 30 ++++++------ tasmota/xx2c_interface.ino | 17 ++----- 39 files changed, 594 insertions(+), 682 deletions(-) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index ffbb9a8e2..14fb7a575 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1547,7 +1547,7 @@ void CmndI2cDriver(void) } } Response_P(PSTR("{\"" D_CMND_I2CDRIVER "\":")); - XI2cDriverState(); + I2cDriverState(); ResponseJsonEnd(); } #endif // USE_I2C diff --git a/tasmota/xdrv_15_pca9685.ino b/tasmota/xdrv_15_pca9685.ino index 39df68b5b..f68cfa77b 100644 --- a/tasmota/xdrv_15_pca9685.ino +++ b/tasmota/xdrv_15_pca9685.ino @@ -179,26 +179,22 @@ void PCA9685_OutputTelemetry(bool telemetry) { bool Xdrv15(uint8_t function) { - if (!XI2cEnabled(XI2C_01)) { return false; } + if (!I2cEnabled(XI2C_01)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_EVERY_SECOND: - PCA9685_Detect(); - if (tele_period == 0) { - PCA9685_OutputTelemetry(true); - } - break; - case FUNC_COMMAND_DRIVER: - if (XDRV_15 == XdrvMailbox.index) { - result = PCA9685_Command(); - } - break; - default: - break; - } + switch (function) { + case FUNC_EVERY_SECOND: + PCA9685_Detect(); + if (tele_period == 0) { + PCA9685_OutputTelemetry(true); + } + break; + case FUNC_COMMAND_DRIVER: + if (XDRV_15 == XdrvMailbox.index) { + result = PCA9685_Command(); + } + break; } return result; } diff --git a/tasmota/xdrv_28_pcf8574.ino b/tasmota/xdrv_28_pcf8574.ino index 2d6ccaaa0..7b2706b5a 100644 --- a/tasmota/xdrv_28_pcf8574.ino +++ b/tasmota/xdrv_28_pcf8574.ino @@ -223,27 +223,25 @@ void Pcf8574SaveSettings() bool Xdrv28(uint8_t function) { - if (!XI2cEnabled(XI2C_02)) { return false; } + if (!I2cEnabled(XI2C_02) || !Pcf8574.type) { return false; } bool result = false; - if (i2c_flg && Pcf8574.type) { - switch (function) { - case FUNC_SET_POWER: - Pcf8574SwitchRelay(); - break; + switch (function) { + case FUNC_SET_POWER: + Pcf8574SwitchRelay(); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_ADD_BUTTON: - WSContentSend_P(HTTP_BTN_MENU_PCF8574); - break; - case FUNC_WEB_ADD_HANDLER: - WebServer->on("/" WEB_HANDLE_PCF8574, HandlePcf8574); - break; + case FUNC_WEB_ADD_BUTTON: + WSContentSend_P(HTTP_BTN_MENU_PCF8574); + break; + case FUNC_WEB_ADD_HANDLER: + WebServer->on("/" WEB_HANDLE_PCF8574, HandlePcf8574); + break; #endif // USE_WEBSERVER - case FUNC_PRE_INIT: - Pcf8574Init(); - break; - } + case FUNC_PRE_INIT: + Pcf8574Init(); + break; } return result; } diff --git a/tasmota/xdsp_01_lcd.ino b/tasmota/xdsp_01_lcd.ino index ed95d7ce5..dfecdca52 100644 --- a/tasmota/xdsp_01_lcd.ino +++ b/tasmota/xdsp_01_lcd.ino @@ -190,28 +190,27 @@ void LcdRefresh(void) // Every second bool Xdsp01(uint8_t function) { - if (!XI2cEnabled(XI2C_03)) { return false; } + if (!I2cEnabled(XI2C_03)) { return false; } bool result = false; - if (i2c_flg) { - if (FUNC_DISPLAY_INIT_DRIVER == function) { - LcdInitDriver(); - } - else if (XDSP_01 == Settings.display_model) { - switch (function) { - case FUNC_DISPLAY_MODEL: - result = true; - break; - case FUNC_DISPLAY_INIT: - LcdInit(dsp_init); - break; - case FUNC_DISPLAY_POWER: - LcdDisplayOnOff(disp_power); - break; - case FUNC_DISPLAY_CLEAR: - lcd->clear(); - break; + if (FUNC_DISPLAY_INIT_DRIVER == function) { + LcdInitDriver(); + } + else if (XDSP_01 == Settings.display_model) { + switch (function) { + case FUNC_DISPLAY_MODEL: + result = true; + break; + case FUNC_DISPLAY_INIT: + LcdInit(dsp_init); + break; + case FUNC_DISPLAY_POWER: + LcdDisplayOnOff(disp_power); + break; + case FUNC_DISPLAY_CLEAR: + lcd->clear(); + break; // case FUNC_DISPLAY_DRAW_HLINE: // break; // case FUNC_DISPLAY_DRAW_VLINE: @@ -230,20 +229,19 @@ bool Xdsp01(uint8_t function) // break; // case FUNC_DISPLAY_FONT_SIZE: // break; - case FUNC_DISPLAY_DRAW_STRING: - LcdDrawStringAt(); - break; - case FUNC_DISPLAY_ONOFF: - LcdDisplayOnOff(dsp_on); - break; + case FUNC_DISPLAY_DRAW_STRING: + LcdDrawStringAt(); + break; + case FUNC_DISPLAY_ONOFF: + LcdDisplayOnOff(dsp_on); + break; // case FUNC_DISPLAY_ROTATION: // break; #ifdef USE_DISPLAY_MODES1TO5 - case FUNC_DISPLAY_EVERY_SECOND: - LcdRefresh(); - break; + case FUNC_DISPLAY_EVERY_SECOND: + LcdRefresh(); + break; #endif // USE_DISPLAY_MODES1TO5 - } } } return result; diff --git a/tasmota/xdsp_02_ssd1306.ino b/tasmota/xdsp_02_ssd1306.ino index bd72f29de..025279378 100644 --- a/tasmota/xdsp_02_ssd1306.ino +++ b/tasmota/xdsp_02_ssd1306.ino @@ -174,25 +174,23 @@ void Ssd1306Refresh(void) // Every second bool Xdsp02(byte function) { - if (!XI2cEnabled(XI2C_04)) { return false; } + if (!I2cEnabled(XI2C_04)) { return false; } bool result = false; - if (i2c_flg) { - if (FUNC_DISPLAY_INIT_DRIVER == function) { - SSD1306InitDriver(); - } - else if (XDSP_02 == Settings.display_model) { - switch (function) { + if (FUNC_DISPLAY_INIT_DRIVER == function) { + SSD1306InitDriver(); + } + else if (XDSP_02 == Settings.display_model) { + switch (function) { #ifdef USE_DISPLAY_MODES1TO5 - case FUNC_DISPLAY_EVERY_SECOND: - Ssd1306Refresh(); - break; + case FUNC_DISPLAY_EVERY_SECOND: + Ssd1306Refresh(); + break; #endif // USE_DISPLAY_MODES1TO5 - case FUNC_DISPLAY_MODEL: - result = true; - break; - } + case FUNC_DISPLAY_MODEL: + result = true; + break; } } return result; diff --git a/tasmota/xdsp_03_matrix.ino b/tasmota/xdsp_03_matrix.ino index 555b8a42b..a97973d57 100644 --- a/tasmota/xdsp_03_matrix.ino +++ b/tasmota/xdsp_03_matrix.ino @@ -331,32 +331,30 @@ void MatrixRefresh(void) // Every second bool Xdsp03(uint8_t function) { - if (!XI2cEnabled(XI2C_05)) { return false; } + if (!I2cEnabled(XI2C_05)) { return false; } bool result = false; - if (i2c_flg) { - if (FUNC_DISPLAY_INIT_DRIVER == function) { - MatrixInitDriver(); - } - else if (XDSP_03 == Settings.display_model) { - switch (function) { - case FUNC_DISPLAY_MODEL: - result = true; - break; - case FUNC_DISPLAY_INIT: - MatrixInit(dsp_init); - break; - case FUNC_DISPLAY_EVERY_50_MSECOND: - MatrixRefresh(); - break; - case FUNC_DISPLAY_POWER: - MatrixOnOff(); - break; - case FUNC_DISPLAY_DRAW_STRING: - MatrixDrawStringAt(dsp_x, dsp_y, dsp_str, dsp_color, dsp_flag); - break; - } + if (FUNC_DISPLAY_INIT_DRIVER == function) { + MatrixInitDriver(); + } + else if (XDSP_03 == Settings.display_model) { + switch (function) { + case FUNC_DISPLAY_MODEL: + result = true; + break; + case FUNC_DISPLAY_INIT: + MatrixInit(dsp_init); + break; + case FUNC_DISPLAY_EVERY_50_MSECOND: + MatrixRefresh(); + break; + case FUNC_DISPLAY_POWER: + MatrixOnOff(); + break; + case FUNC_DISPLAY_DRAW_STRING: + MatrixDrawStringAt(dsp_x, dsp_y, dsp_str, dsp_color, dsp_flag); + break; } } return result; diff --git a/tasmota/xdsp_07_sh1106.ino b/tasmota/xdsp_07_sh1106.ino index a282acb95..5626c1331 100644 --- a/tasmota/xdsp_07_sh1106.ino +++ b/tasmota/xdsp_07_sh1106.ino @@ -168,26 +168,24 @@ void SH1106Refresh(void) // Every second bool Xdsp07(uint8_t function) { - if (!XI2cEnabled(XI2C_06)) { return false; } + if (!I2cEnabled(XI2C_06)) { return false; } bool result = false; - if (i2c_flg) { - if (FUNC_DISPLAY_INIT_DRIVER == function) { - SH1106InitDriver(); - } - else if (XDSP_07 == Settings.display_model) { + if (FUNC_DISPLAY_INIT_DRIVER == function) { + SH1106InitDriver(); + } + else if (XDSP_07 == Settings.display_model) { - switch (function) { - case FUNC_DISPLAY_MODEL: - result = true; - break; + switch (function) { + case FUNC_DISPLAY_MODEL: + result = true; + break; #ifdef USE_DISPLAY_MODES1TO5 - case FUNC_DISPLAY_EVERY_SECOND: - SH1106Refresh(); - break; + case FUNC_DISPLAY_EVERY_SECOND: + SH1106Refresh(); + break; #endif // USE_DISPLAY_MODES1TO5 - } } } return result; diff --git a/tasmota/xnrg_07_ade7953.ino b/tasmota/xnrg_07_ade7953.ino index 9a6b61e7d..f909e21c5 100644 --- a/tasmota/xnrg_07_ade7953.ino +++ b/tasmota/xnrg_07_ade7953.ino @@ -269,7 +269,7 @@ bool Ade7953Command(void) bool Xnrg07(uint8_t function) { - if (!XI2cEnabled(XI2C_07)) { return false; } + if (!I2cEnabled(XI2C_07)) { return false; } bool result = false; diff --git a/tasmota/xsns_07_sht1x.ino b/tasmota/xsns_07_sht1x.ino index 2b6bce978..7e0693b1c 100644 --- a/tasmota/xsns_07_sht1x.ino +++ b/tasmota/xsns_07_sht1x.ino @@ -221,28 +221,26 @@ void ShtShow(bool json) bool Xsns07(uint8_t function) { - if (!XI2cEnabled(XI2C_08)) { return false; } + if (!I2cEnabled(XI2C_08)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { + switch (function) { // case FUNC_PREP_BEFORE_TELEPERIOD: // As this is not a real I2C device it may interfere with other sensors - case FUNC_INIT: // Move detection to restart only removing interference - ShtDetect(); - break; - case FUNC_EVERY_SECOND: - ShtEverySecond(); - break; - case FUNC_JSON_APPEND: - ShtShow(1); - break; + case FUNC_INIT: // Move detection to restart only removing interference + ShtDetect(); + break; + case FUNC_EVERY_SECOND: + ShtEverySecond(); + break; + case FUNC_JSON_APPEND: + ShtShow(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - ShtShow(0); - break; + case FUNC_WEB_SENSOR: + ShtShow(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_08_htu21.ino b/tasmota/xsns_08_htu21.ino index c809713db..f4183428e 100644 --- a/tasmota/xsns_08_htu21.ino +++ b/tasmota/xsns_08_htu21.ino @@ -281,27 +281,25 @@ void HtuShow(bool json) bool Xsns08(uint8_t function) { - if (!XI2cEnabled(XI2C_09)) { return false; } + if (!I2cEnabled(XI2C_09)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - HtuDetect(); - break; - case FUNC_EVERY_SECOND: - HtuEverySecond(); - break; - case FUNC_JSON_APPEND: - HtuShow(1); - break; + switch (function) { + case FUNC_INIT: + HtuDetect(); + break; + case FUNC_EVERY_SECOND: + HtuEverySecond(); + break; + case FUNC_JSON_APPEND: + HtuShow(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - HtuShow(0); - break; + case FUNC_WEB_SENSOR: + HtuShow(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_09_bmp.ino b/tasmota/xsns_09_bmp.ino index 004d5ad06..f4045a203 100644 --- a/tasmota/xsns_09_bmp.ino +++ b/tasmota/xsns_09_bmp.ino @@ -624,27 +624,25 @@ void BmpShow(bool json) bool Xsns09(uint8_t function) { - if (!XI2cEnabled(XI2C_10)) { return false; } + if (!I2cEnabled(XI2C_10)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - BmpDetect(); - break; - case FUNC_EVERY_SECOND: - BmpEverySecond(); - break; - case FUNC_JSON_APPEND: - BmpShow(1); - break; + switch (function) { + case FUNC_INIT: + BmpDetect(); + break; + case FUNC_EVERY_SECOND: + BmpEverySecond(); + break; + case FUNC_JSON_APPEND: + BmpShow(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - BmpShow(0); - break; + case FUNC_WEB_SENSOR: + BmpShow(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_10_bh1750.ino b/tasmota/xsns_10_bh1750.ino index acb0f00aa..b4e50a56a 100644 --- a/tasmota/xsns_10_bh1750.ino +++ b/tasmota/xsns_10_bh1750.ino @@ -113,27 +113,25 @@ void Bh1750Show(bool json) bool Xsns10(uint8_t function) { - if (!XI2cEnabled(XI2C_11)) { return false; } + if (!I2cEnabled(XI2C_11)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - Bh1750Detect(); - break; - case FUNC_EVERY_SECOND: - Bh1750EverySecond(); - break; - case FUNC_JSON_APPEND: - Bh1750Show(1); - break; + switch (function) { + case FUNC_INIT: + Bh1750Detect(); + break; + case FUNC_EVERY_SECOND: + Bh1750EverySecond(); + break; + case FUNC_JSON_APPEND: + Bh1750Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Bh1750Show(0); - break; + case FUNC_WEB_SENSOR: + Bh1750Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_11_veml6070.ino b/tasmota/xsns_11_veml6070.ino index 2998fc0a4..4deaae0de 100644 --- a/tasmota/xsns_11_veml6070.ino +++ b/tasmota/xsns_11_veml6070.ino @@ -305,28 +305,27 @@ void Veml6070Show(bool json) bool Xsns11(uint8_t function) { - if (!XI2cEnabled(XI2C_12)) { return false; } + if (!I2cEnabled(XI2C_12) || + (pin[GPIO_ADE7953_IRQ] < 99)) { return false; } // The ADE7953 uses I2C address 0x38 too but needs priority bool result = false; - if (i2c_flg && !(pin[GPIO_ADE7953_IRQ] < 99)) { // The ADE7953 uses I2C address 0x38 too but needs priority - switch (function) { - case FUNC_INIT: - Veml6070Detect(); // 1[ms], detect and init the sensor - Veml6070UvTableInit(); // 1[ms], initalize the UV compare table only once - break; - case FUNC_EVERY_SECOND: - Veml6070EverySecond(); // 10..15[ms], tested with OLED display, do all the actions needed to get all sensor values - break; - case FUNC_JSON_APPEND: - Veml6070Show(1); - break; + switch (function) { + case FUNC_INIT: + Veml6070Detect(); // 1[ms], detect and init the sensor + Veml6070UvTableInit(); // 1[ms], initalize the UV compare table only once + break; + case FUNC_EVERY_SECOND: + Veml6070EverySecond(); // 10..15[ms], tested with OLED display, do all the actions needed to get all sensor values + break; + case FUNC_JSON_APPEND: + Veml6070Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Veml6070Show(0); - break; + case FUNC_WEB_SENSOR: + Veml6070Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_12_ads1115.ino b/tasmota/xsns_12_ads1115.ino index 7bf3391fa..8efb09f28 100644 --- a/tasmota/xsns_12_ads1115.ino +++ b/tasmota/xsns_12_ads1115.ino @@ -242,24 +242,22 @@ void Ads1115Show(bool json) bool Xsns12(uint8_t function) { - if (!XI2cEnabled(XI2C_13)) { return false; } + if (!I2cEnabled(XI2C_13)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_PREP_BEFORE_TELEPERIOD: - Ads1115Detect(); - break; - case FUNC_JSON_APPEND: - Ads1115Show(1); - break; + switch (function) { + case FUNC_PREP_BEFORE_TELEPERIOD: + Ads1115Detect(); + break; + case FUNC_JSON_APPEND: + Ads1115Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Ads1115Show(0); - break; + case FUNC_WEB_SENSOR: + Ads1115Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_12_ads1115_i2cdev.ino b/tasmota/xsns_12_ads1115_i2cdev.ino index 00c9028ee..77a4268e6 100644 --- a/tasmota/xsns_12_ads1115_i2cdev.ino +++ b/tasmota/xsns_12_ads1115_i2cdev.ino @@ -131,24 +131,22 @@ void Ads1115Show(bool json) bool Xsns12(uint8_t function) { - if (!XI2cEnabled(XI2C_13)) { return false; } + if (!I2cEnabled(XI2C_13)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_PREP_BEFORE_TELEPERIOD: - Ads1115Detect(); - break; - case FUNC_JSON_APPEND: - Ads1115Show(1); - break; + switch (function) { + case FUNC_PREP_BEFORE_TELEPERIOD: + Ads1115Detect(); + break; + case FUNC_JSON_APPEND: + Ads1115Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Ads1115Show(0); - break; + case FUNC_WEB_SENSOR: + Ads1115Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_13_ina219.ino b/tasmota/xsns_13_ina219.ino index 36b0d4305..f9b8e31a4 100644 --- a/tasmota/xsns_13_ina219.ino +++ b/tasmota/xsns_13_ina219.ino @@ -276,32 +276,30 @@ void Ina219Show(bool json) bool Xsns13(uint8_t function) { - if (!XI2cEnabled(XI2C_14)) { return false; } + if (!I2cEnabled(XI2C_14)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_COMMAND_SENSOR: - if ((XSNS_13 == XdrvMailbox.index) && (ina219_type)) { - result = Ina219CommandSensor(); - } - break; - case FUNC_INIT: - Ina219Detect(); - break; - case FUNC_EVERY_SECOND: - Ina219EverySecond(); - break; - case FUNC_JSON_APPEND: - Ina219Show(1); - break; + switch (function) { + case FUNC_COMMAND_SENSOR: + if ((XSNS_13 == XdrvMailbox.index) && (ina219_type)) { + result = Ina219CommandSensor(); + } + break; + case FUNC_INIT: + Ina219Detect(); + break; + case FUNC_EVERY_SECOND: + Ina219EverySecond(); + break; + case FUNC_JSON_APPEND: + Ina219Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Ina219Show(0); - break; + case FUNC_WEB_SENSOR: + Ina219Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_14_sht3x.ino b/tasmota/xsns_14_sht3x.ino index 1adf864a3..b4a256dcb 100644 --- a/tasmota/xsns_14_sht3x.ino +++ b/tasmota/xsns_14_sht3x.ino @@ -139,24 +139,22 @@ void Sht3xShow(bool json) bool Xsns14(uint8_t function) { - if (!XI2cEnabled(XI2C_15)) { return false; } + if (!I2cEnabled(XI2C_15)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - Sht3xDetect(); - break; - case FUNC_JSON_APPEND: - Sht3xShow(1); - break; + switch (function) { + case FUNC_INIT: + Sht3xDetect(); + break; + case FUNC_JSON_APPEND: + Sht3xShow(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Sht3xShow(0); - break; + case FUNC_WEB_SENSOR: + Sht3xShow(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_16_tsl2561.ino b/tasmota/xsns_16_tsl2561.ino index 2b627d579..5eaf7ef4a 100644 --- a/tasmota/xsns_16_tsl2561.ino +++ b/tasmota/xsns_16_tsl2561.ino @@ -122,27 +122,25 @@ void Tsl2561Show(bool json) bool Xsns16(uint8_t function) { - if (!XI2cEnabled(XI2C_16)) { return false; } + if (!I2cEnabled(XI2C_16)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - Tsl2561Detect(); - break; - case FUNC_EVERY_SECOND: - Tsl2561EverySecond(); - break; - case FUNC_JSON_APPEND: - Tsl2561Show(1); - break; + switch (function) { + case FUNC_INIT: + Tsl2561Detect(); + break; + case FUNC_EVERY_SECOND: + Tsl2561EverySecond(); + break; + case FUNC_JSON_APPEND: + Tsl2561Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Tsl2561Show(0); - break; + case FUNC_WEB_SENSOR: + Tsl2561Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_19_mgs.ino b/tasmota/xsns_19_mgs.ino index fb081b314..50123d6a1 100644 --- a/tasmota/xsns_19_mgs.ino +++ b/tasmota/xsns_19_mgs.ino @@ -93,28 +93,26 @@ void MGSShow(bool json) bool Xsns19(uint8_t function) { - if (!XI2cEnabled(XI2C_17)) { return false; } + if (!I2cEnabled(XI2C_17)) { return false; } bool result = false; static int detected = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: + switch (function) { + case FUNC_INIT: // MGSInit(); - break; - case FUNC_PREP_BEFORE_TELEPERIOD: - detected = MGSPrepare(); - break; - case FUNC_JSON_APPEND: - if (detected) MGSShow(1); - break; + break; + case FUNC_PREP_BEFORE_TELEPERIOD: + detected = MGSPrepare(); + break; + case FUNC_JSON_APPEND: + if (detected) MGSShow(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - if (detected) MGSShow(0); - break; + case FUNC_WEB_SENSOR: + if (detected) MGSShow(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_21_sgp30.ino b/tasmota/xsns_21_sgp30.ino index 4c770b241..b2821f986 100644 --- a/tasmota/xsns_21_sgp30.ino +++ b/tasmota/xsns_21_sgp30.ino @@ -154,27 +154,25 @@ void Sgp30Show(bool json) bool Xsns21(uint8_t function) { - if (!XI2cEnabled(XI2C_18)) { return false; } + if (!I2cEnabled(XI2C_18)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - sgp30_Init(); - break; - case FUNC_EVERY_SECOND: - Sgp30Update(); - break; - case FUNC_JSON_APPEND: - Sgp30Show(1); - break; + switch (function) { + case FUNC_INIT: + sgp30_Init(); + break; + case FUNC_EVERY_SECOND: + Sgp30Update(); + break; + case FUNC_JSON_APPEND: + Sgp30Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Sgp30Show(0); - break; + case FUNC_WEB_SENSOR: + Sgp30Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_24_si1145.ino b/tasmota/xsns_24_si1145.ino index d7c5b82c6..2dfe17967 100644 --- a/tasmota/xsns_24_si1145.ino +++ b/tasmota/xsns_24_si1145.ino @@ -351,24 +351,22 @@ void Si1145Show(bool json) bool Xsns24(uint8_t function) { - if (!XI2cEnabled(XI2C_19)) { return false; } + if (!I2cEnabled(XI2C_19)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_EVERY_SECOND: - Si1145Update(); - break; - case FUNC_JSON_APPEND: - Si1145Show(1); - break; + switch (function) { + case FUNC_EVERY_SECOND: + Si1145Update(); + break; + case FUNC_JSON_APPEND: + Si1145Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Si1145Show(0); - break; + case FUNC_WEB_SENSOR: + Si1145Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_26_lm75ad.ino b/tasmota/xsns_26_lm75ad.ino index e0aacc908..4d99c286e 100644 --- a/tasmota/xsns_26_lm75ad.ino +++ b/tasmota/xsns_26_lm75ad.ino @@ -104,24 +104,22 @@ void LM75ADShow(bool json) bool Xsns26(uint8_t function) { - if (!XI2cEnabled(XI2C_20)) { return false; } + if (!I2cEnabled(XI2C_20)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_EVERY_SECOND: - LM75ADDetect(); - break; - case FUNC_JSON_APPEND: - LM75ADShow(1); - break; + switch (function) { + case FUNC_EVERY_SECOND: + LM75ADDetect(); + break; + case FUNC_JSON_APPEND: + LM75ADShow(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - LM75ADShow(0); - break; + case FUNC_WEB_SENSOR: + LM75ADShow(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_27_apds9960.ino b/tasmota/xsns_27_apds9960.ino index 8f5a2dd0d..eab4e9a5c 100644 --- a/tasmota/xsns_27_apds9960.ino +++ b/tasmota/xsns_27_apds9960.ino @@ -2027,32 +2027,30 @@ bool APDS9960CommandSensor(void) bool Xsns27(uint8_t function) { - if (!XI2cEnabled(XI2C_21)) { return false; } + if (!I2cEnabled(XI2C_21)) { return false; } bool result = false; - if (i2c_flg) { - if (FUNC_INIT == function) { - APDS9960_detect(); - } else if (APDS9960type) { - switch (function) { - case FUNC_EVERY_50_MSECOND: - APDS9960_loop(); - break; - case FUNC_COMMAND_SENSOR: - if (XSNS_27 == XdrvMailbox.index) { - result = APDS9960CommandSensor(); - } - break; - case FUNC_JSON_APPEND: - APDS9960_show(1); - break; -#ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - APDS9960_show(0); + if (FUNC_INIT == function) { + APDS9960_detect(); + } else if (APDS9960type) { + switch (function) { + case FUNC_EVERY_50_MSECOND: + APDS9960_loop(); break; + case FUNC_COMMAND_SENSOR: + if (XSNS_27 == XdrvMailbox.index) { + result = APDS9960CommandSensor(); + } + break; + case FUNC_JSON_APPEND: + APDS9960_show(1); + break; +#ifdef USE_WEBSERVER + case FUNC_WEB_SENSOR: + APDS9960_show(0); + break; #endif // USE_WEBSERVER - } } } return result; diff --git a/tasmota/xsns_29_mcp230xx.ino b/tasmota/xsns_29_mcp230xx.ino index db85e00ce..c1dfa2c88 100644 --- a/tasmota/xsns_29_mcp230xx.ino +++ b/tasmota/xsns_29_mcp230xx.ino @@ -777,60 +777,56 @@ void MCP230xx_Interrupt_Retain_Report(void) { bool Xsns29(uint8_t function) { - if (!XI2cEnabled(XI2C_22)) { return false; } + if (!I2cEnabled(XI2C_22)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_EVERY_SECOND: - MCP230xx_Detect(); - if (mcp230xx_int_counter_en) { - mcp230xx_int_sec_counter++; - if (mcp230xx_int_sec_counter >= Settings.mcp230xx_int_timer) { // Interrupt counter interval reached, lets report - MCP230xx_Interrupt_Counter_Report(); - } + switch (function) { + case FUNC_EVERY_SECOND: + MCP230xx_Detect(); + if (mcp230xx_int_counter_en) { + mcp230xx_int_sec_counter++; + if (mcp230xx_int_sec_counter >= Settings.mcp230xx_int_timer) { // Interrupt counter interval reached, lets report + MCP230xx_Interrupt_Counter_Report(); } - if (tele_period == 0) { - if (mcp230xx_int_retainer_en) { // We have pins configured for interrupt retain reporting - MCP230xx_Interrupt_Retain_Report(); - } + } + if (tele_period == 0) { + if (mcp230xx_int_retainer_en) { // We have pins configured for interrupt retain reporting + MCP230xx_Interrupt_Retain_Report(); } + } #ifdef USE_MCP230xx_OUTPUT - if (tele_period == 0) { - MCP230xx_OutputTelemetry(); - } + if (tele_period == 0) { + MCP230xx_OutputTelemetry(); + } #endif // USE_MCP230xx_OUTPUT - break; - case FUNC_EVERY_50_MSECOND: - if ((mcp230xx_int_en) && (mcp230xx_type)) { // Only check for interrupts if its enabled on one of the pins - mcp230xx_int_prio_counter++; - if ((mcp230xx_int_prio_counter) >= (Settings.mcp230xx_int_prio)) { - MCP230xx_CheckForInterrupt(); - mcp230xx_int_prio_counter=0; - } + break; + case FUNC_EVERY_50_MSECOND: + if ((mcp230xx_int_en) && (mcp230xx_type)) { // Only check for interrupts if its enabled on one of the pins + mcp230xx_int_prio_counter++; + if ((mcp230xx_int_prio_counter) >= (Settings.mcp230xx_int_prio)) { + MCP230xx_CheckForInterrupt(); + mcp230xx_int_prio_counter=0; } - break; - case FUNC_JSON_APPEND: - MCP230xx_Show(1); - break; - case FUNC_COMMAND_SENSOR: - if (XSNS_29 == XdrvMailbox.index) { - result = MCP230xx_Command(); - } - break; + } + break; + case FUNC_JSON_APPEND: + MCP230xx_Show(1); + break; + case FUNC_COMMAND_SENSOR: + if (XSNS_29 == XdrvMailbox.index) { + result = MCP230xx_Command(); + } + break; #ifdef USE_WEBSERVER #ifdef USE_MCP230xx_OUTPUT #ifdef USE_MCP230xx_DISPLAYOUTPUT - case FUNC_WEB_SENSOR: - MCP230xx_UpdateWebData(); - break; + case FUNC_WEB_SENSOR: + MCP230xx_UpdateWebData(); + break; #endif // USE_MCP230xx_DISPLAYOUTPUT #endif // USE_MCP230xx_OUTPUT #endif // USE_WEBSERVER - default: - break; - } } return result; } diff --git a/tasmota/xsns_30_mpr121.ino b/tasmota/xsns_30_mpr121.ino index 413097be1..12df09909 100644 --- a/tasmota/xsns_30_mpr121.ino +++ b/tasmota/xsns_30_mpr121.ino @@ -400,7 +400,7 @@ void Mpr121Show(struct mpr121 *pS, uint8_t function) */ bool Xsns30(uint8_t function) { - if (!XI2cEnabled(XI2C_23)) { return false; } + if (!I2cEnabled(XI2C_23)) { return false; } // ??? bool result = false; @@ -409,31 +409,29 @@ bool Xsns30(uint8_t function) static struct mpr121 mpr121; // Check if I2C is enabled - if (i2c_flg) { - switch (function) { + switch (function) { - // Initialize Sensors - case FUNC_INIT: - Mpr121Init(&mpr121); - break; + // Initialize Sensors + case FUNC_INIT: + Mpr121Init(&mpr121); + break; - // Run ever 50 milliseconds (near real-time functions) - case FUNC_EVERY_50_MSECOND: - Mpr121Show(&mpr121, FUNC_EVERY_50_MSECOND); - break; + // Run ever 50 milliseconds (near real-time functions) + case FUNC_EVERY_50_MSECOND: + Mpr121Show(&mpr121, FUNC_EVERY_50_MSECOND); + break; - // Generate JSON telemetry string - case FUNC_JSON_APPEND: - Mpr121Show(&mpr121, FUNC_JSON_APPEND); - break; + // Generate JSON telemetry string + case FUNC_JSON_APPEND: + Mpr121Show(&mpr121, FUNC_JSON_APPEND); + break; #ifdef USE_WEBSERVER - // Show sensor data on main web page - case FUNC_WEB_SENSOR: - Mpr121Show(&mpr121, FUNC_WEB_SENSOR); - break; + // Show sensor data on main web page + case FUNC_WEB_SENSOR: + Mpr121Show(&mpr121, FUNC_WEB_SENSOR); + break; #endif // USE_WEBSERVER - } } // Return bool result return result; diff --git a/tasmota/xsns_31_ccs811.ino b/tasmota/xsns_31_ccs811.ino index 3d3f9bea8..34c4d3a7a 100644 --- a/tasmota/xsns_31_ccs811.ino +++ b/tasmota/xsns_31_ccs811.ino @@ -104,24 +104,22 @@ void CCS811Show(bool json) bool Xsns31(uint8_t function) { - if (!XI2cEnabled(XI2C_24)) { return false; } + if (!I2cEnabled(XI2C_24)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_EVERY_SECOND: - CCS811Update(); - break; - case FUNC_JSON_APPEND: - CCS811Show(1); - break; + switch (function) { + case FUNC_EVERY_SECOND: + CCS811Update(); + break; + case FUNC_JSON_APPEND: + CCS811Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - CCS811Show(0); - break; + case FUNC_WEB_SENSOR: + CCS811Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_32_mpu6050.ino b/tasmota/xsns_32_mpu6050.ino index 983e2743a..ffdcb6a96 100644 --- a/tasmota/xsns_32_mpu6050.ino +++ b/tasmota/xsns_32_mpu6050.ino @@ -226,30 +226,28 @@ void MPU_6050Show(bool json) bool Xsns32(uint8_t function) { - if (!XI2cEnabled(XI2C_25)) { return false; } + if (!I2cEnabled(XI2C_25)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_PREP_BEFORE_TELEPERIOD: - MPU_6050Detect(); - break; - case FUNC_EVERY_SECOND: - if (tele_period == Settings.tele_period -3) { - MPU_6050PerformReading(); - } - break; - case FUNC_JSON_APPEND: - MPU_6050Show(1); - break; -#ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - MPU_6050Show(0); + switch (function) { + case FUNC_PREP_BEFORE_TELEPERIOD: + MPU_6050Detect(); + break; + case FUNC_EVERY_SECOND: + if (tele_period == Settings.tele_period -3) { MPU_6050PerformReading(); - break; + } + break; + case FUNC_JSON_APPEND: + MPU_6050Show(1); + break; +#ifdef USE_WEBSERVER + case FUNC_WEB_SENSOR: + MPU_6050Show(0); + MPU_6050PerformReading(); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_33_ds3231.ino b/tasmota/xsns_33_ds3231.ino index 60eab4ff5..ca268df65 100644 --- a/tasmota/xsns_33_ds3231.ino +++ b/tasmota/xsns_33_ds3231.ino @@ -134,45 +134,43 @@ void SetDS3231Time (uint32_t epoch_time) { bool Xsns33(uint8_t function) { - if (!XI2cEnabled(XI2C_26)) { return false; } + if (!I2cEnabled(XI2C_26)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - DS3231Detect(); - break; - case FUNC_EVERY_SECOND: - TIME_T tmpTime; - if (!ds3231ReadStatus && DS3231chipDetected && Rtc.utc_time < START_VALID_TIME ) { // We still did not sync with NTP (time not valid) , so, read time from DS3231 - ntp_force_sync = true; //force to sync with ntp - Rtc.utc_time = ReadFromDS3231(); //we read UTC TIME from DS3231 - // from this line, we just copy the function from "void RtcSecond()" at the support.ino ,line 2143 and above - // We need it to set rules etc. - BreakTime(Rtc.utc_time, tmpTime); - if (Rtc.utc_time < START_VALID_TIME ) { - ds3231ReadStatus = true; //if time in DS3231 is valid, do not update again - } - RtcTime.year = tmpTime.year + 1970; - Rtc.daylight_saving_time = RuleToTime(Settings.tflag[1], RtcTime.year); - Rtc.standard_time = RuleToTime(Settings.tflag[0], RtcTime.year); - AddLog_P2(LOG_LEVEL_INFO, PSTR("Set time from DS3231 to RTC (" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), - GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); - if (Rtc.local_time < START_VALID_TIME) { // 2016-01-01 - rules_flag.time_init = 1; - } else { - rules_flag.time_set = 1; - } + switch (function) { + case FUNC_INIT: + DS3231Detect(); + break; + case FUNC_EVERY_SECOND: + TIME_T tmpTime; + if (!ds3231ReadStatus && DS3231chipDetected && Rtc.utc_time < START_VALID_TIME ) { // We still did not sync with NTP (time not valid) , so, read time from DS3231 + ntp_force_sync = true; //force to sync with ntp + Rtc.utc_time = ReadFromDS3231(); //we read UTC TIME from DS3231 + // from this line, we just copy the function from "void RtcSecond()" at the support.ino ,line 2143 and above + // We need it to set rules etc. + BreakTime(Rtc.utc_time, tmpTime); + if (Rtc.utc_time < START_VALID_TIME ) { + ds3231ReadStatus = true; //if time in DS3231 is valid, do not update again } - else if (!ds3231WriteStatus && DS3231chipDetected && Rtc.utc_time > START_VALID_TIME && abs(Rtc.utc_time - ReadFromDS3231()) > 60) {//if time is valid and is drift from RTC in more that 60 second - AddLog_P2(LOG_LEVEL_INFO, PSTR("Write Time TO DS3231 from NTP (" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), - GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); - SetDS3231Time (Rtc.utc_time); //update the DS3231 time - ds3231WriteStatus = true; + RtcTime.year = tmpTime.year + 1970; + Rtc.daylight_saving_time = RuleToTime(Settings.tflag[1], RtcTime.year); + Rtc.standard_time = RuleToTime(Settings.tflag[0], RtcTime.year); + AddLog_P2(LOG_LEVEL_INFO, PSTR("Set time from DS3231 to RTC (" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), + GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); + if (Rtc.local_time < START_VALID_TIME) { // 2016-01-01 + rules_flag.time_init = 1; + } else { + rules_flag.time_set = 1; } - break; - } + } + else if (!ds3231WriteStatus && DS3231chipDetected && Rtc.utc_time > START_VALID_TIME && abs(Rtc.utc_time - ReadFromDS3231()) > 60) {//if time is valid and is drift from RTC in more that 60 second + AddLog_P2(LOG_LEVEL_INFO, PSTR("Write Time TO DS3231 from NTP (" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), + GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); + SetDS3231Time (Rtc.utc_time); //update the DS3231 time + ds3231WriteStatus = true; + } + break; } return result; } diff --git a/tasmota/xsns_36_mgc3130.ino b/tasmota/xsns_36_mgc3130.ino index ae795b0bc..07969f894 100644 --- a/tasmota/xsns_36_mgc3130.ino +++ b/tasmota/xsns_36_mgc3130.ino @@ -603,33 +603,31 @@ bool MGC3130CommandSensor() bool Xsns36(uint8_t function) { - if (!XI2cEnabled(XI2C_27)) { return false; } + if (!I2cEnabled(XI2C_27)) { return false; } bool result = false; - if (i2c_flg) { - if ((FUNC_INIT == function) && (pin[GPIO_MGC3130_XFER] < 99) && (pin[GPIO_MGC3130_RESET] < 99)) { - MGC3130_detect(); - } - else if (MGC3130_type) { - switch (function) { - case FUNC_EVERY_50_MSECOND: - MGC3130_loop(); - break; - case FUNC_COMMAND_SENSOR: - if (XSNS_36 == XdrvMailbox.index) { - result = MGC3130CommandSensor(); - } - break; - case FUNC_JSON_APPEND: - MGC3130_show(1); - break; + if ((FUNC_INIT == function) && (pin[GPIO_MGC3130_XFER] < 99) && (pin[GPIO_MGC3130_RESET] < 99)) { + MGC3130_detect(); + } + else if (MGC3130_type) { + switch (function) { + case FUNC_EVERY_50_MSECOND: + MGC3130_loop(); + break; + case FUNC_COMMAND_SENSOR: + if (XSNS_36 == XdrvMailbox.index) { + result = MGC3130CommandSensor(); + } + break; + case FUNC_JSON_APPEND: + MGC3130_show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - MGC3130_show(0); - break; + case FUNC_WEB_SENSOR: + MGC3130_show(0); + break; #endif // USE_WEBSERVER - } } } return result; diff --git a/tasmota/xsns_41_max44009.ino b/tasmota/xsns_41_max44009.ino index 277dfc5a1..a3dc2d731 100644 --- a/tasmota/xsns_41_max44009.ino +++ b/tasmota/xsns_41_max44009.ino @@ -150,27 +150,25 @@ void Max4409Show(bool json) bool Xsns41(uint8_t function) { - if (!XI2cEnabled(XI2C_28)) { return false; } + if (!I2cEnabled(XI2C_28)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - Max4409Detect(); - break; - case FUNC_EVERY_SECOND: - Max4409EverySecond(); - break; - case FUNC_JSON_APPEND: - Max4409Show(1); - break; + switch (function) { + case FUNC_INIT: + Max4409Detect(); + break; + case FUNC_EVERY_SECOND: + Max4409EverySecond(); + break; + case FUNC_JSON_APPEND: + Max4409Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Max4409Show(0); - break; + case FUNC_WEB_SENSOR: + Max4409Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_42_scd30.ino b/tasmota/xsns_42_scd30.ino index 4735d9e98..5c3e741f1 100644 --- a/tasmota/xsns_42_scd30.ino +++ b/tasmota/xsns_42_scd30.ino @@ -473,27 +473,25 @@ void Scd30Show(bool json) bool Xsns42(byte function) { - if (!XI2cEnabled(XI2C_29)) { return false; } + if (!I2cEnabled(XI2C_29)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_EVERY_SECOND: - Scd30Update(); - break; - case FUNC_COMMAND: - result = Scd30CommandSensor(); - break; - case FUNC_JSON_APPEND: - Scd30Show(1); - break; + switch (function) { + case FUNC_EVERY_SECOND: + Scd30Update(); + break; + case FUNC_COMMAND: + result = Scd30CommandSensor(); + break; + case FUNC_JSON_APPEND: + Scd30Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Scd30Show(0); - break; + case FUNC_WEB_SENSOR: + Scd30Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_44_sps30.ino b/tasmota/xsns_44_sps30.ino index b1443b274..266b9ca47 100644 --- a/tasmota/xsns_44_sps30.ino +++ b/tasmota/xsns_44_sps30.ino @@ -284,32 +284,30 @@ bool SPS30_cmd(void) { bool Xsns44(byte function) { - if (!XI2cEnabled(XI2C_30)) { return false; } + if (!I2cEnabled(XI2C_30)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - SPS30_Detect(); - break; - case FUNC_EVERY_SECOND: - SPS30_Every_Second(); - break; - case FUNC_JSON_APPEND: - SPS30_Show(1); - break; - case FUNC_COMMAND_SENSOR: - if (XSNS_44 == XdrvMailbox.index) { - result = SPS30_cmd(); - } - break; + switch (function) { + case FUNC_INIT: + SPS30_Detect(); + break; + case FUNC_EVERY_SECOND: + SPS30_Every_Second(); + break; + case FUNC_JSON_APPEND: + SPS30_Show(1); + break; + case FUNC_COMMAND_SENSOR: + if (XSNS_44 == XdrvMailbox.index) { + result = SPS30_cmd(); + } + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - SPS30_Show(0); - break; + case FUNC_WEB_SENSOR: + SPS30_Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_45_vl53l0x.ino b/tasmota/xsns_45_vl53l0x.ino index a69b30792..18e972649 100644 --- a/tasmota/xsns_45_vl53l0x.ino +++ b/tasmota/xsns_45_vl53l0x.ino @@ -136,27 +136,25 @@ void Vl53l0Show(boolean json) bool Xsns45(byte function) { - if (!XI2cEnabled(XI2C_31)) { return false; } + if (!I2cEnabled(XI2C_31)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - Vl53l0Detect(); - break; - case FUNC_EVERY_250_MSECOND: - Vl53l0Every_250MSecond(); - break; - case FUNC_JSON_APPEND: - Vl53l0Show(1); - break; + switch (function) { + case FUNC_INIT: + Vl53l0Detect(); + break; + case FUNC_EVERY_250_MSECOND: + Vl53l0Every_250MSecond(); + break; + case FUNC_JSON_APPEND: + Vl53l0Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Vl53l0Show(0); - break; + case FUNC_WEB_SENSOR: + Vl53l0Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_46_MLX90614.ino b/tasmota/xsns_46_MLX90614.ino index 1b8548b29..d8afcbae7 100644 --- a/tasmota/xsns_46_MLX90614.ino +++ b/tasmota/xsns_46_MLX90614.ino @@ -117,27 +117,25 @@ void MLX90614_Show(uint8_t json) { bool Xsns46(byte function) { - if (!XI2cEnabled(XI2C_32)) { return false; } + if (!I2cEnabled(XI2C_32)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - MLX90614_Init(); + switch (function) { + case FUNC_INIT: + MLX90614_Init(); + break; + case FUNC_EVERY_SECOND: + MLX90614_Every_Second(); + break; + case FUNC_JSON_APPEND: + MLX90614_Show(1); break; - case FUNC_EVERY_SECOND: - MLX90614_Every_Second(); - break; - case FUNC_JSON_APPEND: - MLX90614_Show(1); - break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - MLX90614_Show(0); - break; + case FUNC_WEB_SENSOR: + MLX90614_Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_48_chirp.ino b/tasmota/xsns_48_chirp.ino index b2a3abaea..8a1d366c7 100644 --- a/tasmota/xsns_48_chirp.ino +++ b/tasmota/xsns_48_chirp.ino @@ -523,33 +523,31 @@ bool ChirpCmd(void) { bool Xsns48(uint8_t function) { - if (!XI2cEnabled(XI2C_33)) { return false; } + if (!I2cEnabled(XI2C_33)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - ChirpDetect(); // We can call CHIRPSCAN later to re-detect - break; - case FUNC_EVERY_100_MSECOND: - if(chirp_found_sensors > 0){ - ChirpEvery100MSecond(); - } - break; - case FUNC_COMMAND: - result = ChirpCmd(); - break; - case FUNC_JSON_APPEND: - ChirpShow(1); - chirp_next_job = 14; // TELE done, now compute time for next measure cycle - break; + switch (function) { + case FUNC_INIT: + ChirpDetect(); // We can call CHIRPSCAN later to re-detect + break; + case FUNC_EVERY_100_MSECOND: + if(chirp_found_sensors > 0){ + ChirpEvery100MSecond(); + } + break; + case FUNC_COMMAND: + result = ChirpCmd(); + break; + case FUNC_JSON_APPEND: + ChirpShow(1); + chirp_next_job = 14; // TELE done, now compute time for next measure cycle + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - ChirpShow(0); - break; + case FUNC_WEB_SENSOR: + ChirpShow(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_50_paj7620.ino b/tasmota/xsns_50_paj7620.ino index 39038f109..b147caf36 100644 --- a/tasmota/xsns_50_paj7620.ino +++ b/tasmota/xsns_50_paj7620.ino @@ -537,34 +537,32 @@ bool PAJ7620Cmd(void) { bool Xsns50(uint8_t function) { - if (!XI2cEnabled(XI2C_34)) { return false; } + if (!I2cEnabled(XI2C_34)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_INIT: - DEBUG_SENSOR_LOG(PSTR("PAJ7620: 1 second until init")); - break; - case FUNC_COMMAND_SENSOR: - if (XSNS_50 == XdrvMailbox.index){ - result = PAJ7620Cmd(); - } - break; - case FUNC_EVERY_100_MSECOND: - if(PAJ7620_next_job <255) { - PAJ7620Loop(); - } - break; - case FUNC_JSON_APPEND: - PAJ7620Show(1); - break; + switch (function) { + case FUNC_INIT: + DEBUG_SENSOR_LOG(PSTR("PAJ7620: 1 second until init")); + break; + case FUNC_COMMAND_SENSOR: + if (XSNS_50 == XdrvMailbox.index){ + result = PAJ7620Cmd(); + } + break; + case FUNC_EVERY_100_MSECOND: + if(PAJ7620_next_job <255) { + PAJ7620Loop(); + } + break; + case FUNC_JSON_APPEND: + PAJ7620Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - PAJ7620Show(0); - break; + case FUNC_WEB_SENSOR: + PAJ7620Show(0); + break; #endif // USE_WEBSERVER - } } return result; } diff --git a/tasmota/xsns_54_ina226.ino b/tasmota/xsns_54_ina226.ino index f4a43cdbf..e92122571 100644 --- a/tasmota/xsns_54_ina226.ino +++ b/tasmota/xsns_54_ina226.ino @@ -532,37 +532,33 @@ void Ina226Show(bool json) */ bool Xsns54(byte callback_id) { - if (!XI2cEnabled(XI2C_35)) { return false; } + if (!I2cEnabled(XI2C_35)) { return false; } // Set return value to `false` bool result = false; - // Check if I2C interface mode is enabled - if(i2c_flg) { - - // Check which callback ID is called by Tasmota - switch (callback_id) { - case FUNC_EVERY_SECOND: - Ina226EverySecond(); - break; - case FUNC_INIT: - Ina226Init(); - break; - case FUNC_JSON_APPEND: - Ina226Show(1); - break; + // Check which callback ID is called by Tasmota + switch (callback_id) { + case FUNC_EVERY_SECOND: + Ina226EverySecond(); + break; + case FUNC_INIT: + Ina226Init(); + break; + case FUNC_JSON_APPEND: + Ina226Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Ina226Show(0); - break; + case FUNC_WEB_SENSOR: + Ina226Show(0); + break; #endif // USE_WEBSERVER - case FUNC_COMMAND_SENSOR: - if (XSNS_54 == XdrvMailbox.index) { - result = Ina226CommandSensor(); - } - break; - } - } // if(i2c_flg) + case FUNC_COMMAND_SENSOR: + if (XSNS_54 == XdrvMailbox.index) { + result = Ina226CommandSensor(); + } + break; + } // Return boolean result return result; } diff --git a/tasmota/xsns_55_hih_series.ino b/tasmota/xsns_55_hih_series.ino index dc9d89f1d..f89b4334a 100644 --- a/tasmota/xsns_55_hih_series.ino +++ b/tasmota/xsns_55_hih_series.ino @@ -135,27 +135,25 @@ void Hih6Show(bool json) bool Xsns55(uint8_t function) { - if (!XI2cEnabled(XI2C_36)) { return false; } + if (!I2cEnabled(XI2C_36)) { return false; } bool result = false; - if (i2c_flg) { - switch (function) { - case FUNC_EVERY_SECOND: - Hih6EverySecond(); - break; - case FUNC_JSON_APPEND: - Hih6Show(1); - break; + switch (function) { + case FUNC_EVERY_SECOND: + Hih6EverySecond(); + break; + case FUNC_JSON_APPEND: + Hih6Show(1); + break; #ifdef USE_WEBSERVER - case FUNC_WEB_SENSOR: - Hih6Show(0); - break; + case FUNC_WEB_SENSOR: + Hih6Show(0); + break; #endif // USE_WEBSERVER - case FUNC_INIT: - Hih6Detect(); - break; - } + case FUNC_INIT: + Hih6Detect(); + break; } return result; } diff --git a/tasmota/xx2c_interface.ino b/tasmota/xx2c_interface.ino index 9f211e382..6a05b2948 100644 --- a/tasmota/xx2c_interface.ino +++ b/tasmota/xx2c_interface.ino @@ -412,23 +412,12 @@ const uint8_t kI2cList[] = { /*********************************************************************************************/ -bool XI2cEnabled(uint32_t i2c_index) +bool I2cEnabled(uint32_t i2c_index) { -/* - if (i2c_index < sizeof(kI2cList)) { -#ifdef XFUNC_PTR_IN_ROM - uint32_t index = pgm_read_byte(kI2cList + i2c_index); -#else - uint32_t index = kI2cList[i2c_index]; -#endif - return bitRead(Settings.i2c_drivers[index / 32], index % 32); - } - return true; -*/ - return bitRead(Settings.i2c_drivers[i2c_index / 32], i2c_index % 32); + return (i2c_flg && bitRead(Settings.i2c_drivers[i2c_index / 32], i2c_index % 32)); } -void XI2cDriverState(void) +void I2cDriverState(void) { ResponseAppend_P(PSTR("\"")); // Use string for enable/disable signal for (uint32_t i = 0; i < sizeof(kI2cList); i++) {