From 31523756233d57e47ad12c45f58d792044d7e56d Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sat, 18 May 2024 20:41:55 +0200 Subject: [PATCH 1/7] pin definitions in a dedicated file --- gateway/include/huzzah.h | 5 ----- gateway/include/pins.h | 12 ++++++++++++ gateway/include/pro-mini.h | 4 ---- gateway/src/gateway.cpp | 1 + 4 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 gateway/include/pins.h diff --git a/gateway/include/huzzah.h b/gateway/include/huzzah.h index 03b855e..3290d17 100644 --- a/gateway/include/huzzah.h +++ b/gateway/include/huzzah.h @@ -1,10 +1,5 @@ #include -#define SEND_PIN 14 -#define RECEIVE_PIN 12 -#define RED_LED LED_BUILTIN -#define BLUE_LED 2 - using namespace std; Scheduler ts; diff --git a/gateway/include/pins.h b/gateway/include/pins.h new file mode 100644 index 0000000..728511f --- /dev/null +++ b/gateway/include/pins.h @@ -0,0 +1,12 @@ +#pragma once + +#if defined(ESP8266) +#define SEND_PIN 14 +#define RECEIVE_PIN 12 +#define RED_LED LED_BUILTIN +#define BLUE_LED 2 +#else +#define RESET_PIN 10 +#define SEND_PIN 11 +#define RECEIVE_PIN 2 +#endif diff --git a/gateway/include/pro-mini.h b/gateway/include/pro-mini.h index fed8722..b43e076 100644 --- a/gateway/include/pro-mini.h +++ b/gateway/include/pro-mini.h @@ -1,9 +1,5 @@ #include "output.h" -#define RESET_PIN 10 -#define SEND_PIN 11 -#define RECEIVE_PIN 2 - namespace Board { void setup() { diff --git a/gateway/src/gateway.cpp b/gateway/src/gateway.cpp index cdafa1d..f112496 100644 --- a/gateway/src/gateway.cpp +++ b/gateway/src/gateway.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "pins.h" #include "Dht.h" #include "Protocol_1.h" #include "Protocol_2.h" From e9c404a4d53fcf23eb80d9862602c7627c89357d Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sat, 18 May 2024 21:17:23 +0200 Subject: [PATCH 2/7] add doorbell protocol --- gateway/include/Protocol_Doorbell.h | 64 +++++++++++++++++++++++++++++ gateway/include/devices.h | 13 ++++++ gateway/src/gateway.cpp | 3 ++ 3 files changed, 80 insertions(+) create mode 100644 gateway/include/Protocol_Doorbell.h 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