diff --git a/gateway/include/Protocol_Doorbell.h b/gateway/include/Protocol_Doorbell.h new file mode 100644 index 0000000..59285cf --- /dev/null +++ b/gateway/include/Protocol_Doorbell.h @@ -0,0 +1,64 @@ +#pragma once +#include "Protocol.h" + +#define BIT_LENGTH 40 +#define BIT_LENGTH_3 BIT_LENGTH*3 +#define TX_DELAY 620 + +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"); + } + } + + void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) override { + } + + void toJson(unsigned long value, JsonDocument& jsonDoc) override { + } + +private: + void transmitBit(uint8_t value) { + digitalWrite(SEND_PIN, value); + delayMicroseconds(BIT_LENGTH); + 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++) { + transmitBit(HIGH); + transmitBit(LOW); + } + 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 b59c9cb..604ab27 100644 --- a/gateway/include/devices.h +++ b/gateway/include/devices.h @@ -101,6 +101,19 @@ Command* commands[] = { if (strcmp("PRESS", msg) == 0) ESP.restart(); } }).asDevice(gatewayDevice).build(), + Builder