连接wifi时按下boot重置wifi

This commit is contained in:
Terrence
2024-11-25 02:27:21 +08:00
parent 472219d5bf
commit b07ec1a148
10 changed files with 49 additions and 6 deletions

View File

@@ -517,7 +517,7 @@ void Application::AudioEncodeTask() {
audio_decode_queue_.pop_front(); audio_decode_queue_.pop_front();
lock.unlock(); lock.unlock();
if (skip_to_end_ || chat_state_ != kChatStateSpeaking) { if (skip_to_end_) {
continue; continue;
} }

View File

@@ -7,6 +7,7 @@
#include "led.h" #include "led.h"
#include "config.h" #include "config.h"
#include <wifi_station.h>
#include <esp_log.h> #include <esp_log.h>
#include <driver/i2c_master.h> #include <driver/i2c_master.h>
@@ -38,7 +39,11 @@ private:
void InitializeButtons() { void InitializeButtons() {
boot_button_.OnClick([this]() { boot_button_.OnClick([this]() {
Application::GetInstance().ToggleChatState(); auto& app = Application::GetInstance();
if (app.GetChatState() == kChatStateUnknown && !WifiStation::GetInstance().IsConnected()) {
ResetWifiConfiguration();
}
app.ToggleChatState();
}); });
volume_up_button_.OnClick([this]() { volume_up_button_.OnClick([this]() {

View File

@@ -2,6 +2,7 @@
#include "application.h" #include "application.h"
#include "system_info.h" #include "system_info.h"
#include "font_awesome_symbols.h" #include "font_awesome_symbols.h"
#include "settings.h"
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
#include <freertos/task.h> #include <freertos/task.h>
@@ -149,3 +150,15 @@ void WifiBoard::SetPowerSaveMode(bool enabled) {
auto& wifi_station = WifiStation::GetInstance(); auto& wifi_station = WifiStation::GetInstance();
wifi_station.SetPowerSaveMode(enabled); wifi_station.SetPowerSaveMode(enabled);
} }
void WifiBoard::ResetWifiConfiguration() {
// Reset the wifi station
{
Settings settings("wifi", true);
settings.EraseAll();
}
GetDisplay()->ShowNotification("已重置 WiFi...");
vTaskDelay(pdMS_TO_TICKS(1000));
// Reboot the device
esp_restart();
}

View File

@@ -19,6 +19,7 @@ public:
virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) override; virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) override;
virtual const char* GetNetworkStateIcon() override; virtual const char* GetNetworkStateIcon() override;
virtual void SetPowerSaveMode(bool enabled) override; virtual void SetPowerSaveMode(bool enabled) override;
virtual void ResetWifiConfiguration();
}; };
#endif // WIFI_BOARD_H #endif // WIFI_BOARD_H

View File

@@ -11,6 +11,7 @@
#include <esp_lcd_panel_vendor.h> #include <esp_lcd_panel_vendor.h>
#include <driver/i2c_master.h> #include <driver/i2c_master.h>
#include <driver/spi_common.h> #include <driver/spi_common.h>
#include <wifi_station.h>
#define TAG "LichuangDevBoard" #define TAG "LichuangDevBoard"
@@ -71,7 +72,11 @@ private:
void InitializeButtons() { void InitializeButtons() {
boot_button_.OnClick([this]() { boot_button_.OnClick([this]() {
Application::GetInstance().ToggleChatState(); auto& app = Application::GetInstance();
if (app.GetChatState() == kChatStateUnknown && !WifiStation::GetInstance().IsConnected()) {
ResetWifiConfiguration();
}
app.ToggleChatState();
}); });
} }

View File

@@ -184,7 +184,6 @@ void Ssd1306Display::SetupUI_128x64() {
status_label_ = lv_label_create(status_bar_); status_label_ = lv_label_create(status_bar_);
lv_obj_set_flex_grow(status_label_, 1); lv_obj_set_flex_grow(status_label_, 1);
lv_label_set_long_mode(status_label_, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_label_set_text(status_label_, "正在初始化"); lv_label_set_text(status_label_, "正在初始化");
lv_obj_set_style_text_align(status_label_, LV_TEXT_ALIGN_CENTER, 0); lv_obj_set_style_text_align(status_label_, LV_TEXT_ALIGN_CENTER, 0);
@@ -255,11 +254,14 @@ void Ssd1306Display::SetupUI_128x32() {
status_label_ = lv_label_create(side_bar_); status_label_ = lv_label_create(side_bar_);
lv_obj_set_flex_grow(status_label_, 1); lv_obj_set_flex_grow(status_label_, 1);
lv_obj_set_width(status_label_, width_ - 32);
lv_label_set_long_mode(status_label_, LV_LABEL_LONG_SCROLL_CIRCULAR); lv_label_set_long_mode(status_label_, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_label_set_text(status_label_, "正在初始化"); lv_label_set_text(status_label_, "正在初始化");
notification_label_ = lv_label_create(side_bar_); notification_label_ = lv_label_create(side_bar_);
lv_obj_set_flex_grow(notification_label_, 1); lv_obj_set_flex_grow(notification_label_, 1);
lv_obj_set_width(notification_label_, width_ - 32);
lv_label_set_long_mode(notification_label_, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_label_set_text(notification_label_, "通知"); lv_label_set_text(notification_label_, "通知");
lv_obj_add_flag(notification_label_, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(notification_label_, LV_OBJ_FLAG_HIDDEN);
} }

View File

@@ -198,7 +198,6 @@ void St7789Display::SetupUI() {
status_label_ = lv_label_create(status_bar_); status_label_ = lv_label_create(status_bar_);
lv_obj_set_flex_grow(status_label_, 1); lv_obj_set_flex_grow(status_label_, 1);
lv_label_set_long_mode(status_label_, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_label_set_text(status_label_, "正在初始化"); lv_label_set_text(status_label_, "正在初始化");
lv_obj_set_style_text_align(status_label_, LV_TEXT_ALIGN_CENTER, 0); lv_obj_set_style_text_align(status_label_, LV_TEXT_ALIGN_CENTER, 0);

View File

@@ -1,6 +1,6 @@
## IDF Component Manager Manifest File ## IDF Component Manager Manifest File
dependencies: dependencies:
78/esp-wifi-connect: "~1.4.0" 78/esp-wifi-connect: "~1.4.1"
78/esp-opus-encoder: "~1.1.0" 78/esp-opus-encoder: "~1.1.0"
78/esp-ml307: "~1.6.3" 78/esp-ml307: "~1.6.3"
espressif/led_strip: "^2.4.1" espressif/led_strip: "^2.4.1"

View File

@@ -63,3 +63,19 @@ void Settings::SetInt(const std::string& key, int32_t value) {
ESP_LOGW(TAG, "Namespace %s is not open for writing", ns_.c_str()); ESP_LOGW(TAG, "Namespace %s is not open for writing", ns_.c_str());
} }
} }
void Settings::EraseKey(const std::string& key) {
if (read_write_) {
ESP_ERROR_CHECK(nvs_erase_key(nvs_handle_, key.c_str()));
} else {
ESP_LOGW(TAG, "Namespace %s is not open for writing", ns_.c_str());
}
}
void Settings::EraseAll() {
if (read_write_) {
ESP_ERROR_CHECK(nvs_erase_all(nvs_handle_));
} else {
ESP_LOGW(TAG, "Namespace %s is not open for writing", ns_.c_str());
}
}

View File

@@ -13,6 +13,8 @@ public:
void SetString(const std::string& key, const std::string& value); void SetString(const std::string& key, const std::string& value);
int32_t GetInt(const std::string& key, int32_t default_value = 0); int32_t GetInt(const std::string& key, int32_t default_value = 0);
void SetInt(const std::string& key, int32_t value); void SetInt(const std::string& key, int32_t value);
void EraseKey(const std::string& key);
void EraseAll();
private: private:
std::string ns_; std::string ns_;