feat: Adiciona suporte para controle de LED RGB e animações de estado

This commit is contained in:
2026-01-15 22:55:23 +00:00
parent a05ac96d97
commit 2b9642ebd2
9 changed files with 354 additions and 11 deletions
+9 -1
View File
@@ -22,6 +22,7 @@
#include "ha/esp_zigbee_ha_standard.h"
#include "zcl_utility.h"
#include "esp_zb_switch.h"
#include "led_indicator.h"
typedef struct light_bulb_device_params_s {
esp_zb_ieee_addr_t ieee_addr;
@@ -58,6 +59,9 @@ static void zb_buttons_handler(switch_func_pair_t *button_func_pair)
static esp_err_t deferred_driver_init(void)
{
/* Inicializa o LED RGB */
led_indicator_init(GPIO_LED_RGB);
/* Inicializa o relay */
relay_driver_init();
@@ -161,9 +165,11 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
if (esp_zb_bdb_is_factory_new()) {
ESP_LOGI(TAG, "Start network steering (joining network)");
ESP_LOGI(TAG, "Scanning for available Zigbee networks on all channels...");
led_indicator_set_state(LED_PAIRING); /* LED azul piscando */
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
} else {
ESP_LOGI(TAG, "Device rebooted, rejoining network");
led_indicator_set_state(LED_PAIRING); /* LED azul piscando */
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
}
} else {
@@ -193,6 +199,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
ESP_LOGI(TAG, " IEEE Address: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
ieee_addr[7], ieee_addr[6], ieee_addr[5], ieee_addr[4],
ieee_addr[3], ieee_addr[2], ieee_addr[1], ieee_addr[0]);
led_indicator_set_state(LED_CONNECTED); /* LED verde fixo */
} else {
ESP_LOGW(TAG, "Network steering failed (status: %s)", esp_err_to_name(err_status));
ESP_LOGI(TAG, "No networks found or unable to join. Retrying in 5 seconds...");
@@ -200,6 +207,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
ESP_LOGI(TAG, " 1. Powered on and working");
ESP_LOGI(TAG, " 2. In 'permit join' mode (network open)");
ESP_LOGI(TAG, " 3. Within range (< 10 meters recommended)");
led_indicator_set_state(LED_DISCONNECTED); /* LED vermelho piscando */
esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_STEERING, 5000);
}
break;
@@ -266,7 +274,7 @@ static void esp_zb_task(void *pvParameters)
esp_zb_core_action_handler_register(zb_action_handler);
ESP_LOGI(TAG, "Setting channel mask: 0x%08lx (channel 20)", (unsigned long)ESP_ZB_PRIMARY_CHANNEL_MASK);
ESP_LOGI(TAG, "Setting channel mask: 0x%08lx (all channels)", (unsigned long)ESP_ZB_PRIMARY_CHANNEL_MASK);
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
ESP_ERROR_CHECK(esp_zb_start(false));
esp_zb_stack_main_loop();