Browse Source

Added inching support

fastled
Xose Pérez 7 years ago
parent
commit
4c06e7e280
5 changed files with 60 additions and 3 deletions
  1. BIN
      code/data/index.html.gz
  2. +22
    -2
      code/html/index.html
  3. +10
    -0
      code/src/config/general.h
  4. +25
    -0
      code/src/relay.ino
  5. +3
    -1
      code/src/web.ino

BIN
code/data/index.html.gz View File


+ 22
- 2
code/html/index.html View File

@ -189,7 +189,7 @@
<div class="pure-g module module-multirelay">
<label class="pure-u-1 pure-u-md-1-4" for="relaySync">Relay sync mode</label>
<div class="pure-u-1 pure-u-md-3-4">
<select name="relaySync" class="pure-u-1-2" tabindex="2">
<select name="relaySync" class="pure-u-1-2" tabindex="3">
<option value="0">No synchonisation</a>
<option value="1">Zero or one relays active</a>
<option value="2">One and just one relay active</a>
@ -200,9 +200,29 @@
<div class="pure-u-1 pure-u-md-3-4 hint">Define how the different relays should be synchronized.</div>
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-md-1-4" for="relayInch">Relay inching mode</label>
<div class="pure-u-1 pure-u-md-3-4">
<select name="relayInch" class="pure-u-1-2" tabindex="4">
<option value="0">No inching</a>
<option value="1">Normally OFF (stays on for a brief interval)</a>
<option value="2">Normally ON (stays off for a brief interval)</a>
</select>
</div>
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">When inching enable the relay will automatically switch back to its normal state after the inching time (below).</div>
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-md-1-4" for="relayInchTime">Relay inching time</label>
<input name="relayInchTime" class="pure-u-1 pure-u-md-3-4" type="number" min="1" tabindex="5" />
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">Inching time in seconds.</div>
</div>
<div class="pure-g module module-fauxmo">
<div class="pure-u-1 pure-u-sm-1-4"><label for="fauxmoEnabled">Enable WeMo emulation</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="fauxmoEnabled" /></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="fauxmoEnabled" tabindex="6" /></div>
</div>
</fieldset>


+ 10
- 0
code/src/config/general.h View File

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


+ 25
- 0
code/src/relay.ino View File

@ -8,6 +8,7 @@ Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
*/
#include <EEPROM.h>
#include <Ticker.h>
#include <ArduinoJson.h>
#include <vector>
@ -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();
}


+ 3
- 1
code/src/web.ino View File

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


Loading…
Cancel
Save