38 lines
938 B
C++
38 lines
938 B
C++
#pragma once
|
|
#include <ArduinoJson.h>
|
|
#include <RCSwitch.h>
|
|
|
|
using namespace std;
|
|
|
|
class Protocol {
|
|
protected:
|
|
unsigned int no;
|
|
|
|
public:
|
|
static unordered_map<unsigned int, Protocol*> mapProtocols;
|
|
|
|
Protocol(unsigned int protocol) {
|
|
no = protocol;
|
|
mapProtocols.insert({ no, this });
|
|
}
|
|
|
|
Protocol& setProtocol(unsigned int p) {
|
|
no = p;
|
|
return *this;
|
|
}
|
|
|
|
virtual void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) {
|
|
unsigned int 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;
|
|
}
|
|
};
|
|
unordered_map<unsigned int, Protocol*> Protocol::mapProtocols;
|
|
Protocol fallbackProtocol{ 0 };
|