feat: desktop connection status icon.
This commit is contained in:
parent
b7476428a2
commit
324a307fe3
21
main/gui.c
21
main/gui.c
@ -1,8 +1,4 @@
|
|||||||
/*
|
#pragma once
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -34,10 +30,10 @@ static const char *GUI_TAG = "LVGL_GUI";
|
|||||||
// EF 87 AB
|
// EF 87 AB
|
||||||
#define APP_WIFI_GOOD_SYMBOL "\xEF\x87\xAB"
|
#define APP_WIFI_GOOD_SYMBOL "\xEF\x87\xAB"
|
||||||
|
|
||||||
// EE 87 8C
|
|
||||||
#define APP_CONNECTED_SYMBOL "\xEE\x87\x8C"
|
|
||||||
// EE 87 8B
|
// EE 87 8B
|
||||||
#define APP_DISCONNECTED_SYMBOL "\xEE\x87\x8B"
|
#define APP_CONNECTED_SYMBOL "\xEE\x87\x8B"
|
||||||
|
// EE 87 8C
|
||||||
|
#define APP_DISCONNECTED_SYMBOL "\xEE\x87\x8C"
|
||||||
|
|
||||||
// EE 8A 9E
|
// EE 8A 9E
|
||||||
#define APP_TIMER_SYMBOL "\xEE\x8A\x9E"
|
#define APP_TIMER_SYMBOL "\xEE\x8A\x9E"
|
||||||
@ -144,13 +140,14 @@ static void gui_set_wifi_connecting() {
|
|||||||
|
|
||||||
static void gui_set_wifi_connected() {
|
static void gui_set_wifi_connected() {
|
||||||
lv_anim_del(wifi_label, NULL);
|
lv_anim_del(wifi_label, NULL);
|
||||||
|
vTaskDelay(300 / portTICK_PERIOD_MS);
|
||||||
lv_obj_clear_flag(wifi_label, LV_OBJ_FLAG_HIDDEN);
|
lv_obj_clear_flag(wifi_label, LV_OBJ_FLAG_HIDDEN);
|
||||||
lv_label_set_text(wifi_label, APP_WIFI_GOOD_SYMBOL);
|
lv_label_set_text(wifi_label, APP_WIFI_GOOD_SYMBOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gui_set_wifi_disconnected() {
|
static void gui_set_wifi_disconnected() {
|
||||||
lv_anim_del(&wifi_label, NULL);
|
lv_anim_del(&wifi_label, NULL);
|
||||||
|
vTaskDelay(300 / portTICK_PERIOD_MS);
|
||||||
lv_obj_clear_flag(wifi_label, LV_OBJ_FLAG_HIDDEN);
|
lv_obj_clear_flag(wifi_label, LV_OBJ_FLAG_HIDDEN);
|
||||||
lv_label_set_text(wifi_label, APP_WIFI_WEAK_SYMBOL);
|
lv_label_set_text(wifi_label, APP_WIFI_WEAK_SYMBOL);
|
||||||
}
|
}
|
||||||
@ -160,13 +157,15 @@ static void gui_set_server_connecting() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void gui_set_server_connected() {
|
static void gui_set_server_connected() {
|
||||||
lv_anim_del(&desktop_label, NULL);
|
lv_anim_del(desktop_label, NULL);
|
||||||
|
vTaskDelay(300 / portTICK_PERIOD_MS);
|
||||||
lv_obj_clear_flag(desktop_label, LV_OBJ_FLAG_HIDDEN);
|
lv_obj_clear_flag(desktop_label, LV_OBJ_FLAG_HIDDEN);
|
||||||
lv_label_set_text(desktop_label, APP_CONNECTED_SYMBOL);
|
lv_label_set_text(desktop_label, APP_CONNECTED_SYMBOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gui_set_server_disconnected() {
|
static void gui_set_server_disconnected() {
|
||||||
lv_anim_del(&desktop_label, NULL);
|
lv_anim_del(desktop_label, NULL);
|
||||||
|
vTaskDelay(300 / portTICK_PERIOD_MS);
|
||||||
lv_obj_clear_flag(desktop_label, LV_OBJ_FLAG_HIDDEN);
|
lv_obj_clear_flag(desktop_label, LV_OBJ_FLAG_HIDDEN);
|
||||||
lv_label_set_text(desktop_label, APP_DISCONNECTED_SYMBOL);
|
lv_label_set_text(desktop_label, APP_DISCONNECTED_SYMBOL);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ void app_main(void) {
|
|||||||
gui_set_wifi_disconnected();
|
gui_set_wifi_disconnected();
|
||||||
}
|
}
|
||||||
udp_server_init();
|
udp_server_init();
|
||||||
// service_discovery_init();
|
service_discovery_init();
|
||||||
// vTaskDelay(pdMS_TO_TICKS(1000));
|
// vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
// mqtt_app_start();
|
// mqtt_app_start();
|
||||||
// if (waiting_for_mqtt_connected()) {
|
// if (waiting_for_mqtt_connected()) {
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "esp_wifi.h"
|
#include "esp_wifi.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
|
#include "gui.c"
|
||||||
#include "light.c"
|
#include "light.c"
|
||||||
#include "lwip/err.h"
|
#include "lwip/err.h"
|
||||||
#include "lwip/sockets.h"
|
#include "lwip/sockets.h"
|
||||||
@ -20,6 +21,9 @@
|
|||||||
|
|
||||||
static const char *UDP_SERVER_TAG = "UDP_SERVER";
|
static const char *UDP_SERVER_TAG = "UDP_SERVER";
|
||||||
|
|
||||||
|
static bool desktop_connected = false;
|
||||||
|
static uint64_t last_desktop_ping_at = 0;
|
||||||
|
|
||||||
static void udp_server_task(void *pvParameters) {
|
static void udp_server_task(void *pvParameters) {
|
||||||
char rx_buffer[1024];
|
char rx_buffer[1024];
|
||||||
char addr_str[128];
|
char addr_str[128];
|
||||||
@ -84,6 +88,7 @@ static void udp_server_task(void *pvParameters) {
|
|||||||
|
|
||||||
switch (rx_buffer[0]) {
|
switch (rx_buffer[0]) {
|
||||||
case 1:
|
case 1:
|
||||||
|
last_desktop_ping_at = esp_timer_get_time();
|
||||||
sendto(sock, rx_buffer, 1, 0, (struct sockaddr *)&source_addr,
|
sendto(sock, rx_buffer, 1, 0, (struct sockaddr *)&source_addr,
|
||||||
sizeof(source_addr));
|
sizeof(source_addr));
|
||||||
break;
|
break;
|
||||||
@ -127,8 +132,28 @@ static void udp_server_task(void *pvParameters) {
|
|||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_server_init(void) {
|
static void change_desktop_connection_status(bool connected) {
|
||||||
ESP_ERROR_CHECK(nvs_flash_init());
|
desktop_connected = connected;
|
||||||
ESP_ERROR_CHECK(esp_netif_init());
|
if (connected) {
|
||||||
xTaskCreate(udp_server_task, "udp_server", 4096, (void *)AF_INET, 5, NULL);
|
gui_set_server_connected();
|
||||||
|
} else {
|
||||||
|
gui_set_server_disconnected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void desktop_online_check_task(void *pvParameters) {
|
||||||
|
while (1) {
|
||||||
|
if (esp_timer_get_time() - last_desktop_ping_at > 5000000) { // 2 seconds
|
||||||
|
change_desktop_connection_status(false);
|
||||||
|
} else {
|
||||||
|
change_desktop_connection_status(true);
|
||||||
|
}
|
||||||
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void udp_server_init(void) {
|
||||||
|
xTaskCreate(udp_server_task, "udp_server", 4096, (void *)AF_INET, 5, NULL);
|
||||||
|
xTaskCreate(desktop_online_check_task, "desktop_online_check", 4096, NULL, 10,
|
||||||
|
NULL);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user