From b57fb49a4d8852f7cd10d1a46a104d76786f552e Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sun, 19 May 2024 18:13:49 +0200 Subject: [PATCH] use rc-switch library for ringing the doorbell --- gateway/include/Protocol_Doorbell.h | 42 +++++++---------------------- gateway/include/devices.h | 8 +++++- gateway/include/huzzah.h | 2 +- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/gateway/include/Protocol_Doorbell.h b/gateway/include/Protocol_Doorbell.h index 59285cf..ed0abcc 100644 --- a/gateway/include/Protocol_Doorbell.h +++ b/gateway/include/Protocol_Doorbell.h @@ -5,23 +5,23 @@ #define BIT_LENGTH_3 BIT_LENGTH*3 #define TX_DELAY 620 +// { 40, { 1, 15 }, { 1, 3 }, { 3, 1 }, false } // protocol 13 (Thomson Doorbell) + class Protocol_Doorbell : public Protocol { public: - Protocol_Doorbell() : Protocol(16) {} - - void ring() { - preamble(); - for (int i = 0; i < 7; i++) { - delayMicroseconds(TX_DELAY); - code("00000000110100101000100"); - } - } + Protocol_Doorbell() : Protocol(13) {} void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) override { + preamble(); + rcDevice.setRepeatTransmit(7); + Protocol::fromJson(rcSwitch, rcDevice); } - void toJson(unsigned long value, JsonDocument& jsonDoc) override { + void toJson(const char* value, JsonDocument& jsonDoc) { + JsonObject rcSwitch = jsonDoc.createNestedObject("rcSwitch"); + rcSwitch["protocol"] = no; + rcSwitch["value"] = value; } private: @@ -31,20 +31,6 @@ private: digitalWrite(SEND_PIN, LOW); } - void transmitHigh() { - digitalWrite(SEND_PIN, HIGH); - delayMicroseconds(BIT_LENGTH_3); - digitalWrite(SEND_PIN, LOW); - delayMicroseconds(BIT_LENGTH); - } - - void transmitLow() { - digitalWrite(SEND_PIN, HIGH); - delayMicroseconds(BIT_LENGTH); - digitalWrite(SEND_PIN, LOW); - delayMicroseconds(BIT_LENGTH_3); - } - void preamble() { noInterrupts(); for (int i = 0; i < 370; i++) { @@ -53,12 +39,4 @@ private: } interrupts(); } - - void code(const char* value) { - noInterrupts(); - for (const char* p = value; *p; p++) { - *p == '1' ? transmitHigh() : transmitLow(); - } - interrupts(); - } } doorbell; diff --git a/gateway/include/devices.h b/gateway/include/devices.h index 4353af7..638328f 100644 --- a/gateway/include/devices.h +++ b/gateway/include/devices.h @@ -109,7 +109,13 @@ Command* commands[] = { }).asDevice(gatewayDevice).build(), Builder