43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#pragma once
|
|
#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;}
|
|
};
|
|
constexpr ProtocolNo NO_PROTOCOL{ 0 };
|
|
constexpr ProtocolNo PROTOCOL_1{ 1 };
|
|
constexpr ProtocolNo PROTOCOL_2{ 2 };
|
|
constexpr ProtocolNo PROTOCOL_13{ 13 };
|
|
|
|
class Protocol {
|
|
protected:
|
|
ProtocolNo no;
|
|
|
|
public:
|
|
Protocol(ProtocolNo protocol) : no(protocol) {}
|
|
|
|
Protocol& setProtocol(ProtocolNo p) {
|
|
no = p;
|
|
return *this;
|
|
}
|
|
|
|
virtual void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) {
|
|
ProtocolNo protocol = rcSwitch["protocol"];
|
|
rcDevice.setProtocol(protocol);
|
|
rcDevice.send(rcSwitch["value"]);
|
|
}
|
|
|
|
virtual void toJson(unsigned long value, JsonDocument& jsonDoc) {
|
|
JsonObject rcSwitch = jsonDoc.createNestedObject("rcSwitch");
|
|
rcSwitch["protocol"] = no;
|
|
rcSwitch["value"] = value;
|
|
}
|
|
} fallbackProtocol{ NO_PROTOCOL };
|