From 6d8fab10f3527ef296e8d07032cbd1e87f90fc26 Mon Sep 17 00:00:00 2001 From: Mickael Gaillard Date: Sun, 19 Apr 2020 00:37:41 +0200 Subject: [PATCH 1/8] Add Debug Chip ID And Fifo Signed-off-by: Mickael Gaillard --- tasmota/xsns_27_apds9960.ino | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tasmota/xsns_27_apds9960.ino b/tasmota/xsns_27_apds9960.ino index 5f33ad6c7..c361cc76e 100644 --- a/tasmota/xsns_27_apds9960.ino +++ b/tasmota/xsns_27_apds9960.ino @@ -1425,6 +1425,10 @@ int16_t readGesture(void) { /* Read the current FIFO level */ fifo_level = I2cRead8(APDS9960_I2C_ADDR, APDS9960_GFLVL); +#ifdef USE_DEBUG_DRIVER + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DRV: FIFO Level : %d"), fifo_level); +#endif // USE_DEBUG_DRIVER + /* If there's stuff in the FIFO, read it into our data block */ if (fifo_level > 0) { bytes_read = wireReadDataBlock(APDS9960_GFIFO_U, (uint8_t*)fifo_data, (fifo_level * 4)); @@ -1432,6 +1436,16 @@ int16_t readGesture(void) { return APDS9960_ERROR; } +#ifdef USE_DEBUG_DRIVER + char output[(bytes_read * 2) + 1]; + char *ptr = &output[0]; + + for ( i = 0; i < bytes_read; i++ ) { + ptr += sprintf(ptr, "%02X", fifo_data[i]); + } + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DRV: FIFO Dump : %s"), output); +#endif // USE_DEBUG_DRIVER + /* If at least 1 set of data, sort the data into U/D/L/R */ if (bytes_read >= 4) { for (i = 0; i < bytes_read; i += 4) { @@ -1763,6 +1777,12 @@ void APDS9960_detect(void) { if (APDS9960type || I2cActive(APDS9960_I2C_ADDR)) { return; } APDS9960type = I2cRead8(APDS9960_I2C_ADDR, APDS9960_ID); + +#ifdef USE_DEBUG_DRIVER + // Debug new chip + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DRV: %s Chip %X"), APDS9960stype, APDS9960type); +#endif // USE_DEBUG_DRIVER + if (APDS9960type == APDS9960_CHIPID_1 || APDS9960type == APDS9960_CHIPID_2 || APDS9960type == APDS9960_CHIPID_3) { if (APDS9960_init()) { I2cSetActiveFound(APDS9960_I2C_ADDR, APDS9960stype); From bb0d4387ff600ac73cb9e3c2394f464dec28236e Mon Sep 17 00:00:00 2001 From: Mickael Gaillard Date: Thu, 23 Apr 2020 23:04:25 +0200 Subject: [PATCH 2/8] Resync at commit 258bea2da Signed-off-by: Mickael Gaillard --- tasmota/xsns_27_apds9960.ino | 79 ++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/tasmota/xsns_27_apds9960.ino b/tasmota/xsns_27_apds9960.ino index 5f33ad6c7..2bedbe5af 100644 --- a/tasmota/xsns_27_apds9960.ino +++ b/tasmota/xsns_27_apds9960.ino @@ -213,7 +213,7 @@ const char HTTP_APDS_9960_SNS[] PROGMEM = #define GWTIME_39_2MS 7 /* Default values */ -#define DEFAULT_ATIME 0xdb // 103ms = 0xdb +#define DEFAULT_ATIME 0xdb // 103ms = 0xdb = 219 #define DEFAULT_WTIME 246 // 27ms #define DEFAULT_PROX_PPULSE 0x87 // 16us, 8 pulses #define DEFAULT_GESTURE_PPULSE 0x89 // 16us, 10 pulses ---89 @@ -250,12 +250,16 @@ enum { DIR_RIGHT, DIR_UP, DIR_DOWN, + DIR_NEAR, + DIR_FAR, DIR_ALL }; /* State definitions*/ enum { APDS9960_NA_STATE, + APDS9960_NEAR_STATE, + APDS9960_FAR_STATE, APDS9960_ALL_STATE }; @@ -282,9 +286,9 @@ int16_t gesture_motion_ = DIR_NONE; typedef struct color_data_type { uint16_t a; // measured ambient - uint16_t r; - uint16_t g; - uint16_t b; + uint16_t r; // Red + uint16_t g; // Green + uint16_t b; // Blue uint8_t p; // proximity uint16_t cct; // calculated color temperature uint16_t lux; // calculated illuminance - atm only from rgb @@ -391,6 +395,7 @@ uint8_t getProxIntLowThresh(void) { /* Read value from PILT register */ val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_PILT); + return val; } @@ -413,6 +418,7 @@ uint8_t getProxIntHighThresh(void) { /* Read value from PIHT register */ val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_PIHT); + return val; } @@ -441,6 +447,7 @@ uint8_t getLEDDrive(void) { /* Read value from CONTROL register */ val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONTROL); + /* Shift and mask out LED drive bits */ val = (val >> 6) & 0b00000011; @@ -490,6 +497,7 @@ uint8_t getProximityGain(void) { /* Read value from CONTROL register */ val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONTROL); + /* Shift and mask out PDRIVE bits */ val = (val >> 2) & 0b00000011; @@ -534,6 +542,17 @@ void setProximityGain(uint8_t drive) { * * @return the value of the ALS gain. 0xFF on failure. */ +uint8_t getAmbientLightGain() { + uint8_t val; + + /* Read value from CONTROL register */ + val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONTROL); + + /* Shift and mask out ADRIVE bits */ + val &= 0b00000011; + + return val; +} /** * @brief Sets the receiver gain for the ambient light sensor (ALS) @@ -600,6 +619,7 @@ void setLEDBoost(uint8_t boost) { /* Read value from CONFIG2 register */ val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONFIG2); + /* Set bits in register to given value */ boost &= 0b00000011; boost = boost << 4; @@ -1193,6 +1213,8 @@ void setGestureMode(uint8_t mode) { bool APDS9960_init(void) { + setMode(ALL, OFF); + /* Set default values for ambient light and proximity registers */ I2cWrite8(APDS9960_I2C_ADDR, APDS9960_ATIME, DEFAULT_ATIME); I2cWrite8(APDS9960_I2C_ADDR, APDS9960_WTIME, DEFAULT_WTIME); @@ -1296,9 +1318,9 @@ void setMode(uint8_t mode, uint8_t enable) { void enableLightSensor(void) { /* Set default gain, interrupts, enable power, and enable sensor */ setAmbientLightGain(DEFAULT_AGAIN); - setAmbientLightIntEnable(0); + setAmbientLightIntEnable(OFF); enablePower(); - setMode(AMBIENT_LIGHT, 1); + setMode(AMBIENT_LIGHT, ON); } /** @@ -1306,8 +1328,8 @@ void enableLightSensor(void) { * */ void disableLightSensor(void) { - setAmbientLightIntEnable(0); - setMode(AMBIENT_LIGHT, 0); + setAmbientLightIntEnable(OFF); + setMode(AMBIENT_LIGHT, OFF); } /** @@ -1319,9 +1341,9 @@ void enableProximitySensor(void) { /* Set default gain, LED, interrupts, enable power, and enable sensor */ setProximityGain(DEFAULT_PGAIN); setLEDDrive(DEFAULT_LDRIVE); - setProximityIntEnable(0); + setProximityIntEnable(OFF); enablePower(); - setMode(PROXIMITY, 1); + setMode(PROXIMITY, ON); } /** @@ -1329,8 +1351,8 @@ void enableProximitySensor(void) { * */ void disableProximitySensor(void) { - setProximityIntEnable(0); - setMode(PROXIMITY, 0); + setProximityIntEnable(OFF); + setMode(PROXIMITY, OFF); } /** @@ -1350,12 +1372,12 @@ void enableGestureSensor(void) { I2cWrite8(APDS9960_I2C_ADDR, APDS9960_WTIME, 0xFF); I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PPULSE, DEFAULT_GESTURE_PPULSE); setLEDBoost(LED_BOOST_100); // tip from jonn26 - 100 for 300 ---- 200 from Adafruit - setGestureIntEnable(0); - setGestureMode(1); + setGestureIntEnable(OFF); + setGestureMode(ON); enablePower(); - setMode(WAIT, 1); - setMode(PROXIMITY, 1); - setMode(GESTURE, 1); + setMode(WAIT, ON); + setMode(PROXIMITY, ON); + setMode(GESTURE, ON); } /** @@ -1364,9 +1386,9 @@ void enableGestureSensor(void) { */ void disableGestureSensor(void) { resetGestureParameters(); - setGestureIntEnable(0); - setGestureMode(0); - setMode(GESTURE, 0); + setGestureIntEnable(OFF); + setGestureMode(OFF); + setMode(GESTURE, OFF); } /** @@ -1414,6 +1436,7 @@ int16_t readGesture(void) { AddLog_P(LOG_LEVEL_DEBUG, PSTR("Sensor overload")); } gesture_loop_counter += 1; + /* Wait some time to collect next batch of FIFO data */ delay(FIFO_PAUSE_TIME); @@ -1435,14 +1458,10 @@ int16_t readGesture(void) { /* If at least 1 set of data, sort the data into U/D/L/R */ if (bytes_read >= 4) { for (i = 0; i < bytes_read; i += 4) { - gesture_data_.u_data[gesture_data_.index] = \ - fifo_data[i + 0]; - gesture_data_.d_data[gesture_data_.index] = \ - fifo_data[i + 1]; - gesture_data_.l_data[gesture_data_.index] = \ - fifo_data[i + 2]; - gesture_data_.r_data[gesture_data_.index] = \ - fifo_data[i + 3]; + gesture_data_.u_data[gesture_data_.index] = fifo_data[i + 0]; + gesture_data_.d_data[gesture_data_.index] = fifo_data[i + 1]; + gesture_data_.l_data[gesture_data_.index] = fifo_data[i + 2]; + gesture_data_.r_data[gesture_data_.index] = fifo_data[i + 3]; gesture_data_.index++; gesture_data_.total_gestures++; } @@ -1474,7 +1493,7 @@ int16_t readGesture(void) { * */ void enablePower(void) { - setMode(POWER, 1); + setMode(POWER, ON); } /** @@ -1482,7 +1501,7 @@ void enablePower(void) { * */ void disablePower(void) { - setMode(POWER, 0); + setMode(POWER, OFF); } From 3c6d4ef56b1210bf2fd3e5906268e47fa8ea6a68 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 24 Apr 2020 09:18:52 +0200 Subject: [PATCH 3/8] NimBLE ESP32 warning suppression needs to work a entry in build_unflags --- platformio_override_sample.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/platformio_override_sample.ini b/platformio_override_sample.ini index 0d693b7b0..f1af6d4b7 100644 --- a/platformio_override_sample.ini +++ b/platformio_override_sample.ini @@ -235,6 +235,7 @@ board_build.partitions = esp32_partition_app1984k_spiffs64k.csv board_build.flash_mode = ${common.board_build.flash_mode} board_build.f_cpu = ${common.board_build.f_cpu} build_unflags = ${common.build_unflags} + -Wpointer-arith monitor_speed = ${common.monitor_speed} upload_port = ${common.upload_port} upload_resetmethod = ${common.upload_resetmethod} From f8f654c9defcfcab8d3d05f40587dce5af57a2e0 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 24 Apr 2020 10:57:39 +0200 Subject: [PATCH 4/8] Use latest Arduino git version for Tasmota... feature stage. -> rc v.7.0 --- platformio_override_sample.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio_override_sample.ini b/platformio_override_sample.ini index f1af6d4b7..3c3ca8cfd 100644 --- a/platformio_override_sample.ini +++ b/platformio_override_sample.ini @@ -132,7 +132,7 @@ build_flags = ${esp82xx_defaults.build_flags} [tasmota_feature_stage] ; *** Esp8266 core for Arduino version Tasmota feature stage platform = espressif8266@2.4.0 -platform_packages = framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git#d600cc7fa6c3fc5c31ed903ec12fd2e2da2c3678 +platform_packages = framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git#36e047e908cfa6eafaaf824988070b49f2c2ff2a build_flags = ${esp82xx_defaults.build_flags} -DBEARSSL_SSL_BASIC ; NONOSDK221 From 06841bbdff971530698cd8971d1430b367aae094 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 24 Apr 2020 11:27:30 +0200 Subject: [PATCH 5/8] Use RC candidate of core v.2.7 --- platformio.ini | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/platformio.ini b/platformio.ini index f29d5f363..7be94333c 100755 --- a/platformio.ini +++ b/platformio.ini @@ -107,14 +107,14 @@ build_flags = -DUSE_IR_REMOTE_FULL -DDECODE_PRONTO=false -DSEND_PRONTO=false [core_active] -platform = ${tasmota_core_stage.platform} -platform_packages = ${tasmota_core_stage.platform_packages} -build_flags = ${tasmota_core_stage.build_flags} +platform = ${tasmota_core.platform} +platform_packages = ${tasmota_core.platform_packages} +build_flags = ${tasmota_core.build_flags} -[tasmota_core_stage] -; *** Esp8266 core for Arduino version stable beta +[tasmota_core] +; *** Esp8266 Arduino core version Tasmota platform = espressif8266@2.4.0 -platform_packages = framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git#372a3ec297dfe8501bed1ec4552244695b5e8ced +platform_packages = framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git#36e047e908cfa6eafaaf824988070b49f2c2ff2a build_flags = ${esp82xx_defaults.build_flags} -DBEARSSL_SSL_BASIC ; NONOSDK22x_190703 = 2.2.2-dev(38a443e) From 97f89f98a8eb96260ea229e3eea794592493ab7c Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 24 Apr 2020 11:30:03 +0200 Subject: [PATCH 6/8] Core changed and ESP32 added --- .github/PULL_REQUEST_TEMPLATE.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 2839ba02b..86917c8d6 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -6,6 +6,7 @@ - [ ] The pull request is done against the latest dev branch - [ ] Only relevant files were touched - [ ] Only one feature/fix was added per PR. - - [ ] The code change is tested and works on core Tasmota_core_stage + - [ ] The code change is tested and works on core Tasmota_core + - [ ] The code change is tested and works on core ESP32 - [ ] The code change pass travis tests. **Your PR cannot be merged unless tests pass** - [ ] I accept the [CLA](https://github.com/arendst/Tasmota/blob/development/CONTRIBUTING.md#contributor-license-agreement-cla). From 5f75a4c354a8e6daf8a2d47537c2960709d7e040 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 24 Apr 2020 15:50:27 +0200 Subject: [PATCH 7/8] Fix future compile error ;-) --- tasmota/support_tasmota.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index d10e91d98..d8f33d9a7 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -339,7 +339,7 @@ void SetPowerOnState(void) void SetLedPowerIdx(uint32_t led, uint32_t state) { if ((99 == pin[GPIO_LEDLNK]) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present - if (pin[GPIO_LED2] < 99) { + if (pin[GPIO_LED1 +1] < 99) { led = 1; } } From 9ed8e7c254591b6f78ce7efa1c79eb1c4b99ac92 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 24 Apr 2020 17:39:26 +0200 Subject: [PATCH 8/8] Fix internal array size checks --- tasmota/settings.ino | 4 ++-- tasmota/support.ino | 19 ++++++++++++++----- tasmota/support_command.ino | 10 +++++----- tasmota/support_tasmota.ino | 8 ++++---- tasmota/tasmota.ino | 2 +- tasmota/xdrv_01_webserver.ino | 10 +++++----- tasmota/xdrv_16_tuyamcu.ino | 2 +- 7 files changed, 32 insertions(+), 23 deletions(-) diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 6c299ff06..6ebdf9977 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -741,7 +741,7 @@ void SettingsDefaultSet2(void) Settings.interlock[0] = 0xFF; // Legacy support using all relays in one interlock group Settings.module = MODULE; ModuleDefault(WEMOS); -// for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { Settings.my_gp.io[i] = GPIO_NONE; } +// for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { Settings.my_gp.io[i] = GPIO_NONE; } SettingsUpdateText(SET_FRIENDLYNAME1, FRIENDLY_NAME); SettingsUpdateText(SET_FRIENDLYNAME2, FRIENDLY_NAME"2"); SettingsUpdateText(SET_FRIENDLYNAME3, FRIENDLY_NAME"3"); @@ -1098,7 +1098,7 @@ void SettingsDelta(void) Settings.switchmode[i] = SWITCH_MODE; } } - for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { + for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { if (Settings.my_gp.io[i] >= GPIO_SWT5) { // Move up from GPIO_SWT5 to GPIO_KEY1 Settings.my_gp.io[i] += 4; } diff --git a/tasmota/support.ino b/tasmota/support.ino index 403f9f062..96b2b533b 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1120,10 +1120,15 @@ String ModuleName(void) void ModuleGpios(myio *gp) { +//#ifdef ESP8266 uint8_t *dest = (uint8_t *)gp; - memset(dest, GPIO_NONE, sizeof(myio)); + uint8_t src[sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0])]; +//#else +// uint16_t *dest = (uint16_t *)gp; +// uint16_t src[sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0])]; +//#endif - uint8_t src[sizeof(mycfgio)]; + memset(dest, GPIO_NONE, sizeof(myio)); if (USER_MODULE == Settings.module) { memcpy(&src, &Settings.user_template.gp, sizeof(mycfgio)); } else { @@ -1138,7 +1143,7 @@ void ModuleGpios(myio *gp) // AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&src, sizeof(mycfgio)); uint32_t j = 0; - for (uint32_t i = 0; i < sizeof(mycfgio); i++) { + for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) { if (6 == i) { j = 9; } if (8 == i) { j = 12; } dest[j] = src[i]; @@ -1226,7 +1231,11 @@ bool ValidAdc(void) return (ADC0_USER == template_adc0); } +//#ifdef ESP8266 bool GetUsedInModule(uint32_t val, uint8_t *arr) +//#else +//bool GetUsedInModule(uint32_t val, uint16_t *arr) +//#endif { int offset = 0; @@ -1307,7 +1316,7 @@ bool JsonTemplate(const char* dataBuf) SettingsUpdateText(SET_TEMPLATE_NAME, name); } if (obj[D_JSON_GPIO].success()) { - for (uint32_t i = 0; i < sizeof(mycfgio); i++) { + for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) { Settings.user_template.gp.io[i] = obj[D_JSON_GPIO][i] | 0; } } @@ -1326,7 +1335,7 @@ bool JsonTemplate(const char* dataBuf) void TemplateJson(void) { Response_P(PSTR("{\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), SettingsText(SET_TEMPLATE_NAME)); - for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) { + for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) { ResponseAppend_P(PSTR("%s%d"), (i>0)?",":"", Settings.user_template.gp.io[i]); } ResponseAppend_P(PSTR("],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"), Settings.user_template.flag, Settings.user_template_base +1); diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 3bb271f3a..a60a57b4c 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1000,7 +1000,7 @@ void CmndModule(void) Settings.module = XdrvMailbox.payload; SetModuleType(); if (Settings.last_module != XdrvMailbox.payload) { - for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { + for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { Settings.my_gp.io[i] = GPIO_NONE; } } @@ -1036,7 +1036,7 @@ void CmndModules(void) void CmndGpio(void) { - if (XdrvMailbox.index < sizeof(Settings.my_gp)) { + if (XdrvMailbox.index < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0])) { myio cmodule; ModuleGpios(&cmodule); if (ValidGPIO(XdrvMailbox.index, cmodule.io[XdrvMailbox.index]) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < GPIO_SENSOR_END)) { @@ -1046,7 +1046,7 @@ void CmndGpio(void) if (midx == XdrvMailbox.payload) { present = true; } } if (present) { - for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { + for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { if (ValidGPIO(i, cmodule.io[i]) && (Settings.my_gp.io[i] == XdrvMailbox.payload)) { Settings.my_gp.io[i] = GPIO_NONE; } @@ -1057,7 +1057,7 @@ void CmndGpio(void) } Response_P(PSTR("{")); bool jsflg = false; - for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { + for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { if (ValidGPIO(i, cmodule.io[i]) || ((GPIO_USER == XdrvMailbox.payload) && !FlashPin(i))) { if (jsflg) { ResponseAppend_P(PSTR(",")); } jsflg = true; @@ -1137,7 +1137,7 @@ void CmndTemplate(void) } SettingsUpdateText(SET_TEMPLATE_NAME, "Merged"); uint32_t j = 0; - for (uint32_t i = 0; i < sizeof(mycfgio); i++) { + for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) { if (6 == i) { j = 9; } if (8 == i) { j = 12; } if (my_module.io[j] > GPIO_NONE) { diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index d8f33d9a7..0ae1671e7 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1354,7 +1354,7 @@ void GpioInit(void) Settings.serial_config = TS_SERIAL_8N1; } - for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) { + for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) { if ((Settings.user_template.gp.io[i] >= GPIO_SENSOR_END) && (Settings.user_template.gp.io[i] < GPIO_USER)) { Settings.user_template.gp.io[i] = GPIO_USER; // Fix not supported sensor ids in template } @@ -1362,7 +1362,7 @@ void GpioInit(void) myio def_gp; ModuleGpios(&def_gp); - for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { + for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { if ((Settings.my_gp.io[i] >= GPIO_SENSOR_END) && (Settings.my_gp.io[i] < GPIO_USER)) { Settings.my_gp.io[i] = GPIO_NONE; // Fix not supported sensor ids in module } @@ -1388,7 +1388,7 @@ void GpioInit(void) for (uint32_t i = 0; i < GPIO_MAX; i++) { pin[i] = 99; } - for (uint32_t i = 0; i < sizeof(my_module.io); i++) { + for (uint32_t i = 0; i < sizeof(my_module.io)/sizeof(my_module.io[0]); i++) { mpin = ValidPin(i, my_module.io[i]); DEBUG_CORE_LOG(PSTR("INI: gpio pin %d, mpin %d"), i, mpin); @@ -1465,7 +1465,7 @@ void GpioInit(void) // Set any non-used GPIO to INPUT - Related to resetPins() in support_legacy_cores.ino // Doing it here solves relay toggles at restart. - for (uint32_t i = 0; i < sizeof(my_module.io); i++) { + for (uint32_t i = 0; i < sizeof(my_module.io)/sizeof(my_module.io[0]); i++) { mpin = ValidPin(i, my_module.io[i]); // AddLog_P2(LOG_LEVEL_DEBUG, PSTR("INI: gpio pin %d, mpin %d"), i, mpin); if (((i < 6) || (i > 11)) && (0 == mpin)) { // Skip SPI flash interface diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 7ae7d60bb..b3ba8e4f3 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -260,7 +260,7 @@ void setup(void) Settings.rule_enabled = 0; // Disable all rules } if (RtcReboot.fast_reboot_count > Settings.param[P_BOOT_LOOP_OFFSET] +3) { // Restarted 5 times - for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { + for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { Settings.my_gp.io[i] = GPIO_NONE; // Reset user defined GPIO disabling sensors } Settings.my_adc0 = ADC0_NONE; // Reset user defined ADC0 disabling sensors diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index bbdda0834..398e4ec90 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1466,7 +1466,7 @@ void HandleTemplateConfiguration(void) } WSContentSend_P(PSTR("}1")); // Field separator - for (uint32_t i = 0; i < sizeof(cmodule); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255 + for (uint32_t i = 0; i < sizeof(cmodule.io)/sizeof(cmodule.io[0]); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255 if (!FlashPin(i)) { WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", cmodule.io[i]); } @@ -1518,7 +1518,7 @@ void TemplateSaveSettings(void) snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp); uint32_t j = 0; - for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) { + for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) { if (6 == i) { j = 9; } if (8 == i) { j = 12; } snprintf_P(webindex, sizeof(webindex), PSTR("g%d"), j); @@ -1604,7 +1604,7 @@ void HandleModuleConfiguration(void) WSContentStart_P(S_CONFIGURE_MODULE); WSContentSend_P(HTTP_SCRIPT_MODULE_TEMPLATE); WSContentSend_P(HTTP_SCRIPT_MODULE1, Settings.module); - for (uint32_t i = 0; i < sizeof(cmodule); i++) { + for (uint32_t i = 0; i < sizeof(cmodule.io)/sizeof(cmodule.io[0]); i++) { if (ValidGPIO(i, cmodule.io[i])) { WSContentSend_P(PSTR("sk(%d,%d);"), my_module.io[i], i); // g0 - g16 } @@ -1612,7 +1612,7 @@ void HandleModuleConfiguration(void) WSContentSend_P(HTTP_SCRIPT_MODULE2, Settings.my_adc0); WSContentSendStyle(); WSContentSend_P(HTTP_FORM_MODULE, AnyModuleName(MODULE).c_str()); - for (uint32_t i = 0; i < sizeof(cmodule); i++) { + for (uint32_t i = 0; i < sizeof(cmodule.io)/sizeof(cmodule.io[0]); i++) { if (ValidGPIO(i, cmodule.io[i])) { snprintf_P(stemp, 3, PINS_WEMOS +i*2); #ifdef ESP8266 @@ -1652,7 +1652,7 @@ void ModuleSaveSettings(void) myio cmodule; ModuleGpios(&cmodule); String gpios = ""; - for (uint32_t i = 0; i < sizeof(cmodule); i++) { + for (uint32_t i = 0; i < sizeof(cmodule.io)/sizeof(cmodule.io[0]); i++) { if (Settings.last_module != new_module) { Settings.my_gp.io[i] = GPIO_NONE; } else { diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index 9c1834fb0..9acbc1923 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -569,7 +569,7 @@ void TuyaNormalPowerModePacketProcess(void) uint8_t key1_gpio = Tuya.buffer[7]; bool key1_set = false; bool led1_set = false; - for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { + for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { if (Settings.my_gp.io[i] == GPIO_LED1) led1_set = true; else if (Settings.my_gp.io[i] == GPIO_KEY1) key1_set = true; }