Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matter example patch #10618

Merged
merged 7 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -22,7 +22,9 @@
MatterDimmableLight DimmableLight;

// it will keep last OnOff & Brightness state stored, using Preferences
Preferences lastStatePref;
Preferences matterPref;
const char *onOffPrefKey = "OnOffState";
const char *brightnessPrefKey = "BrightnessState";

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

// Initialize Matter EndPoint
lastStatePref.begin("matterLight", false);
matterPref.begin("MatterPrefs", false);
// default OnOff state is ON if not stored before
bool lastOnOffState = lastStatePref.getBool("lastOnOffState", true);
bool lastOnOffState = matterPref.getBool(onOffPrefKey, true);
// default brightness ~= 6% (15/255)
uint8_t lastBrightness = lastStatePref.getUChar("lastBrightness", 15);
uint8_t lastBrightness = matterPref.getUChar(brightnessPrefKey, 15);
DimmableLight.begin(lastOnOffState, lastBrightness);
// set the callback function to handle the Light state change
DimmableLight.onChange(setLightState);
Original file line number Diff line number Diff line change
@@ -22,7 +22,8 @@
MatterOnOffLight OnOffLight;

// it will keep last OnOff state stored, using Preferences
Preferences lastStatePref;
Preferences matterPref;
const char *onOffPrefKey = "OnOffState";

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

// Initialize Matter EndPoint
lastStatePref.begin("matterLight", false);
bool lastOnOffState = lastStatePref.getBool("lastOnOffState", true);
matterPref.begin("MatterPrefs", false);
bool lastOnOffState = matterPref.getBool(onOffPrefKey, true);
OnOffLight.begin(lastOnOffState);
OnOffLight.onChange(setLightOnOff);