From aa78ffb733a89072644a072c8670ef3b2d0bb49d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 20 Jan 2023 14:28:58 +0100 Subject: [PATCH] Prep Shelly Pro 4PM --- tasmota/include/tasmota.h | 33 ++++++++++++------- tasmota/include/tasmota_template.h | 2 +- tasmota/tasmota_support/support_button_v3.ino | 14 ++------ ...pport_switch.ino => support_switch_v3.ino} | 4 --- .../tasmota_xx2c_global/xdrv_interface.ino | 16 ++------- .../tasmota_xx2c_global/xsns_interface.ino | 6 ++-- 6 files changed, 30 insertions(+), 45 deletions(-) rename tasmota/tasmota_support/{support_switch.ino => support_switch_v3.ino} (99%) diff --git a/tasmota/include/tasmota.h b/tasmota/include/tasmota.h index fdc87cc1d..f3e9bfbde 100644 --- a/tasmota/include/tasmota.h +++ b/tasmota/include/tasmota.h @@ -386,18 +386,27 @@ enum LightSubtypes { LST_NONE, LST_SINGLE, LST_COLDWARM, LST_RGB, LST_RGBW, LS enum LightTypes { LT_BASIC, LT_PWM1, LT_PWM2, LT_PWM3, LT_PWM4, LT_PWM5, LT_PWM6, LT_PWM7, LT_NU8, LT_SERIAL1, LT_SERIAL2, LT_RGB, LT_RGBW, LT_RGBWC, LT_NU14, LT_NU15 }; // Do not insert new fields -enum XsnsFunctions {FUNC_SETTINGS_OVERRIDE, FUNC_PIN_STATE, FUNC_I2C_INIT, FUNC_MODULE_INIT, FUNC_PRE_INIT, FUNC_INIT, - FUNC_LOOP, FUNC_SLEEP_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND, - FUNC_SAVE_SETTINGS, FUNC_SAVE_AT_MIDNIGHT, FUNC_SAVE_BEFORE_RESTART, FUNC_INTERRUPT_STOP, FUNC_INTERRUPT_START, - FUNC_AFTER_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_SENSOR, FUNC_WEB_COL_SENSOR, FUNC_COMMAND, FUNC_COMMAND_SENSOR, FUNC_COMMAND_DRIVER, - FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, - FUNC_SET_POWER, FUNC_SET_DEVICE_POWER, FUNC_SHOW_SENSOR, FUNC_ANY_KEY, FUNC_LED_LINK, - FUNC_ENERGY_EVERY_SECOND, FUNC_ENERGY_RESET, - FUNC_RULES_PROCESS, FUNC_TELEPERIOD_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_BUTTON_PRESSED, FUNC_BUTTON_MULTI_PRESSED, - FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_CONSOLE_BUTTON, FUNC_WEB_ADD_MANAGEMENT_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON, - FUNC_WEB_GET_ARG, FUNC_WEB_ADD_HANDLER, FUNC_SET_CHANNELS, FUNC_SET_SCHEME, FUNC_HOTPLUG_SCAN, FUNC_TIME_SYNCED, - FUNC_DEVICE_GROUP_ITEM, - FUNC_NETWORK_UP, FUNC_NETWORK_DOWN }; +enum XsnsFunctions { FUNC_SETTINGS_OVERRIDE, FUNC_I2C_INIT, FUNC_PRE_INIT, FUNC_INIT, + FUNC_LOOP, FUNC_SLEEP_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND, + FUNC_SAVE_SETTINGS, FUNC_SAVE_AT_MIDNIGHT, FUNC_SAVE_BEFORE_RESTART, FUNC_INTERRUPT_STOP, FUNC_INTERRUPT_START, + FUNC_AFTER_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_SENSOR, FUNC_WEB_COL_SENSOR, + FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, + FUNC_SET_POWER, FUNC_SHOW_SENSOR, FUNC_ANY_KEY, FUNC_LED_LINK, + FUNC_ENERGY_EVERY_SECOND, FUNC_ENERGY_RESET, + FUNC_TELEPERIOD_RULES_PROCESS, FUNC_FREE_MEM, + FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_CONSOLE_BUTTON, FUNC_WEB_ADD_MANAGEMENT_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON, + FUNC_WEB_GET_ARG, FUNC_WEB_ADD_HANDLER, FUNC_SET_SCHEME, FUNC_HOTPLUG_SCAN, FUNC_TIME_SYNCED, + FUNC_DEVICE_GROUP_ITEM, + FUNC_NETWORK_UP, FUNC_NETWORK_DOWN, + FUNC_return_result = 200, // Insert function WITHOUT return results before here. Following functions return results + FUNC_PIN_STATE, FUNC_MODULE_INIT, FUNC_ADD_BUTTON, FUNC_ADD_SWITCH, FUNC_BUTTON_PRESSED, FUNC_BUTTON_MULTI_PRESSED, + FUNC_SET_DEVICE_POWER, + FUNC_MQTT_DATA, FUNC_SERIAL, + FUNC_COMMAND, FUNC_COMMAND_SENSOR, FUNC_COMMAND_DRIVER, + FUNC_RULES_PROCESS, + FUNC_SET_CHANNELS, + FUNC_last_function // Insert functions with return results before here + }; enum AddressConfigSteps { ADDR_IDLE, ADDR_RECEIVE, ADDR_SEND }; diff --git a/tasmota/include/tasmota_template.h b/tasmota/include/tasmota_template.h index 700481241..ecd43e1d1 100644 --- a/tasmota/include/tasmota_template.h +++ b/tasmota/include/tasmota_template.h @@ -812,7 +812,7 @@ const uint16_t kGpioNiceList[] PROGMEM = { #endif #ifdef USE_ADE7953 #if defined(USE_I2C) || defined(USE_SPI) - AGPIO(GPIO_ADE7953_IRQ) + 5, // ADE7953 IRQ - (1 = Shelly 2.5, 2 = Shelly EM, 3 = Shelly Plus 2PM, 4 = Shelly Pro 1PM, 5 = Shelly Pro 2PM) + AGPIO(GPIO_ADE7953_IRQ) + 6, // ADE7953 IRQ - (1 = Shelly 2.5, 2 = Shelly EM, 3 = Shelly Plus 2PM, 4 = Shelly Pro 1PM, 5 = Shelly Pro 2PM, 6 = Shelly Pro 4PM) AGPIO(GPIO_ADE7953_RST), // ADE7953 Reset #ifdef USE_SPI AGPIO(GPIO_ADE7953_CS) + 2, // ADE7953 SPI Chip Select (1 = CS1 (1PM, 2PM), 2 = CS2 (2PM)) diff --git a/tasmota/tasmota_support/support_button_v3.ino b/tasmota/tasmota_support/support_button_v3.ino index 5fbfdff94..b12ef5714 100644 --- a/tasmota/tasmota_support/support_button_v3.ino +++ b/tasmota/tasmota_support/support_button_v3.ino @@ -83,14 +83,6 @@ void ButtonTouchFlag(uint32_t button_bit) { } #endif // ESP32 SOC_TOUCH_VERSION_1 or SOC_TOUCH_VERSION_2 -uint32_t ButtonGetVirtualOffset(void) { - return Button.present; -} - -void ButtonSetVirtual(uint32_t index, uint32_t state) { - Button.virtual_state[index] = state; -} - /*********************************************************************************************/ void ButtonProbe(void) { @@ -283,7 +275,7 @@ uint8_t ButtonSerial(uint8_t serial_in_byte) { * SetOption73 (0) - Decouple button from relay and send just mqtt topic \*********************************************************************************************/ -void ButtonHandler(uint32_t mode) { +void ButtonHandler(void) { if (TasmotaGlobal.uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit uint8_t hold_time_extent = IMMINENT_RESET_FACTOR; // Extent hold time factor in case of iminnent Reset command @@ -308,7 +300,7 @@ void ButtonHandler(uint32_t mode) { } } else #endif // ESP8266 - if (PinUsed(GPIO_KEY1, button_index) || (mode)) { + if (PinUsed(GPIO_KEY1, button_index)) { #if defined(SOC_TOUCH_VERSION_1) || defined(SOC_TOUCH_VERSION_2) if (bitRead(TouchButton.touch_mask, button_index) && bitRead(TouchButton.calibration, button_index +1)) { // Touch @@ -536,7 +528,7 @@ void ButtonLoop(void) { if (Button.present) { if (TimeReached(Button.debounce)) { SetNextTimeInterval(Button.debounce, Settings->button_debounce); // ButtonDebounce (50) - ButtonHandler(0); + ButtonHandler(); } } } diff --git a/tasmota/tasmota_support/support_switch.ino b/tasmota/tasmota_support/support_switch_v3.ino similarity index 99% rename from tasmota/tasmota_support/support_switch.ino rename to tasmota/tasmota_support/support_switch_v3.ino index 0f4eaf9c9..f00160131 100644 --- a/tasmota/tasmota_support/support_switch.ino +++ b/tasmota/tasmota_support/support_switch_v3.ino @@ -65,10 +65,6 @@ void SwitchPulldownFlag(uint32 switch_bit) { bitSet(Switch.pulldown_mask, switch_bit); } -uint32_t SwitchGetVirtualOffset(void) { - return Switch.present; -} - void SwitchSetVirtual(uint32_t index, uint32_t state) { Switch.virtual_state[index] = state; } diff --git a/tasmota/tasmota_xx2c_global/xdrv_interface.ino b/tasmota/tasmota_xx2c_global/xdrv_interface.ino index 247e7adb2..fda25f067 100644 --- a/tasmota/tasmota_xx2c_global/xdrv_interface.ino +++ b/tasmota/tasmota_xx2c_global/xdrv_interface.ino @@ -1143,24 +1143,14 @@ bool XdrvCall(uint32_t function) { #ifdef USE_PROFILE_FUNCTION #ifdef XFUNC_PTR_IN_ROM - uint32_t index = pgm_read_byte(kXdrvList + x); + uint32_t index = pgm_read_byte(kXdrvList + x); #else - uint32_t index = kXdrvList[x]; + uint32_t index = kXdrvList[x]; #endif PROFILE_FUNCTION("drv", index, function, profile_function_start); #endif // USE_PROFILE_FUNCTION - if (result && ((FUNC_COMMAND == function) || - (FUNC_COMMAND_DRIVER == function) || - (FUNC_MQTT_DATA == function) || - (FUNC_RULES_PROCESS == function) || - (FUNC_BUTTON_PRESSED == function) || - (FUNC_SERIAL == function) || - (FUNC_MODULE_INIT == function) || - (FUNC_SET_CHANNELS == function) || - (FUNC_PIN_STATE == function) || - (FUNC_SET_DEVICE_POWER == function) - )) { + if (result && (function > FUNC_return_result)) { break; } } diff --git a/tasmota/tasmota_xx2c_global/xsns_interface.ino b/tasmota/tasmota_xx2c_global/xsns_interface.ino index 71f3dceb4..acff24be0 100644 --- a/tasmota/tasmota_xx2c_global/xsns_interface.ino +++ b/tasmota/tasmota_xx2c_global/xsns_interface.ino @@ -1135,12 +1135,10 @@ bool XsnsCall(uint32_t function) { PROFILE_FUNCTION("sns", index, function, profile_function_start); #endif // USE_PROFILE_FUNCTION - if (result && ((FUNC_COMMAND == function) || - (FUNC_PIN_STATE == function) || - (FUNC_COMMAND_SENSOR == function) - )) { + if (result && (function > FUNC_return_result)) { break; } + } }