From 4c06e7e280edd2163d30f01eb82d5c578bfa5e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 19 Dec 2016 12:56:24 +0100 Subject: [PATCH] Added inching support --- code/data/index.html.gz | Bin 2579 -> 2753 bytes code/html/index.html | 24 ++++++++++++++++++++++-- code/src/config/general.h | 10 ++++++++++ code/src/relay.ino | 25 +++++++++++++++++++++++++ code/src/web.ino | 4 +++- 5 files changed, 60 insertions(+), 3 deletions(-) diff --git a/code/data/index.html.gz b/code/data/index.html.gz index d879c6416c1a747e0513785478c4c96b25875c19..42bf102c36f5c34bc5919cef235f24b59152e543 100644 GIT binary patch literal 2753 zcmV;y3O@B8iwFP!000001I=6EZreB#eifb$*G+-gPMq$d*xCkyG}#8%roP%m(ED?s zCCcK4615^_$NOma^PcQxNXnLEIgVqyTNH>XiZh%U4!@Zp)!yIUf4&-j8(x!0$70ZP ze;Ex1JsTcxGFS|H0iO{b^gTfrGS~2y zI*Px?EXh6d4qG3AIS3@EQnsUo)4_O^(gb+AAG+db=u;fCJehiR z+gt9rSf>zNX`}o4E3R2wR>*6jMy&#>DfH5WfjKqRIap~lz8rrY8HGB6A8>*xOISvQ zH~8)P?)uB+$0JOkn4f1{FF=dytFK>f$KQ@H$()DW8{FUC+#Z2>{D+2B{q(Q#csp|v z%ODrb{j^d!-+4NqVVO4=e!jo{vYN1yi;DZklqao8uC+{X8`)Ncz3Z|+tvrP}m^b)p zetR9;Js{gDGX^_9VLsU4OVQko9>57{;b%$L>wqrRza`}y)YLXCTE}8QWp@w*Cw(vA zDh1&9bt0tyP$k8kj5h5>=gYkW&0f?UT;*8?Qz5#Ae41xebD6-~Zi84U;3hB$WfoWT zH66=ViwZtXSb!rr69K5b4m?wY2|8g_5XoET#5GjhI&Z!42yn#3PV$iY8eV}GpGr^Q z9LQzR<4FoIznR$uGPC%v*&{%)h4%_)z-t=FL@fGV(ej$iu)6{_Sa^f?=67GA9k=6& z>qk80uz*+aO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CImaF)g-m!U6phNHH_O$WN4B~Jh5<mW67&6sk&a;M#PRG1&`+(p6{DGpMn<>X<{! z$2GTiP^w2cfcPnaWZg`mL_J+q%YaxK+iEyH<^mg18h?vaj(ft6CdLroBFzNs8uWM; zoWccSmZNN+{Mx`04SKPz27rx>*>;{-9$X*zA3JS}o&HBqW$>hePqE5!keG+RhZgcA
-
+
+ +
+ +
+
 
+
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);