status led implemented
This commit is contained in:
@@ -6,7 +6,5 @@ Generalnie co ma dzialac to juz dziala, thank fuck. Ja pierdole ale api do zigbe
|
|||||||
|
|
||||||
### TODO
|
### TODO
|
||||||
- hardware
|
- hardware
|
||||||
- weird start up behavior
|
|
||||||
- factory reset zigbee zeby bylo legitnie, dzwonisz po `esp_zb_factory_reset();`
|
- factory reset zigbee zeby bylo legitnie, dzwonisz po `esp_zb_factory_reset();`
|
||||||
- status LED zeby bylo legitnie (pokazuje factory reset i OTA kiedys)
|
|
||||||
- ota?
|
- ota?
|
||||||
|
|||||||
9
include/status_led.h
Normal file
9
include/status_led.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef STATUS_LED_H
|
||||||
|
#define STATUS_LED_H
|
||||||
|
|
||||||
|
void status_led_task(void *pvParameter);
|
||||||
|
void set_status_connecting();
|
||||||
|
void set_status_joined();
|
||||||
|
void set_status_error_or_resetting();
|
||||||
|
|
||||||
|
#endif //STATUS_LED_H
|
||||||
@@ -2,9 +2,11 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "zigbee.h"
|
#include "zigbee.h"
|
||||||
|
#include "status_led.h"
|
||||||
|
|
||||||
|
|
||||||
void app_main(void) {
|
void app_main(void) {
|
||||||
|
xTaskCreate(status_led_task, "status LED", 4096, NULL, 10, NULL);
|
||||||
ESP_ERROR_CHECK(nvs_flash_init());
|
ESP_ERROR_CHECK(nvs_flash_init());
|
||||||
xTaskCreate(zigbee_task, "Zigbee_main", 4096, NULL, 5, NULL);
|
xTaskCreate(zigbee_task, "Zigbee_main", 4096, NULL, 5, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
106
main/status_led.c
Normal file
106
main/status_led.c
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#include "status_led.h"
|
||||||
|
|
||||||
|
#include <hal/ledc_hal.h>
|
||||||
|
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/semphr.h"
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
|
||||||
|
enum led_states_t {
|
||||||
|
STATUS_OFF,
|
||||||
|
STATUS_SLOW_BLINK,
|
||||||
|
STATUS_FAST_BLINK,
|
||||||
|
STATUS_ON
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char* TAG = "status_led";
|
||||||
|
SemaphoreHandle_t status_sem = NULL;
|
||||||
|
static const uint8_t status_led_pin = 15;
|
||||||
|
static enum led_states_t current_state = STATUS_OFF;
|
||||||
|
static bool led_on = false;
|
||||||
|
|
||||||
|
void set_status_connecting() {
|
||||||
|
xSemaphoreTake(status_sem, portMAX_DELAY);
|
||||||
|
current_state = STATUS_FAST_BLINK;
|
||||||
|
xSemaphoreGive(status_sem);
|
||||||
|
ESP_LOGI(TAG, "status connecting");
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_status_joined() {
|
||||||
|
xSemaphoreTake(status_sem, portMAX_DELAY);
|
||||||
|
current_state = STATUS_ON;
|
||||||
|
xSemaphoreGive(status_sem);
|
||||||
|
ESP_LOGI(TAG, "status joined");
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_status_error_or_resetting() {
|
||||||
|
xSemaphoreTake(status_sem, portMAX_DELAY);
|
||||||
|
current_state = STATUS_SLOW_BLINK;
|
||||||
|
xSemaphoreGive(status_sem);
|
||||||
|
ESP_LOGI(TAG, "status error or resetting");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_led_on(void) {
|
||||||
|
led_on = true;
|
||||||
|
gpio_set_level(status_led_pin, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_led_off(void) {
|
||||||
|
led_on = false;
|
||||||
|
gpio_set_level(status_led_pin, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_led_toggle(void) {
|
||||||
|
led_on = !led_on;
|
||||||
|
gpio_set_level(status_led_pin, !led_on);
|
||||||
|
}
|
||||||
|
|
||||||
|
static enum led_states_t get_state(void) {
|
||||||
|
xSemaphoreTake(status_sem, portMAX_DELAY);
|
||||||
|
const enum led_states_t s = current_state;
|
||||||
|
xSemaphoreGive(status_sem);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void status_led_task(void *pvParameter) {
|
||||||
|
const gpio_config_t io_conf = {
|
||||||
|
.pin_bit_mask = (1ULL << status_led_pin),
|
||||||
|
.mode = GPIO_MODE_OUTPUT,
|
||||||
|
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||||
|
.intr_type = GPIO_INTR_DISABLE,
|
||||||
|
};
|
||||||
|
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
set_led_off();
|
||||||
|
|
||||||
|
status_sem = xSemaphoreCreateMutex();
|
||||||
|
xSemaphoreGive(status_sem);
|
||||||
|
ESP_LOGI(TAG, "status LED inited");
|
||||||
|
|
||||||
|
enum led_states_t prev_state = STATUS_OFF;
|
||||||
|
while (true) { // NOLINT
|
||||||
|
const enum led_states_t state = get_state();
|
||||||
|
if (state != prev_state) {
|
||||||
|
prev_state = state;
|
||||||
|
switch (state) {
|
||||||
|
case STATUS_OFF:
|
||||||
|
set_led_off();
|
||||||
|
break;
|
||||||
|
case STATUS_SLOW_BLINK:
|
||||||
|
set_led_toggle();
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(500));
|
||||||
|
break;
|
||||||
|
case STATUS_FAST_BLINK:
|
||||||
|
set_led_toggle();
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
break;
|
||||||
|
case STATUS_ON:
|
||||||
|
set_led_on();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(15));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "light_driver.h"
|
#include "light_driver.h"
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <esp_err.h>
|
#include <esp_err.h>
|
||||||
|
#include "status_led.h"
|
||||||
#include <esp_check.h>
|
#include <esp_check.h>
|
||||||
|
|
||||||
static const char* TAG = "zigbee";
|
static const char* TAG = "zigbee";
|
||||||
@@ -200,8 +201,8 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t* signal_s) {
|
|||||||
else {
|
else {
|
||||||
ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type),
|
ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type),
|
||||||
esp_err_to_name(err_status));
|
esp_err_to_name(err_status));
|
||||||
esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb,
|
esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_INITIALIZATION, 1000);
|
||||||
ESP_ZB_BDB_MODE_INITIALIZATION, 1000);
|
set_status_error_or_resetting();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -214,10 +215,12 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t* signal_s) {
|
|||||||
extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], extended_pan_id[0],
|
extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], extended_pan_id[0],
|
||||||
esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address());
|
esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address());
|
||||||
zigbee_report_on_off_level(false, 254);
|
zigbee_report_on_off_level(false, 254);
|
||||||
|
set_status_joined();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ESP_LOGI(TAG, "Network steering was not successful (status: %s)", esp_err_to_name(err_status));
|
ESP_LOGI(TAG, "Network steering was not successful (status: %s)", esp_err_to_name(err_status));
|
||||||
esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_STEERING, 1000);
|
esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_STEERING, 1000);
|
||||||
|
set_status_error_or_resetting();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -256,6 +259,7 @@ void zigbee_task(void* pvParameters) {
|
|||||||
|
|
||||||
ESP_ERROR_CHECK(esp_zb_platform_config(&zb_platform_config));
|
ESP_ERROR_CHECK(esp_zb_platform_config(&zb_platform_config));
|
||||||
esp_zb_init(&zb_nwk_cfg);
|
esp_zb_init(&zb_nwk_cfg);
|
||||||
|
set_status_connecting();
|
||||||
|
|
||||||
esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create();
|
esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create();
|
||||||
esp_zb_ep_list_t *endpoint_list = esp_zb_ep_list_create();
|
esp_zb_ep_list_t *endpoint_list = esp_zb_ep_list_create();
|
||||||
|
|||||||
Reference in New Issue
Block a user