From 1526a59162f0097bcd4440a0f6aa35b22f7706e3 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 30 Dec 2019 14:23:37 +0100 Subject: [PATCH] Refactor HotPlug --- tasmota/i18n.h | 3 +++ tasmota/my_user_config.h | 1 + tasmota/support_tasmota.ino | 1 + tasmota/tasmota.ino | 2 ++ tasmota/tasmota_post.h | 4 ++-- tasmota/xdrv_32_hotplug.ino | 41 +++++++++++++++++++------------------ 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index e726fdf5d..9e33de8bb 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -511,6 +511,9 @@ #define D_CMND_SHUTTER_MOTORDELAY "MotorDelay" #define D_CMND_SHUTTER_FREQUENCY "Frequency" +// Commands xdrv_32_hotplug.ino +#define D_CMND_HOTPLUG "HotPlug" + // Commands xsns_02_analog.ino #define D_CMND_ADCPARAM "AdcParam" diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 538301695..5239f152c 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -349,6 +349,7 @@ #define USE_DEEPSLEEP // Add support for deepsleep (+1k code) //#define USE_EXS_DIMMER // Add support for ES-Store WiFi Dimmer (+1k5 code) // #define EXS_MCU_CMNDS // Add command to send MCU commands (+0k8 code) +//#define USE_HOTPLUG // Add support for sensor HotPlug // -- Optional light modules ---------------------- #define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+5k code, +1k mem, 232 iram) - Disable by // diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 8f520940c..28edd25c3 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1170,6 +1170,7 @@ void GpioInit(void) if (Settings.module != Settings.last_module) { Settings.baudrate = APP_BAUDRATE / 300; + Settings.serial_config = TS_SERIAL_8N1; } for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) { diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 5e6947699..9b2ce358e 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -272,6 +272,8 @@ void setup(void) GetEspHardwareType(); GpioInit(); +// SetSerialBaudrate(Settings.baudrate * 300); // Allow reset of serial interface if current baudrate is different from requested baudrate + WifiConnect(); if (MOTOR == my_module_type) { Settings.poweronstate = POWER_ALL_ON; } // Needs always on else in limbo! diff --git a/tasmota/tasmota_post.h b/tasmota/tasmota_post.h index 2440afbbb..8c7c65198 100644 --- a/tasmota/tasmota_post.h +++ b/tasmota/tasmota_post.h @@ -98,8 +98,8 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack #define USE_ARILUX_RF // Add support for Arilux RF remote controller (+0k8 code, 252 iram (non 2.3.0)) //#define USE_SHUTTER // Add Shutter support for up to 4 shutter with different motortypes (+6k code) #define USE_DEEPSLEEP // Add support for deepsleep (+1k code) -#define USE_EXS_DIMMER // Add support for EX-Store WiFi Dimmer -#define USE_HOTPLUG // Add support for HotPlug +#define USE_EXS_DIMMER // Add support for EX-Store WiFi Dimmer +#define USE_HOTPLUG // Add support for sensor HotPlug // -- Optional light modules ---------------------- #define USE_LIGHT // Add Dimmer/Light support diff --git a/tasmota/xdrv_32_hotplug.ino b/tasmota/xdrv_32_hotplug.ino index a2a52a90f..7c368b45f 100644 --- a/tasmota/xdrv_32_hotplug.ino +++ b/tasmota/xdrv_32_hotplug.ino @@ -23,42 +23,43 @@ * * - Rescan bus every N seconds. It send FUNC_HOTPLUG_SCAN event to every sensors. * - If HotPlug is 0 or 0xFF -- HotPlug is off - * - * See wiki https://github.com/arendst/Tasmota/wiki/HotPlug FIXME \*********************************************************************************************/ -#define XDRV_32 32 +#define XDRV_32 32 -#define D_PRFX_HOTPLUG "HotPlug" +const uint32_t HOTPLUG_MAX = 254; // 0 and 0xFF is OFF -const uint32_t HOTPLUG_MAX = 254; // 0 and 0xFF is OFF +const char kHotPlugCommands[] PROGMEM = "|" // No prefix + D_CMND_HOTPLUG; -const char kHotPlugCommands[] PROGMEM = "|" D_PRFX_HOTPLUG; -void (* const HotPlugCommand[])(void) PROGMEM = { &CmndHotPlugTime }; +void (* const HotPlugCommand[])(void) PROGMEM = { + &CmndHotPlugTime }; -uint32_t hotplug_sleeptime = 0; -bool hotplug_enabled = false; -uint8_t hotplug_timeout = 0; +struct { +// uint32_t sleeptime = 0; + bool enabled = false; + uint8_t timeout = 0; +} Hotplug; void HotPlugInit(void) { // If empty eeprom is 0xFF by default - if (Settings.hotplug_scan == 0xFF) Settings.hotplug_scan = 0; + if (Settings.hotplug_scan == 0xFF) { Settings.hotplug_scan = 0; } if (Settings.hotplug_scan != 0) { - hotplug_enabled = true; - hotplug_timeout = 1; // first scan in a second + Hotplug.enabled = true; + Hotplug.timeout = 1; // First scan in a second } else - hotplug_enabled = false; + Hotplug.enabled = false; } void HotPlugEverySecond(void) { - if (hotplug_enabled) { - if (hotplug_timeout == 0) { + if (Hotplug.enabled) { + if (Hotplug.timeout == 0) { XsnsCall(FUNC_HOTPLUG_SCAN); - hotplug_timeout = Settings.hotplug_scan; + Hotplug.timeout = Settings.hotplug_scan; } - hotplug_timeout--; + Hotplug.timeout--; } } @@ -72,7 +73,7 @@ void CmndHotPlugTime(void) Settings.hotplug_scan = XdrvMailbox.payload; HotPlugInit(); } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.hotplug_scan); + ResponseCmndNumber(Settings.hotplug_scan); } /*********************************************************************************************\ @@ -96,5 +97,5 @@ bool Xdrv32(uint8_t function) } return result; } - + #endif //USE_HOTPLUG