separate sensor from generic in protocol 2
This commit is contained in:
parent
f9bcdecb57
commit
95dd0f771f
@ -1,9 +1,9 @@
|
|||||||
# pragma once
|
#pragma once
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <RCSwitch.h>
|
#include <RCSwitch.h>
|
||||||
|
|
||||||
class Protocol {
|
class Protocol {
|
||||||
|
protected:
|
||||||
unsigned int protocol;
|
unsigned int protocol;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# pragma once
|
#pragma once
|
||||||
#include "Protocol.h"
|
#include "Protocol.h"
|
||||||
|
|
||||||
#define RC_STATE(value) value & 0x1
|
#define RC_STATE(value) value & 0x1
|
||||||
@ -21,7 +21,7 @@ public:
|
|||||||
|
|
||||||
void toJson(unsigned long value, JsonDocument& jsonDoc) override {
|
void toJson(unsigned long value, JsonDocument& jsonDoc) override {
|
||||||
JsonObject rcSwitch = jsonDoc.createNestedObject("rcSwitch");
|
JsonObject rcSwitch = jsonDoc.createNestedObject("rcSwitch");
|
||||||
rcSwitch["protocol"] = 1;
|
rcSwitch["protocol"] = protocol;
|
||||||
Decoder decoder;
|
Decoder decoder;
|
||||||
decoder.decode(value);
|
decoder.decode(value);
|
||||||
rcSwitch["state"] = decoder.state;
|
rcSwitch["state"] = decoder.state;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# pragma once
|
#pragma once
|
||||||
#include "Protocol.h"
|
#include "Protocol.h"
|
||||||
#include "Tiny.h"
|
#include "Tiny.h"
|
||||||
|
|
||||||
@ -23,7 +23,10 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if (!buildSensorJson(jsonDoc, value)) {
|
StaticJsonDocument<200> jsonSensor;
|
||||||
|
if (buildSensorJson(value, jsonSensor)) {
|
||||||
|
jsonDoc.add(jsonSensor);
|
||||||
|
} else {
|
||||||
Protocol::toJson(value, jsonDoc);
|
Protocol::toJson(value, jsonDoc);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -31,7 +34,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool buildSensorJson(JsonDocument& jsonDoc, unsigned long value) {
|
bool buildSensorJson(unsigned long value, JsonDocument& jsonDoc) {
|
||||||
JsonObject sensor = jsonDoc.createNestedObject("sensor");
|
JsonObject sensor = jsonDoc.createNestedObject("sensor");
|
||||||
sensor["id"] = ID(value);
|
sensor["id"] = ID(value);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user