- move code for all devices in dedicated folder - move code for gateway in the root folder
36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
#pragma once
|
|
#include "Protocol.h"
|
|
#include "RcDecoder.h"
|
|
|
|
class Protocol_1 : public Protocol {
|
|
|
|
public:
|
|
Protocol_1() : Protocol(PROTOCOL_1) {}
|
|
|
|
void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) override {
|
|
ProtocolNo protocol = rcSwitch["protocol"];
|
|
rcDevice.setProtocol(protocol);
|
|
const char* group = rcSwitch["group"];
|
|
int channel = rcSwitch["channel"];
|
|
rcSwitch["state"] ? rcDevice.switchOn(group, channel) : rcDevice.switchOff(group, channel);
|
|
}
|
|
|
|
void toJson(unsigned long value, JsonDocument& jsonDoc) override {
|
|
JsonObject rcSwitch = jsonDoc.createNestedObject("rcSwitch");
|
|
rcSwitch["protocol"] = no;
|
|
RcDecoder decoder;
|
|
decoder.decode(value);
|
|
rcSwitch["state"] = decoder.state;
|
|
rcSwitch["group"] = decoder.group;
|
|
rcSwitch["channel"] = decoder.device;
|
|
rcSwitch["raw_value"] = value;
|
|
}
|
|
|
|
#if defined(ESP8266)
|
|
static std::string buildId(const char* group, const unsigned char channel) {
|
|
char uId[30];
|
|
sprintf(uId, "%s_%d", group, channel);
|
|
return std::string{ uId };
|
|
}
|
|
#endif
|
|
} protocol1; |