@@ -41,33 +41,28 @@ const char *ssid = "your-ssid"; // Change this to your WiFi SSID
41
41
const char *password = " your-password" ; // Change this to your WiFi password
42
42
43
43
// 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) {
45
45
Serial.printf (" Setting Light to State: %s and Brightness: %d\r\n " , DimmableLight ? " ON" : " OFF" , brightness);
46
46
if (state) {
47
47
rgbLedWrite (ledPin, brightness, brightness, brightness);
48
48
} else {
49
49
digitalWrite (ledPin, LOW);
50
50
}
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 ;
51
56
}
52
57
53
58
// Matter Protocol Endpoint On-Off Change Callback
54
59
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 ());
61
61
}
62
62
63
63
// Matter Protocol Endpoint Brightness Change Callback
64
64
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);
71
66
}
72
67
73
68
void setup () {
0 commit comments