Skip to content

Commit

Permalink
Merge pull request #7368 from BASM/hotplug
Browse files Browse the repository at this point in the history
HotPlug for sensors support added
  • Loading branch information
arendst committed Dec 30, 2019
2 parents a9af1c5 + ed53301 commit 3fabf6d
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 5 deletions.
1 change: 1 addition & 0 deletions BUILDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | - | - | - | - | - | - | - |
Expand Down
3 changes: 2 additions & 1 deletion tasmota/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tasmota/support_features.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tasmota/tasmota.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down
5 changes: 5 additions & 0 deletions tasmota/tasmota_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
100 changes: 100 additions & 0 deletions tasmota/xdrv_32_hotplug.ino
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#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
2 changes: 0 additions & 2 deletions tasmota/xsns_59_ds1624.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 3fabf6d

Please sign in to comment.