Browse Source

Backend for RELAY_MODE_FOLLOW

fastled
Xose Pérez 7 years ago
parent
commit
4dd0f358b4
3 changed files with 19 additions and 0 deletions
  1. +12
    -0
      code/espurna/button.ino
  2. +2
    -0
      code/espurna/config/general.h
  3. +5
    -0
      code/espurna/relay.ino

+ 12
- 0
code/espurna/button.ino View File

@ -30,6 +30,18 @@ void buttonMQTT(unsigned char id, uint8_t event) {
}
#endif
int buttonFromRelay(unsigned int relayID) {
for (unsigned int i=0; i < _buttons.size(); i++) {
if (_buttons[i].relayID == relayID) return i;
}
return -1;
}
bool buttonState(unsigned char id) {
if (id >= _buttons.size()) return false;
return _buttons[id].button->pressed();
}
unsigned char buttonAction(unsigned char id, unsigned char event) {
if (id >= _buttons.size()) return BUTTON_MODE_NONE;
unsigned long actions = _buttons[id].actions;


+ 2
- 0
code/espurna/config/general.h View File

@ -62,6 +62,7 @@
#define RELAY_MODE_ON 1
#define RELAY_MODE_SAME 2
#define RELAY_MODE_TOOGLE 3
#define RELAY_MODE_FOLLOW 4
#define RELAY_SYNC_ANY 0
#define RELAY_SYNC_NONE_OR_ONE 1
@ -90,6 +91,7 @@
// Relay requests flood protection window - in seconds
#define RELAY_FLOOD_WINDOW 3
// Allowed actual relay changes inside requests flood protection window
#define RELAY_FLOOD_CHANGES 5


+ 5
- 0
code/espurna/relay.ino View File

@ -477,6 +477,11 @@ void relaySetup() {
pinMode(_relays[i].pin, OUTPUT);
if (relayMode == RELAY_MODE_OFF) relayStatus(i, false);
if (relayMode == RELAY_MODE_ON) relayStatus(i, true);
if (relayMode == RELAY_MODE_FOLLOW) {
// retrieve the status of the linked button
int buttonID = buttonFromRelay(i);
relayStatus(i, (buttonID >=0) ? buttonState(buttonID) : false);
}
}
if (relayMode == RELAY_MODE_SAME) relayRetrieve(false);
if (relayMode == RELAY_MODE_TOOGLE) relayRetrieve(true);


Loading…
Cancel
Save