use rc-switch library for ringing the doorbell
This commit is contained in:
parent
b140fd08ac
commit
b57fb49a4d
@ -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;
|
||||
|
||||
@ -109,7 +109,13 @@ Command* commands[] = {
|
||||
}).asDevice(gatewayDevice).build(),
|
||||
Builder<Button>::instance(new Button{"Front door", "doorbell_front",
|
||||
[](const char* msg) {
|
||||
if (strcmp("PRESS", msg) == 0) doorbell.ring();
|
||||
if (strcmp("PRESS", msg) == 0) {
|
||||
StaticJsonDocument<128> jsonDoc;
|
||||
doorbell.toJson("00000000110100101000100", jsonDoc);
|
||||
string msg;
|
||||
serializeJson(jsonDoc, msg);
|
||||
runJsonCommand(msg.data());
|
||||
}
|
||||
}
|
||||
})
|
||||
.asDevice(
|
||||
|
||||
@ -48,6 +48,7 @@ namespace Board {
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
case 13:
|
||||
break;
|
||||
default: {
|
||||
unsigned long value = rcSwitch["value"];
|
||||
@ -84,4 +85,3 @@ namespace Board {
|
||||
Mqtt::publish("homeassistant/sensor/rc-gateway/raw", message);
|
||||
}
|
||||
}
|
||||
// {"rcSwitch":{"protocol":1,"state":false,"group":"11111","channel":4}}
|
||||
Loading…
x
Reference in New Issue
Block a user