mirror of
https://gitlab.com/wirelos/sprocket-plugin-rcswitch.git
synced 2025-12-16 22:36:41 +01:00
rf switch plugin
This commit is contained in:
48
src/RcSwitchConfig.h
Normal file
48
src/RcSwitchConfig.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef __RC_SWITCH_CONFIG__
|
||||
#define __RC_SWITCH_CONFIG__
|
||||
|
||||
#include <JsonStruct.h>
|
||||
#include "utils/print.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
struct RcSwitchConfig
|
||||
{
|
||||
int txPin;
|
||||
};
|
||||
|
||||
struct RcSwitchPayload
|
||||
{
|
||||
const char *group;
|
||||
const char *device;
|
||||
};
|
||||
|
||||
struct RcSwitchPayloadJson : public RcSwitchPayload, public JsonStruct
|
||||
{
|
||||
int verifyJsonObject(JsonObject &json)
|
||||
{
|
||||
return json.containsKey("group")
|
||||
&& json.containsKey("device")
|
||||
&& json.success();
|
||||
};
|
||||
void mapJsonObject(JsonObject &root)
|
||||
{
|
||||
root["group"] = group;
|
||||
root["device"] = device;
|
||||
}
|
||||
void fromJsonObject(JsonObject &json)
|
||||
{
|
||||
if (!verifyJsonObject(json))
|
||||
{
|
||||
Serial.println("ERROR: cannot parse JSON object");
|
||||
valid = 0;
|
||||
return;
|
||||
}
|
||||
group = getAttr(json, "group", group);
|
||||
device = getAttr(json, "device", device);
|
||||
valid = 1;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user