From 83b97b913ad719ec3d0ecc54f9ae0cfb20bb4fe9 Mon Sep 17 00:00:00 2001 From: Andrew Andrianov Date: Tue, 23 Feb 2021 21:36:36 +0300 Subject: [PATCH 1/2] sensors: Relay: Add inverted option Signed-off-by: Andrew Andrianov --- sensors/SensorRelay.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sensors/SensorRelay.h b/sensors/SensorRelay.h index 0e0db277..1b447f56 100644 --- a/sensors/SensorRelay.h +++ b/sensors/SensorRelay.h @@ -27,8 +27,9 @@ SensorRelay class SensorRelay: public SensorDigitalOutput { public: - SensorRelay(int8_t pin, uint8_t child_id = 0): SensorDigitalOutput(pin, child_id) { + SensorRelay(int8_t pin, bool inverted = false, uint8_t child_id = 0): SensorDigitalOutput(pin, child_id) { _name = "RELAY"; + setInvertValueToWrite(inverted); children.get()->setPresentation(S_BINARY); children.get()->setType(V_STATUS); children.get()->setDescription(_name); From a8c34ac88e2333887a2ec2e8369b772cfa1b1b8a Mon Sep 17 00:00:00 2001 From: Andrew Andrianov Date: Tue, 23 Feb 2021 21:36:59 +0300 Subject: [PATCH 2/2] SensorDigitalOutput: Avoid relay toggling during pin initialization Signed-off-by: Andrew Andrianov --- sensors/SensorDigitalOutput.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sensors/SensorDigitalOutput.h b/sensors/SensorDigitalOutput.h index 7f54f756..fbf3eded 100644 --- a/sensors/SensorDigitalOutput.h +++ b/sensors/SensorDigitalOutput.h @@ -111,7 +111,9 @@ class SensorDigitalOutput: public Sensor { void onSetup() { // do not average the value children.get()->setValueProcessing(NONE); - // setup the pin + // First, set pin status. This will effect only the pullup at first + setStatus(OFF); + // Now, setup the pin mode pinMode(_pin, OUTPUT); // setup the off pin if needed if (_pin_off > 0) pinMode(_pin_off, OUTPUT); @@ -121,8 +123,7 @@ class SensorDigitalOutput: public Sensor { // keep track of the value in EEPROM so to restore it upon a reboot children.get()->setPersistValue(true); #else - // turn the output off by default - setStatus(OFF); + #endif };