57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#define MASK_ID 0x1F
|
|
#define MASK_VCC 0x1FFF
|
|
#define MASK_VALUE 0x3FF
|
|
#define MASK_STATE 0x1
|
|
#define MASK_TYPE 0xF
|
|
|
|
#define ID(value) ((uint32_t)value & MASK_ID)
|
|
#define VCC(value) (((uint32_t)value & MASK_VCC) << 5)
|
|
#define TEMP(value) (((uint32_t)value & MASK_VALUE) << 18)
|
|
#define HUMIDITY(value) (((uint32_t)value & MASK_VALUE) << 18)
|
|
#define VALUE(value) (((uint32_t)value & MASK_VALUE) << 18)
|
|
#define STATE(value) (((uint32_t)value & MASK_STATE) << 27)
|
|
#define TYPE(value) (((uint32_t)value & MASK_TYPE) << 28)
|
|
|
|
#define GET_TYPE(value) (((uint32_t)value >> 28) & MASK_TYPE)
|
|
#define GET_STATE(value) (((uint32_t)value >> 27) & MASK_STATE)
|
|
#define GET_TEMP(value) (((uint32_t)value >> 18) & MASK_VALUE)
|
|
#define GET_HUMIDITY(value) (((uint32_t)value >> 18) & MASK_VALUE)
|
|
#define GET_VALUE(value) (((uint32_t)value >> 18) & MASK_VALUE)
|
|
#define GET_VCC(value) (((uint32_t)value >> 5) & MASK_VCC)
|
|
|
|
enum SensorType : uint8_t {
|
|
GENERIC = 4,
|
|
HUMIDITY = 5,
|
|
TEMPERATURE = 6,
|
|
CONTACT = 7
|
|
};
|
|
|
|
class SensorId {
|
|
uint8_t value = 0;
|
|
char strValue[4];
|
|
|
|
public:
|
|
explicit SensorId(uint8_t id) {
|
|
value = id;
|
|
snprintf(strValue, 4, "%u", value);
|
|
}
|
|
|
|
operator uint8_t() {
|
|
return value;
|
|
}
|
|
|
|
operator const char*() {
|
|
return strValue;
|
|
}
|
|
}
|
|
WINDOW1(1),
|
|
WINDOW2(2),
|
|
WATER_SENSOR(3),
|
|
TEMP_SENSOR(4),
|
|
LIGHT_SENSOR(5),
|
|
MOVEMENT_SENSOR(6),
|
|
OIL_SENSOR(7),
|
|
PRESENCE_SENSOR(8);
|