add generic sensor

This commit is contained in:
Nicu Hodos 2022-10-06 09:09:39 +02:00
parent fdc9dd452d
commit 2db7d778f5
4 changed files with 48 additions and 1 deletions

View File

@ -40,7 +40,24 @@
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp"
"utility": "cpp",
"__bit_reference": "cpp",
"__node_handle": "cpp",
"atomic": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"cstddef": "cpp",
"__memory": "cpp",
"filesystem": "cpp",
"limits": "cpp",
"locale": "cpp",
"random": "cpp",
"ratio": "cpp",
"__functional_base": "cpp",
"algorithm": "cpp",
"iterator": "cpp",
"memory": "cpp",
"variant": "cpp"
}
}
}

View File

@ -65,6 +65,13 @@ void readRcSwitch(JsonDocument& jsonDoc) {
motion["basement"] = value == 1879048230L ? "on" : "off";
return;
}
if (GET_TYPE(value) == SensorType::GENERIC) {
JsonObject sensor = jsonDoc.createNestedObject("sensor");
sensor["id"] = ID(value);
sensor["value"] = GET_VALUE(value);
sensor["voltage"] = GET_VCC(value);
return;
}
if (GET_TYPE(value) == SensorType::TEMPERATURE) {
JsonObject sensor = jsonDoc.createNestedObject("sensor");
sensor["id"] = ID(value);

View File

@ -0,0 +1,20 @@
#pragma once
#include <TinySensor.h>
class GenericSensor : public TinySensor {
SensorType sensorType = GENERIC;
public:
GenericSensor(short id) :
TinySensor(id) {
}
void sendValueAndVoltage(int value) {
sendInfo(ID(id) | VCC(readVcc()) | VALUE(value) | TYPE(sensorType));
}
void sendValue(int value) {
sendInfo(ID(id) | TEMP(value) | TYPE(sensorType));
}
};

View File

@ -4,6 +4,7 @@
#define VCC(value) ((value & 0x1FFF) << 5)
#define TEMP(value) (((unsigned long)value & 0x2FF) << 18)
#define HUMIDITY(value) (((unsigned long)value & 0x2FF) << 18)
#define VALUE(value) (((unsigned long)value & 0x2FF) << 18)
#define STATE(value) ((value & 0x1) << 27)
#define TYPE(value) (((unsigned long)value & 0xF) << 28)
@ -11,9 +12,11 @@
#define GET_STATE(value) ((value >> 27) & 0x1)
#define GET_TEMP(value) (((unsigned long)value >> 18) & 0x2FF)
#define GET_HUMIDITY(value) (((unsigned long)value >> 18) & 0x2FF)
#define GET_VALUE(value) (((unsigned long)value >> 18) & 0x2FF)
#define GET_VCC(value) ((value >> 5) & 0x1FFF)
enum SensorType {
GENERIC = 4,
HUMIDITY = 5,
TEMPERATURE = 6,
CONTACT = 7