disable transmit pin when idle to avoid noise
This commit is contained in:
parent
4a3c54b024
commit
14f41cf0f9
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <RCSwitch.h>
|
#include "RC.h"
|
||||||
|
|
||||||
class Protocol {
|
class Protocol {
|
||||||
protected:
|
protected:
|
||||||
@ -15,7 +15,9 @@ public:
|
|||||||
virtual void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) {
|
virtual void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) {
|
||||||
unsigned int protocol = rcSwitch["protocol"];
|
unsigned int protocol = rcSwitch["protocol"];
|
||||||
rcDevice.setProtocol(protocol);
|
rcDevice.setProtocol(protocol);
|
||||||
|
mySwitch.enableTransmit(SEND_PIN);
|
||||||
rcDevice.send(rcSwitch["value"]);
|
rcDevice.send(rcSwitch["value"]);
|
||||||
|
mySwitch.disableTransmit();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void toJson(unsigned long value, JsonDocument& jsonDoc) {
|
virtual void toJson(unsigned long value, JsonDocument& jsonDoc) {
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "RC.h"
|
||||||
#include "Protocol.h"
|
#include "Protocol.h"
|
||||||
#include "RcDecoder.h"
|
#include "RcDecoder.h"
|
||||||
|
|
||||||
@ -13,7 +14,9 @@ public:
|
|||||||
rcDevice.setProtocol(protocol);
|
rcDevice.setProtocol(protocol);
|
||||||
const char* group = rcSwitch["group"];
|
const char* group = rcSwitch["group"];
|
||||||
int channel = rcSwitch["channel"];
|
int channel = rcSwitch["channel"];
|
||||||
|
mySwitch.enableTransmit(SEND_PIN);
|
||||||
rcSwitch["state"] ? rcDevice.switchOn(group, channel) : rcDevice.switchOff(group, channel);
|
rcSwitch["state"] ? rcDevice.switchOn(group, channel) : rcDevice.switchOff(group, channel);
|
||||||
|
mySwitch.disableTransmit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void toJson(unsigned long value, JsonDocument& jsonDoc) override {
|
void toJson(unsigned long value, JsonDocument& jsonDoc) override {
|
||||||
|
|||||||
15
gateway/include/RC.h
Normal file
15
gateway/include/RC.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <RCSwitch.h>
|
||||||
|
|
||||||
|
#define SEND_PIN 11
|
||||||
|
#define RECEIVE_PIN 2
|
||||||
|
|
||||||
|
RCSwitch mySwitch;
|
||||||
|
|
||||||
|
namespace RC {
|
||||||
|
void setup() {
|
||||||
|
mySwitch.enableReceive(digitalPinToInterrupt(RECEIVE_PIN));
|
||||||
|
mySwitch.setRepeatTransmit(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <RCSwitch.h>
|
#include <RCSwitch.h>
|
||||||
#include "Dht.h"
|
#include "Dht.h"
|
||||||
|
#include "RC.h"
|
||||||
#include "Protocol_1.h"
|
#include "Protocol_1.h"
|
||||||
#include "Protocol_2.h"
|
#include "Protocol_2.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
@ -19,10 +20,7 @@ void setup() {
|
|||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
|
|
||||||
mySwitch.enableReceive(digitalPinToInterrupt(RECEIVE_PIN));
|
RC::setup();
|
||||||
mySwitch.enableTransmit(SEND_PIN);
|
|
||||||
mySwitch.setRepeatTransmit(10);
|
|
||||||
|
|
||||||
Dht::setup();
|
Dht::setup();
|
||||||
|
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user