Browse Source

Added synchornise all option for multi-relay boards

fastled
Xose Pérez 8 years ago
parent
commit
d1c8435b2d
5 changed files with 21 additions and 14 deletions
  1. BIN
      code/data/index.html.gz
  2. +2
    -1
      code/html/index.html
  3. +11
    -2
      code/src/config/general.h
  4. +1
    -1
      code/src/mqtt.ino
  5. +7
    -10
      code/src/relay.ino

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


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

@ -186,9 +186,10 @@
<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">
<option value="0">No synchonization</a>
<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>
<option value="3">All synchonised</a>
</select>
</div>
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>


+ 11
- 2
code/src/config/general.h View File

@ -12,11 +12,20 @@
// RELAY
//--------------------------------------------------------------------------------
#define RELAY_MODE_OFF 0
#define RELAY_MODE_ON 1
#define RELAY_MODE_SAME 2
#define RELAY_SYNC_ANY 0
#define RELAY_SYNC_NONE_OR_ONE 1
#define RELAY_SYNC_ONE 2
#define RELAY_SYNC_SAME 3
// 0 means OFF, 1 ON and 2 whatever was before
#define RELAY_MODE 1
#define RELAY_MODE RELAY_MODE_OFF
// 0 means ANY, 1 zero or one and 2 one and only one
#define RELAY_SYNC 0
#define RELAY_SYNC RELAY_SYNC_ANY
// -----------------------------------------------------------------------------
// WIFI & WEB


+ 1
- 1
code/src/mqtt.ino View File

@ -86,7 +86,7 @@ void _mqttOnMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
if (isFirstMessage) {
isFirstMessage = false;
byte relayMode = getSetting("relayMode", String(RELAY_MODE)).toInt();
if (relayMode != 2) return;
if (relayMode != RELAY_MODE_SAME) return;
}
// Get relay ID


+ 7
- 10
code/src/relay.ino View File

@ -17,15 +17,6 @@ bool recursive = false;
unsigned char dualRelayStatus = 0;
#endif
#define RELAY_MODE_OFF 0
#define RELAY_MODE_ON 1
#define RELAY_MODE_SAME 2
#define RELAY_SYNC_ANY 0
#define RELAY_SYNC_NONE_OR_ONE 1
#define RELAY_SYNC_ONE 2
// -----------------------------------------------------------------------------
// RELAY
// -----------------------------------------------------------------------------
@ -98,8 +89,14 @@ void relaySync(unsigned char id) {
byte relaySync = getSetting("relaySync", String(RELAY_SYNC)).toInt();
bool status = relayStatus(id);
// If RELAY_SYNC_SAME all relays should have the same state
if (relaySync == RELAY_SYNC_SAME) {
for (unsigned short i=0; i<_relays.size(); i++) {
if (i != id) relayStatus(i, status);
}
// If NONE_OR_ONE or ONE and setting ON we should set OFF all the others
if (status) {
} else if (status) {
if (relaySync != RELAY_SYNC_ANY) {
for (unsigned short i=0; i<_relays.size(); i++) {
if (i != id) relayStatus(i, false);


Loading…
Cancel
Save