Browse Source

Lock relay status on boot (#1705)

* relays: locked status

* remove debug

* Disable relay toggle when locked

* fixup! Disable relay toggle when locked

* Send lock with status, fix "disable" condition

* typo

* Update WebUI
master
Max Prokhorov 5 years ago
committed by GitHub
parent
commit
d4311211ad
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 18813 additions and 18739 deletions
  1. +6
    -0
      code/espurna/config/types.h
  2. BIN
      code/espurna/data/index.all.html.gz
  3. BIN
      code/espurna/data/index.light.html.gz
  4. BIN
      code/espurna/data/index.lightfox.html.gz
  5. BIN
      code/espurna/data/index.rfbridge.html.gz
  6. BIN
      code/espurna/data/index.rfm69.html.gz
  7. BIN
      code/espurna/data/index.sensor.html.gz
  8. BIN
      code/espurna/data/index.small.html.gz
  9. BIN
      code/espurna/data/index.thermostat.html.gz
  10. +39
    -3
      code/espurna/relay.ino
  11. +3236
    -3233
      code/espurna/static/index.all.html.gz.h
  12. +2203
    -2200
      code/espurna/static/index.light.html.gz.h
  13. +1843
    -1840
      code/espurna/static/index.lightfox.html.gz.h
  14. +1860
    -1857
      code/espurna/static/index.rfbridge.html.gz.h
  15. +3221
    -3218
      code/espurna/static/index.rfm69.html.gz.h
  16. +1887
    -1885
      code/espurna/static/index.sensor.html.gz.h
  17. +1843
    -1840
      code/espurna/static/index.small.html.gz.h
  18. +2661
    -2658
      code/espurna/static/index.thermostat.html.gz.h
  19. +12
    -5
      code/html/custom.js
  20. +2
    -0
      code/html/index.html

+ 6
- 0
code/espurna/config/types.h View File

@ -75,6 +75,8 @@
#define RELAY_BOOT_ON 1 #define RELAY_BOOT_ON 1
#define RELAY_BOOT_SAME 2 #define RELAY_BOOT_SAME 2
#define RELAY_BOOT_TOGGLE 3 #define RELAY_BOOT_TOGGLE 3
#define RELAY_BOOT_LOCKED_OFF 4
#define RELAY_BOOT_LOCKED_ON 5
#define RELAY_TYPE_NORMAL 0 #define RELAY_TYPE_NORMAL 0
#define RELAY_TYPE_INVERSE 1 #define RELAY_TYPE_INVERSE 1
@ -101,6 +103,10 @@
#define RELAY_GROUP_SYNC_INVERSE 1 #define RELAY_GROUP_SYNC_INVERSE 1
#define RELAY_GROUP_SYNC_RECEIVEONLY 2 #define RELAY_GROUP_SYNC_RECEIVEONLY 2
#define RELAY_LOCK_OFF 0
#define RELAY_LOCK_ON 1
#define RELAY_LOCK_DISABLED 2
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// UDP SYSLOG // UDP SYSLOG
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------


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


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


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


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


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


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


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


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


+ 39
- 3
code/espurna/relay.ino View File

@ -28,6 +28,7 @@ typedef struct {
bool current_status; // Holds the current (physical) status of the relay bool current_status; // Holds the current (physical) status of the relay
bool target_status; // Holds the target status bool target_status; // Holds the target status
unsigned char lock; // Holds the value of target status, that cannot be changed afterwards. (0 for false, 1 for true, 2 to disable)
unsigned long fw_start; // Flood window start time unsigned long fw_start; // Flood window start time
unsigned char fw_count; // Number of changes within the current flood window unsigned char fw_count; // Number of changes within the current flood window
unsigned long change_time; // Scheduled time to change unsigned long change_time; // Scheduled time to change
@ -174,6 +175,23 @@ void _relayProcess(bool mode) {
// Only process the relays we have to change to the requested mode // Only process the relays we have to change to the requested mode
if (target != mode) continue; if (target != mode) continue;
// Only process the relays that can be changed
switch (_relays[id].lock) {
case RELAY_LOCK_ON:
case RELAY_LOCK_OFF:
{
bool lock = _relays[id].lock == 1;
if (lock != _relays[id].target_status) {
_relays[id].target_status = lock;
continue;
}
break;
}
case RELAY_LOCK_DISABLED:
default:
break;
}
// Only process if the change_time has arrived // Only process if the change_time has arrived
if (current_time < _relays[id].change_time) continue; if (current_time < _relays[id].change_time) continue;
@ -521,6 +539,7 @@ void _relayBoot() {
auto mask = std::bitset<RELAY_SAVE_MASK_MAX>(stored_mask); auto mask = std::bitset<RELAY_SAVE_MASK_MAX>(stored_mask);
// Walk the relays // Walk the relays
unsigned char lock;
bool status; bool status;
for (unsigned char i=0; i<relayCount(); ++i) { for (unsigned char i=0; i<relayCount(); ++i) {
@ -528,6 +547,7 @@ void _relayBoot() {
DEBUG_MSG_P(PSTR("[RELAY] Relay #%u boot mode %u\n"), i, boot_mode); DEBUG_MSG_P(PSTR("[RELAY] Relay #%u boot mode %u\n"), i, boot_mode);
status = false; status = false;
lock = RELAY_LOCK_DISABLED;
switch (boot_mode) { switch (boot_mode) {
case RELAY_BOOT_SAME: case RELAY_BOOT_SAME:
if (i < 8) { if (i < 8) {
@ -541,6 +561,13 @@ void _relayBoot() {
trigger_save = true; trigger_save = true;
} }
break; break;
case RELAY_BOOT_LOCKED_ON:
status = true;
lock = RELAY_LOCK_ON;
break;
case RELAY_BOOT_LOCKED_OFF:
lock = RELAY_LOCK_OFF;
break;
case RELAY_BOOT_ON: case RELAY_BOOT_ON:
status = true; status = true;
break; break;
@ -556,7 +583,10 @@ void _relayBoot() {
#else #else
_relays[i].change_time = millis(); _relays[i].change_time = millis();
#endif #endif
}
_relays[i].lock = lock;
}
// Save if there is any relay in the RELAY_BOOT_TOGGLE mode // Save if there is any relay in the RELAY_BOOT_TOGGLE mode
if (trigger_save) { if (trigger_save) {
@ -599,9 +629,15 @@ bool _relayWebSocketOnKeyCheck(const char * key, JsonVariant& value) {
} }
void _relayWebSocketUpdate(JsonObject& root) { void _relayWebSocketUpdate(JsonObject& root) {
JsonArray& relay = root.createNestedArray("relayStatus");
JsonObject& state = root.createNestedObject("relayState");
state["size"] = relayCount();
JsonArray& status = state.createNestedArray("status");
JsonArray& lock = state.createNestedArray("lock");
for (unsigned char i=0; i<relayCount(); i++) { for (unsigned char i=0; i<relayCount(); i++) {
relay.add<uint8_t>(_relays[i].target_status);
status.add<uint8_t>(_relays[i].target_status);
lock.add(_relays[i].lock);
} }
} }


+ 3236
- 3233
code/espurna/static/index.all.html.gz.h
File diff suppressed because it is too large
View File


+ 2203
- 2200
code/espurna/static/index.light.html.gz.h
File diff suppressed because it is too large
View File


+ 1843
- 1840
code/espurna/static/index.lightfox.html.gz.h
File diff suppressed because it is too large
View File


+ 1860
- 1857
code/espurna/static/index.rfbridge.html.gz.h
File diff suppressed because it is too large
View File


+ 3221
- 3218
code/espurna/static/index.rfm69.html.gz.h
File diff suppressed because it is too large
View File


+ 1887
- 1885
code/espurna/static/index.sensor.html.gz.h
File diff suppressed because it is too large
View File


+ 1843
- 1840
code/espurna/static/index.small.html.gz.h
File diff suppressed because it is too large
View File


+ 2661
- 2658
code/espurna/static/index.thermostat.html.gz.h
File diff suppressed because it is too large
View File


+ 12
- 5
code/html/custom.js View File

@ -987,6 +987,15 @@ function initRelays(data) {
} }
function updateRelays(data) {
var size = data.size;
for (var i=0; i<size; ++i) {
var elem = $("input[name='relay'][data='" + i + "']");
elem.prop("checked", data.status[i]);
elem.prop("disabled", data.lock[i] < 2); // RELAY_LOCK_DISABLED=2
}
}
function createCheckboxes() { function createCheckboxes() {
$("input[type='checkbox']").each(function() { $("input[type='checkbox']").each(function() {
@ -1565,11 +1574,9 @@ function processData(data) {
// Relays // Relays
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
if ("relayStatus" === key) {
initRelays(value);
for (i in value) {
$("input[name='relay'][data='" + i + "']").prop("checked", value[i]);
}
if ("relayState" === key) {
initRelays(value.status);
updateRelays(value);
return; return;
} }


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

@ -1874,6 +1874,8 @@
<option value="1">Always ON</option> <option value="1">Always ON</option>
<option value="2">Same as before</option> <option value="2">Same as before</option>
<option value="3">Toggle before</option> <option value="3">Toggle before</option>
<option value="4">Locked OFF</option>
<option value="5">Locked ON</option>
</select> </select>
</div> </div>
<div class="pure-g"> <div class="pure-g">


Loading…
Cancel
Save