fix 3.5 touch freeze: async WiFi scan and GT911 reset.

Scan no longer blocks LVGL; always hw-reset GT911; larger buttons and click areas.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-25 20:01:37 +08:00
parent 9cbbb296b7
commit d9773a8b97
7 changed files with 129 additions and 42 deletions

View File

@@ -26,6 +26,7 @@ static DNSServer *g_dns = nullptr;
static WebServer *g_http = nullptr;
static bool g_portal = false;
static char g_ap_ssid[33] = WIFI_PROV_AP_SSID;
static bool g_scan_async = false;
static void set_state(WifiProvState s) {
if (g_state == s) {
@@ -269,27 +270,11 @@ void wifi_prov_connect_to(const char *ssid, const char *password) {
begin_sta_connect(g_ssid, g_pass);
}
int wifi_prov_scan(WifiScanItem *out, int max_items) {
if (!out || max_items <= 0) {
return 0;
}
if (max_items > WIFI_PROV_MAX_SCAN) {
max_items = WIFI_PROV_MAX_SCAN;
}
// SoftAP 时用 APSTA,否则扫描会关掉 AP
if (g_portal) {
WiFi.mode(WIFI_AP_STA);
} else {
WiFi.mode(WIFI_STA);
}
const int found = WiFi.scanNetworks(/*async=*/false, /*hidden=*/true);
static int fill_scan_results(WifiScanItem *out, int max_items, int found) {
if (found <= 0) {
WiFi.scanDelete();
return 0;
}
const int n = found < max_items ? found : max_items;
for (int i = 0; i < n; ++i) {
String s = WiFi.SSID(i);
@@ -302,6 +287,76 @@ int wifi_prov_scan(WifiScanItem *out, int max_items) {
return n;
}
int wifi_prov_scan(WifiScanItem *out, int max_items) {
if (!out || max_items <= 0) {
return 0;
}
if (max_items > WIFI_PROV_MAX_SCAN) {
max_items = WIFI_PROV_MAX_SCAN;
}
if (g_scan_async) {
WiFi.scanDelete();
g_scan_async = false;
}
if (g_portal) {
WiFi.mode(WIFI_AP_STA);
} else {
WiFi.mode(WIFI_STA);
}
const int found = WiFi.scanNetworks(/*async=*/false, /*hidden=*/true);
return fill_scan_results(out, max_items, found);
}
bool wifi_prov_scan_start() {
if (g_scan_async) {
return true;
}
if (g_portal) {
WiFi.mode(WIFI_AP_STA);
} else {
WiFi.mode(WIFI_STA);
}
/* async — does not block LVGL loop */
const int16_t rc = WiFi.scanNetworks(/*async=*/true, /*hidden=*/true);
if (rc == WIFI_SCAN_FAILED) {
Serial.println("[wifi] scan start failed");
return false;
}
g_scan_async = true;
Serial.println("[wifi] scan async started");
return true;
}
bool wifi_prov_scan_busy() { return g_scan_async; }
int wifi_prov_scan_poll(WifiScanItem *out, int max_items) {
if (!g_scan_async) {
return 0;
}
if (!out || max_items <= 0) {
return 0;
}
if (max_items > WIFI_PROV_MAX_SCAN) {
max_items = WIFI_PROV_MAX_SCAN;
}
const int16_t found = WiFi.scanComplete();
if (found == WIFI_SCAN_RUNNING) {
return -1;
}
g_scan_async = false;
if (found == WIFI_SCAN_FAILED) {
WiFi.scanDelete();
Serial.println("[wifi] scan failed");
return 0;
}
const int n = fill_scan_results(out, max_items, found);
Serial.printf("[wifi] scan done n=%d\n", n);
return n;
}
void wifi_prov_portal_start(const char *ap_ssid) {
if (g_portal) {
return;