Refactor HotPlug

This commit is contained in:
Theo Arends 2019-12-30 14:23:37 +01:00
parent 3fabf6d2f9
commit 1526a59162
6 changed files with 30 additions and 22 deletions

View File

@ -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"

View File

@ -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 //

View File

@ -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++) {

View File

@ -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!

View File

@ -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

View File

@ -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