From 2db7d778f5ad0b7f08133e88a0c83e6596b12958 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Thu, 6 Oct 2022 09:09:39 +0200 Subject: [PATCH] add generic sensor --- arduino_projects.code-workspace | 19 ++++++++++++++++++- gateway/src/gateway.cpp | 7 +++++++ libraries/Tiny/GenericSensor.h | 20 ++++++++++++++++++++ libraries/Tiny/Tiny.h | 3 +++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 libraries/Tiny/GenericSensor.h diff --git a/arduino_projects.code-workspace b/arduino_projects.code-workspace index 1f2825c..5c5a603 100644 --- a/arduino_projects.code-workspace +++ b/arduino_projects.code-workspace @@ -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" } } } \ No newline at end of file diff --git a/gateway/src/gateway.cpp b/gateway/src/gateway.cpp index 9fcba96..c8a70df 100644 --- a/gateway/src/gateway.cpp +++ b/gateway/src/gateway.cpp @@ -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); diff --git a/libraries/Tiny/GenericSensor.h b/libraries/Tiny/GenericSensor.h new file mode 100644 index 0000000..2522267 --- /dev/null +++ b/libraries/Tiny/GenericSensor.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +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)); + } +}; diff --git a/libraries/Tiny/Tiny.h b/libraries/Tiny/Tiny.h index 949bdd0..67dc4c4 100644 --- a/libraries/Tiny/Tiny.h +++ b/libraries/Tiny/Tiny.h @@ -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