forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor.h
161 lines (144 loc) · 4.38 KB
/
sensor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Copyright (c) 2017 dresden elektronik ingenieurtechnik gmbh.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
*/
#ifndef SENSOR_H
#define SENSOR_H
#include <QString>
#include <deconz.h>
#include "resource.h"
#include "rest_node_base.h"
// Sensor State
#define INVALID_ENDPOINT 0xff
#define SENSOR_CHECK_COUNTER_INIT 10
#define S_BUTTON_ACTION_INITIAL_PRESS 0
#define S_BUTTON_ACTION_HOLD 1
#define S_BUTTON_ACTION_SHORT_RELEASED 2
#define S_BUTTON_ACTION_LONG_RELEASED 3
#define S_BUTTON_ACTION_DOUBLE_PRESS 4
#define S_BUTTON_ACTION_TREBLE_PRESS 5
#define S_BUTTON_ACTION_QUADRUPLE_PRESS 6
#define S_BUTTON_ACTION_SHAKE 7
#define S_BUTTON_ACTION_DROP 8
#define S_BUTTON_ACTION_TILT 9
#define S_BUTTON_ACTION_MANY_PRESS 10
#define GESTURE_NONE 0
#define GESTURE_SHAKE 1
#define GESTURE_DROP 2
#define GESTURE_FLIP_90 3
#define GESTURE_FLIP_180 4
#define GESTURE_PUSH 5
#define GESTURE_DOUBLE_TAP 6
#define GESTURE_ROTATE_CLOCKWISE 7
#define GESTURE_ROTATE_COUNTER_CLOCKWISE 8
#define S_BUTTON_1 1000
#define S_BUTTON_2 2000
#define S_BUTTON_3 3000
#define S_BUTTON_4 4000
#define S_BUTTON_5 5000
#define S_BUTTON_6 6000
#define S_BUTTON_7 7000
#define S_BUTTON_8 8000
#define S_BUTTON_9 9000
struct SensorFingerprint
{
SensorFingerprint() : checkCounter(0), endpoint(INVALID_ENDPOINT), profileId(0xffff), deviceId(0xffff) {}
bool operator==(const SensorFingerprint &rhs) const
{
return (endpoint == rhs.endpoint &&
profileId == rhs.profileId &&
deviceId == rhs.deviceId &&
inClusters == rhs.inClusters &&
outClusters == rhs.outClusters);
}
QString toString() const;
bool readFromJsonString(const QString &json);
bool hasEndpoint() const { return endpoint != 0xFF; }
bool hasInCluster(quint16 clusterId) const;
bool hasOutCluster(quint16 clusterId) const;
int checkCounter;
quint8 endpoint;
quint16 profileId;
quint16 deviceId;
std::vector<quint16> inClusters;
std::vector<quint16> outClusters;
};
/*! \class Sensor
Represents a HA based Sensor.
*/
class Sensor : public Resource,
public RestNodeBase
{
public:
enum SensorMode
{
ModeNone = 0,
ModeScenes = 1,
ModeTwoGroups = 2,
ModeColorTemperature = 3,
ModeDimmer = 4
};
enum DeletedState
{
StateNormal,
StateDeleted
};
struct ButtonMap
{
Sensor::SensorMode mode;
quint8 endpoint;
quint16 clusterId;
quint8 zclCommandId;
quint16 zclParam0;
int button;
const char *name;
};
Sensor();
DeletedState deletedState() const;
void setDeletedState(DeletedState deletedstate);
bool isAvailable() const;
const QString &name() const;
void setName(const QString &name);
const QString &type() const;
void setType(const QString &type);
const QString &modelId() const;
void setModelId(const QString &mid);
const QString &manufacturer() const;
void setManufacturer(const QString &manufacturer);
const QString &swVersion() const;
void setSwVersion(const QString &swversion);
SensorMode mode() const;
void setMode(SensorMode mode);
uint8_t resetRetryCount() const;
void setResetRetryCount(uint8_t resetRetryCount);
uint8_t zdpResetSeq() const;
void setZdpResetSeq(uint8_t zdpResetSeq);
void updateStateTimestamp();
void incrementRxCounter();
int rxCounter() const;
QString stateToString();
QString configToString();
void jsonToState(const QString &json);
void jsonToConfig(const QString &json);
SensorFingerprint &fingerPrint();
const SensorFingerprint &fingerPrint() const;
QString etag;
const ButtonMap *buttonMap();
uint8_t previousDirection;
QDateTime lastConfigPush;
QDateTime durationDue;
private:
DeletedState m_deletedstate;
SensorFingerprint m_fingerPrint;
SensorMode m_mode;
uint8_t m_resetRetryCount;
uint8_t m_zdpResetSeq;
const ButtonMap *m_buttonMap;
int m_rxCounter;
};
#endif // SENSOR_H