Skip to content

Commit afbcfe6

Browse files
committed
feat(matter): example code simplification
1 parent 025e01c commit afbcfe6

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

libraries/Matter/examples/MatterDimmableLight/MatterDimmableLight.ino

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,28 @@ const char *ssid = "your-ssid"; // Change this to your WiFi SSID
4141
const char *password = "your-password"; // Change this to your WiFi password
4242

4343
// Set the RGB LED Light based on the current state of the Dimmable Light
44-
void setRGBLight(bool state, uint8_t brightness) {
44+
bool setRGBLight(bool state, uint8_t brightness) {
4545
Serial.printf("Setting Light to State: %s and Brightness: %d\r\n", DimmableLight ? "ON" : "OFF", brightness);
4646
if (state) {
4747
rgbLedWrite(ledPin, brightness, brightness, brightness);
4848
} else {
4949
digitalWrite(ledPin, LOW);
5050
}
51+
// store last Brightness and OnOff state for when the Light is restarted / power goes off
52+
lastStatePref.putUChar("lastBrightness", brightness);
53+
lastStatePref.putBool("lastOnOffState", state);
54+
// This callback must return the success state to Matter core
55+
return true;
5156
}
5257

5358
// Matter Protocol Endpoint On-Off Change Callback
5459
bool setLightOnOff(bool state) {
55-
Serial.printf("User Callback :: New Light State = %s\r\n", state ? "ON" : "OFF");
56-
setRGBLight(state, DimmableLight.getBrightness());
57-
// store last OnOff state for when the Light is restarted / power goes off
58-
lastStatePref.putBool("lastOnOffState", state);
59-
// This callback must return the success state to Matter core
60-
return true;
60+
return setRGBLight(state, DimmableLight.getBrightness());
6161
}
6262

6363
// Matter Protocol Endpoint Brightness Change Callback
6464
bool setLightBrightness(uint8_t brightness) {
65-
Serial.printf("User Callback :: New Light Brigthness = %.2f%% [Val = %d]\r\n", ((float) brightness * 100) / MatterDimmableLight::MAX_BRIGHTNESS, brightness);
66-
setRGBLight(DimmableLight.getOnOff(), brightness);
67-
// store last Brightness for when the Light is restarted / power goes off
68-
lastStatePref.putUChar("lastBrightness", brightness);
69-
// This callback must return the success state to Matter core
70-
return true;
65+
return setRGBLight(DimmableLight.getOnOff(), brightness);
7166
}
7267

7368
void setup() {

0 commit comments

Comments
 (0)