Skip to content

Commit

Permalink
feat(matter):replacing code in examples and header files
Browse files Browse the repository at this point in the history
  • Loading branch information
SuGlider committed Dec 16, 2024
1 parent 7d465f3 commit 3f7c597
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
// Color Light Endpoint
MatterColorLight ColorLight;

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// it will keep last OnOff & HSV Color state stored, using Preferences
Preferences matterPref;
const char *onOffPrefKey = "OnOff";
Expand All @@ -43,10 +47,6 @@ bool button_state = false; // false = released | true = pres
const uint32_t debouceTime = 250; // button debouncing time (ms)
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// Set the RGB LED Light based on the current state of the Color Light
bool setLightState(bool state, espHsvColor_t colorHSV) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
// Matter Contact Sensor Endpoint
MatterContactSensor ContactSensor;

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// LED will be used to indicate the Contact Sensor state
// set your board RGB LED pin here
#ifdef RGB_BUILTIN
Expand All @@ -48,10 +52,6 @@ const uint8_t ledPin = 2; // Set your pin here if your board has not defined LE
// set your board USER BUTTON pin here - decommissioning and Manual Contact Sensor toggle button
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// Button control
uint32_t button_time_stamp = 0; // debouncing control
bool button_state = false; // false = released | true = pressed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
// Dimmable Light Endpoint
MatterDimmableLight DimmableLight;

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// it will keep last OnOff & Brightness state stored, using Preferences
Preferences matterPref;
const char *onOffPrefKey = "OnOff";
Expand All @@ -43,10 +47,6 @@ bool button_state = false; // false = released | true = pres
const uint32_t debouceTime = 250; // button debouncing time (ms)
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// Set the RGB LED Light based on the current state of the Dimmable Light
bool setLightState(bool state, uint8_t brightness) {
if (state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
// Color Light Endpoint
MatterEnhancedColorLight EnhancedColorLight;

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// It will use HSV color to control all Matter Attribute Changes
HsvColor_t currentHSVColor = {0, 0, 0};

Expand All @@ -46,10 +50,6 @@ bool button_state = false; // false = released | true = pres
const uint32_t debouceTime = 250; // button debouncing time (ms)
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// Set the RGB LED Light based on the current state of the Enhanced Color Light
bool setLightState(bool state, espHsvColor_t colorHSV, uint8_t brighteness, uint16_t temperature_Mireds) {

Expand Down
8 changes: 4 additions & 4 deletions libraries/Matter/examples/MatterFan/MatterFan.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
// Fan Endpoint - On/Off control + Speed Percent Control + Fan Modes
MatterFan Fan;

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// set your board USER BUTTON pin here - used for toggling On/Off and decommission the Matter Node
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.

Expand All @@ -41,10 +45,6 @@ const uint8_t dcMotorPin = 2; // Set your pin here if your board has not define
#warning "Do not forget to set the RGB LED pin"
#endif

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

void fanDCMotorDrive(bool fanState, uint8_t speedPercent) {
// drive the Fan DC motor
if (fanState == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
// Matter Humidity Sensor Endpoint
MatterHumiditySensor SimulatedHumiditySensor;

// set your board USER BUTTON pin here - decommissioning button
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// set your board USER BUTTON pin here - decommissioning button
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.

// Button control - decommision the Matter Node
uint32_t button_time_stamp = 0; // debouncing control
bool button_state = false; // false = released | true = pressed
Expand Down
12 changes: 6 additions & 6 deletions libraries/Matter/examples/MatterMinimum/MatterMinimum.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
// Single On/Off Light Endpoint - at least one per node
MatterOnOffLight OnOffLight;

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// Light GPIO that can be controlled by Matter APP
#ifdef LED_BUILTIN
const uint8_t ledPin = LED_BUILTIN;
Expand All @@ -44,16 +48,12 @@ bool button_state = false; // false = released | true = pres
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission

// Matter Protocol Endpoint (On/OFF Light) Callback
bool matterCB(bool state) {
bool onOffLightCallback(bool state) {
digitalWrite(ledPin, state ? HIGH : LOW);
// This callback must return the success state to Matter core
return true;
}

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

void setup() {
// Initialize the USER BUTTON (Boot button) that will be used to decommission the Matter Node
pinMode(buttonPin, INPUT_PULLUP);
Expand All @@ -71,7 +71,7 @@ void setup() {
OnOffLight.begin();

// Associate a callback to the Matter Controller
OnOffLight.onChange(matterCB);
OnOffLight.onChange(onOffLightCallback);

// Matter beginning - Last step, after all EndPoints are initialized
Matter.begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
// Matter Occupancy Sensor Endpoint
MatterOccupancySensor OccupancySensor;

// set your board USER BUTTON pin here - decommissioning only
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// set your board USER BUTTON pin here - decommissioning only
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.

// Button control
uint32_t button_time_stamp = 0; // debouncing control
bool button_state = false; // false = released | true = pressed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include <WiFi.h>
#include <Preferences.h>

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// List of Matter Endpoints for this Node
// On/Off Light Endpoint
MatterOnOffLight OnOffLight;
Expand All @@ -42,10 +46,6 @@ bool button_state = false; // false = released | true = pres
const uint32_t debouceTime = 250; // button debouncing time (ms)
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// Matter Protocol Endpoint Callback
bool setLightOnOff(bool state) {
Serial.printf("User Callback :: New Light State = %s\r\n", state ? "ON" : "OFF");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
// On/Off Plugin Endpoint
MatterOnOffPlugin OnOffPlugin;

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// it will keep last OnOff state stored, using Preferences
Preferences matterPref;
const char *onOffPrefKey = "OnOff";
Expand All @@ -41,10 +45,6 @@ uint32_t button_time_stamp = 0; // debouncing control
bool button_state = false; // false = released | true = pressed
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// Matter Protocol Endpoint Callback
bool setPluginOnOff(bool state) {
Serial.printf("User Callback :: New Plugin State = %s\r\n", state ? "ON" : "OFF");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
// Matter Pressure Sensor Endpoint
MatterPressureSensor SimulatedPressureSensor;

// set your board USER BUTTON pin here - decommissioning button
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// set your board USER BUTTON pin here - decommissioning button
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.

// Button control - decommision the Matter Node
uint32_t button_time_stamp = 0; // debouncing control
bool button_state = false; // false = released | true = pressed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
// Generic Switch Endpoint - works as a smart button with a single click
MatterGenericSwitch SmartButton;

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// set your board USER BUTTON pin here
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.

Expand All @@ -29,10 +33,6 @@ bool button_state = false; // false = released | true = pres
const uint32_t debouceTime = 250; // button debouncing time (ms)
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

void setup() {
// Initialize the USER BUTTON (Boot button) GPIO that will act as a smart button or to decommission the Matter Node
pinMode(buttonPin, INPUT_PULLUP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
// Color Temperature CW/WW Light Endpoint
MatterColorTemperatureLight CW_WW_Light;

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// it will keep last OnOff & Brightness state stored, using Preferences
Preferences matterPref;
const char *onOffPrefKey = "OnOff";
Expand All @@ -44,10 +48,6 @@ bool button_state = false; // false = released | true = pres
const uint32_t debouceTime = 250; // button debouncing time (ms)
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// Set the RGB LED Light based on the current state of the Color Temperature Light
bool setLightState(bool state, uint8_t brightness, uint16_t temperature_Mireds) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
// Matter Temperature Sensor Endpoint
MatterTemperatureSensor SimulatedTemperatureSensor;

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// set your board USER BUTTON pin here - decommissioning button
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.

Expand All @@ -35,10 +39,6 @@ uint32_t button_time_stamp = 0; // debouncing control
bool button_state = false; // false = released | true = pressed
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission

// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password

// Simulate a temperature sensor - add your preferred temperature sensor library code here
float getSimulatedTemperature() {
// The Endpoint implementation keeps an int16_t as internal value information,
Expand Down
20 changes: 10 additions & 10 deletions libraries/Matter/src/MatterEndpoints/MatterColorLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ class MatterColorLight : public MatterEndPoint {
bool setColorHSV(espHsvColor_t hsvColor); // returns true if successful
espHsvColor_t getColorHSV(); // returns current HSV Color

// used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory();

operator bool(); // returns current on/off light state
void operator=(bool state); // turns light on or off

// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);

// User Callback for whenever the Light On/Off state is changed by the Matter Controller
using EndPointOnOffCB = std::function<bool(bool)>;
void onChangeOnOff(EndPointOnOffCB onChangeCB) {
Expand All @@ -64,6 +54,16 @@ class MatterColorLight : public MatterEndPoint {
_onChangeCB = onChangeCB;
}

// used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory();

operator bool(); // returns current on/off light state
void operator=(bool state); // turns light on or off

// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);

protected:
bool started = false;
bool onOffState = false; // default initial state is off, but it can be changed by begin(bool)
Expand Down
20 changes: 10 additions & 10 deletions libraries/Matter/src/MatterEndpoints/MatterColorTemperatureLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ class MatterColorTemperatureLight : public MatterEndPoint {
bool setColorTemperature(uint16_t newTemperature); // returns true if successful
uint16_t getColorTemperature(); // returns current temperature

// used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory();

operator bool(); // returns current on/off light state
void operator=(bool state); // turns light on or off

// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);

// User Callback for whenever the Light On/Off state is changed by the Matter Controller
using EndPointOnOffCB = std::function<bool(bool)>;
void onChangeOnOff(EndPointOnOffCB onChangeCB) {
Expand All @@ -76,6 +66,16 @@ class MatterColorTemperatureLight : public MatterEndPoint {
_onChangeCB = onChangeCB;
}

// used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory();

operator bool(); // returns current on/off light state
void operator=(bool state); // turns light on or off

// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);

protected:
bool started = false;
bool onOffState = false; // default initial state is off, but it can be changed by begin(bool)
Expand Down
Loading

0 comments on commit 3f7c597

Please sign in to comment.