mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
ci: format current code
This commit is contained in:
@@ -12,9 +12,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_matter.h>
|
||||
#include <string.h>
|
||||
|
||||
#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 <invalid value> **********", name, endpoint, attribute);
|
||||
|
||||
@@ -15,15 +15,14 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <esp_err.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <esp_err.h>
|
||||
|
||||
#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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
#include <esp_log.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <lib/shell/Engine.h>
|
||||
#include <esp_matter_console.h>
|
||||
#include <lib/shell/Engine.h>
|
||||
|
||||
#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 */
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
#include <esp_err.h>
|
||||
|
||||
#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 {
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <button_driver.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
static const char *TAG = "button_driver_hollow";
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
#include <esp_err.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
#include <light_driver.h>
|
||||
#include <button_driver.h>
|
||||
#include <light_driver.h>
|
||||
|
||||
#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";
|
||||
|
||||
@@ -13,17 +13,16 @@
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
#include <light_driver.h>
|
||||
#include <button_driver.h>
|
||||
#include <light_driver.h>
|
||||
|
||||
#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()
|
||||
|
||||
@@ -13,12 +13,11 @@
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
#include <light_driver.h>
|
||||
#include <button_driver.h>
|
||||
#include <light_driver.h>
|
||||
|
||||
#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";
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
#include <esp_err.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
esp_err_t device_init();
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
#include <light_driver.h>
|
||||
#include <button_driver.h>
|
||||
#include <light_driver.h>
|
||||
|
||||
#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";
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <driver/ledc.h>
|
||||
#include <esp_log.h>
|
||||
#include <hal/ledc_types.h>
|
||||
|
||||
#include <light_driver.h>
|
||||
@@ -122,5 +122,5 @@ uint8_t light_driver_get_saturation()
|
||||
|
||||
uint32_t light_driver_get_temperature()
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
#include <color_format.h>
|
||||
#include <esp_log.h>
|
||||
#include <light_driver.h>
|
||||
#include <color_format.h>
|
||||
|
||||
static const char *TAG = "light_driver_hollow";
|
||||
static bool current_power = false;
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
#include <esp_err.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -13,44 +13,44 @@
|
||||
|
||||
#include <color_format.h>
|
||||
|
||||
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;
|
||||
|
||||
@@ -11,15 +11,15 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
#include <string.h>
|
||||
#include <esp_system.h>
|
||||
#include <esp_log.h>
|
||||
#include <driver/ledc.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_system.h>
|
||||
#include <string.h>
|
||||
#include <tft.h>
|
||||
#include <tftspi.h>
|
||||
|
||||
#include <light_driver.h>
|
||||
#include <color_format.h>
|
||||
#include <light_driver.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <driver/rmt.h>
|
||||
#include <led_strip.h>
|
||||
#include <color_format.h>
|
||||
#include <driver/rmt.h>
|
||||
#include <esp_log.h>
|
||||
#include <led_strip.h>
|
||||
#include <light_driver.h>
|
||||
|
||||
static const char *TAG = "light_driver_ws2812";
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <esp_log.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <esp_matter.h>
|
||||
#include <esp_matter_standard.h>
|
||||
#include <esp_matter_console.h>
|
||||
#include <app_driver.h>
|
||||
#include <device.h>
|
||||
#include <esp_matter.h>
|
||||
#include <esp_matter_console.h>
|
||||
#include <esp_matter_standard.h>
|
||||
#include <light_driver.h>
|
||||
|
||||
#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 <invalid value>", endpoint, attribute);
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI(TAG, "%s's %s is <invalid value>", 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 <set|get> <endpoint_name> <attribute_name> [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 <set|get> "
|
||||
"<endpoint_name> <attribute_name> [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) {
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <esp_err.h>
|
||||
|
||||
@@ -8,20 +8,20 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <core/CHIPError.h>
|
||||
#include <esp_log.h>
|
||||
#include <platform/CHIPDeviceLayer.h>
|
||||
#include <setup_payload/SetupPayload.h>
|
||||
#include <setup_payload/ManualSetupPayloadGenerator.h>
|
||||
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
|
||||
#include <setup_payload/SetupPayload.h>
|
||||
|
||||
#include <qrcode.h>
|
||||
#include <app_qrcode.h>
|
||||
#include <qrcode.h>
|
||||
|
||||
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;
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
#include <esp_err.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Print the QR code for commissioning
|
||||
|
||||
@@ -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 <invalid value>", endpoint, attribute);
|
||||
break;
|
||||
default:
|
||||
ESP_LOGD(TAG, "%s's %s is <invalid value>", 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();
|
||||
|
||||
@@ -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 <cstdint>
|
||||
#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);
|
||||
|
||||
@@ -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 <invalid value>", endpoint, attribute);
|
||||
break;
|
||||
default:
|
||||
ESP_LOGD(TAG, "%s's %s is <invalid value>", 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();
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include "app-common/zap-generated/att-storage.h"
|
||||
#include "app-common/zap-generated/attribute-id.h"
|
||||
#include "app-common/zap-generated/attribute-type.h"
|
||||
|
||||
@@ -6,32 +6,32 @@
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <esp_log.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <esp_log.h>
|
||||
#include <nvs_flash.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <esp_rmaker_core.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
#include <esp_rmaker_standard_devices.h>
|
||||
#include <esp_rmaker_standard_types.h>
|
||||
#include <esp_rmaker_ota.h>
|
||||
#include <esp_rmaker_schedule.h>
|
||||
#include <esp_rmaker_standard_devices.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
#include <esp_rmaker_standard_types.h>
|
||||
#include <esp_rmaker_user_mapping.h>
|
||||
|
||||
#include <esp_matter.h>
|
||||
#include <esp_matter_standard.h>
|
||||
#include <esp_matter_console.h>
|
||||
#include <app_rainmaker.h>
|
||||
#include "app_constants.h"
|
||||
#include <app_rainmaker.h>
|
||||
#include <esp_matter.h>
|
||||
#include <esp_matter_console.h>
|
||||
#include <esp_matter_standard.h>
|
||||
|
||||
#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 <user_id> <secret_key>",
|
||||
.description = "Initiate ESP RainMaker User-Node mapping from the node. Usage: chip esp rainmaker add-user "
|
||||
"<user_id> <secret_key>",
|
||||
.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);
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
#include <esp_err.h>
|
||||
|
||||
#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.
|
||||
|
||||
Reference in New Issue
Block a user