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 BIT_LENGTH_3 BIT_LENGTH*3
|
||||||
#define TX_DELAY 620
|
#define TX_DELAY 620
|
||||||
|
|
||||||
|
// { 40, { 1, 15 }, { 1, 3 }, { 3, 1 }, false } // protocol 13 (Thomson Doorbell)
|
||||||
|
|
||||||
class Protocol_Doorbell : public Protocol {
|
class Protocol_Doorbell : public Protocol {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Protocol_Doorbell() : Protocol(16) {}
|
Protocol_Doorbell() : Protocol(13) {}
|
||||||
|
|
||||||
void ring() {
|
|
||||||
preamble();
|
|
||||||
for (int i = 0; i < 7; i++) {
|
|
||||||
delayMicroseconds(TX_DELAY);
|
|
||||||
code("00000000110100101000100");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) override {
|
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:
|
private:
|
||||||
@ -31,20 +31,6 @@ private:
|
|||||||
digitalWrite(SEND_PIN, LOW);
|
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() {
|
void preamble() {
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
for (int i = 0; i < 370; i++) {
|
for (int i = 0; i < 370; i++) {
|
||||||
@ -53,12 +39,4 @@ private:
|
|||||||
}
|
}
|
||||||
interrupts();
|
interrupts();
|
||||||
}
|
}
|
||||||
|
|
||||||
void code(const char* value) {
|
|
||||||
noInterrupts();
|
|
||||||
for (const char* p = value; *p; p++) {
|
|
||||||
*p == '1' ? transmitHigh() : transmitLow();
|
|
||||||
}
|
|
||||||
interrupts();
|
|
||||||
}
|
|
||||||
} doorbell;
|
} doorbell;
|
||||||
|
|||||||
@ -109,7 +109,13 @@ Command* commands[] = {
|
|||||||
}).asDevice(gatewayDevice).build(),
|
}).asDevice(gatewayDevice).build(),
|
||||||
Builder<Button>::instance(new Button{"Front door", "doorbell_front",
|
Builder<Button>::instance(new Button{"Front door", "doorbell_front",
|
||||||
[](const char* msg) {
|
[](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(
|
.asDevice(
|
||||||
|
|||||||
@ -48,6 +48,7 @@ namespace Board {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
|
case 13:
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
unsigned long value = rcSwitch["value"];
|
unsigned long value = rcSwitch["value"];
|
||||||
@ -84,4 +85,3 @@ namespace Board {
|
|||||||
Mqtt::publish("homeassistant/sensor/rc-gateway/raw", message);
|
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