Skip to content

Commit f92791e

Browse files
committed
feat(matter): adds fan endpoint to matter main structure
1 parent 29acdc6 commit f92791e

File tree

4 files changed

+108
-2
lines changed

4 files changed

+108
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ set(ARDUINO_LIBRARY_Matter_SRCS
172172
libraries/Matter/src/MatterEndpoints/MatterDimmableLight.cpp
173173
libraries/Matter/src/MatterEndpoints/MatterColorTemperatureLight.cpp
174174
libraries/Matter/src/MatterEndpoints/MatterColorLight.cpp
175+
libraries/Matter/src/MatterEndpoints/MatterFan.cpp
175176
libraries/Matter/src/Matter.cpp)
176177

177178
set(ARDUINO_LIBRARY_PPP_SRCS

libraries/Matter/keywords.txt

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ MatterDimmableLight KEYWORD1
1313
MatterColorTemperatureLight KEYWORD1
1414
MatterColorLight KEYWORD1
1515
MatterEndPoint KEYWORD1
16+
MatterFan KEYWORD1
17+
FanMode_t KEYWORD1
18+
FanModeSequence_t KEYWORD1
1619

1720
#######################################
1821
# Methods and Functions (KEYWORD2)
@@ -30,6 +33,7 @@ decommission KEYWORD2
3033
attributeChangeCB KEYWORD2
3134
setOnOff KEYWORD2
3235
getOnOff KEYWORD2
36+
toggle KEYWORD2
3337
setBrightness KEYWORD2
3438
getBrightness KEYWORD2
3539
setColorTemperature KEYWORD2
@@ -38,14 +42,23 @@ setColorRGB KEYWORD2
3842
getColorRGB KEYWORD2
3943
setColorHSV KEYWORD2
4044
getColorHSV KEYWORD2
41-
toggle KEYWORD2
4245
updateAccessory KEYWORD2
4346
onChange KEYWORD2
4447
onChangeOnOff KEYWORD2
4548
onChangeBrightness KEYWORD2
4649
onChangeColorTemperature KEYWORD2
4750
onChangeColorHSV KEYWORD2
48-
51+
getAttribute KEYWORD2
52+
getAttributeVal KEYWORD2
53+
setAttributeVal KEYWORD2
54+
updateAttributeVal KEYWORD2
55+
getFanModeString KEYWORD2
56+
setSpeedPercent KEYWORD2
57+
getSpeedPercent KEYWORD2
58+
setMode KEYWORD2
59+
getMode KEYWORD2
60+
onChangeMode KEYWORD2
61+
onChangeSpeedPercent KEYWORD2
4962

5063
#######################################
5164
# Constants (LITERAL1)
@@ -54,3 +67,21 @@ onChangeColorHSV KEYWORD2
5467
MAX_BRIGHTNESS LITERAL1
5568
MAX_COLOR_TEMPERATURE LITERAL1
5669
MIN_COLOR_TEMPERATURE LITERAL1
70+
ATTR_SET LITERAL1
71+
ATTR_UPDATE LITERAL1
72+
MAX_SPEED LITERAL1
73+
MIN_SPEED LITERAL1
74+
OFF_SPEED LITERAL1
75+
FAN_MODE_OFF LITERAL1
76+
FAN_MODE_LOW LITERAL1
77+
FAN_MODE_MEDIUM LITERAL1
78+
FAN_MODE_HIGH LITERAL1
79+
FAN_MODE_ON LITERAL1
80+
FAN_MODE_AUTO LITERAL1
81+
FAN_MODE_SMART LITERAL1
82+
FAN_MODE_SEQ_OFF_LOW_MED_HIGH LITERAL1
83+
FAN_MODE_SEQ_OFF_LOW_HIGH LITERAL1
84+
FAN_MODE_SEQ_OFF_LOW_MED_HIGH_AUTO LITERAL1
85+
FAN_MODE_SEQ_OFF_LOW_HIGH_AUTO LITERAL1
86+
FAN_MODE_SEQ_OFF_HIGH_AUTO LITERAL1
87+
FAN_MODE_SEQ_OFF_HIGH LITERAL1

libraries/Matter/src/Matter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <MatterEndpoints/MatterDimmableLight.h>
2424
#include <MatterEndpoints/MatterColorTemperatureLight.h>
2525
#include <MatterEndpoints/MatterColorLight.h>
26+
#include <MatterEndpoints/MatterFan.h>
2627

2728
using namespace esp_matter;
2829

@@ -52,6 +53,7 @@ class ArduinoMatter {
5253
friend class MatterDimmableLight;
5354
friend class MatterColorTemperatureLight;
5455
friend class MatterColorLight;
56+
friend class MatterFan;
5557

5658
protected:
5759
static void _init();

libraries/Matter/src/MatterEndPoint.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,87 @@
1919
#include <Matter.h>
2020
#include <functional>
2121

22+
using namespace esp_matter;
23+
2224
// Matter Endpoint Base Class. Controls the endpoint ID and allows the child class to overwrite attribute change call
2325
class MatterEndPoint {
2426
public:
27+
28+
enum attrOperation_t {
29+
ATTR_SET = false,
30+
ATTR_UPDATE = true
31+
};
32+
2533
uint16_t getEndPointId() {
2634
return endpoint_id;
2735
}
36+
2837
void setEndPointId(uint16_t ep) {
2938
endpoint_id = ep;
3039
}
40+
41+
// helper functions for attribute manipulation
42+
attribute_t * getAttribute(uint32_t cluster_id, uint32_t attribute_id){
43+
if (endpoint_id == 0) {
44+
log_e("Endpoint ID is not set");
45+
return NULL;
46+
}
47+
endpoint_t *endpoint = endpoint::get(node::get(), endpoint_id);
48+
if (endpoint == NULL) {
49+
log_e("Endpoint [%d] not found", endpoint_id);
50+
return NULL;
51+
}
52+
cluster_t *cluster = cluster::get(endpoint, cluster_id);
53+
if (cluster == NULL) {
54+
log_e("Cluster [%d] not found", cluster_id);
55+
return NULL;
56+
}
57+
attribute_t *attribute = attribute::get(cluster, attribute_id);
58+
if (attribute == NULL) {
59+
log_e("Attribute [%d] not found", attribute_id);
60+
return NULL;
61+
}
62+
return attribute;
63+
}
64+
65+
// get the value of an attribute from its cluster id and attribute it
66+
bool getAttributeVal(uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *attrVal){
67+
attribute_t *attribute = getAttribute(cluster_id, attribute_id);
68+
if (attribute == NULL) {
69+
return false;
70+
}
71+
if (attribute::get_val(attribute, attrVal) == ESP_OK) {
72+
log_v("GET_VAL Suceess for cluster %d, attribute %d with value %d", cluster_id, attribute_id, attrVal->val.u32);
73+
return true;
74+
}
75+
log_v("GET_VAL FAILED! for cluster %d, attribute %d with value %d", cluster_id, attribute_id, attrVal->val.u32);
76+
return false;
77+
}
78+
79+
// set the value of an attribute from its cluster id and attribute it
80+
bool setAttributeVal(uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *attrVal){
81+
attribute_t *attribute = getAttribute(cluster_id, attribute_id);
82+
if (attribute == NULL) {
83+
return false;
84+
}
85+
if (attribute::set_val(attribute, attrVal) == ESP_OK) {
86+
log_v("SET_VAL Suceess for cluster %d, attribute %d with value %d", cluster_id, attribute_id, attrVal->val.u32);
87+
return true;
88+
}
89+
log_v("SET_VAL FAILED! for cluster %d, attribute %d with value %d", cluster_id, attribute_id, attrVal->val.u32);
90+
return false;
91+
}
92+
93+
// update the value of an attribute from its cluster id and attribute it
94+
bool updateAttributeVal(uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *attrVal){
95+
if (attribute::update(endpoint_id, cluster_id, attribute_id, attrVal) == ESP_OK) {
96+
log_v("Update Suceess for cluster %d, attribute %d with value %d", cluster_id, attribute_id, attrVal->val.u32);
97+
return true;
98+
}
99+
log_v("Update FAILED! for cluster %d, attribute %d with value %d", cluster_id, attribute_id, attrVal->val.u32);
100+
return false;
101+
}
102+
31103
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
32104
virtual bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val) = 0;
33105

0 commit comments

Comments
 (0)