Skip to content

feat(Matter): New Matter Endpoint - Dimmable Light #10543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(matter): it shuold work even when no callback is set
  • Loading branch information
SuGlider committed Nov 4, 2024
commit 46d35f5f2f28d6b11f039bcc2cc3e9f73c482684
10 changes: 5 additions & 5 deletions libraries/Matter/src/MatterEndpoints/MatterDimmableLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ bool MatterDimmableLight::attributeChangeCB(uint16_t endpoint_id, uint32_t clust
log_d("Dimmable Attr update callback: endpoint: %u, cluster: %u, attribute: %u, val: %u", endpoint_id, cluster_id, attribute_id, val->val.u32);

if (endpoint_id == getEndPointId()) {
bool ret = false;
bool ret = true;
switch(cluster_id) {
case OnOff::Id:
if (attribute_id == OnOff::Attributes::OnOff::Id) {
log_d("DimmableLight On/Off State changed to %d", val->val.b);
if (_onChangeOnOffCB != NULL) {
ret |= _onChangeOnOffCB(val->val.b);
ret &= _onChangeOnOffCB(val->val.b);
}
if (_onChangeCB != NULL) {
ret |= _onChangeCB(val->val.b, brightnessLevel);
ret &= _onChangeCB(val->val.b, brightnessLevel);
}
if (ret == true) {
onOffState = val->val.b;
Expand All @@ -53,10 +53,10 @@ bool MatterDimmableLight::attributeChangeCB(uint16_t endpoint_id, uint32_t clust
if (attribute_id == LevelControl::Attributes::CurrentLevel::Id) {
log_d("DimmableLight Brightness changed to %d", val->val.u8);
if (_onChangeBrightnessCB != NULL) {
ret |= _onChangeBrightnessCB(val->val.u8);
ret &= _onChangeBrightnessCB(val->val.u8);
}
if (_onChangeCB != NULL) {
ret |= _onChangeCB(onOffState, val->val.u8);
ret &= _onChangeCB(onOffState, val->val.u8);
}
if (ret == true) {
brightnessLevel = val->val.u8;
Expand Down
14 changes: 9 additions & 5 deletions libraries/Matter/src/MatterEndpoints/MatterOnOffLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ bool MatterOnOffLight::attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_
log_d("OnOff Attr update callback: endpoint: %u, cluster: %u, attribute: %u, val: %u", endpoint_id, cluster_id, attribute_id, val->val.u32);

if (endpoint_id == getEndPointId()) {
log_d("OnOffLight state changed to %d", val->val.b);
bool ret = true;
if (cluster_id == OnOff::Id) {
if (attribute_id == OnOff::Attributes::OnOff::Id) {
if (_onChangeOnOffCB != NULL) {
ret &= _onChangeOnOffCB(val->val.b);
}
if (_onChangeCB != NULL) {
ret = _onChangeCB(val->val.b);
log_d("OnOffLight state changed to %d", val->val.b);
if (ret == true) {
onOffState = val->val.b;
}
ret &= _onChangeCB(val->val.b);
}
if (ret == true) {
onOffState = val->val.b;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions libraries/Matter/src/MatterEndpoints/MatterOnOffLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ class MatterOnOffLight : public MatterEndPoint {
void onChange(EndPointCB onChangeCB) {
_onChangeCB = onChangeCB;
}
void onChangeOnOff(EndPointCB onChangeCB) {
_onChangeOnOffCB = onChangeCB;
}

protected:
bool started = false;
bool onOffState = false; // default initial state is off, but it can be changed by begin(bool)
EndPointCB _onChangeCB = NULL;
EndPointCB _onChangeOnOffCB = NULL;
};
#endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */
Loading