Zigbee: Add light example
* provide light example for acting as zigbee coordinator, router and end-device * remove unused componenent for example usage * remove unused variable * clean up unused header include for example * update the license header * update copyright * Add readme for instruction adding esp-zboss-lib component * esp-idf:update copy_right_check ignore file * CI: fix the ci check error from pipeline * sdkconfig: default set change for better user use * use Button (BOOT) as switch input * update the statemachine for debouncing * esp-zboss-lib: support lib 0.0.2 * fix warning issue from example
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS
|
||||
$ENV{IDF_PATH}/examples/common_components/led_strip
|
||||
)
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(light_bulb)
|
||||
@@ -0,0 +1,53 @@
|
||||
| Supported Targets | ESP32-H2 |
|
||||
| ----------------- | -------- |
|
||||
|
||||
# Light Bulb Example
|
||||
|
||||
(See the `README.md` file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
This test code shows how to configure Zigbee router device and use it as a light bulb
|
||||
|
||||
## Hardware Required
|
||||
|
||||
* One development board with ESP32-H2 SoC acting as Zigbee router (loaded with light bulb example)
|
||||
* A USB cable for power supply and programming
|
||||
* Choose another ESP32-H2 as Zigbee coordinator (see [light coordinator example](../light_coordinator))
|
||||
* Choose another ESP32-H2 as Zigbee end-device (see [light switch example](../light_switch))
|
||||
|
||||
## Configure the project
|
||||
|
||||
[**Mandatory**] Download esp-zboss-lib packages from [Espressif's component serivce](https://components.espressif.com/).
|
||||
You can add them to your project via `idf.py add-dependency espressif/esp-zboss-lib==0.0.2`
|
||||
|
||||
Before project configuration and build, make sure to set the correct chip target using `idf.py set-target esp32h2`.
|
||||
|
||||
## Build and Flash
|
||||
|
||||
Build the project, flash it to the board, and start the monitor tool to view the serial output by running `idf.py -p PORT flash monitor`.
|
||||
|
||||
(To exit the serial monitor, type ``Ctrl-]``.)
|
||||
|
||||
## Example Output
|
||||
|
||||
As you run the example, you will see the following log:
|
||||
|
||||
light bulb:
|
||||
I (9638) ESP_ZB_LIGHT: status: 255
|
||||
I (9638) ESP_ZB_LIGHT: Zigbee stack initialized
|
||||
I (9648) ESP_ZB_LIGHT: Start network steering
|
||||
I (12368) ESP_ZB_LIGHT: Joined network successfully (Extended PAN ID: f9:54:2d:01:a0:03:f7:84, PAN ID: 0xf5b5)
|
||||
I (12398) ESP_ZB_LIGHT: status: 0
|
||||
I (18158) ESP_ZB_LIGHT: on/off attribute setting to 1
|
||||
I (19388) ESP_ZB_LIGHT: on/off attribute setting to 0
|
||||
I (20418) ESP_ZB_LIGHT: on/off attribute setting to 1
|
||||
I (21558) ESP_ZB_LIGHT: on/off attribute setting to 0
|
||||
I (22478) ESP_ZB_LIGHT: on/off attribute setting to 1
|
||||
I (23088) ESP_ZB_LIGHT: on/off attribute setting to 0
|
||||
|
||||
## Light Control Functions
|
||||
|
||||
* By toggling the switch button (BOOT) on the ESP32-H2 board loaded with the `light switch` example, the LED on this board loaded with `light bulb` example will be on and off.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
|
||||
@@ -0,0 +1,6 @@
|
||||
idf_component_register(
|
||||
SRCS
|
||||
"esp_zb_light.c"
|
||||
"light_driver.c"
|
||||
INCLUDE_DIRS "."
|
||||
)
|
||||
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Espressif Systems (Shanghai) CO LTD
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Espressif Systems
|
||||
* integrated circuit in a product or a software update for such product,
|
||||
* must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* 4. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_zb_light.h"
|
||||
|
||||
static bulb_device_ctx_t esp_light_ctx = {
|
||||
/* basic cluster attributes data */
|
||||
.basic_attr.zcl_version = ZB_ZCL_VERSION,
|
||||
.basic_attr.power_source = ZB_ZCL_BASIC_POWER_SOURCE_UNKNOWN,
|
||||
/* identify cluster attributes data */
|
||||
.identify_attr.identify_time = 0,
|
||||
/* groups cluster attributes data */
|
||||
.groups_attr.name_support = 0,
|
||||
/* on/off cluster attributes data */
|
||||
.on_off_attr.on_off = ZB_ZCL_ON_OFF_IS_OFF,
|
||||
};
|
||||
|
||||
static const char *TAG = "ESP_ZB_LIGHT";
|
||||
/******************* Declare attributes ************************/
|
||||
|
||||
/* basic cluster attributes data */
|
||||
ZB_ZCL_DECLARE_BASIC_ATTRIB_LIST(basic_attr_list,
|
||||
&esp_light_ctx.basic_attr.zcl_version,
|
||||
&esp_light_ctx.basic_attr.power_source);
|
||||
|
||||
/* identify cluster attributes data */
|
||||
ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST(identify_attr_list,
|
||||
&esp_light_ctx.identify_attr.identify_time);
|
||||
|
||||
/* groups cluster attributes data */
|
||||
ZB_ZCL_DECLARE_GROUPS_ATTRIB_LIST(groups_attr_list,
|
||||
&esp_light_ctx.groups_attr.name_support);
|
||||
|
||||
/* scenes cluster attribute data */
|
||||
ZB_ZCL_DECLARE_SCENES_ATTRIB_LIST(scenes_attr_list,
|
||||
&esp_light_ctx.scenes_attr.scene_count,
|
||||
&esp_light_ctx.scenes_attr.current_scene,
|
||||
&esp_light_ctx.scenes_attr.current_group,
|
||||
&esp_light_ctx.scenes_attr.scene_valid,
|
||||
&esp_light_ctx.scenes_attr.name_support);
|
||||
|
||||
/* on/off cluster attributes data */
|
||||
ZB_ZCL_DECLARE_ON_OFF_ATTRIB_LIST(on_off_attr_list,
|
||||
&esp_light_ctx.on_off_attr.on_off);
|
||||
|
||||
/********************* Declare device **************************/
|
||||
ZB_HA_DECLARE_ON_OFF_OUTPUT_CLUSTER_LIST(custom_light_clusters,
|
||||
on_off_attr_list,
|
||||
basic_attr_list,
|
||||
identify_attr_list,
|
||||
groups_attr_list,
|
||||
scenes_attr_list);
|
||||
|
||||
ZB_HA_DECLARE_ON_OFF_OUTPUT_EP(custom_esp_light_ep,
|
||||
HA_ESP_LIGHT_ENDPOINT,
|
||||
custom_light_clusters);
|
||||
|
||||
ZB_HA_DECLARE_ON_OFF_OUTPUT_CTX(esp_zb_light_ctx,
|
||||
custom_esp_light_ep);
|
||||
|
||||
/********************* Define functions **************************/
|
||||
static void bdb_start_top_level_commissioning_cb(zb_uint8_t mode_mask)
|
||||
{
|
||||
if (!bdb_start_top_level_commissioning(mode_mask)) {
|
||||
ESP_LOGE(TAG, "In BDB commissioning, an error occurred (for example: the device has already been running)");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Zigbee zboss stack event signal handler.
|
||||
*
|
||||
* @param bufid Zigbee zboss stack buffer id used to pass signal.
|
||||
*/
|
||||
void zboss_signal_handler(zb_uint8_t bufid)
|
||||
{
|
||||
zb_uint8_t status = ZB_GET_APP_SIGNAL_STATUS(bufid);
|
||||
zb_zdo_app_signal_type_t sig = zb_get_app_signal(bufid, NULL);
|
||||
|
||||
switch (sig) {
|
||||
case ZB_ZDO_SIGNAL_SKIP_STARTUP:
|
||||
ESP_LOGI(TAG, "Zigbee stack initialized");
|
||||
bdb_start_top_level_commissioning(ZB_BDB_INITIALIZATION);
|
||||
break;
|
||||
case ZB_BDB_SIGNAL_DEVICE_FIRST_START:
|
||||
if (status == RET_OK) {
|
||||
ESP_LOGI(TAG, "Start network steering");
|
||||
bdb_start_top_level_commissioning(ZB_BDB_NETWORK_STEERING);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %d)", status);
|
||||
}
|
||||
break;
|
||||
case ZB_BDB_SIGNAL_STEERING:
|
||||
if (status == RET_OK) {
|
||||
zb_ext_pan_id_t extended_pan_id;
|
||||
zb_get_extended_pan_id(extended_pan_id);
|
||||
ESP_LOGI(TAG, "Joined network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx)",
|
||||
extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4],
|
||||
extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], extended_pan_id[0],
|
||||
ZB_PIBCACHE_PAN_ID());
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Network steering was not successful (status: %d)", status);
|
||||
ZB_SCHEDULE_APP_ALARM((zb_callback_t)bdb_start_top_level_commissioning_cb, ZB_BDB_NETWORK_STEERING, ZB_TIME_ONE_SECOND);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI(TAG, "status: %d", status);
|
||||
break;
|
||||
}
|
||||
if (bufid) {
|
||||
zb_buf_free(bufid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for turning on/off the light bulb.
|
||||
*
|
||||
* @param power Boolean light bulb state power on/off.
|
||||
*/
|
||||
static void esp_zb_light_set_value(zb_bool_t power)
|
||||
{
|
||||
ZB_ZCL_SET_ATTRIBUTE(HA_ESP_LIGHT_ENDPOINT,
|
||||
ZB_ZCL_CLUSTER_ID_ON_OFF,
|
||||
ZB_ZCL_CLUSTER_SERVER_ROLE,
|
||||
ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID,
|
||||
(zb_uint8_t *)&power,
|
||||
ZB_FALSE);
|
||||
|
||||
light_driver_set_power(power);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback function for handling attribute value from ZCL.
|
||||
*
|
||||
* @param bufid Zigbee zboss stack buffer id used to pass received data.
|
||||
*/
|
||||
static void esp_zb_light_cb(zb_bufid_t bufid)
|
||||
{
|
||||
zb_zcl_device_callback_param_t *p_device_cb_param = ZB_BUF_GET_PARAM(bufid, zb_zcl_device_callback_param_t);
|
||||
zb_zcl_device_callback_id_t device_cb_id = p_device_cb_param->device_cb_id;
|
||||
zb_uint16_t cluster_id = p_device_cb_param->cb_param.set_attr_value_param.cluster_id;
|
||||
zb_uint16_t attr_id = p_device_cb_param->cb_param.set_attr_value_param.attr_id;
|
||||
p_device_cb_param->status = RET_OK;
|
||||
|
||||
switch (device_cb_id) {
|
||||
/* ZCL set attribute value */
|
||||
case ZB_ZCL_SET_ATTR_VALUE_CB_ID:
|
||||
if (cluster_id == ZB_ZCL_CLUSTER_ID_ON_OFF) {
|
||||
uint8_t value = p_device_cb_param->cb_param.set_attr_value_param.values.data8;
|
||||
ESP_LOGI(TAG, "on/off attribute setting to %hd", value);
|
||||
|
||||
if (attr_id == ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID) {
|
||||
/* implemented light on/off control */
|
||||
esp_zb_light_set_value((zb_bool_t) value);
|
||||
}
|
||||
} else if (cluster_id == ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL) {
|
||||
uint16_t value = p_device_cb_param->cb_param.set_attr_value_param.values.data16;
|
||||
ESP_LOGI(TAG, "level control attribute setting to %hd", value);
|
||||
|
||||
if (attr_id == ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID) {
|
||||
/* implement light level control if needed */
|
||||
}
|
||||
} else if (cluster_id == ZB_ZCL_CLUSTER_ID_COLOR_CONTROL) {
|
||||
uint16_t value = p_device_cb_param->cb_param.set_attr_value_param.values.data8;
|
||||
ESP_LOGI(TAG, "attribute 0x%x setting to %d", attr_id, value);
|
||||
|
||||
if (attr_id == ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_HUE_ID) {
|
||||
/* implement light color change if needed */
|
||||
}
|
||||
} else {
|
||||
/* other clusters attribute handled here */
|
||||
ESP_LOGI(TAG, "Unhandled cluster attribute id: %d", cluster_id);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
p_device_cb_param->status = RET_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
zb_ret_t zb_err_code;
|
||||
zb_ieee_addr_t g_ieee_addr;
|
||||
|
||||
/* initialize Zigbee stack */
|
||||
ZB_INIT("light_bulb");
|
||||
esp_read_mac(g_ieee_addr, ESP_MAC_IEEE802154);
|
||||
zb_set_long_address(g_ieee_addr);
|
||||
zb_set_network_router_role(IEEE_CHANNEL_MASK);
|
||||
zb_set_max_children(MAX_CHILDREN);
|
||||
zb_set_nvram_erase_at_start(ERASE_PERSISTENT_CONFIG);
|
||||
zb_set_keepalive_timeout(ZB_MILLISECONDS_TO_BEACON_INTERVAL(3000));
|
||||
/* hardware related and device init */
|
||||
light_driver_init(LIGHT_DEFAULT_OFF);
|
||||
/* register callback for handling ZCL commands */
|
||||
ZB_ZCL_REGISTER_DEVICE_CB(esp_zb_light_cb);
|
||||
/* register light device context (endpoints) */
|
||||
ZB_AF_REGISTER_DEVICE_CTX(&esp_zb_light_ctx);
|
||||
zb_err_code = zboss_start_no_autostart();
|
||||
ESP_ERROR_CHECK(zb_err_code);
|
||||
|
||||
while (1) {
|
||||
zboss_main_loop_iteration();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Espressif Systems (Shanghai) CO LTD
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Espressif Systems
|
||||
* integrated circuit in a product or a software update for such product,
|
||||
* must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* 4. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "light_driver.h"
|
||||
#include "zboss_api.h"
|
||||
|
||||
/* Zigbee configuration */
|
||||
#define IEEE_CHANNEL_MASK (1l << 13) /* Zigbee default setting is channel 13 for light example usage */
|
||||
#define ERASE_PERSISTENT_CONFIG ZB_TRUE /* erase network devices before running example */
|
||||
#define MAX_CHILDREN 10 /* the max amount of connected devices */
|
||||
|
||||
/* groups cluster attributes */
|
||||
typedef struct {
|
||||
zb_uint8_t name_support;
|
||||
} zb_zcl_groups_attrs_t;
|
||||
|
||||
/* scene cluster attributes */
|
||||
typedef struct {
|
||||
zb_uint8_t scene_count;
|
||||
zb_uint8_t current_scene;
|
||||
zb_uint8_t scene_valid;
|
||||
zb_uint8_t name_support;
|
||||
zb_uint16_t current_group;
|
||||
} zb_zcl_scenes_attrs_t;
|
||||
|
||||
/* light bulb device cluster attributes */
|
||||
typedef struct {
|
||||
zb_zcl_basic_attrs_t basic_attr;
|
||||
zb_zcl_identify_attrs_t identify_attr;
|
||||
zb_zcl_groups_attrs_t groups_attr;
|
||||
zb_zcl_scenes_attrs_t scenes_attr;
|
||||
zb_zcl_on_off_attrs_t on_off_attr;
|
||||
} bulb_device_ctx_t;
|
||||
|
||||
#define HA_ESP_LIGHT_ENDPOINT 10 /* esp light bulb device endpoint, used to process light controlling commands */
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Espressif Systems (Shanghai) CO LTD
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Espressif Systems
|
||||
* integrated circuit in a product or a software update for such product,
|
||||
* must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* 4. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "light_driver.h"
|
||||
#include "led_strip.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static led_strip_t *led_strip;
|
||||
|
||||
void light_driver_set_power(bool power)
|
||||
{
|
||||
ESP_ERROR_CHECK(led_strip->set_pixel(led_strip, 0, 255 * power, 255 * power, 255 * power));
|
||||
ESP_ERROR_CHECK(led_strip->refresh(led_strip, 100));
|
||||
}
|
||||
|
||||
int light_driver_init(bool power)
|
||||
{
|
||||
led_strip = led_strip_init(RMT_TX_CHANNEL, CONFIG_EXAMPLE_RMT_TX_GPIO, CONFIG_EXAMPLE_STRIP_LED_NUMBER);
|
||||
light_driver_set_power(power);
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Espressif Systems (Shanghai) CO LTD
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Espressif Systems
|
||||
* integrated circuit in a product or a software update for such product,
|
||||
* must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* 4. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "driver/rmt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* light intensity level */
|
||||
#define LIGHT_DEFAULT_ON 1
|
||||
#define LIGHT_DEFAULT_OFF 0
|
||||
|
||||
/* LED strip configuration */
|
||||
#define RMT_TX_CHANNEL RMT_CHANNEL_0
|
||||
#define CONFIG_EXAMPLE_RMT_TX_GPIO 8
|
||||
#define CONFIG_EXAMPLE_STRIP_LED_NUMBER 1
|
||||
|
||||
/**
|
||||
* @brief Set light power (on/off).
|
||||
*
|
||||
* @param power The light power to be set
|
||||
*/
|
||||
void light_driver_set_power(bool power);
|
||||
|
||||
/**
|
||||
* @brief color light driver init, be invoked where you want to use color light
|
||||
*
|
||||
* @param power power on/off
|
||||
*/
|
||||
int light_driver_init(bool power);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
@@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
||||
nvs, data, nvs, 0x9000, 0x6000,
|
||||
phy_init, data, phy, 0xf000, 0x1000,
|
||||
factory, app, factory, 0x10000, 1M,
|
||||
zb_storage, data, fat, , 128K,
|
||||
|
@@ -0,0 +1,42 @@
|
||||
CONFIG_IDF_TARGET="esp32h2"
|
||||
|
||||
#
|
||||
# libsodium
|
||||
#
|
||||
CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y
|
||||
# end of libsodium
|
||||
|
||||
#
|
||||
# Partition Table
|
||||
#
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||
CONFIG_PARTITION_TABLE_MD5=y
|
||||
# end of Partition Table
|
||||
|
||||
#
|
||||
# mbedTLS
|
||||
#
|
||||
CONFIG_MBEDTLS_HARDWARE_AES=n
|
||||
CONFIG_MBEDTLS_HARDWARE_MPI=n
|
||||
CONFIG_MBEDTLS_HARDWARE_SHA=n
|
||||
CONFIG_MBEDTLS_CMAC_C=y
|
||||
CONFIG_MBEDTLS_SSL_PROTO_DTLS=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y
|
||||
# end of TLS Key Exchange Methods
|
||||
|
||||
CONFIG_MBEDTLS_ECJPAKE_C=y
|
||||
# end of mbedTLS
|
||||
|
||||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
|
||||
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
|
||||
|
||||
#
|
||||
# Zboss
|
||||
#
|
||||
CONFIG_ZB_ENABLED=y
|
||||
CONFIG_ZB_ZCZR=y
|
||||
# end of Zboss
|
||||
# end of Component config
|
||||
Reference in New Issue
Block a user