From 14f41cf0f96fdb3c504f3213ae2c3f5e91253d58 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Mon, 18 Dec 2023 14:53:02 +0100 Subject: [PATCH] disable transmit pin when idle to avoid noise --- gateway/include/Protocol.h | 4 +++- gateway/include/Protocol_1.h | 3 +++ gateway/include/RC.h | 15 +++++++++++++++ gateway/src/gateway.cpp | 6 ++---- 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 gateway/include/RC.h diff --git a/gateway/include/Protocol.h b/gateway/include/Protocol.h index 9d966c9..b0a4498 100644 --- a/gateway/include/Protocol.h +++ b/gateway/include/Protocol.h @@ -1,6 +1,6 @@ #pragma once #include -#include +#include "RC.h" class Protocol { protected: @@ -15,7 +15,9 @@ public: virtual void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) { unsigned int protocol = rcSwitch["protocol"]; rcDevice.setProtocol(protocol); + mySwitch.enableTransmit(SEND_PIN); rcDevice.send(rcSwitch["value"]); + mySwitch.disableTransmit(); } virtual void toJson(unsigned long value, JsonDocument& jsonDoc) { diff --git a/gateway/include/Protocol_1.h b/gateway/include/Protocol_1.h index 935904e..330ea33 100644 --- a/gateway/include/Protocol_1.h +++ b/gateway/include/Protocol_1.h @@ -1,4 +1,5 @@ #pragma once +#include "RC.h" #include "Protocol.h" #include "RcDecoder.h" @@ -13,7 +14,9 @@ public: rcDevice.setProtocol(protocol); const char* group = rcSwitch["group"]; int channel = rcSwitch["channel"]; + mySwitch.enableTransmit(SEND_PIN); rcSwitch["state"] ? rcDevice.switchOn(group, channel) : rcDevice.switchOff(group, channel); + mySwitch.disableTransmit(); } void toJson(unsigned long value, JsonDocument& jsonDoc) override { diff --git a/gateway/include/RC.h b/gateway/include/RC.h new file mode 100644 index 0000000..42f38f0 --- /dev/null +++ b/gateway/include/RC.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#define SEND_PIN 11 +#define RECEIVE_PIN 2 + +RCSwitch mySwitch; + +namespace RC { + void setup() { + mySwitch.enableReceive(digitalPinToInterrupt(RECEIVE_PIN)); + mySwitch.setRepeatTransmit(10); + } +} \ No newline at end of file diff --git a/gateway/src/gateway.cpp b/gateway/src/gateway.cpp index 4a8e019..6c64c86 100644 --- a/gateway/src/gateway.cpp +++ b/gateway/src/gateway.cpp @@ -1,6 +1,7 @@ #include #include #include "Dht.h" +#include "RC.h" #include "Protocol_1.h" #include "Protocol_2.h" #include "output.h" @@ -19,10 +20,7 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); pinMode(RESET_PIN, OUTPUT); - mySwitch.enableReceive(digitalPinToInterrupt(RECEIVE_PIN)); - mySwitch.enableTransmit(SEND_PIN); - mySwitch.setRepeatTransmit(10); - + RC::setup(); Dht::setup(); Serial.begin(9600);