From eb1035a196cb86bab55b828071777411b99ed244 Mon Sep 17 00:00:00 2001 From: Charlesguo11 <1958186952@qq.com> Date: Mon, 25 Jul 2022 00:44:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BA=86=E7=9C=8B=E9=97=A8?= =?UTF-8?q?=E7=8B=97=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=EF=BC=8C=E7=82=B9?= =?UTF-8?q?=E5=87=BBreset=20wii=E5=8D=B3=E5=8F=AF=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/gui/ui_net_config.c | 34 +++++++++++++++++++++++++++++++--- main/main.c | 4 ++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/main/gui/ui_net_config.c b/main/gui/ui_net_config.c index f6b47a9..18298da 100644 --- a/main/gui/ui_net_config.c +++ b/main/gui/ui_net_config.c @@ -12,6 +12,8 @@ #include "app_rmaker.h" #include "ui_main.h" #include "ui_net_config.h" +#include "nvs_flash.h" +#include "nvs.h" static const char *TAG = "ui_net_config"; @@ -21,9 +23,16 @@ static lv_obj_t *g_qr = NULL; static lv_obj_t *g_img = NULL; static lv_obj_t *g_page = NULL; static ui_net_state_t g_net_state = UI_NET_EVT_LOARDING; +static void nvs_erase(void); static void (*g_net_config_end_cb)(void) = NULL; +static void nvs_erase(void){ + nvs_flash_erase(); + // ESP_LOGI("Wifi is reset, please scan the QR to reconnect the wifi again"); + printf("Wifi is reset, please scan the QR to reconnect the wifi again\n"); +} + static void ui_app_page_return_click_cb(lv_event_t *e) { lv_obj_t *obj = lv_event_get_user_data(e); @@ -183,9 +192,25 @@ void ui_net_config_update_cb(ui_net_state_t state, void *args) lv_img_set_src(g_img, &icon_rmaker); lv_obj_align(g_img, LV_ALIGN_CENTER, 0, -10); lv_obj_clear_flag(g_hint_lab, LV_OBJ_FLAG_HIDDEN); - lv_label_set_text_fmt(g_hint_lab, "Device already connected to cloud\n" - "Wi-Fi is connected to #000000 %s#", ssid); - lv_obj_align_to(g_hint_lab, g_img, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); + // lv_label_set_text_fmt(g_hint_lab, "Device already connected to cloud\n" + // "Wi-Fi is connected to #000000 %s#", ssid); + // lv_obj_align_to(g_hint_lab, g_img, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); + + //Create a button to erase the nvs space where the wifi ssid and its password are located + lv_obj_t *wifi_reset=lv_btn_create(g_page); + lv_obj_set_size(wifi_reset, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_obj_add_style(wifi_reset, &ui_button_styles()->style, 0); + lv_obj_add_style(wifi_reset, &ui_button_styles()->style_pr, LV_STATE_PRESSED); + lv_obj_add_style(wifi_reset, &ui_button_styles()->style_focus, LV_STATE_FOCUS_KEY); + lv_obj_add_style(wifi_reset, &ui_button_styles()->style_focus, LV_STATE_FOCUSED); + lv_obj_align_to(wifi_reset, g_img,LV_ALIGN_OUT_BOTTOM_MID, -30, 10); + lv_obj_t *reset_label=lv_label_create(wifi_reset); + lv_label_set_text_static(reset_label,"Reset WiFi"); + lv_obj_set_style_text_color(reset_label, lv_color_make(18, 18, 18), LV_STATE_DEFAULT); + lv_obj_align(reset_label, LV_ALIGN_CENTER, 0, 0); + lv_obj_add_event_cb(wifi_reset, nvs_erase, LV_EVENT_CLICKED, NULL); + + } break; default: @@ -232,6 +257,8 @@ void ui_net_config_start(void (*fn)(void)) lv_indev_set_button_points(ui_get_button_indev(), points_array); } + + /* **************** APP NOT INSTALLED **************** */ g_btn_app_hint = lv_btn_create(ui_main_get_status_bar()); lv_obj_set_size(g_btn_app_hint, LV_SIZE_CONTENT, LV_SIZE_CONTENT); @@ -240,6 +267,7 @@ void ui_net_config_start(void (*fn)(void)) lv_obj_add_style(g_btn_app_hint, &ui_button_styles()->style_focus, LV_STATE_FOCUS_KEY); lv_obj_add_style(g_btn_app_hint, &ui_button_styles()->style_focus, LV_STATE_FOCUSED); lv_obj_align(g_btn_app_hint, LV_ALIGN_RIGHT_MID, 0, 0); + lv_obj_t *lab_app_inst = lv_label_create(g_btn_app_hint); lv_label_set_text_static(lab_app_inst, "To install APP"); lv_obj_set_style_text_color(lab_app_inst, lv_color_make(18, 18, 18), LV_STATE_DEFAULT); diff --git a/main/main.c b/main/main.c index 118c73b..d209729 100644 --- a/main/main.c +++ b/main/main.c @@ -43,6 +43,7 @@ #include #include #include +#include"app_wifi.h" extern bool s_connected; void * play_sound(const char *path); @@ -62,7 +63,6 @@ bool recv_warning_flag=0; //AED socket void * aedSocketMonitorFunc(void* args){ - while(!s_connected)sleep(60); while(1){ int emergencyReponseSocket=socket(AF_INET,SOCK_STREAM,0);/*建立socket*/ if(emergencyReponseSocket==-1){ @@ -367,8 +367,8 @@ void app_main(void) app_sr_start(false); app_rmaker_start(); + while(!s_connected){sleep(5);}; pthread_t aedMontorThread; pthread_create(&aedMontorThread,NULL,aedSocketMonitorFunc,NULL); pthread_join(aedMontorThread,NULL); } - -- GitLab