diff --git a/examples/light/main/app_driver.cpp b/examples/light/main/app_driver.cpp index b0243a00d..82f8f6b43 100644 --- a/examples/light/main/app_driver.cpp +++ b/examples/light/main/app_driver.cpp @@ -14,21 +14,11 @@ #include #include -#include +#include static const char *TAG = "app_driver"; extern int light_endpoint_id; -#define STANDARD_BRIGHTNESS 100 -#define STANDARD_HUE 360 -#define STANDARD_SATURATION 100 -#define STANDARD_TEMPERATURE 100 - -#define MATTER_BRIGHTNESS 255 -#define MATTER_HUE 255 -#define MATTER_SATURATION 255 -#define MATTER_TEMPERATURE 255 - /* Do any conversions/remapping for the actual value here */ static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t *val) { diff --git a/examples/light/main/app_main.cpp b/examples/light/main/app_main.cpp index bef70ebc6..35bf6847b 100644 --- a/examples/light/main/app_main.cpp +++ b/examples/light/main/app_main.cpp @@ -15,14 +15,9 @@ #include #include -#include +#include #include -#define DEFAULT_POWER true -#define DEFAULT_BRIGHTNESS 64 -#define DEFAULT_HUE 127 -#define DEFAULT_SATURATION 254 - static const char *TAG = "app_main"; int light_endpoint_id = 0; diff --git a/examples/rainmaker_light/main/app_driver.h b/examples/light/main/app_priv.h similarity index 71% rename from examples/rainmaker_light/main/app_driver.h rename to examples/light/main/app_priv.h index 99aa09a93..7893878ae 100644 --- a/examples/rainmaker_light/main/app_driver.h +++ b/examples/light/main/app_priv.h @@ -8,13 +8,22 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif - #include #include +#define STANDARD_BRIGHTNESS 100 +#define STANDARD_HUE 360 +#define STANDARD_SATURATION 100 + +#define MATTER_BRIGHTNESS 254 +#define MATTER_HUE 255 +#define MATTER_SATURATION 255 + +#define DEFAULT_POWER true +#define DEFAULT_BRIGHTNESS 64 +#define DEFAULT_HUE 128 +#define DEFAULT_SATURATION 255 + /** Initialize the board and the drivers * * This initializes the selected board, which then initializes the respective drivers associated with it. @@ -25,7 +34,3 @@ extern "C" { esp_err_t app_driver_init(void); esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val); - -#ifdef __cplusplus -} -#endif diff --git a/examples/rainmaker_light/main/app_driver.cpp b/examples/rainmaker_light/main/app_driver.cpp index b0243a00d..82f8f6b43 100644 --- a/examples/rainmaker_light/main/app_driver.cpp +++ b/examples/rainmaker_light/main/app_driver.cpp @@ -14,21 +14,11 @@ #include #include -#include +#include static const char *TAG = "app_driver"; extern int light_endpoint_id; -#define STANDARD_BRIGHTNESS 100 -#define STANDARD_HUE 360 -#define STANDARD_SATURATION 100 -#define STANDARD_TEMPERATURE 100 - -#define MATTER_BRIGHTNESS 255 -#define MATTER_HUE 255 -#define MATTER_SATURATION 255 -#define MATTER_TEMPERATURE 255 - /* Do any conversions/remapping for the actual value here */ static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t *val) { diff --git a/examples/rainmaker_light/main/app_main.cpp b/examples/rainmaker_light/main/app_main.cpp index ca6cbcdff..8594af3ce 100644 --- a/examples/rainmaker_light/main/app_main.cpp +++ b/examples/rainmaker_light/main/app_main.cpp @@ -14,15 +14,10 @@ #include #include -#include +#include #include #include -#define DEFAULT_POWER true -#define DEFAULT_BRIGHTNESS 64 -#define DEFAULT_HUE 127 -#define DEFAULT_SATURATION 254 - static const char *TAG = "app_main"; int light_endpoint_id = 0; diff --git a/examples/switch/main/app_driver.h b/examples/rainmaker_light/main/app_priv.h similarity index 71% rename from examples/switch/main/app_driver.h rename to examples/rainmaker_light/main/app_priv.h index 99aa09a93..7893878ae 100644 --- a/examples/switch/main/app_driver.h +++ b/examples/rainmaker_light/main/app_priv.h @@ -8,13 +8,22 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif - #include #include +#define STANDARD_BRIGHTNESS 100 +#define STANDARD_HUE 360 +#define STANDARD_SATURATION 100 + +#define MATTER_BRIGHTNESS 254 +#define MATTER_HUE 255 +#define MATTER_SATURATION 255 + +#define DEFAULT_POWER true +#define DEFAULT_BRIGHTNESS 64 +#define DEFAULT_HUE 128 +#define DEFAULT_SATURATION 255 + /** Initialize the board and the drivers * * This initializes the selected board, which then initializes the respective drivers associated with it. @@ -25,7 +34,3 @@ extern "C" { esp_err_t app_driver_init(void); esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val); - -#ifdef __cplusplus -} -#endif diff --git a/examples/rainmaker_light/main/app_rainmaker.cpp b/examples/rainmaker_light/main/app_rainmaker.cpp index e6750f5f8..45f4e2b8f 100644 --- a/examples/rainmaker_light/main/app_rainmaker.cpp +++ b/examples/rainmaker_light/main/app_rainmaker.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -29,8 +30,25 @@ extern int light_endpoint_id; #define DEFAULT_LIGHT_NAME "Light" -static esp_rmaker_param_val_t app_rainmaker_get_rmaker_val(esp_matter_attr_val_t *val) +static esp_rmaker_param_val_t app_rainmaker_get_rmaker_val(esp_matter_attr_val_t *val, int cluster_id, int attribute_id) { + /* Attributes which need to be remapped */ + if (cluster_id == ZCL_LEVEL_CONTROL_CLUSTER_ID) { + if (attribute_id == ZCL_CURRENT_LEVEL_ATTRIBUTE_ID) { + int value = REMAP_TO_RANGE(val->val.u8, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS); + return esp_rmaker_int(value); + } + } else if (cluster_id == ZCL_COLOR_CONTROL_CLUSTER_ID) { + if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) { + int value = REMAP_TO_RANGE(val->val.u8, MATTER_HUE, STANDARD_HUE); + return esp_rmaker_int(value); + } else if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID) { + int value = REMAP_TO_RANGE(val->val.u8, MATTER_SATURATION, STANDARD_SATURATION); + return esp_rmaker_int(value); + } + } + + /* Attributes which don't need to be remapped */ if (val->type == ESP_MATTER_VAL_TYPE_BOOLEAN) { return esp_rmaker_bool(val->val.b); } else if (val->type == ESP_MATTER_VAL_TYPE_INTEGER) { @@ -49,16 +67,33 @@ static esp_rmaker_param_val_t app_rainmaker_get_rmaker_val(esp_matter_attr_val_t return esp_rmaker_int(0); } -static esp_matter_attr_val_t app_rainmaker_get_matter_val(esp_rmaker_param_val_t val) +static esp_matter_attr_val_t app_rainmaker_get_matter_val(esp_rmaker_param_val_t *val, int cluster_id, int attribute_id) { - if (val.type == RMAKER_VAL_TYPE_BOOLEAN) { - return esp_matter_bool(val.val.b); - } else if (val.type == RMAKER_VAL_TYPE_INTEGER) { - return esp_matter_int(val.val.i); - } else if (val.type == RMAKER_VAL_TYPE_FLOAT) { - return esp_matter_float(val.val.f); + /* Attributes which need to be remapped */ + if (cluster_id == ZCL_LEVEL_CONTROL_CLUSTER_ID) { + if (attribute_id == ZCL_CURRENT_LEVEL_ATTRIBUTE_ID) { + uint8_t value = REMAP_TO_RANGE(val->val.i, STANDARD_BRIGHTNESS, MATTER_BRIGHTNESS); + return esp_matter_uint8(value); + } + } else if (cluster_id == ZCL_COLOR_CONTROL_CLUSTER_ID) { + if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) { + uint8_t value = REMAP_TO_RANGE(val->val.i, STANDARD_HUE, MATTER_HUE); + return esp_matter_uint8(value); + } else if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID) { + uint8_t value = REMAP_TO_RANGE(val->val.i, STANDARD_SATURATION, MATTER_SATURATION); + return esp_matter_uint8(value); + } + } + + /* Attributes which don't need to be remapped */ + if (val->type == RMAKER_VAL_TYPE_BOOLEAN) { + return esp_matter_bool(val->val.b); + } else if (val->type == RMAKER_VAL_TYPE_INTEGER) { + return esp_matter_int(val->val.i); + } else if (val->type == RMAKER_VAL_TYPE_FLOAT) { + return esp_matter_float(val->val.f); } else { - ESP_LOGE(TAG, "Invalid val type: %d", val.type); + ESP_LOGE(TAG, "Invalid val type: %d", val->type); } return esp_matter_int(0); } @@ -139,7 +174,7 @@ static const char *app_rainmaker_get_param_ui_type_from_id(int cluster_id, int a } } else if (cluster_id == ZCL_COLOR_CONTROL_CLUSTER_ID) { if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) { - return ESP_RMAKER_UI_SLIDER; + return ESP_RMAKER_UI_HUE_SLIDER; } else if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID) { return ESP_RMAKER_UI_SLIDER; } @@ -149,26 +184,22 @@ static const char *app_rainmaker_get_param_ui_type_from_id(int cluster_id, int a static bool app_rainmaker_get_param_bounds_from_id(int cluster_id, int attribute_id, int *min, int *max, int *step) { - if (cluster_id == ZCL_ON_OFF_CLUSTER_ID) { - if (attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) { - return false; - } - } else if (cluster_id == ZCL_LEVEL_CONTROL_CLUSTER_ID) { + if (cluster_id == ZCL_LEVEL_CONTROL_CLUSTER_ID) { if (attribute_id == ZCL_CURRENT_LEVEL_ATTRIBUTE_ID) { *min = 0; - *max = 255; + *max = STANDARD_BRIGHTNESS; *step = 1; return true; } } else if (cluster_id == ZCL_COLOR_CONTROL_CLUSTER_ID) { if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) { *min = 0; - *max = 255; + *max = STANDARD_HUE; *step = 1; return true; } else if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID) { *min = 0; - *max = 255; + *max = STANDARD_SATURATION; *step = 1; return true; } @@ -191,17 +222,17 @@ static esp_err_t app_rainmaker_param_add_ui_type(esp_rmaker_param_t *param, esp_ static esp_err_t app_rainmaker_param_add_bounds(esp_rmaker_param_t *param, esp_matter_cluster_t *cluster, esp_matter_attribute_t *attribute) { + int cluster_id = esp_matter_cluster_get_id(cluster); + int attribute_id = esp_matter_attribute_get_id(attribute); esp_matter_attr_bounds_t *bounds = esp_matter_attribute_get_bounds(attribute); if (bounds) { - esp_rmaker_param_val_t min_val = app_rainmaker_get_rmaker_val(&bounds->min); - esp_rmaker_param_val_t max_val = app_rainmaker_get_rmaker_val(&bounds->max); + esp_rmaker_param_val_t min_val = app_rainmaker_get_rmaker_val(&bounds->min, cluster_id, attribute_id); + esp_rmaker_param_val_t max_val = app_rainmaker_get_rmaker_val(&bounds->max, cluster_id, attribute_id); esp_rmaker_param_val_t step_val = esp_rmaker_int(1); return esp_rmaker_param_add_bounds(param, min_val, max_val, step_val); } /* If bounds are not set for the attribute, check if there are any bounds to be added based on the id */ - int cluster_id = esp_matter_cluster_get_id(cluster); - int attribute_id = esp_matter_attribute_get_id(attribute); int min = 0, max = 0, step = 0; bool add_bounds = app_rainmaker_get_param_bounds_from_id(cluster_id, attribute_id, &min, &max, &step); if (add_bounds) { @@ -254,7 +285,7 @@ esp_err_t app_rainmaker_attribute_update(int endpoint_id, int cluster_id, int at const esp_rmaker_node_t *node = esp_rmaker_get_node(); esp_rmaker_device_t *device = esp_rmaker_node_get_device_by_name(node, device_name); esp_rmaker_param_t *param = esp_rmaker_device_get_param_by_name(device, param_name); - esp_rmaker_param_val_t rmaker_val = app_rainmaker_get_rmaker_val(val); + esp_rmaker_param_val_t rmaker_val = app_rainmaker_get_rmaker_val(val, cluster_id, attribute_id); if (!param) { ESP_LOGE(TAG, "Param not found"); return ESP_FAIL; @@ -283,7 +314,7 @@ static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_pa int endpoint_id = app_rainmaker_get_endpoint_id_from_name(device_name); int cluster_id = app_rainmaker_get_cluster_id_from_name(param_name); int attribute_id = app_rainmaker_get_attribute_id_from_name(param_name); - esp_matter_attr_val_t matter_val = app_rainmaker_get_matter_val(val); + esp_matter_attr_val_t matter_val = app_rainmaker_get_matter_val((esp_rmaker_param_val_t *)&val, cluster_id, attribute_id); return esp_matter_attribute_update(endpoint_id, cluster_id, attribute_id, &matter_val); } @@ -321,7 +352,7 @@ static esp_rmaker_param_t *app_rainmaker_param_create(esp_rmaker_device_t *devic const char *param_type = app_rainmaker_get_param_type_from_id(cluster_id, attribute_id); esp_matter_attr_val_t val = esp_matter_invalid(NULL); esp_matter_attribute_get_val(attribute, &val); - esp_rmaker_param_val_t rmaker_val = app_rainmaker_get_rmaker_val(&val); + esp_rmaker_param_val_t rmaker_val = app_rainmaker_get_rmaker_val(&val, cluster_id, attribute_id); esp_rmaker_param_t *param = esp_rmaker_param_create(param_name, param_type, rmaker_val, PROP_FLAG_READ | PROP_FLAG_WRITE); if (!param) { diff --git a/examples/switch/main/app_driver.cpp b/examples/switch/main/app_driver.cpp index 4a999a3ea..fb0604687 100644 --- a/examples/switch/main/app_driver.cpp +++ b/examples/switch/main/app_driver.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include using chip::kInvalidClusterId; static constexpr chip::CommandId kInvalidCommandId = 0xFFFF'FFFF; diff --git a/examples/switch/main/app_main.cpp b/examples/switch/main/app_main.cpp index 2468d7cbb..52f93ffbb 100644 --- a/examples/switch/main/app_main.cpp +++ b/examples/switch/main/app_main.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include static const char *TAG = "app_main"; diff --git a/examples/light/main/app_driver.h b/examples/switch/main/app_priv.h similarity index 91% rename from examples/light/main/app_driver.h rename to examples/switch/main/app_priv.h index 99aa09a93..74d586985 100644 --- a/examples/light/main/app_driver.h +++ b/examples/switch/main/app_priv.h @@ -8,10 +8,6 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif - #include #include @@ -25,7 +21,3 @@ extern "C" { esp_err_t app_driver_init(void); esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val); - -#ifdef __cplusplus -} -#endif diff --git a/examples/zap_light/main/app_driver.cpp b/examples/zap_light/main/app_driver.cpp index 68f821c0c..a54962759 100644 --- a/examples/zap_light/main/app_driver.cpp +++ b/examples/zap_light/main/app_driver.cpp @@ -14,21 +14,11 @@ #include #include -#include +#include static const char *TAG = "app_driver"; extern int light_endpoint_id; -#define STANDARD_BRIGHTNESS 100 -#define STANDARD_HUE 360 -#define STANDARD_SATURATION 100 -#define STANDARD_TEMPERATURE 100 - -#define MATTER_BRIGHTNESS 255 -#define MATTER_HUE 255 -#define MATTER_SATURATION 255 -#define MATTER_TEMPERATURE 255 - /* Do any conversions/remapping for the actual value here */ static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t *val) { diff --git a/examples/zap_light/main/app_main.cpp b/examples/zap_light/main/app_main.cpp index b1b2ce9f4..d05fed0c5 100644 --- a/examples/zap_light/main/app_main.cpp +++ b/examples/zap_light/main/app_main.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include static const char *TAG = "app_main"; diff --git a/examples/zap_light/main/app_driver.h b/examples/zap_light/main/app_priv.h similarity index 81% rename from examples/zap_light/main/app_driver.h rename to examples/zap_light/main/app_priv.h index bd0376d5c..dbe85c504 100644 --- a/examples/zap_light/main/app_driver.h +++ b/examples/zap_light/main/app_priv.h @@ -8,13 +8,17 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif - #include #include +#define STANDARD_BRIGHTNESS 100 +#define STANDARD_HUE 360 +#define STANDARD_SATURATION 100 + +#define MATTER_BRIGHTNESS 254 +#define MATTER_HUE 255 +#define MATTER_SATURATION 255 + /** Initialize the board and the drivers * * This initializes the selected board, which then initializes the respective drivers associated with it. @@ -27,7 +31,3 @@ esp_err_t app_driver_init(void); esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val); esp_err_t app_driver_attribute_set_defaults(); - -#ifdef __cplusplus -} -#endif diff --git a/examples/zap_light/main/zap-generated/endpoint_config.h b/examples/zap_light/main/zap-generated/endpoint_config.h index 61d85a247..e395011e9 100644 --- a/examples/zap_light/main/zap-generated/endpoint_config.h +++ b/examples/zap_light/main/zap-generated/endpoint_config.h @@ -346,9 +346,9 @@ \ /* Endpoint: 1, Cluster: Color Control (server) */ \ {0x00000000, ZAP_TYPE(INT8U), 1, 0, \ - ZAP_SIMPLE_DEFAULT(0x7F)}, /* current hue */ \ + ZAP_SIMPLE_DEFAULT(0x80)}, /* current hue */ \ {0x00000001, ZAP_TYPE(INT8U), 1, 0, \ - ZAP_SIMPLE_DEFAULT(0xFE)}, /* current saturation */ \ + ZAP_SIMPLE_DEFAULT(0xFF)}, /* current saturation */ \ {0x00000003, ZAP_TYPE(INT16U), 2, 0, \ ZAP_SIMPLE_DEFAULT(0x616B)}, /* current x */ \ {0x00000004, ZAP_TYPE(INT16U), 2, 0, \ diff --git a/examples/zap_light/main/zap-generated/light.zap b/examples/zap_light/main/zap-generated/light.zap index f3921a520..69274f938 100644 --- a/examples/zap_light/main/zap-generated/light.zap +++ b/examples/zap_light/main/zap-generated/light.zap @@ -4736,7 +4736,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "0x7F", + "defaultValue": "0x80", "reportable": 1, "minInterval": 1, "maxInterval": 65534, @@ -4751,7 +4751,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "0xFE", + "defaultValue": "0xFF", "reportable": 1, "minInterval": 1, "maxInterval": 65534,