use enum for protocol
This commit is contained in:
parent
45e0ea3261
commit
f668beeca2
@ -2,19 +2,12 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
class ProtocolNo {
|
||||
protected:
|
||||
unsigned int no;
|
||||
|
||||
public:
|
||||
constexpr ProtocolNo(unsigned int protocol) : no(protocol) {}
|
||||
constexpr operator unsigned int() const { return no; }
|
||||
ProtocolNo& operator=(unsigned int p){ no = p; return *this;}
|
||||
enum ProtocolNo : unsigned int {
|
||||
NO_PROTOCOL = 0,
|
||||
PROTOCOL_1 = 1,
|
||||
PROTOCOL_2 = 2,
|
||||
PROTOCOL_13 = 13
|
||||
};
|
||||
constexpr ProtocolNo NO_PROTOCOL{ 0 };
|
||||
constexpr ProtocolNo PROTOCOL_1{ 1 };
|
||||
constexpr ProtocolNo PROTOCOL_2{ 2 };
|
||||
constexpr ProtocolNo PROTOCOL_13{ 13 };
|
||||
|
||||
class Protocol {
|
||||
protected:
|
||||
@ -23,8 +16,8 @@ protected:
|
||||
public:
|
||||
Protocol(ProtocolNo protocol) : no(protocol) {}
|
||||
|
||||
Protocol& setProtocol(ProtocolNo p) {
|
||||
no = p;
|
||||
Protocol& setProtocol(unsigned int p) {
|
||||
no = static_cast<ProtocolNo>(p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ class Protocol_Doorbell : public Protocol {
|
||||
public:
|
||||
Protocol_Doorbell() : Protocol(PROTOCOL_13) {}
|
||||
|
||||
static void ring(const char* value) {
|
||||
void ring(const char* value) {
|
||||
preamble();
|
||||
for (int i = 0; i < 7; i++) {
|
||||
delayMicroseconds(TX_DELAY);
|
||||
@ -19,27 +19,27 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static void transmitBit(uint8_t value) {
|
||||
void transmitBit(uint8_t value) {
|
||||
digitalWrite(SEND_PIN, value);
|
||||
delayMicroseconds(BIT_LENGTH);
|
||||
digitalWrite(SEND_PIN, LOW);
|
||||
}
|
||||
|
||||
static void transmitHigh() {
|
||||
void transmitHigh() {
|
||||
digitalWrite(SEND_PIN, HIGH);
|
||||
delayMicroseconds(BIT_LENGTH_3);
|
||||
digitalWrite(SEND_PIN, LOW);
|
||||
delayMicroseconds(BIT_LENGTH);
|
||||
}
|
||||
|
||||
static void transmitLow() {
|
||||
void transmitLow() {
|
||||
digitalWrite(SEND_PIN, HIGH);
|
||||
delayMicroseconds(BIT_LENGTH);
|
||||
digitalWrite(SEND_PIN, LOW);
|
||||
delayMicroseconds(BIT_LENGTH_3);
|
||||
}
|
||||
|
||||
static void preamble() {
|
||||
void preamble() {
|
||||
noInterrupts();
|
||||
for (int i = 0; i < 370; i++) {
|
||||
transmitBit(HIGH);
|
||||
@ -48,7 +48,7 @@ private:
|
||||
interrupts();
|
||||
}
|
||||
|
||||
static void code(const char* value) {
|
||||
void code(const char* value) {
|
||||
noInterrupts();
|
||||
for (const char* p = value; *p; p++) {
|
||||
*p == '1' ? transmitHigh() : transmitLow();
|
||||
|
||||
@ -109,7 +109,7 @@ Command* commands[] = {
|
||||
}).asDevice(gatewayDevice).build(),
|
||||
Builder<Button>::instance(new Button{"Front door", "doorbell_front",
|
||||
[](const char* msg) {
|
||||
if (strcmp("PRESS", msg) == 0) Protocol_Doorbell::ring("00000000110100101000100");
|
||||
if (strcmp("PRESS", msg) == 0) doorbell.ring("00000000110100101000100");
|
||||
}
|
||||
})
|
||||
.asDevice(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user