add support for humidity
This commit is contained in:
parent
da4bacd82f
commit
69cf0dae0d
@ -72,6 +72,13 @@ void readRcSwitch(JsonDocument& jsonDoc) {
|
||||
sensor["voltage"] = GET_VCC(value);
|
||||
return;
|
||||
}
|
||||
if (GET_TYPE(value) == SensorType::HUMIDITY) {
|
||||
JsonObject sensor = jsonDoc.createNestedObject("sensor");
|
||||
sensor["id"] = ID(value);
|
||||
sensor["humidity"] = GET_HUMIDITY(value);
|
||||
sensor["voltage"] = GET_VCC(value);
|
||||
return;
|
||||
}
|
||||
if (GET_TYPE(value) == SensorType::CONTACT) {
|
||||
JsonObject sensor = jsonDoc.createNestedObject("contact");
|
||||
sensor["id"] = ID(value);
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <TinySensor.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
class ContactSensor: public TinySensor {
|
||||
SensorType sensorType = CONTACT;
|
||||
|
||||
20
libraries/Tiny/HumiditySensor.h
Normal file
20
libraries/Tiny/HumiditySensor.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <TinySensor.h>
|
||||
|
||||
class HumiditySensor : public TinySensor {
|
||||
SensorType sensorType = HUMIDITY;
|
||||
|
||||
public:
|
||||
HumiditySensor(short id, short senderPin) :
|
||||
TinySensor(id, senderPin) {
|
||||
}
|
||||
|
||||
void sendHumidityAndVoltage(int humidity) {
|
||||
sendInfo(ID(id) | VCC(readVcc()) | HUMIDITY(humidity) | TYPE(sensorType));
|
||||
}
|
||||
|
||||
void sendHumidity(int humidity) {
|
||||
sendInfo(ID(id) | HUMIDITY(humidity) | TYPE(sensorType));
|
||||
}
|
||||
};
|
||||
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <TinySensor.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
class TempSensor : public TinySensor {
|
||||
SensorType sensorType = TEMPERATURE;
|
||||
|
||||
@ -4,14 +4,17 @@
|
||||
#define STATE(value) ((value & 0x1) << 5)
|
||||
#define VCC(value) ((value & 0x1FFF) << 6)
|
||||
#define TEMP(value) (((unsigned long)value & 0x1FF) << 19)
|
||||
#define HUMIDITY(value) (((unsigned long)value & 0x7F) << 19)
|
||||
#define TYPE(value) (((unsigned long)value & 0xF) << 28)
|
||||
|
||||
#define GET_TYPE(value) (((unsigned long)value >> 28) & 0xF)
|
||||
#define GET_TEMP(value) (((unsigned long)value >> 19) & 0x1FF)
|
||||
#define GET_HUMIDITY(value) (((unsigned long)value >> 19) & 0x7F)
|
||||
#define GET_VCC(value) ((value >> 6) & 0x1FFF)
|
||||
#define GET_STATE(value) ((value >> 5) & 0x1)
|
||||
|
||||
typedef enum SensorType {
|
||||
enum SensorType {
|
||||
HUMIDITY = 5,
|
||||
TEMPERATURE = 6,
|
||||
CONTACT = 7
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user