|
@ -11,7 +11,11 @@ Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com> |
|
|
#include <ArduinoJson.h>
|
|
|
#include <ArduinoJson.h>
|
|
|
#include <vector>
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
std::vector<unsigned char> _relays; |
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
|
|
unsigned char pin; |
|
|
|
|
|
bool reverse; |
|
|
|
|
|
} relay_t; |
|
|
|
|
|
std::vector<relay_t> _relays; |
|
|
bool recursive = false; |
|
|
bool recursive = false; |
|
|
#ifdef SONOFF_DUAL
|
|
|
#ifdef SONOFF_DUAL
|
|
|
unsigned char dualRelayStatus = 0; |
|
|
unsigned char dualRelayStatus = 0; |
|
@ -58,7 +62,8 @@ bool relayStatus(unsigned char id) { |
|
|
return ((dualRelayStatus & (1 << id)) > 0); |
|
|
return ((dualRelayStatus & (1 << id)) > 0); |
|
|
#else
|
|
|
#else
|
|
|
if (id >= _relays.size()) return false; |
|
|
if (id >= _relays.size()) return false; |
|
|
return (digitalRead(_relays[id]) == HIGH); |
|
|
|
|
|
|
|
|
bool status = (digitalRead(_relays[id].pin) == HIGH); |
|
|
|
|
|
return _relays[id].reverse ? !status : status; |
|
|
#endif
|
|
|
#endif
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -84,7 +89,7 @@ bool relayStatus(unsigned char id, bool status, bool report) { |
|
|
Serial.flush(); |
|
|
Serial.flush(); |
|
|
|
|
|
|
|
|
#else
|
|
|
#else
|
|
|
digitalWrite(_relays[id], status); |
|
|
|
|
|
|
|
|
digitalWrite(_relays[id].pin, _relays[id].reverse ? !status : status); |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
if (!recursive) { |
|
|
if (!recursive) { |
|
@ -218,22 +223,22 @@ void relaySetup() { |
|
|
#ifdef SONOFF_DUAL
|
|
|
#ifdef SONOFF_DUAL
|
|
|
|
|
|
|
|
|
// Two dummy relays for the dual
|
|
|
// Two dummy relays for the dual
|
|
|
_relays.push_back(0); |
|
|
|
|
|
_relays.push_back(0); |
|
|
|
|
|
|
|
|
_relays.push_back((relay_t) {0, 0}); |
|
|
|
|
|
_relays.push_back((relay_t) {0, 0}); |
|
|
|
|
|
|
|
|
#else
|
|
|
#else
|
|
|
|
|
|
|
|
|
#ifdef RELAY1_PIN
|
|
|
#ifdef RELAY1_PIN
|
|
|
_relays.push_back(RELAY1_PIN); |
|
|
|
|
|
|
|
|
_relays.push_back((relay_t) { RELAY1_PIN, RELAY1_PIN_INVERSE }); |
|
|
#endif
|
|
|
#endif
|
|
|
#ifdef RELAY2_PIN
|
|
|
#ifdef RELAY2_PIN
|
|
|
_relays.push_back(RELAY2_PIN); |
|
|
|
|
|
|
|
|
_relays.push_back((relay_t) { RELAY2_PIN, RELAY2_PIN_INVERSE }); |
|
|
#endif
|
|
|
#endif
|
|
|
#ifdef RELAY3_PIN
|
|
|
#ifdef RELAY3_PIN
|
|
|
_relays.push_back(RELAY3_PIN); |
|
|
|
|
|
|
|
|
_relays.push_back((relay_t) { RELAY3_PIN, RELAY3_PIN_INVERSE }); |
|
|
#endif
|
|
|
#endif
|
|
|
#ifdef RELAY4_PIN
|
|
|
#ifdef RELAY4_PIN
|
|
|
_relays.push_back(RELAY4_PIN); |
|
|
|
|
|
|
|
|
_relays.push_back((relay_t) { RELAY4_PIN, RELAY4_PIN_INVERSE }); |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
#endif
|
|
|
#endif
|
|
@ -242,7 +247,7 @@ void relaySetup() { |
|
|
byte relayMode = getSetting("relayMode", RELAY_MODE).toInt(); |
|
|
byte relayMode = getSetting("relayMode", RELAY_MODE).toInt(); |
|
|
|
|
|
|
|
|
for (unsigned int i=0; i < _relays.size(); i++) { |
|
|
for (unsigned int i=0; i < _relays.size(); i++) { |
|
|
pinMode(_relays[i], OUTPUT); |
|
|
|
|
|
|
|
|
pinMode(_relays[i].pin, OUTPUT); |
|
|
if (relayMode == RELAY_MODE_OFF) relayStatus(i, false); |
|
|
if (relayMode == RELAY_MODE_OFF) relayStatus(i, false); |
|
|
if (relayMode == RELAY_MODE_ON) relayStatus(i, true); |
|
|
if (relayMode == RELAY_MODE_ON) relayStatus(i, true); |
|
|
} |
|
|
} |
|
|