diff --git a/ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.h b/ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.h index 1f970a436..83bec9bee 100644 --- a/ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.h +++ b/ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.h @@ -174,15 +174,6 @@ extern "C" \"op_inv\": false,\ \"val_ip\": false,\ \"val_op\": false\ - },\ - {\ - \"dev_type\": 10,\ - \"dev_name\": \"GY61\",\ - \"id_room\": \"\",\ - \"id_item\": 28,\ - \"gpio1\": 33,\ - \"gpio2\": 34,\ - \"gpio3\": 35\ }\ ], \ \"dev_total\": 5}"; diff --git a/ezlopi-core/ezlopi-core-timer/ezlopi_core_timer.c b/ezlopi-core/ezlopi-core-timer/ezlopi_core_timer.c index 63b8c7010..522c97064 100644 --- a/ezlopi-core/ezlopi-core-timer/ezlopi_core_timer.c +++ b/ezlopi-core/ezlopi-core-timer/ezlopi_core_timer.c @@ -196,6 +196,7 @@ void ezlopi_timer_start_1000ms(void) #else void ezlopi_timer_start_1000ms(void) { + TRACE_D("initializing timer for 1000 ms interrupt..."); ezlopi_timer_init_timer_event(0, 1000, EZLOPI_ACTION_NOTIFY_1000_MS); } #endif diff --git a/ezlopi-core/ezlopi-core-websocket_client/ezlopi_core_websocket_client.c b/ezlopi-core/ezlopi-core-websocket_client/ezlopi_core_websocket_client.c index eba46aab2..c2689d608 100644 --- a/ezlopi-core/ezlopi-core-websocket_client/ezlopi_core_websocket_client.c +++ b/ezlopi-core/ezlopi-core-websocket_client/ezlopi_core_websocket_client.c @@ -17,26 +17,26 @@ #include "ezlopi_core_websocket_client.h" static esp_websocket_client_handle_t client = NULL; -static void (*__msg_upcall)(const char *, uint32_t) = NULL; +static void (*__msg_upcall)(const char*, uint32_t) = NULL; typedef struct s_ws_event_arg { esp_websocket_client_handle_t client; - void (*msg_upcall)(const char *, uint32_t); + void (*msg_upcall)(const char*, uint32_t); void (*connection_upcall)(bool connected); } s_ws_event_arg_t; typedef struct s_ws_data_buffer { - char *buffer; + char* buffer; uint32_t len; uint32_t tot_len; - struct s_ws_data_buffer *next; + struct s_ws_data_buffer* next; } s_ws_data_buffer_t; -static void websocket_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data); +static void websocket_event_handler(void* handler_args, esp_event_base_t base, int32_t event_id, void* event_data); -int ezlopi_websocket_client_send(char *data, uint32_t len) +int ezlopi_websocket_client_send(char* data, uint32_t len) { int ret = 0; @@ -65,14 +65,14 @@ void ezlopi_websocket_client_kill(void) client = NULL; } -esp_websocket_client_handle_t ezlopi_websocket_client_init(cJSON *uri, void (*msg_upcall)(const char *, uint32_t), void (*connection_upcall)(bool connected)) +esp_websocket_client_handle_t ezlopi_websocket_client_init(cJSON* uri, void (*msg_upcall)(const char*, uint32_t), void (*connection_upcall)(bool connected)) { if ((NULL == client) && (NULL != uri) && (NULL != uri->valuestring) && (NULL != msg_upcall)) { - char *ca_cert = ezlopi_factory_info_v3_get_ca_certificate(); - char *ssl_shared = ezlopi_factory_info_v3_get_ssl_shared_key(); - char *ssl_priv = ezlopi_factory_info_v3_get_ssl_private_key(); + char* ca_cert = ezlopi_factory_info_v3_get_ca_certificate(); + char* ssl_shared = ezlopi_factory_info_v3_get_ssl_shared_key(); + char* ssl_priv = ezlopi_factory_info_v3_get_ssl_private_key(); __msg_upcall = msg_upcall; static s_ws_event_arg_t event_arg; @@ -97,7 +97,7 @@ esp_websocket_client_handle_t ezlopi_websocket_client_init(cJSON *uri, void (*ms client = esp_websocket_client_init(&websocket_cfg); if (client) { - esp_websocket_register_events(client, WEBSOCKET_EVENT_ANY, websocket_event_handler, (void *)&event_arg); + esp_websocket_register_events(client, WEBSOCKET_EVENT_ANY, websocket_event_handler, (void*)&event_arg); esp_websocket_client_start(client); } else @@ -115,10 +115,10 @@ esp_websocket_client_handle_t ezlopi_websocket_client_init(cJSON *uri, void (*ms return client; } -static void websocket_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) +static void websocket_event_handler(void* handler_args, esp_event_base_t base, int32_t event_id, void* event_data) { - s_ws_event_arg_t *event_arg = (s_ws_event_arg_t *)handler_args; - esp_websocket_event_data_t *data = (esp_websocket_event_data_t *)event_data; + s_ws_event_arg_t* event_arg = (s_ws_event_arg_t*)handler_args; + esp_websocket_event_data_t* data = (esp_websocket_event_data_t*)event_data; switch (event_id) { case WEBSOCKET_EVENT_CONNECTED: diff --git a/ezlopi-main/CMakeLists.txt b/ezlopi-main/CMakeLists.txt index bf40c5962..a93fb8d97 100644 --- a/ezlopi-main/CMakeLists.txt +++ b/ezlopi-main/CMakeLists.txt @@ -47,6 +47,7 @@ ezlopi-service-ble ezlopi-service-meshbot ezlopi-service-ws-server ezlopi-service-broadcast + ezlopi-service-led-indicator ) # Register the components diff --git a/ezlopi-main/Kconfig.projbuild b/ezlopi-main/Kconfig.projbuild index 5b009d56f..7f7fac558 100644 --- a/ezlopi-main/Kconfig.projbuild +++ b/ezlopi-main/Kconfig.projbuild @@ -34,7 +34,7 @@ menu "EzloPi User Config" config EZLOPI_BLE_ENABLE bool "Enable BLE" - default n + default y help Enable BLE @@ -101,6 +101,17 @@ menu "EzloPi User Config" endmenu + choice + prompt "Select the indicator LED available in the device (current target $(IDF_TARGET))" + depends on IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32 + config EZPI_ON_OFF_LED + bool "Onboard LED" + depends on IDF_TARGET_ESP32 + config EZPI_RGB_LED + bool "Onboard addressable LED" + depends on IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 + endchoice + endmenu diff --git a/ezlopi-main/ezlopi_main.c b/ezlopi-main/ezlopi_main.c index 4b4e91169..f05d03e64 100644 --- a/ezlopi-main/ezlopi_main.c +++ b/ezlopi-main/ezlopi_main.c @@ -26,34 +26,16 @@ #include "ezlopi_service_webprov.h" #include "ezlopi_service_ws_server.h" #include "ezlopi_service_broadcast.h" +#include "ezlopi_service_led_indicator.h" #include "pt.h" -#define ENABLE_HEARTBIT_LED 1 - static void __blinky(void* pv); -static void __init_heartbeat_led(void); -static void __toggle_heartbeat_led(void); - -static struct pt pt1; -PT_THREAD(example(struct pt* pt)) -{ - static uint32_t curr_ticks; - PT_BEGIN(pt); - - while (1) - { - curr_ticks = xTaskGetTickCount(); - PT_WAIT_UNTIL(pt, (xTaskGetTickCount() - curr_ticks) > 1000); - __toggle_heartbeat_led(); - } - - PT_END(pt); -} void app_main(void) { + ezlopi_service_led_indicator_init(); gpio_install_isr_service(0); gpio_isr_service_init(); @@ -80,39 +62,13 @@ void app_main(void) ezlopi_scenes_meshbot_init(); #endif - xTaskCreate(__blinky, "__blinky", 2 * 2048, NULL, 1, NULL); + xTaskCreate(__blinky, "__blinky", 2 * 2048, NULL, 0, NULL); } -static void __init_heartbeat_led(void) -{ -#if (1 == ENABLE_HEARTBIT_LED) - gpio_config_t io_conf = { - .pin_bit_mask = (1ULL << GPIO_NUM_2), - .mode = GPIO_MODE_OUTPUT, - .pull_up_en = GPIO_PULLUP_DISABLE, - .pull_down_en = GPIO_PULLDOWN_DISABLE, - .intr_type = GPIO_INTR_DISABLE, - }; - - gpio_config(&io_conf); -#endif -} - -static void __toggle_heartbeat_led(void) -{ -#if (1 == ENABLE_HEARTBIT_LED) - static uint32_t state = 0; - - state ^= 1; - gpio_set_level(GPIO_NUM_2, state); -#endif -} static void __blinky(void* pv) { - __init_heartbeat_led(); - PT_INIT(&pt1); uint32_t count = 0; while (1) @@ -128,6 +84,5 @@ static void __blinky(void* pv) } vTaskDelay(5 / portTICK_PERIOD_MS); - example(&pt1); } } diff --git a/ezlopi-sensors-devices/device-0001-digitalOut-generic/device_0001_digitalOut_generic.c b/ezlopi-sensors-devices/device-0001-digitalOut-generic/device_0001_digitalOut_generic.c index 6e3290914..3df7d028d 100644 --- a/ezlopi-sensors-devices/device-0001-digitalOut-generic/device_0001_digitalOut_generic.c +++ b/ezlopi-sensors-devices/device-0001-digitalOut-generic/device_0001_digitalOut_generic.c @@ -43,7 +43,6 @@ uint32_t settings_ids[2]; int device_0001_digitalOut_generic(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg) { int ret = 0; - switch (action) { case EZLOPI_ACTION_PREPARE: diff --git a/ezlopi-services/ezlopi-service-ble/CMakeLists.txt b/ezlopi-services/ezlopi-service-ble/CMakeLists.txt index 1a6e6a9a5..cbb735415 100644 --- a/ezlopi-services/ezlopi-service-ble/CMakeLists.txt +++ b/ezlopi-services/ezlopi-service-ble/CMakeLists.txt @@ -5,6 +5,7 @@ set(EZLOPI_CORE_COMPONENTS ezlopi-core-devices ezlopi-core-ble ezlopi-core-reset + ezlopi-core-ping # ezlopi-user-config ) diff --git a/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble.h b/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble.h index 32eed9673..9f1bb4f28 100644 --- a/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble.h +++ b/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble.h @@ -29,10 +29,13 @@ #define BLE_DEVICE_INFO_ID_HANDLE 3 #define BLE_DEVICE_INFO_SERVICE_UUID 0x00E4 #define BLE_DEVICE_INFO_CHAR_UUID 0xE401 +#define BLE_DEVICE_STATUS_CHAR_NET_INFO_UUDI 0xE402 +#define BLE_DEVICE_INFO_MAC_CHAR_UUID 0xE403 #define BLE_DYNAMIC_CONFIG_HANDLE 4 #define BLE_DYNAMIC_CONFIG_SERVICE_UUID 0x00E5 #define BLE_DYNAMIC_CONFIG_CHAR_UUID 0xE501 + void ezlopi_ble_service_init(void); int ezlopi_ble_service_get_ble_mac(uint8_t mac[6]); diff --git a/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_device_info.c b/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_device_info.c index be730cd85..b6cf85d5e 100644 --- a/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_device_info.c +++ b/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_device_info.c @@ -17,6 +17,7 @@ #include "ezlopi_core_ble_buffer.h" #include "ezlopi_core_ble_profile.h" #include "ezlopi_core_factory_info.h" +#include "ezlopi_core_event_group.h" #include "ezlopi_hal_system_info.h" @@ -29,6 +30,8 @@ static s_gatt_service_t* g_device_info_service = NULL; static char* device_info_jsonify(void); static void __add_factory_info_to_root(cJSON* root, char* key, char* value); static void device_info_read_func(esp_gatt_value_t* value, esp_ble_gatts_cb_param_t* param); +static void device_status_read_func(esp_gatt_value_t* value, esp_ble_gatts_cb_param_t* param); +static void device_mac_read_func(esp_gatt_value_t* value, esp_ble_gatts_cb_param_t* param); void ezlopi_ble_service_device_info_init(void) { @@ -47,8 +50,123 @@ void ezlopi_ble_service_device_info_init(void) properties = ESP_GATT_CHAR_PROP_BIT_READ; ezlopi_ble_gatt_add_characteristic(g_device_info_service, &uuid, permission, properties, device_info_read_func, NULL, NULL); TRACE_W("'provisioning_service' character added to ezlopi-ble-stack"); + + uuid.uuid.uuid16 = BLE_DEVICE_STATUS_CHAR_NET_INFO_UUDI; + uuid.len = ESP_UUID_LEN_16; + permission = ESP_GATT_PERM_READ; + properties = ESP_GATT_CHAR_PROP_BIT_NOTIFY | ESP_GATT_CHAR_PROP_BIT_READ; + ezlopi_ble_gatt_add_characteristic(g_device_info_service, &uuid, permission, properties, device_status_read_func, NULL, NULL); + + uuid.uuid.uuid16 = BLE_DEVICE_INFO_MAC_CHAR_UUID; + uuid.len = ESP_UUID_LEN_16; + permission = ESP_GATT_PERM_READ; + properties = ESP_GATT_CHAR_PROP_BIT_READ; + ezlopi_ble_gatt_add_characteristic(g_device_info_service, &uuid, permission, properties, device_mac_read_func, NULL, NULL); +} + +static void ble_device_info_send_data(const cJSON* cj_response_data, esp_gatt_value_t* value, esp_ble_gatts_cb_param_t* param) +{ + char* send_data = cJSON_Print(cj_response_data); + if (send_data) + { + cJSON_Minify(send_data); + + uint32_t total_data_len = strlen(send_data); + uint32_t max_data_buffer_size = ezlopi_ble_gatt_get_max_data_size(); + uint32_t copy_size = ((total_data_len - param->read.offset) < max_data_buffer_size) ? (total_data_len - param->read.offset) : max_data_buffer_size; + + if ((0 != total_data_len) && (total_data_len > param->read.offset)) + { + strncpy((char*)value->value, send_data + param->read.offset, copy_size); + value->len = copy_size; + } + if ((param->read.offset + copy_size) >= total_data_len) + { + free(send_data); + send_data = NULL; + } + } + else + { + TRACE_E("No data to send"); + value->len = 1; + value->value[0] = 0; // Read 0 if the device not provisioned yet. + } } +static void device_mac_read_func(esp_gatt_value_t* value, esp_ble_gatts_cb_param_t* param) +{ + if (value) + { + cJSON* cj_device_mac = cJSON_CreateObject(); + if (cj_device_mac) + { + char* device_mac = ezlopi_factory_info_v3_get_ezlopi_mac(); + cJSON_AddStringToObject(cj_device_mac, "ezlopi_mac", device_mac ? device_mac : "unknown"); + + uint8_t mac[6]; + ezlopi_wifi_get_wifi_mac(mac); + char mac_str[20]; + memset(mac_str, 0, sizeof(mac_str)); + snprintf(mac_str, 20, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + cJSON_AddStringToObject(cj_device_mac, "wifi_mac", mac_str); + + memset(mac, 0, sizeof(mac)); + ezlopi_ble_service_get_ble_mac(mac); + memset(mac_str, 0, sizeof(mac_str)); + snprintf(mac_str, 20, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + cJSON_AddStringToObject(cj_device_mac, "ble_mac", mac_str); + + ble_device_info_send_data(cj_device_mac, value, param); + + cJSON_Delete(cj_device_mac); + free(device_mac); + } + else + { + TRACE_E("Couldn't allocate memory for device mac json"); + } + } + else + { + TRACE_E("Value is empty"); + } +} + +static void device_status_read_func(esp_gatt_value_t* value, esp_ble_gatts_cb_param_t* param) +{ + if (value) + { + cJSON* cj_device_status = cJSON_CreateObject(); + if (cj_device_status) + { + e_ezlopi_event_t event = ezlopi_get_event_bit_status(); + e_ping_status_t ping_status = ezlopi_ping_get_internet_status(); + + cJSON_AddBoolToObject(cj_device_status, "wifi_connection_status", (event & EZLOPI_EVENT_WIFI_CONNECTED) == EZLOPI_EVENT_WIFI_CONNECTED); + cJSON_AddBoolToObject(cj_device_status, "internet_connection_status", ping_status == EZLOPI_PING_STATUS_LIVE); + + cJSON_AddBoolToObject(cj_device_status, "cloud_connection_status", (event & EZLOPI_EVENT_NMA_REG) == EZLOPI_EVENT_NMA_REG); + cJSON_AddBoolToObject(cj_device_status, "provision_completion_status", ezlopi_factory_info_v3_get_provisioning_status()); + + cJSON_AddTrueToObject(cj_device_status, "powered_on"); + + ble_device_info_send_data(cj_device_status, value, param); + + cJSON_Delete(cj_device_status); + } + else + { + TRACE_E("Couldn't allocate memory for device status"); + } + } + else + { + TRACE_E("Value is NULL"); + } +} + + static void device_info_read_func(esp_gatt_value_t* value, esp_ble_gatts_cb_param_t* param) { static char* json_str_device_info; diff --git a/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_provisioning.c b/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_provisioning.c index 02916ed70..83ab06adb 100644 --- a/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_provisioning.c +++ b/ezlopi-services/ezlopi-service-ble/ezlopi_service_ble_provisioning.c @@ -17,6 +17,7 @@ #include "ezlopi_core_ble_profile.h" #include "ezlopi_core_factory_info.h" #include "ezlopi_core_cjson_macros.h" +#include "ezlopi_core_event_group.h" #include "ezlopi_cloud_constants.h" @@ -36,7 +37,7 @@ static char *__base64_decode_provisioning_info(uint32_t total_size); static void __provisioning_info_write_func(esp_gatt_value_t *value, esp_ble_gatts_cb_param_t *param); static void __provisioning_info_read_func(esp_gatt_value_t *value, esp_ble_gatts_cb_param_t *param); -static void __provisioning_status_read_func(esp_gatt_value_t *value, esp_ble_gatts_cb_param_t *param); +static void __provisioning_status_read_func(esp_gatt_value_t* value, esp_ble_gatts_cb_param_t* param); void ezlopi_ble_service_provisioning_init(void) { @@ -61,7 +62,7 @@ void ezlopi_ble_service_provisioning_init(void) ezlopi_ble_gatt_add_characteristic(g_provisioning_service, &uuid, permission, properties, __provisioning_status_read_func, NULL, NULL); } -static char *__provisioning_status_jsonify(void) +static char* __provisioning_status_jsonify(void) { char *prov_status_jstr = NULL; cJSON *root = cJSON_CreateObject(); diff --git a/ezlopi-services/ezlopi-service-led-indicator/CMakeLists.txt b/ezlopi-services/ezlopi-service-led-indicator/CMakeLists.txt new file mode 100644 index 000000000..cad274fcb --- /dev/null +++ b/ezlopi-services/ezlopi-service-led-indicator/CMakeLists.txt @@ -0,0 +1,12 @@ + + + +idf_component_register(SRCS "ezlopi_service_led_indicator.c" + INCLUDE_DIRS "." + REQUIRES ezlopi-util-trace + led_strip + ezlopi-core-event-group + ezlopi-core-ping +) + + diff --git a/ezlopi-services/ezlopi-service-led-indicator/ezlopi_service_led_indicator.c b/ezlopi-services/ezlopi-service-led-indicator/ezlopi_service_led_indicator.c new file mode 100644 index 000000000..19c6b54c7 --- /dev/null +++ b/ezlopi-services/ezlopi-service-led-indicator/ezlopi_service_led_indicator.c @@ -0,0 +1,267 @@ + + +#include "driver/rmt.h" +#include "led_strip.h" +#include "esp_err.h" +#include "color_codes.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "driver/gpio.h" + +#include "ezlopi_util_trace.h" + +#include "ezlopi_core_event_group.h" +#include "ezlopi_core_ping.h" + +#include "ezlopi_service_led_indicator.h" + +#ifdef CONFIG_EZPI_RGB_LED +#define COLOR_GET_RED(x) ( 0xFF & ( x >> 16 )) +#define COLOR_GET_GREEN(x) ( 0xFF & ( x >> 8 ) ) +#define COLOR_GET_BLUE(x) ( 0xFF & x ) + +#define DEVICE_POWERED_ON_LED_COLOR 0xFFFFFF + +#define INDICATOR_LED_FADE_TIME_MS 20 + +#ifdef CONFIG_IDF_TARGET_ESP32S3 +#define INDICATOR_LED_PIN 48 +#elif CONFIG_IDF_TARGET_ESP32C3 +#define INDICATOR_LED_PIN 8 +#endif +#define INDICATOR_RGB_RMT_TX_CHANNEL RMT_CHANNEL_1 + +static led_strip_t indicator_led; +#endif // #ifdef CONFIG_EZPI_RGB_LED + +#ifdef CONFIG_EZPI_ON_OFF_LED +#define INDICATOR_LED_PIN 2 + +#define INDICATTOR_LED_POWER_STATUS_BLINK_MS 20 +#define INDICATTOR_LED_WIFI_STATUS_BLINK_MS 50 +#define INDICATTOR_LED_INTERNET_STATUS_BLINK_MS 100 +#define INDICATTOR_LED_CLOUD_STATUS_BLINK_MS 200 +static bool indicator_led_status = false; +#endif + +static e_indicator_led_priority_t indicator_priority = PRIORITY_CLOUD; + +#ifdef CONFIG_EZPI_RGB_LED +static void indicator_RGB_led_fade_out(uint16_t fade_time_ms) +{ + for (int i = 255; i >= 0; i -= 5) + { + led_strip_set_brightness(&indicator_led, i); + led_strip_flush(&indicator_led); + vTaskDelay(fade_time_ms / portTICK_PERIOD_MS); + } +} + +static void indicator_RGB_led_fade_up(uint16_t fade_time_ms) +{ + for (int i = 0; i < 255; i += 5) + { + led_strip_set_brightness(&indicator_led, i); + led_strip_flush(&indicator_led); + vTaskDelay(fade_time_ms / portTICK_PERIOD_MS); + } +} + +static void indicator_LED_fade_red(uint16_t fade_time_ms) +{ + rgb_t color = { + .red = COLOR_GET_RED(DEVICE_POWERED_ON_LED_COLOR), + .green = 0, + .blue = 0, + }; + led_strip_fill(&indicator_led, 0, indicator_led.length, color); + indicator_RGB_led_fade_out(fade_time_ms); + indicator_RGB_led_fade_up(fade_time_ms); +} + +static void indicator_LED_fade_green(uint16_t fade_time_ms) +{ + rgb_t color = { + .red = 0, + .green = COLOR_GET_GREEN(DEVICE_POWERED_ON_LED_COLOR), + .blue = 0, + }; + led_strip_fill(&indicator_led, 0, indicator_led.length, color); + indicator_RGB_led_fade_out(fade_time_ms); + indicator_RGB_led_fade_up(fade_time_ms); +} + +static void indicator_LED_fade_blue(uint16_t fade_time_ms) +{ + rgb_t color = { + .red = 0, + .green = 0, + .blue = COLOR_GET_BLUE(DEVICE_POWERED_ON_LED_COLOR), + }; + led_strip_fill(&indicator_led, 0, indicator_led.length, color); + indicator_RGB_led_fade_out(fade_time_ms); + indicator_RGB_led_fade_up(fade_time_ms); +} +#endif // #ifdef CONFIG_EZPI_RGB_LED + +static void indicator_LED_power_on_effect() +{ +#ifdef CONFIG_EZPI_ON_OFF_LED + indicator_led_status = !indicator_led_status; + gpio_set_level(INDICATOR_LED_PIN, indicator_led_status); + vTaskDelay(INDICATTOR_LED_POWER_STATUS_BLINK_MS / portTICK_PERIOD_MS); +#endif +#ifdef CONFIG_EZPI_RGB_LED + indicator_LED_fade_red(INDICATOR_LED_FADE_TIME_MS); + indicator_LED_fade_green(INDICATOR_LED_FADE_TIME_MS); + indicator_LED_fade_blue(INDICATOR_LED_FADE_TIME_MS); +#endif // #ifdef CONFIG_EZPI_RGB_LED +} + +static void indicator_LED_wifi_connected_effect() +{ +#ifdef CONFIG_EZPI_ON_OFF_LED + indicator_led_status = !indicator_led_status; + gpio_set_level(INDICATOR_LED_PIN, indicator_led_status); + vTaskDelay(INDICATTOR_LED_WIFI_STATUS_BLINK_MS / portTICK_PERIOD_MS); +#endif +#ifdef CONFIG_EZPI_RGB_LED + indicator_LED_fade_red(INDICATOR_LED_FADE_TIME_MS); +#endif // #ifdef CONFIG_EZPI_RGB_LED +} + +static void indicator_LED_internet_connected_effect() +{ +#ifdef CONFIG_EZPI_ON_OFF_LED + indicator_led_status = !indicator_led_status; + gpio_set_level(INDICATOR_LED_PIN, indicator_led_status); + vTaskDelay(INDICATTOR_LED_INTERNET_STATUS_BLINK_MS / portTICK_PERIOD_MS); +#endif +#ifdef CONFIG_EZPI_RGB_LED + indicator_LED_fade_blue(INDICATOR_LED_FADE_TIME_MS); +#endif // #ifdef CONFIG_EZPI_RGB_LED +} + +static void indicator_LED_cloud_connected_effect() +{ +#ifdef CONFIG_EZPI_ON_OFF_LED + indicator_led_status = !indicator_led_status; + gpio_set_level(INDICATOR_LED_PIN, indicator_led_status); + vTaskDelay(INDICATTOR_LED_CLOUD_STATUS_BLINK_MS / portTICK_PERIOD_MS); +#endif // #ifdef CONFIG_EZPI_ON_OFF_LED +#ifdef CONFIG_EZPI_RGB_LED + indicator_LED_fade_green(INDICATOR_LED_FADE_TIME_MS); +#endif // #ifdef CONFIG_EZPI_RGB_LED +} + +#ifdef CONFIG_EZPI_ON_OFF_LED +static const gpio_config_t indicator_led_configuration = { + .pin_bit_mask = (1ULL << INDICATOR_LED_PIN), + .mode = GPIO_MODE_OUTPUT, + .pull_up_en = GPIO_PULLUP_DISABLE, + .pull_down_en = GPIO_PULLDOWN_ENABLE, + .intr_type = GPIO_INTR_DISABLE, +}; +#endif // #ifdef CONFIG_EZPI_ON_OFF_LED + + +static void process_event() +{ + e_ezlopi_event_t event = ezlopi_get_event_bit_status(); + indicator_priority = PRIORITY_POWER; + if ((event & EZLOPI_EVENT_WIFI_CONNECTED) == EZLOPI_EVENT_WIFI_CONNECTED) + { + indicator_priority = PRIORITY_WIFI; + e_ping_status_t ping_status = ezlopi_ping_get_internet_status(); + if (EZLOPI_PING_STATUS_LIVE == ping_status) + { + indicator_priority = PRIORITY_INTERNET; + if ((event & EZLOPI_EVENT_NMA_REG) == EZLOPI_EVENT_NMA_REG) + { + indicator_priority = PRIORITY_CLOUD; + } + } + } +} + +static void indicator_LED_blinker(void* params) +{ + while (1) + { + process_event(); + switch (indicator_priority) + { + case PRIORITY_POWER: + { + indicator_LED_power_on_effect(); + break; + } + case PRIORITY_WIFI: + { + indicator_LED_wifi_connected_effect(); + break; + } + case PRIORITY_INTERNET: + { + indicator_LED_internet_connected_effect(); + break; + } + case PRIORITY_CLOUD: + { + indicator_LED_cloud_connected_effect(); + break; + } + default: + { + break; + } + } + vTaskDelay(1 / portTICK_PERIOD_MS); + } + vTaskDelete(NULL); +} + +int ezlopi_service_led_indicator_init() +{ + int ret = 0; + +#ifdef CONFIG_EZPI_RGB_LED + indicator_led.type = LED_STRIP_WS2812; + indicator_led.length = 1; + indicator_led.gpio = INDICATOR_LED_PIN; + indicator_led.buf = NULL; + indicator_led.brightness = 255; + indicator_led.channel = INDICATOR_RGB_RMT_TX_CHANNEL; + + led_strip_install(); + if (ESP_OK == led_strip_init(&indicator_led)) + { + rgb_t color = { + .red = COLOR_GET_RED(DEVICE_POWERED_ON_LED_COLOR), + .green = COLOR_GET_GREEN(DEVICE_POWERED_ON_LED_COLOR), + .blue = COLOR_GET_BLUE(DEVICE_POWERED_ON_LED_COLOR), + }; + esp_err_t err = led_strip_fill(&indicator_led, 0, indicator_led.length, color); + if (ESP_OK == (err = led_strip_set_brightness(&indicator_led, 255))) + { + if (ESP_OK == (err = led_strip_flush(&indicator_led))) + { + xTaskCreate(indicator_LED_blinker, "indicator_task", 2048 * 2, NULL, tskIDLE_PRIORITY, NULL); + ret = 1; + } + } + } +#endif // #ifdef CONFIG_EZPI_RGB_LED + +#ifdef CONFIG_EZPI_ON_OFF_LED + + ESP_ERROR_CHECK(gpio_config(&indicator_led_configuration)); + gpio_set_level(INDICATOR_LED_PIN, indicator_led_status); + xTaskCreate(indicator_LED_blinker, "indicator_task", 2048 * 2, NULL, tskIDLE_PRIORITY, NULL); + +#endif // #ifdef CONFIG_EZPI_ON_OFF_LED + + return ret; +} + + diff --git a/ezlopi-services/ezlopi-service-led-indicator/ezlopi_service_led_indicator.h b/ezlopi-services/ezlopi-service-led-indicator/ezlopi_service_led_indicator.h new file mode 100644 index 000000000..31f408c0c --- /dev/null +++ b/ezlopi-services/ezlopi-service-led-indicator/ezlopi_service_led_indicator.h @@ -0,0 +1,18 @@ + + +#ifndef _EZLOPI_SERVICE_LED_INDICATOR_H_ +#define _EZLOPI_SERVICE_LED_INDICATOR_H_ + +typedef enum { + PRIORITY_POWER = 0, + PRIORITY_WIFI, + PRIORITY_INTERNET, + PRIORITY_CLOUD, + PRIORITY_MAX, +}e_indicator_led_priority_t; + +int ezlopi_service_led_indicator_init(); + + +#endif // _EZLOPI_SERVICE_LED_INDICATOR_H_ + diff --git a/ezlopi-services/ezlopi-service-uart/ezlopi_service_uart.c b/ezlopi-services/ezlopi-service-uart/ezlopi_service_uart.c index 98b5385ee..1469450eb 100644 --- a/ezlopi-services/ezlopi-service-uart/ezlopi_service_uart.c +++ b/ezlopi-services/ezlopi-service-uart/ezlopi_service_uart.c @@ -646,7 +646,6 @@ static void ezlopi_service_uart_get_info() char* serial_data_json_string = cJSON_Print(cj_get_info); if (serial_data_json_string) { - TRACE_E("%s", serial_data_json_string); cJSON_Minify(serial_data_json_string); EZPI_SERVICE_uart_tx_data(strlen(serial_data_json_string), (uint8_t*)serial_data_json_string); free(serial_data_json_string); diff --git a/ezlopi-services/ezlopi-service-webprov/ezlopi_service_webprov.c b/ezlopi-services/ezlopi-service-webprov/ezlopi_service_webprov.c index c841fd9cb..a355a0ad7 100644 --- a/ezlopi-services/ezlopi-service-webprov/ezlopi_service_webprov.c +++ b/ezlopi-services/ezlopi-service-webprov/ezlopi_service_webprov.c @@ -161,7 +161,7 @@ static void __message_upcall(const char *payload, uint32_t len) } else { - TRACE_W("no response!"); + TRACE_W("no response!"); } } diff --git a/sdkconfig.esp32c3.4mb b/sdkconfig.esp32c3.4mb index e2343561a..5bfa2f0a2 100644 --- a/sdkconfig.esp32c3.4mb +++ b/sdkconfig.esp32c3.4mb @@ -949,7 +949,7 @@ CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL1=y # CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL3 is not set CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER=y CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y -CONFIG_FREERTOS_HZ=100 +CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y # CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set # CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL is not set