diff --git a/BUILDS.md b/BUILDS.md index 4318635ec..5cac6108f 100644 --- a/BUILDS.md +++ b/BUILDS.md @@ -26,6 +26,7 @@ | USE_SCRIPT | - | - | - | - | - | - | - | | USE_EXPRESSION | - | - | - | - | - | - | - | | SUPPORT_IF_STATEMENT | - | - | - | - | - | - | - | +| USE_HOTPLUG | - | - | - | - | x | - | - | | | | | | | | | | | Feature or Sensor | minimal | lite | tasmota | knx | sensors | ir | display | Remarks | ROTARY_V1 | - | - | - | - | - | - | - | diff --git a/tasmota/settings.h b/tasmota/settings.h index 0c47e5aca..56a44a3ff 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -464,8 +464,9 @@ struct SYSCFG { uint8_t shutter_accuracy; // F00 uint8_t mqttlog_level; // F01 uint8_t sps30_inuse_hours; // F02 + uint8_t hotplug_scan; // F03 -- scan for hotplug every 'hoplugscan' time - uint8_t free_f03[233]; // F03 + uint8_t free_f04[232]; // F04 uint32_t i2c_drivers[3]; // FEC I2cDriver uint32_t cfg_timestamp; // FF8 diff --git a/tasmota/support_features.ino b/tasmota/support_features.ino index 696e5ee5d..07fe0d8f8 100644 --- a/tasmota/support_features.ino +++ b/tasmota/support_features.ino @@ -498,7 +498,9 @@ void GetFeatures(void) #ifdef USE_GPS feature5 |= 0x00400000; #endif -// feature5 |= 0x00800000; +#ifdef USE_HOTPLUG + feature5 |= 0x00800000; +#endif // feature5 |= 0x01000000; // feature5 |= 0x02000000; diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index c0231d3c9..1f57a185f 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -271,7 +271,7 @@ enum XsnsFunctions {FUNC_SETTINGS_OVERRIDE, FUNC_PIN_STATE, FUNC_MODULE_INIT, FU FUNC_SET_POWER, FUNC_SET_DEVICE_POWER, FUNC_SHOW_SENSOR, FUNC_ANY_KEY, FUNC_ENERGY_EVERY_SECOND, FUNC_ENERGY_RESET, FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_BUTTON_PRESSED, - FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON, FUNC_WEB_ADD_HANDLER, FUNC_SET_CHANNELS, FUNC_SET_SCHEME}; + FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON, FUNC_WEB_ADD_HANDLER, FUNC_SET_CHANNELS, FUNC_SET_SCHEME, FUNC_HOTPLUG_SCAN}; enum AddressConfigSteps { ADDR_IDLE, ADDR_RECEIVE, ADDR_SEND }; diff --git a/tasmota/tasmota_post.h b/tasmota/tasmota_post.h index 5571da265..2440afbbb 100644 --- a/tasmota/tasmota_post.h +++ b/tasmota/tasmota_post.h @@ -99,6 +99,7 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack //#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 // -- Optional light modules ---------------------- #define USE_LIGHT // Add Dimmer/Light support @@ -268,6 +269,7 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack #undef USE_SHUTTER // Disable Shutter support for up to 4 shutter with different motortypes (+6k code) #undef USE_DEEPSLEEP // Disable support for deepsleep (+1k code) #undef USE_EXS_DIMMER // Disable support for EX-Store WiFi Dimmer +#undef USE_HOTPLUG // Disable support for HotPlug #undef USE_ENERGY_SENSOR // Disable energy sensors (-14k code) #undef USE_PZEM004T // Disable PZEM004T energy sensor @@ -340,6 +342,7 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack #undef USE_SHUTTER // Disable Shutter support for up to 4 shutter with different motortypes (+6k code) #undef USE_DEEPSLEEP // Disable support for deepsleep (+1k code) #undef USE_EXS_DIMMER // Disable support for EX-Store WiFi Dimmer +#undef USE_HOTPLUG // Disable support for HotPlug // -- Optional light modules ---------------------- //#undef USE_LIGHT // Also disable all Dimmer/Light support @@ -439,6 +442,7 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack #undef USE_SHUTTER // Disable Shutter support for up to 4 shutter with different motortypes (+6k code) #undef USE_DEEPSLEEP // Disable support for deepsleep (+1k code) #undef USE_EXS_DIMMER // Disable support for EX-Store WiFi Dimmer +#undef USE_HOTPLUG // Disable support for HotPlug // -- Optional light modules ---------------------- //#undef USE_LIGHT // Also disable all Dimmer/Light support @@ -547,6 +551,7 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack #undef USE_SHUTTER // Disable Shutter support for up to 4 shutter with different motortypes (+6k code) #undef USE_DEEPSLEEP // Disable support for deepsleep (+1k code) #undef USE_EXS_DIMMER // Disable support for EX-Store WiFi Dimmer +#undef USE_HOTPLUG // Disable support for HotPlug // -- Optional light modules ---------------------- #undef USE_LIGHT // Disable support for lights diff --git a/tasmota/xdrv_32_hotplug.ino b/tasmota/xdrv_32_hotplug.ino new file mode 100644 index 000000000..a2a52a90f --- /dev/null +++ b/tasmota/xdrv_32_hotplug.ino @@ -0,0 +1,100 @@ +/* + xdrv_32_hotplug.ino - HotPlug support for sensors + + Copyright (C) 2019 Leonid Myravjev + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_HOTPLUG +/*********************************************************************************************\ + * HotPlug Support + * + * - 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 D_PRFX_HOTPLUG "HotPlug" + +const uint32_t HOTPLUG_MAX = 254; // 0 and 0xFF is OFF + +const char kHotPlugCommands[] PROGMEM = "|" D_PRFX_HOTPLUG; +void (* const HotPlugCommand[])(void) PROGMEM = { &CmndHotPlugTime }; + +uint32_t hotplug_sleeptime = 0; +bool hotplug_enabled = false; +uint8_t hotplug_timeout = 0; + +void HotPlugInit(void) +{ + // If empty eeprom is 0xFF by default + 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 + } else + hotplug_enabled = false; +} + +void HotPlugEverySecond(void) +{ + if (hotplug_enabled) { + if (hotplug_timeout == 0) { + XsnsCall(FUNC_HOTPLUG_SCAN); + hotplug_timeout = Settings.hotplug_scan; + } + hotplug_timeout--; + } +} + +/*********************************************************************************************\ +* Commands +\*********************************************************************************************/ + +void CmndHotPlugTime(void) +{ + if (XdrvMailbox.payload <= HOTPLUG_MAX) { + Settings.hotplug_scan = XdrvMailbox.payload; + HotPlugInit(); + } + Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.hotplug_scan); +} + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +bool Xdrv32(uint8_t function) +{ + bool result = false; + + switch (function) { + case FUNC_EVERY_SECOND: + HotPlugEverySecond(); + break; + case FUNC_COMMAND: + result = DecodeCommand(kHotPlugCommands, HotPlugCommand); + break; + case FUNC_PRE_INIT: + HotPlugInit(); + break; + } + return result; +} + +#endif //USE_HOTPLUG diff --git a/tasmota/xsns_59_ds1624.ino b/tasmota/xsns_59_ds1624.ino index 06b21d39e..6f3ce5b69 100644 --- a/tasmota/xsns_59_ds1624.ino +++ b/tasmota/xsns_59_ds1624.ino @@ -170,8 +170,6 @@ void DS1624Show(bool json) * Interface \*********************************************************************************************/ -#define FUNC_HOTPLUG_SCAN 255 // FIXME remove it after HOTPLUG supported - bool Xsns59(uint8_t function) { if (!I2cEnabled(XI2C_42)) { return false; }