1
- // Copyright 2024 Espressif Systems (Shanghai) PTE LTD
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
-
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- #pragma once
16
- #include < sdkconfig.h>
17
- #ifdef CONFIG_ESP_MATTER_ENABLE_DATA_MODEL
18
-
19
- #include < Matter.h>
20
- #include < MatterEndPoint.h>
21
-
22
- class MatterColorLight : public MatterEndPoint {
23
- public:
24
- MatterColorLight ();
25
- ~MatterColorLight ();
26
- // default initial state is off, color is red 12% intensity HSV(0, 254, 31)
27
- virtual bool begin (bool initialState = false , espHsvColor_t colorHSV = {0 , 254 , 31 });
28
- // this will just stop processing Light Matter events
29
- void end ();
30
-
31
- bool setOnOff (bool newState); // returns true if successful
32
- bool getOnOff (); // returns current light state
33
- bool toggle (); // returns true if successful
34
-
35
- bool setColorRGB (espRgbColor_t rgbColor); // returns true if successful
36
- espRgbColor_t getColorRGB (); // returns current RGB Color
37
- bool setColorHSV (espHsvColor_t hsvColor); // returns true if successful
38
- espHsvColor_t getColorHSV (); // returns current HSV Color
39
-
40
- // used to update the state of the light using the current Matter Light internal state
41
- // It is necessary to set a user callback function using onChange() to handle the physical light state
42
- void updateAccessory ();
43
-
44
- operator bool (); // returns current on/off light state
45
- void operator =(bool state); // turns light on or off
46
-
47
- // this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
48
- bool attributeChangeCB (uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
49
-
50
- // User Callback for whenever the Light On/Off state is changed by the Matter Controller
51
- using EndPointOnOffCB = std::function<bool (bool )>;
52
- void onChangeOnOff (EndPointOnOffCB onChangeCB) {
53
- _onChangeOnOffCB = onChangeCB;
54
- }
55
- // User Callback for whenever the HSV Color value is changed by the Matter Controller
56
- using EndPointRGBColorCB = std::function<bool (espHsvColor_t)>;
57
- void onChangeColorHSV (EndPointRGBColorCB onChangeCB) {
58
- _onChangeColorCB = onChangeCB;
59
- }
60
-
61
- // User Callback for whenever any parameter is changed by the Matter Controller
62
- using EndPointCB = std::function<bool (bool , espHsvColor_t)>;
63
- void onChange (EndPointCB onChangeCB) {
64
- _onChangeCB = onChangeCB;
65
- }
66
-
67
- protected:
68
- bool started = false ;
69
- bool onOffState = false ; // default initial state is off, but it can be changed by begin(bool)
70
- espHsvColor_t colorHSV = {0 }; // default initial color HSV is black, but it can be changed by begin(bool, espHsvColor_t)
71
- EndPointOnOffCB _onChangeOnOffCB = NULL ;
72
- EndPointRGBColorCB _onChangeColorCB = NULL ;
73
- EndPointCB _onChangeCB = NULL ;
74
- };
75
- #endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */
1
+ // Copyright 2024 Espressif Systems (Shanghai) PTE LTD
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #pragma once
16
+ #include < sdkconfig.h>
17
+ #ifdef CONFIG_ESP_MATTER_ENABLE_DATA_MODEL
18
+
19
+ #include < Matter.h>
20
+ #include < MatterEndPoint.h>
21
+
22
+ class MatterColorLight : public MatterEndPoint {
23
+ public:
24
+ MatterColorLight ();
25
+ ~MatterColorLight ();
26
+ // default initial state is off, color is red 12% intensity HSV(0, 254, 31)
27
+ virtual bool begin (bool initialState = false , espHsvColor_t colorHSV = { 0 , 254 , 31 });
28
+ // this will just stop processing Light Matter events
29
+ void end ();
30
+
31
+ bool setOnOff (bool newState); // returns true if successful
32
+ bool getOnOff (); // returns current light state
33
+ bool toggle (); // returns true if successful
34
+
35
+ bool setColorRGB (espRgbColor_t rgbColor); // returns true if successful
36
+ espRgbColor_t getColorRGB (); // returns current RGB Color
37
+ bool setColorHSV (espHsvColor_t hsvColor); // returns true if successful
38
+ espHsvColor_t getColorHSV (); // returns current HSV Color
39
+
40
+ // used to update the state of the light using the current Matter Light internal state
41
+ // It is necessary to set a user callback function using onChange() to handle the physical light state
42
+ void updateAccessory ();
43
+
44
+ operator bool (); // returns current on/off light state
45
+ void operator =(bool state); // turns light on or off
46
+
47
+ // this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
48
+ bool attributeChangeCB (uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
49
+
50
+ // User Callback for whenever the Light On/Off state is changed by the Matter Controller
51
+ using EndPointOnOffCB = std::function<bool (bool )>;
52
+ void onChangeOnOff (EndPointOnOffCB onChangeCB) {
53
+ _onChangeOnOffCB = onChangeCB;
54
+ }
55
+ // User Callback for whenever the HSV Color value is changed by the Matter Controller
56
+ using EndPointRGBColorCB = std::function<bool (espHsvColor_t)>;
57
+ void onChangeColorHSV (EndPointRGBColorCB onChangeCB) {
58
+ _onChangeColorCB = onChangeCB;
59
+ }
60
+
61
+ // User Callback for whenever any parameter is changed by the Matter Controller
62
+ using EndPointCB = std::function<bool (bool , espHsvColor_t)>;
63
+ void onChange (EndPointCB onChangeCB) {
64
+ _onChangeCB = onChangeCB;
65
+ }
66
+
67
+ protected:
68
+ bool started = false ;
69
+ bool onOffState = false ; // default initial state is off, but it can be changed by begin(bool)
70
+ espHsvColor_t colorHSV = { 0 }; // default initial color HSV is black, but it can be changed by begin(bool, espHsvColor_t)
71
+ EndPointOnOffCB _onChangeOnOffCB = NULL ;
72
+ EndPointRGBColorCB _onChangeColorCB = NULL ;
73
+ EndPointCB _onChangeCB = NULL ;
74
+ };
75
+ #endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */
0 commit comments