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
This commit is contained in:
parent
4a8ba4294e
commit
fe0f016b4f
2 changed files with 13 additions and 10 deletions
|
|
@ -22,7 +22,9 @@
|
||||||
MatterDimmableLight DimmableLight;
|
MatterDimmableLight DimmableLight;
|
||||||
|
|
||||||
// it will keep last OnOff & Brightness state stored, using Preferences
|
// 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
|
// set your board RGB LED pin here
|
||||||
#ifdef RGB_BUILTIN
|
#ifdef RGB_BUILTIN
|
||||||
|
|
@ -51,8 +53,8 @@ bool setLightState(bool state, uint8_t brightness) {
|
||||||
digitalWrite(ledPin, LOW);
|
digitalWrite(ledPin, LOW);
|
||||||
}
|
}
|
||||||
// store last Brightness and OnOff state for when the Light is restarted / power goes off
|
// store last Brightness and OnOff state for when the Light is restarted / power goes off
|
||||||
lastStatePref.putUChar("lastBrightness", brightness);
|
matterPref.putUChar(brightnessPrefKey, brightness);
|
||||||
lastStatePref.putBool("lastOnOffState", state);
|
matterPref.putBool(onOffPrefKey, state);
|
||||||
// This callback must return the success state to Matter core
|
// This callback must return the success state to Matter core
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -86,11 +88,11 @@ void setup() {
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
// Initialize Matter EndPoint
|
// Initialize Matter EndPoint
|
||||||
lastStatePref.begin("matterLight", false);
|
matterPref.begin("MatterPrefs", false);
|
||||||
// default OnOff state is ON if not stored before
|
// 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)
|
// default brightness ~= 6% (15/255)
|
||||||
uint8_t lastBrightness = lastStatePref.getUChar("lastBrightness", 15);
|
uint8_t lastBrightness = matterPref.getUChar(brightnessPrefKey, 15);
|
||||||
DimmableLight.begin(lastOnOffState, lastBrightness);
|
DimmableLight.begin(lastOnOffState, lastBrightness);
|
||||||
// set the callback function to handle the Light state change
|
// set the callback function to handle the Light state change
|
||||||
DimmableLight.onChange(setLightState);
|
DimmableLight.onChange(setLightState);
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,8 @@
|
||||||
MatterOnOffLight OnOffLight;
|
MatterOnOffLight OnOffLight;
|
||||||
|
|
||||||
// it will keep last OnOff state stored, using Preferences
|
// it will keep last OnOff state stored, using Preferences
|
||||||
Preferences lastStatePref;
|
Preferences matterPref;
|
||||||
|
const char *onOffPrefKey = "OnOffState";
|
||||||
|
|
||||||
// set your board LED pin here
|
// set your board LED pin here
|
||||||
#ifdef LED_BUILTIN
|
#ifdef LED_BUILTIN
|
||||||
|
|
@ -48,7 +49,7 @@ bool setLightOnOff(bool state) {
|
||||||
digitalWrite(ledPin, LOW);
|
digitalWrite(ledPin, LOW);
|
||||||
}
|
}
|
||||||
// store last OnOff state for when the Light is restarted / power goes off
|
// 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
|
// This callback must return the success state to Matter core
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -82,8 +83,8 @@ void setup() {
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
// Initialize Matter EndPoint
|
// Initialize Matter EndPoint
|
||||||
lastStatePref.begin("matterLight", false);
|
matterPref.begin("MatterPrefs", false);
|
||||||
bool lastOnOffState = lastStatePref.getBool("lastOnOffState", true);
|
bool lastOnOffState = matterPref.getBool(onOffPrefKey, true);
|
||||||
OnOffLight.begin(lastOnOffState);
|
OnOffLight.begin(lastOnOffState);
|
||||||
OnOffLight.onChange(setLightOnOff);
|
OnOffLight.onChange(setLightOnOff);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue