diff --git a/code/data/index.html.gz b/code/data/index.html.gz index d879c641..42bf102c 100644 Binary files a/code/data/index.html.gz and b/code/data/index.html.gz differ diff --git a/code/html/index.html b/code/html/index.html index c4606df0..e0a53f72 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -189,7 +189,7 @@
-
+
+ +
+ +
+
 
+
When inching enable the relay will automatically switch back to its normal state after the inching time (below).
+
+ +
+ + +
 
+
Inching time in seconds.
+
+
-
+
diff --git a/code/src/config/general.h b/code/src/config/general.h index 250ef440..bf261172 100644 --- a/code/src/config/general.h +++ b/code/src/config/general.h @@ -21,12 +21,22 @@ #define RELAY_SYNC_ONE 2 #define RELAY_SYNC_SAME 3 +#define RELAY_INCHING_NONE 0 +#define RELAY_INCHING_OFF 1 +#define RELAY_INCHING_ON 2 + +// Inching time in seconds +#define RELAY_INCHING_TIME 1 + // 0 means OFF, 1 ON and 2 whatever was before #define RELAY_MODE RELAY_MODE_OFF // 0 means ANY, 1 zero or one and 2 one and only one #define RELAY_SYNC RELAY_SYNC_ANY +// 0 means no inching, 1 means normally off, 2 normally on +#define RELAY_INCHING RELAY_INCHING_NONE + // ----------------------------------------------------------------------------- // WIFI & WEB // ----------------------------------------------------------------------------- diff --git a/code/src/relay.ino b/code/src/relay.ino index 77b7cb92..fd751a25 100644 --- a/code/src/relay.ino +++ b/code/src/relay.ino @@ -8,6 +8,7 @@ Copyright (C) 2016 by Xose PĂ©rez */ #include +#include #include #include @@ -16,6 +17,7 @@ bool recursive = false; #ifdef SONOFF_DUAL unsigned char dualRelayStatus = 0; #endif +Ticker inching; // ----------------------------------------------------------------------------- // RELAY @@ -58,6 +60,28 @@ bool relayStatus(unsigned char id) { #endif } +void relayInchingBack(unsigned char id) { + relayToggle(id); + inching.detach(); +} + +void relayInching(unsigned char id) { + + byte relayInch = getSetting("relayInch", String(RELAY_INCHING)).toInt(); + if (relayInch == RELAY_INCHING_NONE) return; + + bool status = relayStatus(id); + if ((relayInch == RELAY_INCHING_ON) & (status)) return; + if ((relayInch == RELAY_INCHING_OFF) & (!status)) return; + + inching.attach( + getSetting("relayInchTime", String(RELAY_INCHING_TIME)).toInt(), + relayInchingBack, + id + ); + +} + bool relayStatus(unsigned char id, bool status, bool report) { bool changed = false; @@ -82,6 +106,7 @@ bool relayStatus(unsigned char id, bool status, bool report) { #endif if (!recursive) { + relayInching(id); relaySync(id); relaySave(); } diff --git a/code/src/web.ino b/code/src/web.ino index 5645a24b..58fc5d94 100644 --- a/code/src/web.ino +++ b/code/src/web.ino @@ -234,6 +234,8 @@ void _wsStart(uint32_t client_id) { relay.add(relayStatus(relayID)); } root["relayMode"] = getSetting("relayMode", String(RELAY_MODE)); + root["relayInch"] = getSetting("relayInch", String(RELAY_INCHING)); + root["relayInchTime"] = getSetting("relayInchTime", String(RELAY_INCHING_TIME)); if (relayCount() > 1) { root["multirelayVisible"] = 1; root["relaySync"] = getSetting("relaySync", String(RELAY_SYNC)); @@ -502,7 +504,7 @@ void webSetup() { char lastModified[50]; sprintf(lastModified, "%s %s GMT", __DATE__, __TIME__); server.serveStatic("/", SPIFFS, "/").setLastModified(lastModified); - + // 404 server.onNotFound([](AsyncWebServerRequest *request){ request->send(404);