|
22 | 22 | MatterDimmableLight DimmableLight;
|
23 | 23 |
|
24 | 24 | // it will keep last OnOff & Brightness state stored, using Preferences
|
25 |
| -Preferences lastStatePref; |
26 |
| -#define ON_OFF_PREF_KEY "lastOnOffState" |
27 |
| -#define BRIGHTNESS_PREF_KEY "lastBrightness" |
| 25 | +Preferences matterPref; |
| 26 | +const char *onOffPrefKey = "OnOffState" |
| 27 | +const char *brightnessPrefKey = "BrightnessState" |
28 | 28 |
|
29 | 29 | // set your board RGB LED pin here
|
30 | 30 | #ifdef RGB_BUILTIN
|
@@ -53,8 +53,8 @@ bool setLightState(bool state, uint8_t brightness) {
|
53 | 53 | digitalWrite(ledPin, LOW);
|
54 | 54 | }
|
55 | 55 | // store last Brightness and OnOff state for when the Light is restarted / power goes off
|
56 |
| - lastStatePref.putUChar(BRIGHTNESS_PREF_KEY, brightness); |
57 |
| - lastStatePref.putBool(ON_OFF_PREF_KEY, state); |
| 56 | + matterPref.putUChar(brightnessPrefKey, brightness); |
| 57 | + matterPref.putBool(onOffPrefKey, state); |
58 | 58 | // This callback must return the success state to Matter core
|
59 | 59 | return true;
|
60 | 60 | }
|
@@ -88,11 +88,11 @@ void setup() {
|
88 | 88 | delay(500);
|
89 | 89 |
|
90 | 90 | // Initialize Matter EndPoint
|
91 |
| - lastStatePref.begin("matterLight", false); |
| 91 | + matterPref.begin("MatterPrefs", false); |
92 | 92 | // default OnOff state is ON if not stored before
|
93 |
| - bool lastOnOffState = lastStatePref.getBool(ON_OFF_PREF_KEY, true); |
| 93 | + bool lastOnOffState = matterPref.getBool(onOffPrefKey, true); |
94 | 94 | // default brightness ~= 6% (15/255)
|
95 |
| - uint8_t lastBrightness = lastStatePref.getUChar(BRIGHTNESS_PREF_KEY, 15); |
| 95 | + uint8_t lastBrightness = matterPref.getUChar(brightnessPrefKey, 15); |
96 | 96 | DimmableLight.begin(lastOnOffState, lastBrightness);
|
97 | 97 | // set the callback function to handle the Light state change
|
98 | 98 | DimmableLight.onChange(setLightState);
|
|
0 commit comments