forked from espressif/arduino-esp32
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathZigbeeColorDimmableLight.h
108 lines (95 loc) · 5.2 KB
/
ZigbeeColorDimmableLight.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
/* Class of Zigbee On/Off Light endpoint inherited from common EP class */
#pragma once
#include "soc/soc_caps.h"
#include "sdkconfig.h"
#if SOC_IEEE802154_SUPPORTED && CONFIG_ZB_ENABLED
#include "ZigbeeEP.h"
#include "ha/esp_zigbee_ha_standard.h"
#define ZIGBEE_DEFAULT_COLOR_DIMMABLE_LIGHT_CONFIG() \
{ \
.basic_cfg = \
{ \
.zcl_version = ESP_ZB_ZCL_BASIC_ZCL_VERSION_DEFAULT_VALUE, \
.power_source = ESP_ZB_ZCL_BASIC_POWER_SOURCE_DEFAULT_VALUE, \
}, \
.identify_cfg = \
{ \
.identify_time = ESP_ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE, \
}, \
.groups_cfg = \
{ \
.groups_name_support_id = ESP_ZB_ZCL_GROUPS_NAME_SUPPORT_DEFAULT_VALUE, \
}, \
.scenes_cfg = \
{ \
.scenes_count = ESP_ZB_ZCL_SCENES_SCENE_COUNT_DEFAULT_VALUE, \
.current_scene = ESP_ZB_ZCL_SCENES_CURRENT_SCENE_DEFAULT_VALUE, \
.current_group = ESP_ZB_ZCL_SCENES_CURRENT_GROUP_DEFAULT_VALUE, \
.scene_valid = ESP_ZB_ZCL_SCENES_SCENE_VALID_DEFAULT_VALUE, \
.name_support = ESP_ZB_ZCL_SCENES_NAME_SUPPORT_DEFAULT_VALUE, \
}, \
.on_off_cfg = \
{ \
.on_off = ESP_ZB_ZCL_ON_OFF_ON_OFF_DEFAULT_VALUE, \
}, \
.level_cfg = \
{ \
.current_level = ESP_ZB_ZCL_LEVEL_CONTROL_CURRENT_LEVEL_DEFAULT_VALUE, \
}, \
.color_cfg = { \
.current_x = ESP_ZB_ZCL_COLOR_CONTROL_CURRENT_X_DEF_VALUE, \
.current_y = ESP_ZB_ZCL_COLOR_CONTROL_CURRENT_Y_DEF_VALUE, \
.color_mode = ESP_ZB_ZCL_COLOR_CONTROL_COLOR_MODE_DEFAULT_VALUE, \
.options = ESP_ZB_ZCL_COLOR_CONTROL_OPTIONS_DEFAULT_VALUE, \
.enhanced_color_mode = ESP_ZB_ZCL_COLOR_CONTROL_ENHANCED_COLOR_MODE_DEFAULT_VALUE, \
.color_capabilities = 0x0009, \
}, \
}
class ZigbeeColorDimmableLight : public ZigbeeEP {
public:
ZigbeeColorDimmableLight(uint8_t endpoint);
~ZigbeeColorDimmableLight() {}
void onLightChange(void (*callback)(bool, uint8_t, uint8_t, uint8_t, uint8_t)) {
_on_light_change = callback;
}
void restoreLight() {
lightChanged();
}
void setLightState(bool state);
void setLightLevel(uint8_t level);
void setLightColor(uint8_t red, uint8_t green, uint8_t blue);
void setLightColor(espRgbColor_t rgb_color);
void setLightColor(espHsvColor_t hsv_color);
void setLight(bool state, uint8_t level, uint8_t red, uint8_t green, uint8_t blue);
bool getLightState() {
return _current_state;
}
uint8_t getLightLevel() {
return _current_level;
}
espRgbColor_t getLightColor() {
return _current_color;
}
uint8_t getLightRed() {
return _current_color.r;
}
uint8_t getLightGreen() {
return _current_color.g;
}
uint8_t getLightBlue() {
return _current_color.b;
}
private:
void zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) override;
uint16_t getCurrentColorX();
uint16_t getCurrentColorY();
uint8_t getCurrentColorHue();
uint8_t getCurrentColorSaturation();
void lightChanged();
//callback function to be called on light change (State, R, G, B, Level)
void (*_on_light_change)(bool, uint8_t, uint8_t, uint8_t, uint8_t);
bool _current_state;
uint8_t _current_level;
espRgbColor_t _current_color;
};
#endif //SOC_IEEE802154_SUPPORTED && CONFIG_ZB_ENABLED