mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
esp_matter_standard: Adding standard names for endpoints and attributes
Using these standard names in app_driver, app_matter and app_rainmaker files.
This commit is contained in:
@@ -118,7 +118,7 @@ esp_err_t esp_matter_attribute_notify(const char *name, const char *endpoint, co
|
||||
/* Callback */
|
||||
esp_matter_attr_cb_t *current_callback = esp_matter->callbacks;
|
||||
while (current_callback) {
|
||||
if (strcmp(current_callback->name, name) != 0) {
|
||||
if (strncmp(current_callback->name, name, NAME_MAX_LEN) != 0) {
|
||||
if (current_callback->callback) {
|
||||
current_callback->callback(endpoint, attribute, val, current_callback->priv_data);
|
||||
}
|
||||
@@ -177,7 +177,7 @@ esp_err_t esp_matter_attribute_callback_remove(const char *name)
|
||||
esp_matter_attr_cb_t *previous_callback = NULL;
|
||||
esp_matter_attr_cb_t *current_callback = esp_matter->callbacks;
|
||||
while (current_callback) {
|
||||
if (strcmp(current_callback->name, name) == 0) {
|
||||
if (strncmp(current_callback->name, name, NAME_MAX_LEN) == 0) {
|
||||
break;
|
||||
}
|
||||
previous_callback = current_callback;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/********** STANDARD ENDPOINT NAMES **********/
|
||||
#define ESP_MATTER_ENDPOINT_LIGHT "Light"
|
||||
|
||||
/********** STANDARD ATTRIBUTE NAMES **********/
|
||||
#define ESP_MATTER_ATTR_POWER "Power"
|
||||
#define ESP_MATTER_ATTR_BRIGHTNESS "Brightness"
|
||||
#define ESP_MATTER_ATTR_HUE "Hue"
|
||||
#define ESP_MATTER_ATTR_SATURATION "Saturation"
|
||||
#define ESP_MATTER_ATTR_TEMPERATURE "Temperature"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <esp_log.h>
|
||||
|
||||
#include <esp_matter.h>
|
||||
#include <esp_matter_standard.h>
|
||||
#include <app_driver.h>
|
||||
#include <device.h>
|
||||
#include <light_driver.h>
|
||||
@@ -49,19 +50,19 @@ static void app_driver_print_attr_val(const char *endpoint, const char *attribut
|
||||
|
||||
int app_driver_cli_handler(int argc, char** argv)
|
||||
{
|
||||
if (argc == 4 && strcmp(argv[0], "set") == 0) {
|
||||
if (argc == 4 && strncmp(argv[0], "set", sizeof("set")) == 0) {
|
||||
char *endpoint_name = argv[1];
|
||||
char *attribute_name = argv[2];
|
||||
int value = atoi(argv[3]);
|
||||
esp_matter_attr_val_t val = esp_matter_int(value);
|
||||
|
||||
/* Change val if bool */
|
||||
if (strcmp(attribute_name, "Power") == 0) {
|
||||
if (strncmp(attribute_name, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
val.type = ESP_MATTER_VAL_TYPE_BOOLEAN;
|
||||
val.val.b = (bool)value;
|
||||
}
|
||||
app_driver_attribute_set(endpoint_name, attribute_name, val);
|
||||
} else if (argc == 3 && strcmp(argv[0], "get") == 0) {
|
||||
} else if (argc == 3 && strncmp(argv[0], "get", sizeof("get")) == 0) {
|
||||
char *endpoint_name = argv[1];
|
||||
char *attribute_name = argv[2];
|
||||
esp_matter_attr_val_t val = app_driver_attribute_get(endpoint_name, attribute_name);
|
||||
@@ -75,16 +76,16 @@ int app_driver_cli_handler(int argc, char** argv)
|
||||
|
||||
static esp_matter_attr_val_t app_driver_attribute_get(const char *endpoint, const char *attribute)
|
||||
{
|
||||
if (strcmp(endpoint, "Light") == 0) {
|
||||
if (strcmp(attribute, "Power") == 0) {
|
||||
if (strncmp(endpoint, ESP_MATTER_ENDPOINT_LIGHT, sizeof(ESP_MATTER_ENDPOINT_LIGHT)) == 0) {
|
||||
if (strncmp(attribute, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
return esp_matter_bool(light_driver_get_power());
|
||||
} else if (strcmp(attribute, "Brightness") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_BRIGHTNESS, sizeof(ESP_MATTER_ATTR_BRIGHTNESS)) == 0) {
|
||||
return esp_matter_int(light_driver_get_brightness());
|
||||
} else if (strcmp(attribute, "Hue") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_HUE, sizeof(ESP_MATTER_ATTR_HUE)) == 0) {
|
||||
return esp_matter_int(light_driver_get_hue());
|
||||
} else if (strcmp(attribute, "Saturation") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_SATURATION, sizeof(ESP_MATTER_ATTR_SATURATION)) == 0) {
|
||||
return esp_matter_int(light_driver_get_saturation());
|
||||
} else if (strcmp(attribute, "Temperature") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_TEMPERATURE, sizeof(ESP_MATTER_ATTR_TEMPERATURE)) == 0) {
|
||||
return esp_matter_int(light_driver_get_temperature());
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Attribute update not handled: %s", attribute);
|
||||
@@ -101,16 +102,16 @@ static esp_matter_attr_val_t app_driver_attribute_get(const char *endpoint, cons
|
||||
static esp_err_t app_driver_attribute_update(const char *endpoint, const char *attribute, esp_matter_attr_val_t val, void *priv_data)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
if (strcmp(endpoint, "Light") == 0) {
|
||||
if (strcmp(attribute, "Power") == 0) {
|
||||
if (strncmp(endpoint, ESP_MATTER_ENDPOINT_LIGHT, sizeof(ESP_MATTER_ENDPOINT_LIGHT)) == 0) {
|
||||
if (strncmp(attribute, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
err = light_driver_set_power(val.val.b);
|
||||
} else if (strcmp(attribute, "Brightness") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_BRIGHTNESS, sizeof(ESP_MATTER_ATTR_BRIGHTNESS)) == 0) {
|
||||
err = light_driver_set_brightness(val.val.i);
|
||||
} else if (strcmp(attribute, "Hue") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_HUE, sizeof(ESP_MATTER_ATTR_HUE)) == 0) {
|
||||
err = light_driver_set_hue(val.val.i);
|
||||
} else if (strcmp(attribute, "Saturation") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_SATURATION, sizeof(ESP_MATTER_ATTR_SATURATION)) == 0) {
|
||||
err = light_driver_set_saturation(val.val.i);
|
||||
} else if (strcmp(attribute, "Temperature") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_TEMPERATURE, sizeof(ESP_MATTER_ATTR_TEMPERATURE)) == 0) {
|
||||
err = light_driver_set_temperature(val.val.i);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Attribute update not handled: %s", attribute);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_matter.h"
|
||||
#include "esp_matter_standard.h"
|
||||
#include "app_driver.h"
|
||||
#include "app_matter.h"
|
||||
#include "app_constants.h"
|
||||
@@ -104,10 +105,10 @@ extern "C" void app_main()
|
||||
ESP_ERROR_CHECK(app_matter_init());
|
||||
|
||||
/* Set the default attribute values */
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, "Light", "Power", esp_matter_bool(DEFAULT_POWER));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, "Light", "Brightness", esp_matter_int(DEFAULT_BRIGHTNESS));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, "Light", "Hue", esp_matter_int(DEFAULT_HUE));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, "Light", "Saturation", esp_matter_int(DEFAULT_SATURATION));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, ESP_MATTER_ENDPOINT_LIGHT, ESP_MATTER_ATTR_POWER, esp_matter_bool(DEFAULT_POWER));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, ESP_MATTER_ENDPOINT_LIGHT, ESP_MATTER_ATTR_BRIGHTNESS, esp_matter_int(DEFAULT_BRIGHTNESS));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, ESP_MATTER_ENDPOINT_LIGHT, ESP_MATTER_ATTR_HUE, esp_matter_int(DEFAULT_HUE));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, ESP_MATTER_ENDPOINT_LIGHT, ESP_MATTER_ATTR_SATURATION, esp_matter_int(DEFAULT_SATURATION));
|
||||
|
||||
#if CONFIG_ENABLE_CHIP_SHELL
|
||||
xTaskCreate(&ChipShellTask, "chip_shell", 2048, NULL, 5, NULL);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "esp_matter.h"
|
||||
#include "esp_matter_standard.h"
|
||||
#include "app_matter.h"
|
||||
#include "app_constants.h"
|
||||
|
||||
@@ -59,27 +60,27 @@ static const char *TAG = "app_matter";
|
||||
int app_matter_remap(char *attribute, int value, app_matter_remap_t remap)
|
||||
{
|
||||
if (remap == REMAP_MATTER_TO_STANDARD) {
|
||||
if (strcmp(attribute, "Power") == 0) {
|
||||
if (strncmp(attribute, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
return value;
|
||||
} else if (strcmp(attribute, "Brightness") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_BRIGHTNESS, sizeof(ESP_MATTER_ATTR_BRIGHTNESS)) == 0) {
|
||||
return REMAP_TO_RANGE(value, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
} else if (strcmp(attribute, "Hue") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_HUE, sizeof(ESP_MATTER_ATTR_HUE)) == 0) {
|
||||
return REMAP_TO_RANGE(value, MATTER_HUE, STANDARD_HUE);
|
||||
} else if (strcmp(attribute, "Saturation") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_SATURATION, sizeof(ESP_MATTER_ATTR_SATURATION)) == 0) {
|
||||
return REMAP_TO_RANGE(value, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
} else if (strcmp(attribute, "Temperature") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_TEMPERATURE, sizeof(ESP_MATTER_ATTR_TEMPERATURE)) == 0) {
|
||||
return REMAP_TO_RANGE(value, MATTER_TEMPERATURE, STANDARD_TEMPERATURE);
|
||||
}
|
||||
} else if (remap == REMAP_STANDARD_TO_MATTER) {
|
||||
if (strcmp(attribute, "Power") == 0) {
|
||||
if (strncmp(attribute, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
return value;
|
||||
} else if (strcmp(attribute, "Brightness") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_BRIGHTNESS, sizeof(ESP_MATTER_ATTR_BRIGHTNESS)) == 0) {
|
||||
return REMAP_TO_RANGE(value, STANDARD_BRIGHTNESS, MATTER_BRIGHTNESS);
|
||||
} else if (strcmp(attribute, "Hue") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_HUE, sizeof(ESP_MATTER_ATTR_HUE)) == 0) {
|
||||
return REMAP_TO_RANGE(value, STANDARD_HUE, MATTER_HUE);
|
||||
} else if (strcmp(attribute, "Saturation") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_SATURATION, sizeof(ESP_MATTER_ATTR_SATURATION)) == 0) {
|
||||
return REMAP_TO_RANGE(value, STANDARD_SATURATION, MATTER_SATURATION);
|
||||
} else if (strcmp(attribute, "Temperature") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_TEMPERATURE, sizeof(ESP_MATTER_ATTR_TEMPERATURE)) == 0) {
|
||||
return REMAP_TO_RANGE(value, STANDARD_TEMPERATURE, MATTER_TEMPERATURE);
|
||||
}
|
||||
}
|
||||
@@ -88,7 +89,7 @@ int app_matter_remap(char *attribute, int value, app_matter_remap_t remap)
|
||||
|
||||
static EndpointId app_matter_get_endpoint_id(const char *endpoint)
|
||||
{
|
||||
if (strcmp(endpoint, "Light") == 0) {
|
||||
if (strncmp(endpoint, ESP_MATTER_ENDPOINT_LIGHT, sizeof(ESP_MATTER_ENDPOINT_LIGHT)) == 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -97,22 +98,22 @@ static EndpointId app_matter_get_endpoint_id(const char *endpoint)
|
||||
static const char *app_matter_get_endpoint_name(EndpointId endpoint)
|
||||
{
|
||||
if (endpoint == 1) {
|
||||
return "Light";
|
||||
return ESP_MATTER_ENDPOINT_LIGHT;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ClusterId app_matter_get_cluster_id(const char *attribute)
|
||||
{
|
||||
if (strcmp(attribute, "Power") == 0) {
|
||||
if (strncmp(attribute, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
return ZCL_ON_OFF_CLUSTER_ID;
|
||||
} else if (strcmp(attribute, "Brightness") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_BRIGHTNESS, sizeof(ESP_MATTER_ATTR_BRIGHTNESS)) == 0) {
|
||||
return ZCL_LEVEL_CONTROL_CLUSTER_ID;
|
||||
} else if (strcmp(attribute, "Hue") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_HUE, sizeof(ESP_MATTER_ATTR_HUE)) == 0) {
|
||||
return ZCL_COLOR_CONTROL_CLUSTER_ID;
|
||||
} else if (strcmp(attribute, "Saturation") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_SATURATION, sizeof(ESP_MATTER_ATTR_SATURATION)) == 0) {
|
||||
return ZCL_COLOR_CONTROL_CLUSTER_ID;
|
||||
} else if (strcmp(attribute, "Temperature") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_TEMPERATURE, sizeof(ESP_MATTER_ATTR_TEMPERATURE)) == 0) {
|
||||
return ZCL_COLOR_CONTROL_CLUSTER_ID;
|
||||
}
|
||||
return 0;
|
||||
@@ -120,15 +121,15 @@ static ClusterId app_matter_get_cluster_id(const char *attribute)
|
||||
|
||||
static AttributeId app_matter_get_attribute_id(const char *attribute)
|
||||
{
|
||||
if (strcmp(attribute, "Power") == 0) {
|
||||
if (strncmp(attribute, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
return ZCL_ON_OFF_ATTRIBUTE_ID;
|
||||
} else if (strcmp(attribute, "Brightness") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_BRIGHTNESS, sizeof(ESP_MATTER_ATTR_BRIGHTNESS)) == 0) {
|
||||
return ZCL_CURRENT_LEVEL_ATTRIBUTE_ID;
|
||||
} else if (strcmp(attribute, "Hue") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_HUE, sizeof(ESP_MATTER_ATTR_HUE)) == 0) {
|
||||
return ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID;
|
||||
} else if (strcmp(attribute, "Saturation") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_SATURATION, sizeof(ESP_MATTER_ATTR_SATURATION)) == 0) {
|
||||
return ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID;
|
||||
} else if (strcmp(attribute, "Temperature") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_TEMPERATURE, sizeof(ESP_MATTER_ATTR_TEMPERATURE)) == 0) {
|
||||
return ZCL_COLOR_CONTROL_COLOR_TEMPERATURE_ATTRIBUTE_ID;
|
||||
}
|
||||
return 0;
|
||||
@@ -137,16 +138,16 @@ static AttributeId app_matter_get_attribute_id(const char *attribute)
|
||||
static const char *app_matter_get_attribute_name(ClusterId cluster, AttributeId attribute)
|
||||
{
|
||||
if (cluster == ZCL_ON_OFF_CLUSTER_ID) {
|
||||
return "Power";
|
||||
return ESP_MATTER_ATTR_POWER;
|
||||
} else if (cluster == ZCL_LEVEL_CONTROL_CLUSTER_ID) {
|
||||
return "Brightness";
|
||||
return ESP_MATTER_ATTR_BRIGHTNESS;
|
||||
} else if (cluster == ZCL_COLOR_CONTROL_CLUSTER_ID) {
|
||||
if (attribute == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) {
|
||||
return "Hue";
|
||||
return ESP_MATTER_ATTR_HUE;
|
||||
} else if (attribute == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID) {
|
||||
return "Saturation";
|
||||
return ESP_MATTER_ATTR_SATURATION;
|
||||
} else if (attribute == ZCL_COLOR_CONTROL_COLOR_TEMPERATURE_ATTRIBUTE_ID) {
|
||||
return "Temperature";
|
||||
return ESP_MATTER_ATTR_TEMPERATURE;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@@ -174,15 +175,15 @@ static int app_matter_get_attribute_value(esp_matter_attr_val_t val)
|
||||
|
||||
static esp_matter_attr_val_t app_matter_get_attribute_val(char *attribute, int value)
|
||||
{
|
||||
if (strcmp(attribute, "Power") == 0) {
|
||||
if (strncmp(attribute, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
return esp_matter_bool((bool)value);
|
||||
} else if (strcmp(attribute, "Brightness") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_BRIGHTNESS, sizeof(ESP_MATTER_ATTR_BRIGHTNESS)) == 0) {
|
||||
return esp_matter_int(value);
|
||||
} else if (strcmp(attribute, "Hue") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_HUE, sizeof(ESP_MATTER_ATTR_HUE)) == 0) {
|
||||
return esp_matter_int(value);
|
||||
} else if (strcmp(attribute, "Saturation") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_SATURATION, sizeof(ESP_MATTER_ATTR_SATURATION)) == 0) {
|
||||
return esp_matter_int(value);
|
||||
} else if (strcmp(attribute, "Temperature") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_TEMPERATURE, sizeof(ESP_MATTER_ATTR_TEMPERATURE)) == 0) {
|
||||
return esp_matter_int(value);
|
||||
}
|
||||
return esp_matter_int(value);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_matter.h"
|
||||
#include "esp_matter_standard.h"
|
||||
#include "app_driver.h"
|
||||
#include "app_matter.h"
|
||||
#include "app_constants.h"
|
||||
@@ -110,10 +111,10 @@ extern "C" void app_main()
|
||||
app_rainmaker_init();
|
||||
|
||||
/* Set the default attribute values */
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, "Light", "Power", esp_matter_bool(DEFAULT_POWER));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, "Light", "Brightness", esp_matter_int(DEFAULT_BRIGHTNESS));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, "Light", "Hue", esp_matter_int(DEFAULT_HUE));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, "Light", "Saturation", esp_matter_int(DEFAULT_SATURATION));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, ESP_MATTER_ENDPOINT_LIGHT, ESP_MATTER_ATTR_POWER, esp_matter_bool(DEFAULT_POWER));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, ESP_MATTER_ENDPOINT_LIGHT, ESP_MATTER_ATTR_BRIGHTNESS, esp_matter_int(DEFAULT_BRIGHTNESS));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, ESP_MATTER_ENDPOINT_LIGHT, ESP_MATTER_ATTR_HUE, esp_matter_int(DEFAULT_HUE));
|
||||
esp_matter_attribute_notify(APP_MAIN_NAME, ESP_MATTER_ENDPOINT_LIGHT, ESP_MATTER_ATTR_SATURATION, esp_matter_int(DEFAULT_SATURATION));
|
||||
|
||||
#if CONFIG_ENABLE_CHIP_SHELL
|
||||
xTaskCreate(&ChipShellTask, "chip_shell", 2048, NULL, 5, NULL);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "esp_matter.h"
|
||||
#include "esp_matter_standard.h"
|
||||
#include "app_matter.h"
|
||||
#include "app_constants.h"
|
||||
|
||||
@@ -56,27 +57,27 @@ static const char *TAG = "app_matter";
|
||||
int app_matter_remap(char *attribute, int value, app_matter_remap_t remap)
|
||||
{
|
||||
if (remap == REMAP_MATTER_TO_STANDARD) {
|
||||
if (strcmp(attribute, "Power") == 0) {
|
||||
if (strncmp(attribute, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
return value;
|
||||
} else if (strcmp(attribute, "Brightness") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_BRIGHTNESS, sizeof(ESP_MATTER_ATTR_BRIGHTNESS)) == 0) {
|
||||
return REMAP_TO_RANGE(value, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
} else if (strcmp(attribute, "Hue") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_HUE, sizeof(ESP_MATTER_ATTR_HUE)) == 0) {
|
||||
return REMAP_TO_RANGE(value, MATTER_HUE, STANDARD_HUE);
|
||||
} else if (strcmp(attribute, "Saturation") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_SATURATION, sizeof(ESP_MATTER_ATTR_SATURATION)) == 0) {
|
||||
return REMAP_TO_RANGE(value, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
} else if (strcmp(attribute, "Temperature") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_TEMPERATURE, sizeof(ESP_MATTER_ATTR_TEMPERATURE)) == 0) {
|
||||
return REMAP_TO_RANGE(value, MATTER_TEMPERATURE, STANDARD_TEMPERATURE);
|
||||
}
|
||||
} else if (remap == REMAP_STANDARD_TO_MATTER) {
|
||||
if (strcmp(attribute, "Power") == 0) {
|
||||
if (strncmp(attribute, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
return value;
|
||||
} else if (strcmp(attribute, "Brightness") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_BRIGHTNESS, sizeof(ESP_MATTER_ATTR_BRIGHTNESS)) == 0) {
|
||||
return REMAP_TO_RANGE(value, STANDARD_BRIGHTNESS, MATTER_BRIGHTNESS);
|
||||
} else if (strcmp(attribute, "Hue") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_HUE, sizeof(ESP_MATTER_ATTR_HUE)) == 0) {
|
||||
return REMAP_TO_RANGE(value, STANDARD_HUE, MATTER_HUE);
|
||||
} else if (strcmp(attribute, "Saturation") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_SATURATION, sizeof(ESP_MATTER_ATTR_SATURATION)) == 0) {
|
||||
return REMAP_TO_RANGE(value, STANDARD_SATURATION, MATTER_SATURATION);
|
||||
} else if (strcmp(attribute, "Temperature") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_TEMPERATURE, sizeof(ESP_MATTER_ATTR_TEMPERATURE)) == 0) {
|
||||
return REMAP_TO_RANGE(value, STANDARD_TEMPERATURE, MATTER_TEMPERATURE);
|
||||
}
|
||||
}
|
||||
@@ -85,7 +86,7 @@ int app_matter_remap(char *attribute, int value, app_matter_remap_t remap)
|
||||
|
||||
static EndpointId app_matter_get_endpoint_id(const char *endpoint)
|
||||
{
|
||||
if (strcmp(endpoint, "Light") == 0) {
|
||||
if (strncmp(endpoint, ESP_MATTER_ENDPOINT_LIGHT, sizeof(ESP_MATTER_ENDPOINT_LIGHT)) == 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -94,22 +95,22 @@ static EndpointId app_matter_get_endpoint_id(const char *endpoint)
|
||||
static const char *app_matter_get_endpoint_name(EndpointId endpoint)
|
||||
{
|
||||
if (endpoint == 1) {
|
||||
return "Light";
|
||||
return ESP_MATTER_ENDPOINT_LIGHT;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ClusterId app_matter_get_cluster_id(const char *attribute)
|
||||
{
|
||||
if (strcmp(attribute, "Power") == 0) {
|
||||
if (strncmp(attribute, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
return ZCL_ON_OFF_CLUSTER_ID;
|
||||
} else if (strcmp(attribute, "Brightness") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_BRIGHTNESS, sizeof(ESP_MATTER_ATTR_BRIGHTNESS)) == 0) {
|
||||
return ZCL_LEVEL_CONTROL_CLUSTER_ID;
|
||||
} else if (strcmp(attribute, "Hue") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_HUE, sizeof(ESP_MATTER_ATTR_HUE)) == 0) {
|
||||
return ZCL_COLOR_CONTROL_CLUSTER_ID;
|
||||
} else if (strcmp(attribute, "Saturation") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_SATURATION, sizeof(ESP_MATTER_ATTR_SATURATION)) == 0) {
|
||||
return ZCL_COLOR_CONTROL_CLUSTER_ID;
|
||||
} else if (strcmp(attribute, "Temperature") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_TEMPERATURE, sizeof(ESP_MATTER_ATTR_TEMPERATURE)) == 0) {
|
||||
return ZCL_COLOR_CONTROL_CLUSTER_ID;
|
||||
}
|
||||
return 0;
|
||||
@@ -117,15 +118,15 @@ static ClusterId app_matter_get_cluster_id(const char *attribute)
|
||||
|
||||
static AttributeId app_matter_get_attribute_id(const char *attribute)
|
||||
{
|
||||
if (strcmp(attribute, "Power") == 0) {
|
||||
if (strncmp(attribute, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
return ZCL_ON_OFF_ATTRIBUTE_ID;
|
||||
} else if (strcmp(attribute, "Brightness") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_BRIGHTNESS, sizeof(ESP_MATTER_ATTR_BRIGHTNESS)) == 0) {
|
||||
return ZCL_CURRENT_LEVEL_ATTRIBUTE_ID;
|
||||
} else if (strcmp(attribute, "Hue") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_HUE, sizeof(ESP_MATTER_ATTR_HUE)) == 0) {
|
||||
return ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID;
|
||||
} else if (strcmp(attribute, "Saturation") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_SATURATION, sizeof(ESP_MATTER_ATTR_SATURATION)) == 0) {
|
||||
return ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID;
|
||||
} else if (strcmp(attribute, "Temperature") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_TEMPERATURE, sizeof(ESP_MATTER_ATTR_TEMPERATURE)) == 0) {
|
||||
return ZCL_COLOR_CONTROL_COLOR_TEMPERATURE_ATTRIBUTE_ID;
|
||||
}
|
||||
return 0;
|
||||
@@ -134,16 +135,16 @@ static AttributeId app_matter_get_attribute_id(const char *attribute)
|
||||
static const char *app_matter_get_attribute_name(ClusterId cluster, AttributeId attribute)
|
||||
{
|
||||
if (cluster == ZCL_ON_OFF_CLUSTER_ID) {
|
||||
return "Power";
|
||||
return ESP_MATTER_ATTR_POWER;
|
||||
} else if (cluster == ZCL_LEVEL_CONTROL_CLUSTER_ID) {
|
||||
return "Brightness";
|
||||
return ESP_MATTER_ATTR_BRIGHTNESS;
|
||||
} else if (cluster == ZCL_COLOR_CONTROL_CLUSTER_ID) {
|
||||
if (attribute == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) {
|
||||
return "Hue";
|
||||
return ESP_MATTER_ATTR_HUE;
|
||||
} else if (attribute == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID) {
|
||||
return "Saturation";
|
||||
return ESP_MATTER_ATTR_SATURATION;
|
||||
} else if (attribute == ZCL_COLOR_CONTROL_COLOR_TEMPERATURE_ATTRIBUTE_ID) {
|
||||
return "Temperature";
|
||||
return ESP_MATTER_ATTR_TEMPERATURE;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@@ -171,15 +172,15 @@ static int app_matter_get_attribute_value(esp_matter_attr_val_t val)
|
||||
|
||||
static esp_matter_attr_val_t app_matter_get_attribute_val(char *attribute, int value)
|
||||
{
|
||||
if (strcmp(attribute, "Power") == 0) {
|
||||
if (strncmp(attribute, ESP_MATTER_ATTR_POWER, sizeof(ESP_MATTER_ATTR_POWER)) == 0) {
|
||||
return esp_matter_bool((bool)value);
|
||||
} else if (strcmp(attribute, "Brightness") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_BRIGHTNESS, sizeof(ESP_MATTER_ATTR_BRIGHTNESS)) == 0) {
|
||||
return esp_matter_int(value);
|
||||
} else if (strcmp(attribute, "Hue") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_HUE, sizeof(ESP_MATTER_ATTR_HUE)) == 0) {
|
||||
return esp_matter_int(value);
|
||||
} else if (strcmp(attribute, "Saturation") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_SATURATION, sizeof(ESP_MATTER_ATTR_SATURATION)) == 0) {
|
||||
return esp_matter_int(value);
|
||||
} else if (strcmp(attribute, "Temperature") == 0) {
|
||||
} else if (strncmp(attribute, ESP_MATTER_ATTR_TEMPERATURE, sizeof(ESP_MATTER_ATTR_TEMPERATURE)) == 0) {
|
||||
return esp_matter_int(value);
|
||||
}
|
||||
return esp_matter_int(value);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <esp_rmaker_user_mapping.h>
|
||||
|
||||
#include <esp_matter.h>
|
||||
#include <esp_matter_standard.h>
|
||||
#include <app_rainmaker.h>
|
||||
#include "app_constants.h"
|
||||
|
||||
@@ -31,7 +32,7 @@ esp_rmaker_device_t *light_device;
|
||||
|
||||
int app_rainmaker_cli_handler(int argc, char** argv)
|
||||
{
|
||||
if (argc == 3 && strcmp(argv[0], "add-user") == 0) {
|
||||
if (argc == 3 && strncmp(argv[0], "add-user", sizeof("add-user")) == 0) {
|
||||
printf("%s: Starting user-node mapping\n", TAG);
|
||||
if (esp_rmaker_start_user_node_mapping(argv[1], argv[2]) != ESP_OK) {
|
||||
return -1;
|
||||
@@ -135,14 +136,14 @@ esp_err_t app_rainmaker_init()
|
||||
}
|
||||
|
||||
/* Create a device and add the relevant parameters to it */
|
||||
light_device = esp_rmaker_lightbulb_device_create("Light", NULL, DEFAULT_POWER);
|
||||
light_device = esp_rmaker_lightbulb_device_create(ESP_MATTER_ENDPOINT_LIGHT, NULL, DEFAULT_POWER);
|
||||
esp_rmaker_device_add_cb(light_device, write_cb, NULL);
|
||||
|
||||
esp_rmaker_device_add_param(light_device, esp_rmaker_brightness_param_create(ESP_RMAKER_DEF_BRIGHTNESS_NAME, DEFAULT_BRIGHTNESS));
|
||||
esp_rmaker_device_add_param(light_device, esp_rmaker_brightness_param_create(ESP_MATTER_ATTR_BRIGHTNESS, DEFAULT_BRIGHTNESS));
|
||||
|
||||
esp_rmaker_device_add_param(light_device, esp_rmaker_hue_param_create(ESP_RMAKER_DEF_HUE_NAME, DEFAULT_HUE));
|
||||
esp_rmaker_device_add_param(light_device, esp_rmaker_hue_param_create(ESP_MATTER_ATTR_HUE, DEFAULT_HUE));
|
||||
|
||||
esp_rmaker_device_add_param(light_device, esp_rmaker_saturation_param_create(ESP_RMAKER_DEF_SATURATION_NAME, DEFAULT_SATURATION));
|
||||
esp_rmaker_device_add_param(light_device, esp_rmaker_saturation_param_create(ESP_MATTER_ATTR_SATURATION, DEFAULT_SATURATION));
|
||||
|
||||
esp_rmaker_node_add_device(node, light_device);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user