mirror of https://github.com/arendst/Tasmota.git
Fix bistable relay support
This commit is contained in:
parent
485328b94d
commit
8283cee823
|
@ -1048,7 +1048,4 @@
|
|||
#define USE_TLS // flag indicates we need to include TLS code
|
||||
#endif // USE_MQTT_TLS
|
||||
|
||||
// -- Basic features ------------------------------
|
||||
#define USE_BISTABLE_RELAY_SUPPORT // Add support for bistable (latching) relays using GPIO Relay_b or Relay_bi
|
||||
|
||||
#endif // _TASMOTA_CONFIGURATIONS_H_
|
||||
|
|
|
@ -476,18 +476,16 @@ const uint16_t kGpioNiceList[] PROGMEM = {
|
|||
#endif
|
||||
AGPIO(GPIO_REL1) + MAX_RELAYS, // Relays
|
||||
AGPIO(GPIO_REL1_INV) + MAX_RELAYS,
|
||||
#ifdef USE_BISTABLE_RELAY_SUPPORT
|
||||
AGPIO(GPIO_REL1_BI) + MAX_RELAYS, // Bistable (Latching) two coil relays
|
||||
AGPIO(GPIO_REL1_BI_INV) + MAX_RELAYS,
|
||||
#endif
|
||||
AGPIO(GPIO_LED1) + MAX_LEDS, // Leds
|
||||
AGPIO(GPIO_LED1_INV) + MAX_LEDS,
|
||||
#ifdef USE_COUNTER
|
||||
AGPIO(GPIO_CNTR1) + MAX_COUNTERS, // Counters
|
||||
AGPIO(GPIO_CNTR1_NP) + MAX_COUNTERS,
|
||||
#endif
|
||||
AGPIO(GPIO_PWM1) + MAX_PWMS, // RGB Red or C Cold White
|
||||
AGPIO(GPIO_PWM1_INV) + MAX_PWMS, // or extended PWM for ESP32
|
||||
AGPIO(GPIO_PWM1) + MAX_PWMS, // RGB Red or C Cold White
|
||||
AGPIO(GPIO_PWM1_INV) + MAX_PWMS, // or extended PWM for ESP32
|
||||
#ifdef USE_BUZZER
|
||||
AGPIO(GPIO_BUZZER), // Buzzer
|
||||
AGPIO(GPIO_BUZZER_INV), // Inverted buzzer
|
||||
|
|
|
@ -221,9 +221,7 @@ struct TasmotaGlobal_t {
|
|||
|
||||
power_t power; // Current copy of Settings->power
|
||||
power_t rel_inverted; // Relay inverted flag (1 = (0 = On, 1 = Off))
|
||||
#ifdef USE_BISTABLE_RELAY_SUPPORT
|
||||
power_t rel_bistable; // Relay bistable bitmap
|
||||
#endif // USE_BISTABLE_RELAY_SUPPORT
|
||||
power_t last_power; // Last power set state
|
||||
power_t blink_power; // Blink power state
|
||||
power_t blink_powersave; // Blink start power save state
|
||||
|
|
|
@ -239,7 +239,6 @@ void SetLatchingRelay(power_t lpower, uint32_t state) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef USE_BISTABLE_RELAY_SUPPORT
|
||||
void ResetBistableRelays(void) {
|
||||
for (uint32_t i = 0; i < MAX_RELAYS; i++) {
|
||||
if (bitRead(TasmotaGlobal.rel_bistable, i)) {
|
||||
|
@ -247,7 +246,6 @@ void ResetBistableRelays(void) {
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif // USE_BISTABLE_RELAY_SUPPORT
|
||||
|
||||
void SetDevicePower(power_t rpower, uint32_t source) {
|
||||
ShowSource(source);
|
||||
|
@ -306,7 +304,6 @@ void SetDevicePower(power_t rpower, uint32_t source) {
|
|||
{
|
||||
ZeroCrossMomentStart();
|
||||
|
||||
#ifdef USE_BISTABLE_RELAY_SUPPORT
|
||||
uint32_t port = 0;
|
||||
uint32_t port_next;
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||
|
@ -325,15 +322,6 @@ void SetDevicePower(power_t rpower, uint32_t source) {
|
|||
port += port_next; // Select next relay
|
||||
rpower >>= 1;
|
||||
}
|
||||
#else
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||
power_t state = rpower &1;
|
||||
if (i < MAX_RELAYS) {
|
||||
DigitalWrite(GPIO_REL1, i, bitRead(TasmotaGlobal.rel_inverted, i) ? !state : state);
|
||||
}
|
||||
rpower >>= 1;
|
||||
}
|
||||
#endif // USE_BISTABLE_RELAY_SUPPORT
|
||||
|
||||
ZeroCrossMomentEnd();
|
||||
}
|
||||
|
@ -428,7 +416,6 @@ void SetPowerOnState(void)
|
|||
}
|
||||
|
||||
// Issue #526 and #909
|
||||
#ifdef USE_BISTABLE_RELAY_SUPPORT
|
||||
uint32_t port = 0;
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||
#ifdef ESP8266
|
||||
|
@ -447,20 +434,6 @@ void SetPowerOnState(void)
|
|||
SetPulseTimer(i % MAX_PULSETIMERS, Settings->pulse_timer[i % MAX_PULSETIMERS]);
|
||||
}
|
||||
}
|
||||
#else // No USE_BISTABLE_RELAY_SUPPORT
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||
#ifdef ESP8266
|
||||
if (!Settings->flag3.no_power_feedback) { // SetOption63 - Don't scan relay power state at restart - #5594 and #5663
|
||||
if ((i < MAX_RELAYS) && PinUsed(GPIO_REL1, i)) {
|
||||
bitWrite(TasmotaGlobal.power, i, digitalRead(Pin(GPIO_REL1, i)) ^ bitRead(TasmotaGlobal.rel_inverted, i));
|
||||
}
|
||||
}
|
||||
#endif // ESP8266
|
||||
if (bitRead(TasmotaGlobal.power, i) || (POWER_ALL_OFF_PULSETIME_ON == Settings->poweronstate)) {
|
||||
SetPulseTimer(i % MAX_PULSETIMERS, Settings->pulse_timer[i % MAX_PULSETIMERS]);
|
||||
}
|
||||
}
|
||||
#endif // USE_BISTABLE_RELAY_SUPPORT
|
||||
|
||||
TasmotaGlobal.blink_powersave = TasmotaGlobal.power;
|
||||
#ifdef USE_RULES
|
||||
|
@ -1182,9 +1155,7 @@ void Every100mSeconds(void)
|
|||
SetLatchingRelay(0, 0);
|
||||
}
|
||||
#endif // ESP8266
|
||||
#ifdef USE_BISTABLE_RELAY_SUPPORT
|
||||
ResetBistableRelays();
|
||||
#endif // USE_BISTABLE_RELAY_SUPPORT
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2029,7 +2000,6 @@ void GpioInit(void)
|
|||
bitSet(TasmotaGlobal.rel_inverted, mpin - AGPIO(GPIO_REL1_INV));
|
||||
mpin -= (AGPIO(GPIO_REL1_INV) - AGPIO(GPIO_REL1));
|
||||
}
|
||||
#ifdef USE_BISTABLE_RELAY_SUPPORT
|
||||
else if ((mpin >= AGPIO(GPIO_REL1_BI)) && (mpin < (AGPIO(GPIO_REL1_BI) + MAX_RELAYS))) {
|
||||
bitSet(TasmotaGlobal.rel_bistable, mpin - AGPIO(GPIO_REL1_BI));
|
||||
mpin -= (AGPIO(GPIO_REL1_BI) - AGPIO(GPIO_REL1));
|
||||
|
@ -2039,7 +2009,6 @@ void GpioInit(void)
|
|||
bitSet(TasmotaGlobal.rel_inverted, mpin - AGPIO(GPIO_REL1_BI_INV));
|
||||
mpin -= (AGPIO(GPIO_REL1_BI_INV) - AGPIO(GPIO_REL1));
|
||||
}
|
||||
#endif // USE_BISTABLE_RELAY_SUPPORT
|
||||
else if ((mpin >= AGPIO(GPIO_LED1_INV)) && (mpin < (AGPIO(GPIO_LED1_INV) + MAX_LEDS))) {
|
||||
bitSet(TasmotaGlobal.led_inverted, mpin - AGPIO(GPIO_LED1_INV));
|
||||
mpin -= (AGPIO(GPIO_LED1_INV) - AGPIO(GPIO_LED1));
|
||||
|
@ -2234,9 +2203,7 @@ void GpioInit(void)
|
|||
|
||||
GpioInitPwm();
|
||||
|
||||
#ifdef USE_BISTABLE_RELAY_SUPPORT
|
||||
uint32_t bi_device = 0;
|
||||
#endif // USE_BISTABLE_RELAY_SUPPORT
|
||||
for (uint32_t i = 0; i < MAX_RELAYS; i++) {
|
||||
if (PinUsed(GPIO_REL1, i)) {
|
||||
TasmotaGlobal.devices_present++;
|
||||
|
@ -2245,12 +2212,10 @@ void GpioInit(void)
|
|||
if (i &1) { TasmotaGlobal.devices_present--; }
|
||||
}
|
||||
#endif // ESP8266
|
||||
#ifdef USE_BISTABLE_RELAY_SUPPORT
|
||||
if (bitRead(TasmotaGlobal.rel_bistable, i)) {
|
||||
if (bi_device &1) { TasmotaGlobal.devices_present--; }
|
||||
bi_device++;
|
||||
}
|
||||
#endif // USE_BISTABLE_RELAY_SUPPORT
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue