Skip to content

Commit ab2f01c

Browse files
authored
feat(matter_example): use const char * instead of #define
1 parent 3930017 commit ab2f01c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Diff for: libraries/Matter/examples/MatterDimmableLight/MatterDimmableLight.ino

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
MatterDimmableLight DimmableLight;
2323

2424
// 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"
2828

2929
// set your board RGB LED pin here
3030
#ifdef RGB_BUILTIN
@@ -53,8 +53,8 @@ bool setLightState(bool state, uint8_t brightness) {
5353
digitalWrite(ledPin, LOW);
5454
}
5555
// 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);
5858
// This callback must return the success state to Matter core
5959
return true;
6060
}
@@ -88,11 +88,11 @@ void setup() {
8888
delay(500);
8989

9090
// Initialize Matter EndPoint
91-
lastStatePref.begin("matterLight", false);
91+
matterPref.begin("MatterPrefs", false);
9292
// 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);
9494
// default brightness ~= 6% (15/255)
95-
uint8_t lastBrightness = lastStatePref.getUChar(BRIGHTNESS_PREF_KEY, 15);
95+
uint8_t lastBrightness = matterPref.getUChar(brightnessPrefKey, 15);
9696
DimmableLight.begin(lastOnOffState, lastBrightness);
9797
// set the callback function to handle the Light state change
9898
DimmableLight.onChange(setLightState);

0 commit comments

Comments
 (0)