Skip to content

Commit fe0f016

Browse files
authored
Matter example patch (#10618)
* feat(matter): adjust preferences labels in matter examples * feat(matter): adjust preferences labels in matter examples * fix(matter_example): extra blank space in code added by mistake * feat(matter_example): use const char * instead of #define * feat(matter_example): use const char * instead of #define * feat(matter_example): change Preferences names * fix(matter_example): missing semicolon in code
1 parent 4a8ba42 commit fe0f016

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

libraries/Matter/examples/MatterDimmableLight/MatterDimmableLight.ino

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

2424
// it will keep last OnOff & Brightness state stored, using Preferences
25-
Preferences lastStatePref;
25+
Preferences matterPref;
26+
const char *onOffPrefKey = "OnOffState";
27+
const char *brightnessPrefKey = "BrightnessState";
2628

2729
// set your board RGB LED pin here
2830
#ifdef RGB_BUILTIN
@@ -51,8 +53,8 @@ bool setLightState(bool state, uint8_t brightness) {
5153
digitalWrite(ledPin, LOW);
5254
}
5355
// store last Brightness and OnOff state for when the Light is restarted / power goes off
54-
lastStatePref.putUChar("lastBrightness", brightness);
55-
lastStatePref.putBool("lastOnOffState", state);
56+
matterPref.putUChar(brightnessPrefKey, brightness);
57+
matterPref.putBool(onOffPrefKey, state);
5658
// This callback must return the success state to Matter core
5759
return true;
5860
}
@@ -86,11 +88,11 @@ void setup() {
8688
delay(500);
8789

8890
// Initialize Matter EndPoint
89-
lastStatePref.begin("matterLight", false);
91+
matterPref.begin("MatterPrefs", false);
9092
// default OnOff state is ON if not stored before
91-
bool lastOnOffState = lastStatePref.getBool("lastOnOffState", true);
93+
bool lastOnOffState = matterPref.getBool(onOffPrefKey, true);
9294
// default brightness ~= 6% (15/255)
93-
uint8_t lastBrightness = lastStatePref.getUChar("lastBrightness", 15);
95+
uint8_t lastBrightness = matterPref.getUChar(brightnessPrefKey, 15);
9496
DimmableLight.begin(lastOnOffState, lastBrightness);
9597
// set the callback function to handle the Light state change
9698
DimmableLight.onChange(setLightState);

libraries/Matter/examples/MatterOnOffLight/MatterOnOffLight.ino

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
MatterOnOffLight OnOffLight;
2323

2424
// it will keep last OnOff state stored, using Preferences
25-
Preferences lastStatePref;
25+
Preferences matterPref;
26+
const char *onOffPrefKey = "OnOffState";
2627

2728
// set your board LED pin here
2829
#ifdef LED_BUILTIN
@@ -48,7 +49,7 @@ bool setLightOnOff(bool state) {
4849
digitalWrite(ledPin, LOW);
4950
}
5051
// store last OnOff state for when the Light is restarted / power goes off
51-
lastStatePref.putBool("lastOnOffState", state);
52+
matterPref.putBool(onOffPrefKey, state);
5253
// This callback must return the success state to Matter core
5354
return true;
5455
}
@@ -82,8 +83,8 @@ void setup() {
8283
delay(500);
8384

8485
// Initialize Matter EndPoint
85-
lastStatePref.begin("matterLight", false);
86-
bool lastOnOffState = lastStatePref.getBool("lastOnOffState", true);
86+
matterPref.begin("MatterPrefs", false);
87+
bool lastOnOffState = matterPref.getBool(onOffPrefKey, true);
8788
OnOffLight.begin(lastOnOffState);
8889
OnOffLight.onChange(setLightOnOff);
8990

0 commit comments

Comments
 (0)