From ff861b03bea444e6f46be5fd66f4e3a180c3c220 Mon Sep 17 00:00:00 2001 From: Jiacheng Guo Date: Fri, 22 Oct 2021 16:54:40 +0800 Subject: [PATCH] ci: format current code --- components/esp_matter/esp_matter.c | 41 ++++-------- components/esp_matter/esp_matter.h | 19 +++--- components/esp_matter/esp_matter_standard.h | 15 +++-- .../esp_matter_console/esp_matter_console.cpp | 15 ++--- .../esp_matter_console/esp_matter_console.h | 5 +- .../button_driver/hollow/button_driver.c | 2 +- .../button_driver/include/button_driver.h | 3 +- device_hal/device/esp32_devkit_c/device.c | 6 +- device_hal/device/esp32c3_devkit_m/device.c | 7 +-- device_hal/device/esp32h2_devkit_c/device.c | 7 +-- device_hal/device/include/device.h | 3 +- device_hal/device/m5stack/device.c | 6 +- device_hal/light_driver/gpio/light_driver.c | 4 +- device_hal/light_driver/hollow/light_driver.c | 2 +- .../light_driver/include/color_format.h | 5 +- .../light_driver/include/light_driver.h | 3 +- device_hal/light_driver/utils/color_format.c | 52 +++++++-------- device_hal/light_driver/vled/light_driver.c | 56 ++++++++--------- device_hal/light_driver/ws2812/light_driver.c | 6 +- examples/common/app_driver/app_driver.c | 55 ++++++++-------- examples/common/app_driver/app_driver.h | 3 +- examples/common/app_qrcode/app_qrcode.cpp | 28 +++++---- examples/common/app_qrcode/app_qrcode.h | 3 +- examples/light/main/app_main.cpp | 63 ++++++++++--------- examples/light/main/app_matter.cpp | 16 +++-- examples/rainmaker_light/main/app_main.cpp | 63 ++++++++++--------- examples/rainmaker_light/main/app_matter.cpp | 1 + examples/rainmaker_light/main/app_rainmaker.c | 34 +++++----- examples/rainmaker_light/main/app_rainmaker.h | 6 +- 29 files changed, 267 insertions(+), 262 deletions(-) diff --git a/components/esp_matter/esp_matter.c b/components/esp_matter/esp_matter.c index dddf5c5b5..ab012b926 100644 --- a/components/esp_matter/esp_matter.c +++ b/components/esp_matter/esp_matter.c @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include #include +#include #define NAME_MAX_LEN 20 @@ -35,59 +35,42 @@ static esp_matter_t *esp_matter = NULL; esp_matter_attr_val_t esp_matter_bool(bool val) { - esp_matter_attr_val_t attr_val = { - .type = ESP_MATTER_VAL_TYPE_BOOLEAN, - .val.b = val - }; + esp_matter_attr_val_t attr_val = {.type = ESP_MATTER_VAL_TYPE_BOOLEAN, .val.b = val}; return attr_val; } esp_matter_attr_val_t esp_matter_int(int val) { - esp_matter_attr_val_t attr_val = { - .type = ESP_MATTER_VAL_TYPE_INTEGER, - .val.i = val - }; + esp_matter_attr_val_t attr_val = {.type = ESP_MATTER_VAL_TYPE_INTEGER, .val.i = val}; return attr_val; } esp_matter_attr_val_t esp_matter_float(float val) { - esp_matter_attr_val_t attr_val = { - .type = ESP_MATTER_VAL_TYPE_FLOAT, - .val.f = val - }; + esp_matter_attr_val_t attr_val = {.type = ESP_MATTER_VAL_TYPE_FLOAT, .val.f = val}; return attr_val; } esp_matter_attr_val_t esp_matter_str(const char *val) { - esp_matter_attr_val_t attr_val = { - .type = ESP_MATTER_VAL_TYPE_STRING, - .val.s = (char *)val - }; + esp_matter_attr_val_t attr_val = {.type = ESP_MATTER_VAL_TYPE_STRING, .val.s = (char *)val}; return attr_val; } esp_matter_attr_val_t esp_matter_obj(const char *val) { - esp_matter_attr_val_t attr_val = { - .type = ESP_MATTER_VAL_TYPE_OBJECT, - .val.s = (char *)val - }; + esp_matter_attr_val_t attr_val = {.type = ESP_MATTER_VAL_TYPE_OBJECT, .val.s = (char *)val}; return attr_val; } esp_matter_attr_val_t esp_matter_array(const char *val) { - esp_matter_attr_val_t attr_val = { - .type = ESP_MATTER_VAL_TYPE_ARRAY, - .val.s = (char *)val - }; + esp_matter_attr_val_t attr_val = {.type = ESP_MATTER_VAL_TYPE_ARRAY, .val.s = (char *)val}; return attr_val; } -esp_err_t esp_matter_attribute_notify(const char *name, const char *endpoint, const char *attribute, esp_matter_attr_val_t val) +esp_err_t esp_matter_attribute_notify(const char *name, const char *endpoint, const char *attribute, + esp_matter_attr_val_t val) { if (!esp_matter) { ESP_LOGE(TAG, "Init not done"); @@ -98,7 +81,8 @@ esp_err_t esp_matter_attribute_notify(const char *name, const char *endpoint, co return ESP_ERR_INVALID_ARG; } - /* Note: Even if a callback has not been added previously using esp_matter_attribute_callback_add(), it can still call this API to notify others. If this behaviour is to be changed, a check for name can be added here. */ + /* Note: Even if a callback has not been added previously using esp_matter_attribute_callback_add(), it can still + * call this API to notify others. If this behaviour is to be changed, a check for name can be added here. */ /* Print */ if (val.type == ESP_MATTER_VAL_TYPE_BOOLEAN) { @@ -107,7 +91,8 @@ esp_err_t esp_matter_attribute_notify(const char *name, const char *endpoint, co ESP_LOGI(TAG, "********** %s changed %s's %s to %d **********", name, endpoint, attribute, val.val.i); } else if (val.type == ESP_MATTER_VAL_TYPE_FLOAT) { ESP_LOGI(TAG, "********** %s changed %s's %s to %f **********", name, endpoint, attribute, val.val.f); - } else if (val.type == ESP_MATTER_VAL_TYPE_STRING || val.type == ESP_MATTER_VAL_TYPE_OBJECT || val.type == ESP_MATTER_VAL_TYPE_ARRAY) { + } else if (val.type == ESP_MATTER_VAL_TYPE_STRING || val.type == ESP_MATTER_VAL_TYPE_OBJECT || + val.type == ESP_MATTER_VAL_TYPE_ARRAY) { ESP_LOGI(TAG, "********** %s changed %s's %s to %s **********", name, endpoint, attribute, val.val.s); } else { ESP_LOGI(TAG, "********** %s changed %s's %s to **********", name, endpoint, attribute); diff --git a/components/esp_matter/esp_matter.h b/components/esp_matter/esp_matter.h index 38a25bc70..5c48be3e0 100644 --- a/components/esp_matter/esp_matter.h +++ b/components/esp_matter/esp_matter.h @@ -15,15 +15,14 @@ #pragma once #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif +#include #include #include -#include -#define REMAP_TO_RANGE(value, from, to) value * to / from +#define REMAP_TO_RANGE(value, from, to) value *to / from /** ESP Matter Attribute Value type */ typedef enum { @@ -68,7 +67,8 @@ typedef struct { * @return ESP_OK on success. * @return error in case of failure. */ -typedef esp_err_t (*esp_matter_attribute_callback_t)(const char *endpoint, const char *attribute, esp_matter_attr_val_t val, void *priv_data); +typedef esp_err_t (*esp_matter_attribute_callback_t)(const char *endpoint, const char *attribute, + esp_matter_attr_val_t val, void *priv_data); /** * Initialise a Boolean value @@ -134,7 +134,8 @@ esp_matter_attr_val_t esp_matter_array(const char *val); /** Add callback * - * Add a new callback. The callback will then be called if the value of any attributes have been changed by some other callback. + * Add a new callback. The callback will then be called if the value of any attributes have been changed by some other + * callback. * * @param[in] name Callback name * @param[in] callback Callback for value change @@ -144,7 +145,8 @@ esp_matter_attr_val_t esp_matter_array(const char *val); * @return ESP_OK on success. * @return error in case of failure. */ -esp_err_t esp_matter_attribute_callback_add(const char *name, esp_matter_attribute_callback_t callback, void *priv_data); +esp_err_t esp_matter_attribute_callback_add(const char *name, esp_matter_attribute_callback_t callback, + void *priv_data); /** Remove callback * @@ -169,7 +171,8 @@ esp_err_t esp_matter_attribute_callback_remove(const char *name); * @return ESP_OK on success. * @return error in case of failure. */ -esp_err_t esp_matter_attribute_notify(const char *name, const char *endpoint, const char *attribute, esp_matter_attr_val_t val); +esp_err_t esp_matter_attribute_notify(const char *name, const char *endpoint, const char *attribute, + esp_matter_attr_val_t val); /** Initialize ESP Matter * diff --git a/components/esp_matter/esp_matter_standard.h b/components/esp_matter/esp_matter_standard.h index e16bafdd0..5a4265d96 100644 --- a/components/esp_matter/esp_matter_standard.h +++ b/components/esp_matter/esp_matter_standard.h @@ -15,19 +15,18 @@ #pragma once #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /********** STANDARD ENDPOINT NAMES **********/ -#define ESP_MATTER_ENDPOINT_LIGHT "Light" +#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" +#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 } diff --git a/components/esp_matter_console/esp_matter_console.cpp b/components/esp_matter_console/esp_matter_console.cpp index e50f3137f..9dbc8f69b 100644 --- a/components/esp_matter_console/esp_matter_console.cpp +++ b/components/esp_matter_console/esp_matter_console.cpp @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include #include #include +#include -#include #include +#include #define MAX_CONSOLE_COMMANDS CONFIG_ESP_MATTER_CONSOLE_MAX_COMMANDS @@ -47,7 +47,7 @@ static void esp_matter_console_print_help() } } -static esp_err_t esp_matter_console_help_handler(int argc, char** argv) +static esp_err_t esp_matter_console_help_handler(int argc, char **argv) { esp_matter_console_print_help(); return ESP_OK; @@ -55,7 +55,7 @@ static esp_err_t esp_matter_console_help_handler(int argc, char** argv) static esp_err_t esp_matter_console_register_default_commands() { - esp_matter_console_command_t command= { + esp_matter_console_command_t command = { .name = "help", .description = "Print help", .handler = esp_matter_console_help_handler, @@ -63,9 +63,10 @@ static esp_err_t esp_matter_console_register_default_commands() return esp_matter_console_add_command(&command); } -static CHIP_ERROR esp_matter_console_common_handler(int argc, char** argv) +static CHIP_ERROR esp_matter_console_common_handler(int argc, char **argv) { - /* This common handler is added to avoid adding `CHIP_ERROR` and its component requirements in other esp-matter components */ + /* This common handler is added to avoid adding `CHIP_ERROR` and its component requirements in other esp-matter + * components */ if (argc <= 0) { esp_matter_console_print_help(); return CHIP_NO_ERROR; @@ -76,7 +77,7 @@ static CHIP_ERROR esp_matter_console_common_handler(int argc, char** argv) ESP_LOGW(TAG, "No handler set for the command: %s", argv[0]); return CHIP_NO_ERROR; } - if (commands[i].handler(argc - 1, &argv[1]) == ESP_OK) { /* Removing the first argument from argv */ + if (commands[i].handler(argc - 1, &argv[1]) == ESP_OK) { /* Removing the first argument from argv */ return CHIP_NO_ERROR; } /* The command handler returned error */ diff --git a/components/esp_matter_console/esp_matter_console.h b/components/esp_matter_console/esp_matter_console.h index c38fec90b..1ace4cc56 100644 --- a/components/esp_matter_console/esp_matter_console.h +++ b/components/esp_matter_console/esp_matter_console.h @@ -17,8 +17,7 @@ #include #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /** Callback for console commands @@ -28,7 +27,7 @@ extern "C" * @return ESP_OK on success. * @return error in case of failure. */ -typedef esp_err_t (*esp_matter_console_handler_t)(int argc, char** argv); +typedef esp_err_t (*esp_matter_console_handler_t)(int argc, char **argv); /** ESP Matter Console Command */ typedef struct { diff --git a/device_hal/button_driver/hollow/button_driver.c b/device_hal/button_driver/hollow/button_driver.c index fa3292384..f4f7e38ec 100644 --- a/device_hal/button_driver/hollow/button_driver.c +++ b/device_hal/button_driver/hollow/button_driver.c @@ -11,8 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License -#include #include +#include static const char *TAG = "button_driver_hollow"; diff --git a/device_hal/button_driver/include/button_driver.h b/device_hal/button_driver/include/button_driver.h index c0e57f65a..08cc09559 100644 --- a/device_hal/button_driver/include/button_driver.h +++ b/device_hal/button_driver/include/button_driver.h @@ -15,8 +15,7 @@ #include #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif typedef struct { diff --git a/device_hal/device/esp32_devkit_c/device.c b/device_hal/device/esp32_devkit_c/device.c index d5b7c68f6..3d0a6b387 100644 --- a/device_hal/device/esp32_devkit_c/device.c +++ b/device_hal/device/esp32_devkit_c/device.c @@ -13,14 +13,14 @@ #include -#include #include +#include #define DEVICE_VERSION_1_0 #ifdef DEVICE_VERSION_1_0 -#define LED_GPIO_PIN 12 /* GPIO_NUM_12 */ -#define LED_CHANNEL 0 /* LEDC_CHANNEL_0 */ +#define LED_GPIO_PIN 12 /* GPIO_NUM_12 */ +#define LED_CHANNEL 0 /* LEDC_CHANNEL_0 */ #endif static const char *TAG = "device"; diff --git a/device_hal/device/esp32c3_devkit_m/device.c b/device_hal/device/esp32c3_devkit_m/device.c index 6010b208a..0a2728566 100644 --- a/device_hal/device/esp32c3_devkit_m/device.c +++ b/device_hal/device/esp32c3_devkit_m/device.c @@ -13,17 +13,16 @@ #include -#include #include +#include #define DEVICE_VERSION_1_0 #ifdef DEVICE_VERSION_1_0 -#define LED_GPIO_PIN 8 /* GPIO_NUM_8 */ -#define LED_CHANNEL 0 /* RMT_CHANNEL_0 */ +#define LED_GPIO_PIN 8 /* GPIO_NUM_8 */ +#define LED_CHANNEL 0 /* RMT_CHANNEL_0 */ #endif - static const char *TAG = "device"; static esp_err_t device_light_init() diff --git a/device_hal/device/esp32h2_devkit_c/device.c b/device_hal/device/esp32h2_devkit_c/device.c index 5fa9e7cb8..fa52a296a 100644 --- a/device_hal/device/esp32h2_devkit_c/device.c +++ b/device_hal/device/esp32h2_devkit_c/device.c @@ -13,12 +13,11 @@ #include -#include #include +#include -#define LED_GPIO_PIN 8 /* GPIO_NUM_8 */ -#define LED_CHANNEL 0 /* RMT_CHANNEL_0 */ - +#define LED_GPIO_PIN 8 /* GPIO_NUM_8 */ +#define LED_CHANNEL 0 /* RMT_CHANNEL_0 */ static const char *TAG = "device"; diff --git a/device_hal/device/include/device.h b/device_hal/device/include/device.h index b1c46aff1..7fffa9d72 100644 --- a/device_hal/device/include/device.h +++ b/device_hal/device/include/device.h @@ -15,8 +15,7 @@ #include #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif esp_err_t device_init(); diff --git a/device_hal/device/m5stack/device.c b/device_hal/device/m5stack/device.c index 93090c239..5de9bdd2e 100644 --- a/device_hal/device/m5stack/device.c +++ b/device_hal/device/m5stack/device.c @@ -13,14 +13,14 @@ #include -#include #include +#include #define DEVICE_VERSION_1_0 #ifdef DEVICE_VERSION_1_0 -#define LED_GPIO_PIN 32 /* PIN_NUM_BCKL for M5Stack TFT */ -#define LED_CHANNEL 7 /* LEDC_CHANNEL_7 */ +#define LED_GPIO_PIN 32 /* PIN_NUM_BCKL for M5Stack TFT */ +#define LED_CHANNEL 7 /* LEDC_CHANNEL_7 */ #endif static const char *TAG = "device"; diff --git a/device_hal/light_driver/gpio/light_driver.c b/device_hal/light_driver/gpio/light_driver.c index 9097e02f1..94a62152c 100644 --- a/device_hal/light_driver/gpio/light_driver.c +++ b/device_hal/light_driver/gpio/light_driver.c @@ -11,8 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License -#include #include +#include #include #include @@ -122,5 +122,5 @@ uint8_t light_driver_get_saturation() uint32_t light_driver_get_temperature() { - return 0; + return 0; } diff --git a/device_hal/light_driver/hollow/light_driver.c b/device_hal/light_driver/hollow/light_driver.c index 1dd3f3a75..c67ee0f12 100644 --- a/device_hal/light_driver/hollow/light_driver.c +++ b/device_hal/light_driver/hollow/light_driver.c @@ -11,9 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License +#include #include #include -#include static const char *TAG = "light_driver_hollow"; static bool current_power = false; diff --git a/device_hal/light_driver/include/color_format.h b/device_hal/light_driver/include/color_format.h index 7c9fe1e39..53e4c5923 100644 --- a/device_hal/light_driver/include/color_format.h +++ b/device_hal/light_driver/include/color_format.h @@ -15,8 +15,7 @@ #include #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif typedef struct { @@ -32,7 +31,7 @@ typedef struct { void temp_to_hs(uint32_t temperature, HS_color_t *HS); -void hsv_to_rgb(HS_color_t HS,uint8_t brightness, RGB_color_t *RGB); +void hsv_to_rgb(HS_color_t HS, uint8_t brightness, RGB_color_t *RGB); #ifdef __cplusplus } diff --git a/device_hal/light_driver/include/light_driver.h b/device_hal/light_driver/include/light_driver.h index 3c1ab8a73..1174ede25 100644 --- a/device_hal/light_driver/include/light_driver.h +++ b/device_hal/light_driver/include/light_driver.h @@ -15,8 +15,7 @@ #include #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif typedef struct { diff --git a/device_hal/light_driver/utils/color_format.c b/device_hal/light_driver/utils/color_format.c index cd0ad8c67..73f5e812d 100644 --- a/device_hal/light_driver/utils/color_format.c +++ b/device_hal/light_driver/utils/color_format.c @@ -13,44 +13,44 @@ #include -void hsv_to_rgb(HS_color_t HS,uint8_t brightness, RGB_color_t *RGB) +void hsv_to_rgb(HS_color_t HS, uint8_t brightness, RGB_color_t *RGB) { - uint16_t sector = HS.hue / 60; + uint16_t sector = HS.hue / 60; uint16_t rgb_max = brightness; uint16_t rgb_min = rgb_max * (100 - HS.saturation) / 100; - uint16_t offset = HS.hue % 60; + uint16_t offset = HS.hue % 60; uint16_t rgb_adj = (rgb_max - rgb_min) * offset / 60; switch (sector) { case 0: - RGB->red = rgb_max; + RGB->red = rgb_max; RGB->green = rgb_min + rgb_adj; - RGB->blue = rgb_min; + RGB->blue = rgb_min; break; case 1: - RGB->red = rgb_max - rgb_adj; + RGB->red = rgb_max - rgb_adj; RGB->green = rgb_max; - RGB->blue = rgb_min; + RGB->blue = rgb_min; break; case 2: - RGB->red = rgb_min; + RGB->red = rgb_min; RGB->green = rgb_max; - RGB->blue = rgb_min + rgb_adj; + RGB->blue = rgb_min + rgb_adj; break; case 3: - RGB->red = rgb_min; + RGB->red = rgb_min; RGB->green = rgb_max - rgb_adj; - RGB->blue = rgb_max; + RGB->blue = rgb_max; break; case 4: - RGB->red = rgb_min + rgb_adj; + RGB->red = rgb_min + rgb_adj; RGB->green = rgb_min; - RGB->blue = rgb_max; + RGB->blue = rgb_max; break; default: - RGB->red = rgb_max; + RGB->red = rgb_max; RGB->green = rgb_min; - RGB->blue = rgb_max - rgb_adj; + RGB->blue = rgb_max - rgb_adj; break; } } @@ -60,16 +60,16 @@ void hsv_to_rgb(HS_color_t HS,uint8_t brightness, RGB_color_t *RGB) // saturation= temp_table[(temp - 600) / 100].saturation // 600<= temp <= 10000 const HS_color_t temp_table[] = { - {4, 100}, {8, 100}, {11, 100}, {14, 100}, {16, 100}, {18, 100}, {20, 100}, {22, 100}, {24, 100}, {25, 100}, {27, 100}, - {28, 100},{30, 100}, {31, 100}, {31, 95}, {30, 89}, {30, 85}, {29, 80}, {29, 76}, {29, 73}, {29, 69}, {28, 66}, {28, 63}, - {28, 60}, {28, 57}, {28, 54}, {28, 52}, {27, 49}, {27, 47}, {27, 45}, {27, 43}, {27, 41}, {27, 39}, {27, 37}, {27, 35}, - {27, 33}, {27, 31}, {27, 30}, {27, 28}, {27, 26}, {27, 25}, {27, 23}, {27, 22}, {27, 21}, {27, 19}, {27, 18}, {27, 17}, - {27, 15}, {28, 14}, {28, 13}, {28, 12}, {29, 10}, {29, 9}, {30, 8}, {31, 7}, {32, 6}, {34, 5}, {36, 4}, {41, 3}, {49, 2}, - {0, 0}, {294, 2}, {265, 3}, {251, 4}, {242, 5}, {237, 6}, {233, 7}, {231, 8}, {229, 9}, {228, 10}, {227, 11}, {226, 11}, - {226, 12}, {225, 13}, {225, 13}, {224, 14}, {224, 14}, {224, 15}, {224, 15}, {223, 16}, {223, 16}, {223, 17}, {223, 17}, - {223, 17}, {222, 18}, {222, 18}, {222, 19}, {222, 19}, {222, 19}, {222, 19}, {222, 20}, {222, 20}, {222, 20}, {222, 21}, - {222, 21} -}; + {4, 100}, {8, 100}, {11, 100}, {14, 100}, {16, 100}, {18, 100}, {20, 100}, {22, 100}, {24, 100}, {25, 100}, + {27, 100}, {28, 100}, {30, 100}, {31, 100}, {31, 95}, {30, 89}, {30, 85}, {29, 80}, {29, 76}, {29, 73}, + {29, 69}, {28, 66}, {28, 63}, {28, 60}, {28, 57}, {28, 54}, {28, 52}, {27, 49}, {27, 47}, {27, 45}, + {27, 43}, {27, 41}, {27, 39}, {27, 37}, {27, 35}, {27, 33}, {27, 31}, {27, 30}, {27, 28}, {27, 26}, + {27, 25}, {27, 23}, {27, 22}, {27, 21}, {27, 19}, {27, 18}, {27, 17}, {27, 15}, {28, 14}, {28, 13}, + {28, 12}, {29, 10}, {29, 9}, {30, 8}, {31, 7}, {32, 6}, {34, 5}, {36, 4}, {41, 3}, {49, 2}, + {0, 0}, {294, 2}, {265, 3}, {251, 4}, {242, 5}, {237, 6}, {233, 7}, {231, 8}, {229, 9}, {228, 10}, + {227, 11}, {226, 11}, {226, 12}, {225, 13}, {225, 13}, {224, 14}, {224, 14}, {224, 15}, {224, 15}, {223, 16}, + {223, 16}, {223, 17}, {223, 17}, {223, 17}, {222, 18}, {222, 18}, {222, 19}, {222, 19}, {222, 19}, {222, 19}, + {222, 20}, {222, 20}, {222, 20}, {222, 21}, {222, 21}}; void temp_to_hs(uint32_t temperature, HS_color_t *HS) { @@ -80,7 +80,7 @@ void temp_to_hs(uint32_t temperature, HS_color_t *HS) } if (temperature > 10000) { HS->hue = 222; - HS->saturation = 21 + (temperature -10000) * 41 / 990000; + HS->saturation = 21 + (temperature - 10000) * 41 / 990000; return; } HS->hue = temp_table[(temperature - 600) / 100].hue; diff --git a/device_hal/light_driver/vled/light_driver.c b/device_hal/light_driver/vled/light_driver.c index 317a47a2d..a3cc029ef 100644 --- a/device_hal/light_driver/vled/light_driver.c +++ b/device_hal/light_driver/vled/light_driver.c @@ -11,15 +11,15 @@ // See the License for the specific language governing permissions and // limitations under the License -#include -#include -#include #include +#include +#include +#include #include #include -#include #include +#include #define TFT_SPI_CLOCK_INIT_HZ 8000000 #define LEDC_PWM_HZ 1000 @@ -41,27 +41,27 @@ static void SetupBrightnessControl(light_driver_config_t *config) memset(&ledc_timer, 0, sizeof(ledc_timer)); led_driver_channel = config->channel; - ledc_timer.duty_resolution = LEDC_TIMER_8_BIT; // resolution of PWM duty - ledc_timer.freq_hz = LEDC_PWM_HZ; // frequency of PWM signal - ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE; // timer mode - ledc_timer.timer_num = LEDC_TIMER_0; // timer index + ledc_timer.duty_resolution = LEDC_TIMER_8_BIT; // resolution of PWM duty + ledc_timer.freq_hz = LEDC_PWM_HZ; // frequency of PWM signal + ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE; // timer mode + ledc_timer.timer_num = LEDC_TIMER_0; // timer index ledc_timer_config(&ledc_timer); ledc_timer_set(LEDC_HIGH_SPEED_MODE, LEDC_TIMER_0, LEDC_PWM_HZ, LEDC_TIMER_8_BIT, LEDC_REF_TICK); ledc_channel_config_t ledc_channel; memset(&ledc_channel, 0, sizeof(ledc_channel)); - ledc_channel.channel = led_driver_channel; - ledc_channel.duty = BRIGHTNESS_MAX; - ledc_channel.gpio_num = config->gpio; + ledc_channel.channel = led_driver_channel; + ledc_channel.duty = BRIGHTNESS_MAX; + ledc_channel.gpio_num = config->gpio; ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE; - ledc_channel.timer_sel = LEDC_TIMER_0; + ledc_channel.timer_sel = LEDC_TIMER_0; ledc_channel_config(&ledc_channel); } static void SetDisplayBrightness(uint8_t brightness) { if (ledc_set_duty(LEDC_HIGH_SPEED_MODE, led_driver_channel, brightness) || - ledc_update_duty(LEDC_HIGH_SPEED_MODE, led_driver_channel)) { + ledc_update_duty(LEDC_HIGH_SPEED_MODE, led_driver_channel)) { ESP_LOGE(TAG, "Failed to set display brightness..."); } } @@ -71,21 +71,21 @@ static esp_err_t InitDisplay() esp_err_t err; spi_lobo_device_handle_t spi; spi_lobo_bus_config_t buscfg; - memset((void *) &buscfg, 0, sizeof(buscfg)); - buscfg.miso_io_num = PIN_NUM_MISO; // set SPI MISO pin - buscfg.mosi_io_num = PIN_NUM_MOSI; // set SPI MOSI pin - buscfg.sclk_io_num = PIN_NUM_CLK; // set SPI CLK pin + memset((void *)&buscfg, 0, sizeof(buscfg)); + buscfg.miso_io_num = PIN_NUM_MISO; // set SPI MISO pin + buscfg.mosi_io_num = PIN_NUM_MOSI; // set SPI MOSI pin + buscfg.sclk_io_num = PIN_NUM_CLK; // set SPI CLK pin buscfg.quadwp_io_num = -1; buscfg.quadhd_io_num = -1; spi_lobo_device_interface_config_t devcfg; - memset((void *) &devcfg, 0, sizeof(devcfg)); - devcfg.clock_speed_hz = TFT_SPI_CLOCK_INIT_HZ; - devcfg.mode = 0; // SPI mode 0 - devcfg.spics_io_num = -1; // we will use external CS pin - devcfg.spics_ext_io_num = PIN_NUM_CS; // external CS pi - devcfg.flags = LB_SPI_DEVICE_HALFDUPLEX; // ALWAYS SET to HALF DUPLEX MODE!! for display spi - tft_max_rdclock = TFT_SPI_CLOCK_INIT_HZ; + memset((void *)&devcfg, 0, sizeof(devcfg)); + devcfg.clock_speed_hz = TFT_SPI_CLOCK_INIT_HZ; + devcfg.mode = 0; // SPI mode 0 + devcfg.spics_io_num = -1; // we will use external CS pin + devcfg.spics_ext_io_num = PIN_NUM_CS; // external CS pi + devcfg.flags = LB_SPI_DEVICE_HALFDUPLEX; // ALWAYS SET to HALF DUPLEX MODE!! for display spi + tft_max_rdclock = TFT_SPI_CLOCK_INIT_HZ; // Initialize all pins used by display driver. TFT_PinsInit(); @@ -115,7 +115,7 @@ static esp_err_t InitDisplay() TFT_setRotation(LANDSCAPE); TFT_resetclipwin(); - DisplayWidth = (uint16_t)(1 + tft_dispWin.x2 - tft_dispWin.x1); + DisplayWidth = (uint16_t)(1 + tft_dispWin.x2 - tft_dispWin.x1); DisplayHeight = (uint16_t)(1 + tft_dispWin.y2 - tft_dispWin.y1); ESP_LOGI(TAG, "Display initialized (height %u, width %u)", DisplayHeight, DisplayWidth); @@ -145,8 +145,8 @@ esp_err_t light_driver_set_power(bool power) esp_err_t light_driver_set_RGB() { TFT_fillWindow(TFT_BLACK); - TFT_fillCircle(DisplayWidth / 2, DisplayHeight / 2, DisplayWidth / 4, (color_t) {mRGB.red, mRGB.green, mRGB.blue}); - TFT_drawCircle(DisplayWidth / 2, DisplayHeight / 2, DisplayWidth / 4, (color_t) {255, 255, 255}); + TFT_fillCircle(DisplayWidth / 2, DisplayHeight / 2, DisplayWidth / 4, (color_t){mRGB.red, mRGB.green, mRGB.blue}); + TFT_drawCircle(DisplayWidth / 2, DisplayHeight / 2, DisplayWidth / 4, (color_t){255, 255, 255}); return ESP_OK; } esp_err_t light_driver_set_brightness(uint8_t brightness) @@ -181,7 +181,7 @@ esp_err_t light_driver_set_temperature(uint32_t temperature) { uint8_t brightness = current_power ? current_brightness : 0; current_temperature = temperature; - temp_to_hs(current_temperature,¤t_HS); + temp_to_hs(current_temperature, ¤t_HS); hsv_to_rgb(current_HS, brightness, &mRGB); return light_driver_set_RGB(); } diff --git a/device_hal/light_driver/ws2812/light_driver.c b/device_hal/light_driver/ws2812/light_driver.c index 3bc2fb20d..af1c757bd 100644 --- a/device_hal/light_driver/ws2812/light_driver.c +++ b/device_hal/light_driver/ws2812/light_driver.c @@ -11,10 +11,10 @@ // See the License for the specific language governing permissions and // limitations under the License -#include -#include -#include #include +#include +#include +#include #include static const char *TAG = "light_driver_ws2812"; diff --git a/examples/common/app_driver/app_driver.c b/examples/common/app_driver/app_driver.c index 75fe08dd2..09d030bcc 100644 --- a/examples/common/app_driver/app_driver.c +++ b/examples/common/app_driver/app_driver.c @@ -6,14 +6,14 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include #include +#include -#include -#include -#include #include #include +#include +#include +#include #include #define APP_DRIVER_NAME "Driver" @@ -24,32 +24,32 @@ static esp_matter_attr_val_t app_driver_attribute_get(const char *endpoint, cons static void app_driver_print_attr_val(const char *endpoint, const char *attribute, esp_matter_attr_val_t val) { - switch(val.type) { - case ESP_MATTER_VAL_TYPE_BOOLEAN: - ESP_LOGI(TAG, "%s's %s is %d", endpoint, attribute, val.val.b); - break; + switch (val.type) { + case ESP_MATTER_VAL_TYPE_BOOLEAN: + ESP_LOGI(TAG, "%s's %s is %d", endpoint, attribute, val.val.b); + break; - case ESP_MATTER_VAL_TYPE_INTEGER: - ESP_LOGI(TAG, "%s's %s is %d", endpoint, attribute, val.val.i); - break; + case ESP_MATTER_VAL_TYPE_INTEGER: + ESP_LOGI(TAG, "%s's %s is %d", endpoint, attribute, val.val.i); + break; - case ESP_MATTER_VAL_TYPE_FLOAT: - ESP_LOGI(TAG, "%s's %s is %f", endpoint, attribute, val.val.f); - break; + case ESP_MATTER_VAL_TYPE_FLOAT: + ESP_LOGI(TAG, "%s's %s is %f", endpoint, attribute, val.val.f); + break; - case ESP_MATTER_VAL_TYPE_STRING: - case ESP_MATTER_VAL_TYPE_OBJECT: - case ESP_MATTER_VAL_TYPE_ARRAY: - ESP_LOGI(TAG, "%s's %s is %s", endpoint, attribute, val.val.s); - break; + case ESP_MATTER_VAL_TYPE_STRING: + case ESP_MATTER_VAL_TYPE_OBJECT: + case ESP_MATTER_VAL_TYPE_ARRAY: + ESP_LOGI(TAG, "%s's %s is %s", endpoint, attribute, val.val.s); + break; - default: - ESP_LOGI(TAG, "%s's %s is ", endpoint, attribute); - break; + default: + ESP_LOGI(TAG, "%s's %s is ", endpoint, attribute); + break; } } -static esp_err_t app_driver_console_handler(int argc, char** argv) +static esp_err_t app_driver_console_handler(int argc, char **argv) { if (argc == 4 && strncmp(argv[0], "set", sizeof("set")) == 0) { char *endpoint_name = argv[1]; @@ -77,9 +77,11 @@ static esp_err_t app_driver_console_handler(int argc, char** argv) static void app_driver_register_commands() { - esp_matter_console_command_t command= { + esp_matter_console_command_t command = { .name = "driver", - .description = "This can be used to simulate on-device control. Usage: chip esp driver [value]. Example1: chip esp driver set Light Power 1. Example2: chip esp driver get Light Power.", + .description = "This can be used to simulate on-device control. Usage: chip esp driver " + " [value]. Example1: chip esp driver set Light Power 1. " + "Example2: chip esp driver get Light Power.", .handler = app_driver_console_handler, }; esp_matter_console_add_command(&command); @@ -110,7 +112,8 @@ static esp_matter_attr_val_t app_driver_attribute_get(const char *endpoint, cons return val; } -static esp_err_t app_driver_attribute_update(const char *endpoint, const char *attribute, esp_matter_attr_val_t val, void *priv_data) +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 (strncmp(endpoint, ESP_MATTER_ENDPOINT_LIGHT, sizeof(ESP_MATTER_ENDPOINT_LIGHT)) == 0) { diff --git a/examples/common/app_driver/app_driver.h b/examples/common/app_driver/app_driver.h index 1f6d4fe33..ca77abbf5 100644 --- a/examples/common/app_driver/app_driver.h +++ b/examples/common/app_driver/app_driver.h @@ -9,8 +9,7 @@ #pragma once #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #include diff --git a/examples/common/app_qrcode/app_qrcode.cpp b/examples/common/app_qrcode/app_qrcode.cpp index ca7e2274d..070530c23 100644 --- a/examples/common/app_qrcode/app_qrcode.cpp +++ b/examples/common/app_qrcode/app_qrcode.cpp @@ -8,20 +8,20 @@ #include -#include #include +#include #include -#include #include #include +#include -#include #include +#include using namespace ::chip; using namespace ::chip::DeviceLayer; -#define QRCODE_BASE_URL "https://dhrishi.github.io/connectedhomeip/qrcode.html" +#define QRCODE_BASE_URL "https://dhrishi.github.io/connectedhomeip/qrcode.html" static const char *TAG = "app_qrcode"; esp_err_t app_qrcode_get_payload(char **qrcode_text, char **short_manual_code_text, char **long_manual_code_text) @@ -68,12 +68,12 @@ esp_err_t app_qrcode_get_payload(char **qrcode_text, char **short_manual_code_te ESP_LOGI(TAG, "Product ID: %u (0x%x)", product_id, product_id); /* Set details */ - payload.version = 0; - payload.discriminator = discriminator; - payload.setUpPINCode = setup_pin_code; + payload.version = 0; + payload.discriminator = discriminator; + payload.setUpPINCode = setup_pin_code; payload.rendezvousInformation = RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE); - payload.vendorID = vendor_id; - payload.productID = product_id; + payload.vendorID = vendor_id; + payload.productID = product_id; /* Change format and alloc for qrcode */ QRCodeSetupPayloadGenerator qrcode_generator(payload); @@ -166,10 +166,12 @@ esp_err_t app_qrcode_print() /* Print */ ESP_LOGI(TAG, "Scan this QR code from the Matter phone app for Commissioning."); esp_qrcode_config_t cfg = ESP_QRCODE_CONFIG_DEFAULT(); - /* Changing the error tolerance to MED. This increases the size of the qr code and makes it more detailed. The default is set to LOW and sometimes the qr code scanner is not able to recognize that. */ + /* Changing the error tolerance to MED. This increases the size of the qr code and makes it more detailed. The + * default is set to LOW and sometimes the qr code scanner is not able to recognize that. */ cfg.qrcode_ecc_level = ESP_QRCODE_ECC_MED; esp_qrcode_generate(&cfg, qrcode_text); - ESP_LOGI(TAG, "If QR code is not visible, copy paste the URL in a browser: %s?data=%s", QRCODE_BASE_URL, qrcode_text); + ESP_LOGI(TAG, "If QR code is not visible, copy paste the URL in a browser: %s?data=%s", QRCODE_BASE_URL, + qrcode_text); /* Free */ free(qrcode_text); @@ -179,7 +181,9 @@ esp_err_t app_qrcode_print() } if (manual_code_exists) { - ESP_LOGI(TAG, "In case QR code is not supported, manual code mentioned above can be entered in the Matter phone app for Commissioning"); + ESP_LOGI(TAG, + "In case QR code is not supported, manual code mentioned above can be entered in the Matter phone app " + "for Commissioning"); } return err; diff --git a/examples/common/app_qrcode/app_qrcode.h b/examples/common/app_qrcode/app_qrcode.h index 59ce5dd7c..5f7d84f39 100644 --- a/examples/common/app_qrcode/app_qrcode.h +++ b/examples/common/app_qrcode/app_qrcode.h @@ -11,8 +11,7 @@ #include #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /** Print the QR code for commissioning diff --git a/examples/light/main/app_main.cpp b/examples/light/main/app_main.cpp index 82e63fabf..fb028b55b 100644 --- a/examples/light/main/app_main.cpp +++ b/examples/light/main/app_main.cpp @@ -6,13 +6,13 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include "esp_matter.h" -#include "esp_matter_standard.h" -#include "esp_matter_console.h" -#include "app_driver.h" -#include "app_qrcode.h" -#include "app_matter.h" #include "app_constants.h" +#include "app_driver.h" +#include "app_matter.h" +#include "app_qrcode.h" +#include "esp_matter.h" +#include "esp_matter_console.h" +#include "esp_matter_standard.h" #include "esp_err.h" #include "esp_log.h" @@ -24,31 +24,32 @@ #define APP_MAIN_NAME "Main" static const char *TAG = "app_main"; -static esp_err_t app_main_attribute_update(const char *endpoint, const char *attribute, esp_matter_attr_val_t val, void *priv_data) +static esp_err_t app_main_attribute_update(const char *endpoint, const char *attribute, esp_matter_attr_val_t val, + void *priv_data) { /* Just adding this callback to notify the application */ - switch(val.type) { - case ESP_MATTER_VAL_TYPE_BOOLEAN: - ESP_LOGD(TAG, "%s's %s is %d", endpoint, attribute, val.val.b); - break; + switch (val.type) { + case ESP_MATTER_VAL_TYPE_BOOLEAN: + ESP_LOGD(TAG, "%s's %s is %d", endpoint, attribute, val.val.b); + break; - case ESP_MATTER_VAL_TYPE_INTEGER: - ESP_LOGD(TAG, "%s's %s is %d", endpoint, attribute, val.val.i); - break; + case ESP_MATTER_VAL_TYPE_INTEGER: + ESP_LOGD(TAG, "%s's %s is %d", endpoint, attribute, val.val.i); + break; - case ESP_MATTER_VAL_TYPE_FLOAT: - ESP_LOGD(TAG, "%s's %s is %f", endpoint, attribute, val.val.f); - break; + case ESP_MATTER_VAL_TYPE_FLOAT: + ESP_LOGD(TAG, "%s's %s is %f", endpoint, attribute, val.val.f); + break; - case ESP_MATTER_VAL_TYPE_STRING: - case ESP_MATTER_VAL_TYPE_OBJECT: - case ESP_MATTER_VAL_TYPE_ARRAY: - ESP_LOGD(TAG, "%s's %s is %s", endpoint, attribute, val.val.s); - break; + case ESP_MATTER_VAL_TYPE_STRING: + case ESP_MATTER_VAL_TYPE_OBJECT: + case ESP_MATTER_VAL_TYPE_ARRAY: + ESP_LOGD(TAG, "%s's %s is %s", endpoint, attribute, val.val.s); + break; - default: - ESP_LOGD(TAG, "%s's %s is ", endpoint, attribute); - break; + default: + ESP_LOGD(TAG, "%s's %s is ", endpoint, attribute); + break; } return ESP_OK; } @@ -70,10 +71,14 @@ extern "C" void app_main() app_qrcode_print(); /* Set the default attribute values */ - 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)); + 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 esp_matter_console_init(); diff --git a/examples/light/main/app_matter.cpp b/examples/light/main/app_matter.cpp index b3500da7e..4df1523ef 100644 --- a/examples/light/main/app_matter.cpp +++ b/examples/light/main/app_matter.cpp @@ -6,14 +6,15 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include "esp_matter.h" -#include "esp_matter_standard.h" #include "app_matter.h" #include "app_constants.h" +#include "esp_matter.h" +#include "esp_matter_standard.h" #include "esp_heap_caps.h" #include "esp_log.h" +#include #include "app-common/zap-generated/att-storage.h" #include "app-common/zap-generated/attribute-id.h" #include "app-common/zap-generated/attribute-type.h" @@ -34,8 +35,8 @@ using chip::ClusterId; using chip::EndpointId; using chip::DeviceLayer::ChipDeviceEvent; using chip::DeviceLayer::ConnectivityMgr; -using chip::DeviceLayer::DeviceEventType::PublicEventTypes; using chip::DeviceLayer::PlatformMgr; +using chip::DeviceLayer::DeviceEventType::PublicEventTypes; #if CHIP_DEVICE_CONFIG_ENABLE_THREAD using chip::DeviceLayer::ThreadStackMgr; #endif @@ -190,7 +191,8 @@ static esp_matter_attr_val_t app_matter_get_attribute_val(char *attribute, int v return esp_matter_int(value); } -static esp_err_t app_matter_attribute_update(const char *endpoint, const char *attribute, esp_matter_attr_val_t val, void *priv_data) +static esp_err_t app_matter_attribute_update(const char *endpoint, const char *attribute, esp_matter_attr_val_t val, + void *priv_data) { EndpointId endpoint_id = app_matter_get_endpoint_id(endpoint); ClusterId cluster_id = app_matter_get_cluster_id(attribute); @@ -200,7 +202,8 @@ static esp_err_t app_matter_attribute_update(const char *endpoint, const char *a uint8_t value_remap = (uint8_t)app_matter_remap((char *)attribute, value, REMAP_STANDARD_TO_MATTER); ESP_LOGD(TAG, "Changing %s from standard: %d, to matter: %d\n", attribute, value, value_remap); - EmberAfStatus status = emberAfWriteAttribute(endpoint_id, cluster_id, attribute_id, CLUSTER_MASK_SERVER, (uint8_t *)&value_remap, attribute_type); + EmberAfStatus status = emberAfWriteAttribute(endpoint_id, cluster_id, attribute_id, CLUSTER_MASK_SERVER, + (uint8_t *)&value_remap, attribute_type); if (status != EMBER_ZCL_STATUS_SUCCESS) { ESP_LOGE(TAG, "Error updating attribute to matter"); return ESP_FAIL; @@ -208,7 +211,8 @@ static esp_err_t app_matter_attribute_update(const char *endpoint, const char *a return ESP_OK; } -void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId cluster, AttributeId attribute, uint8_t mask, uint16_t manufacturer, uint8_t type, uint16_t size, uint8_t *value) +void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId cluster, AttributeId attribute, uint8_t mask, + uint16_t manufacturer, uint8_t type, uint16_t size, uint8_t *value) { char *endpoint_name = (char *)app_matter_get_endpoint_name(endpoint); char *attribute_name = (char *)app_matter_get_attribute_name(cluster, attribute); diff --git a/examples/rainmaker_light/main/app_main.cpp b/examples/rainmaker_light/main/app_main.cpp index 4e110a86e..46b943679 100644 --- a/examples/rainmaker_light/main/app_main.cpp +++ b/examples/rainmaker_light/main/app_main.cpp @@ -6,14 +6,14 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include "esp_matter.h" -#include "esp_matter_standard.h" -#include "esp_matter_console.h" -#include "app_driver.h" -#include "app_qrcode.h" -#include "app_matter.h" #include "app_constants.h" +#include "app_driver.h" +#include "app_matter.h" +#include "app_qrcode.h" #include "app_rainmaker.h" +#include "esp_matter.h" +#include "esp_matter_console.h" +#include "esp_matter_standard.h" #include "esp_err.h" #include "esp_log.h" @@ -25,31 +25,32 @@ #define APP_MAIN_NAME "Main" static const char *TAG = "app_main"; -static esp_err_t app_main_attribute_update(const char *endpoint, const char *attribute, esp_matter_attr_val_t val, void *priv_data) +static esp_err_t app_main_attribute_update(const char *endpoint, const char *attribute, esp_matter_attr_val_t val, + void *priv_data) { /* Just adding this callback to notify the application */ - switch(val.type) { - case ESP_MATTER_VAL_TYPE_BOOLEAN: - ESP_LOGD(TAG, "%s's %s is %d", endpoint, attribute, val.val.b); - break; + switch (val.type) { + case ESP_MATTER_VAL_TYPE_BOOLEAN: + ESP_LOGD(TAG, "%s's %s is %d", endpoint, attribute, val.val.b); + break; - case ESP_MATTER_VAL_TYPE_INTEGER: - ESP_LOGD(TAG, "%s's %s is %d", endpoint, attribute, val.val.i); - break; + case ESP_MATTER_VAL_TYPE_INTEGER: + ESP_LOGD(TAG, "%s's %s is %d", endpoint, attribute, val.val.i); + break; - case ESP_MATTER_VAL_TYPE_FLOAT: - ESP_LOGD(TAG, "%s's %s is %f", endpoint, attribute, val.val.f); - break; + case ESP_MATTER_VAL_TYPE_FLOAT: + ESP_LOGD(TAG, "%s's %s is %f", endpoint, attribute, val.val.f); + break; - case ESP_MATTER_VAL_TYPE_STRING: - case ESP_MATTER_VAL_TYPE_OBJECT: - case ESP_MATTER_VAL_TYPE_ARRAY: - ESP_LOGD(TAG, "%s's %s is %s", endpoint, attribute, val.val.s); - break; + case ESP_MATTER_VAL_TYPE_STRING: + case ESP_MATTER_VAL_TYPE_OBJECT: + case ESP_MATTER_VAL_TYPE_ARRAY: + ESP_LOGD(TAG, "%s's %s is %s", endpoint, attribute, val.val.s); + break; - default: - ESP_LOGD(TAG, "%s's %s is ", endpoint, attribute); - break; + default: + ESP_LOGD(TAG, "%s's %s is ", endpoint, attribute); + break; } return ESP_OK; } @@ -74,10 +75,14 @@ extern "C" void app_main() app_rainmaker_init(); /* Set the default attribute values */ - 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)); + 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 esp_matter_console_init(); diff --git a/examples/rainmaker_light/main/app_matter.cpp b/examples/rainmaker_light/main/app_matter.cpp index 46dc76241..c212eda05 100644 --- a/examples/rainmaker_light/main/app_matter.cpp +++ b/examples/rainmaker_light/main/app_matter.cpp @@ -14,6 +14,7 @@ #include "esp_heap_caps.h" #include "esp_log.h" +#include #include "app-common/zap-generated/att-storage.h" #include "app-common/zap-generated/attribute-id.h" #include "app-common/zap-generated/attribute-type.h" diff --git a/examples/rainmaker_light/main/app_rainmaker.c b/examples/rainmaker_light/main/app_rainmaker.c index 4cd6f2eac..75cd174bc 100644 --- a/examples/rainmaker_light/main/app_rainmaker.c +++ b/examples/rainmaker_light/main/app_rainmaker.c @@ -6,32 +6,32 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include +#include #include #include -#include #include +#include #include -#include -#include -#include #include #include +#include +#include +#include #include -#include -#include -#include -#include #include "app_constants.h" +#include +#include +#include +#include #define APP_RAINMAKER_NAME "RainMaker" static const char *TAG = "app_rainmaker"; esp_rmaker_device_t *light_device; -static esp_err_t app_rainmaker_console_handler(int argc, char** argv) +static esp_err_t app_rainmaker_console_handler(int argc, char **argv) { if (argc == 3 && strncmp(argv[0], "add-user", sizeof("add-user")) == 0) { printf("%s: Starting user-node mapping\n", TAG); @@ -47,9 +47,10 @@ static esp_err_t app_rainmaker_console_handler(int argc, char** argv) static void app_rainmaker_register_commands() { - esp_matter_console_command_t command= { + esp_matter_console_command_t command = { .name = "rainmaker", - .description = "Initiate ESP RainMaker User-Node mapping from the node. Usage: chip esp rainmaker add-user ", + .description = "Initiate ESP RainMaker User-Node mapping from the node. Usage: chip esp rainmaker add-user " + " ", .handler = app_rainmaker_console_handler, }; esp_matter_console_add_command(&command); @@ -96,7 +97,8 @@ static esp_matter_attr_val_t esp_rmaker_get_matter_val(esp_rmaker_param_val_t va } /* Callback to handle changes received from other sources */ -static esp_err_t app_rainmaker_attribute_update(const char *endpoint, const char *attribute, esp_matter_attr_val_t val, void *priv_data) +static esp_err_t app_rainmaker_attribute_update(const char *endpoint, const char *attribute, esp_matter_attr_val_t val, + void *priv_data) { const esp_rmaker_node_t *node = esp_rmaker_get_node(); esp_rmaker_device_t *device = esp_rmaker_node_get_device_by_name(node, endpoint); @@ -150,11 +152,13 @@ esp_err_t app_rainmaker_init() 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_MATTER_ATTR_BRIGHTNESS, 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_MATTER_ATTR_HUE, DEFAULT_HUE)); - esp_rmaker_device_add_param(light_device, esp_rmaker_saturation_param_create(ESP_MATTER_ATTR_SATURATION, 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); diff --git a/examples/rainmaker_light/main/app_rainmaker.h b/examples/rainmaker_light/main/app_rainmaker.h index d96746cb0..cc1d8237a 100644 --- a/examples/rainmaker_light/main/app_rainmaker.h +++ b/examples/rainmaker_light/main/app_rainmaker.h @@ -11,13 +11,13 @@ #include #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /** Initialize ESP RainMaker * - * This initializes the devices and params for RainMaker, corresponding to the endpoint and attributes. It also adds RainMaker features like OTA, Scheduling, etc. + * This initializes the devices and params for RainMaker, corresponding to the endpoint and attributes. It also adds + * RainMaker features like OTA, Scheduling, etc. * * @return ESP_OK on success. * @return error in case of failure.