add doorbell protocol
This commit is contained in:
parent
3152375623
commit
e9c404a4d5
64
gateway/include/Protocol_Doorbell.h
Normal file
64
gateway/include/Protocol_Doorbell.h
Normal file
@ -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;
|
||||
@ -101,6 +101,19 @@ Command* commands[] = {
|
||||
if (strcmp("PRESS", msg) == 0) ESP.restart();
|
||||
}
|
||||
}).asDevice(gatewayDevice).build(),
|
||||
Builder<Button>::instance(new Button{"Front door", "doorbell_front",
|
||||
[](const char* msg) {
|
||||
if (strcmp("PRESS", msg) == 0) doorbell.ring();
|
||||
}
|
||||
})
|
||||
.asDevice(
|
||||
DeviceConfig::create("doorbell")
|
||||
->withName("Doorbell")
|
||||
->withManufacturer("Thomson")
|
||||
->withModel("Kinetic Halo")
|
||||
->withParent(gatewayDevice)
|
||||
)
|
||||
.build(),
|
||||
(new EasyHomeSwitch{"FritzBox", "easy_home_a", (unsigned long[4]) { 4483136, 4626800, 4661552, 4819632 }, (unsigned long[4]) { 4326544, 4537104, 4767520, 4972704 }, "Basement"})->withStateTopic(),
|
||||
(new EasyHomeSwitch{"Outside", "easy_home_b", (unsigned long[4]) { 4483140, 4626804, 4661556, 4819636 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }, "Basement"})->withStateTopic(),
|
||||
(new PollinSwitch{"Meeting sensor", "00001", 1, "Dining room"})->withStateTopic(),
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include "Dht.h"
|
||||
#include "Protocol_1.h"
|
||||
#include "Protocol_2.h"
|
||||
#include "Protocol_Doorbell.h"
|
||||
|
||||
RCSwitch mySwitch;
|
||||
SerialReader<200> serialReader;
|
||||
@ -36,6 +37,8 @@ Protocol* findProtocol(unsigned int protocol) {
|
||||
return new Protocol_1();
|
||||
case 2:
|
||||
return new Protocol_2();
|
||||
case 16:
|
||||
return new Protocol_Doorbell();
|
||||
default:
|
||||
return new Protocol(protocol);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user