fix 3.5 backlight and GT911 for cyd_35r.
TFT_BL was wrongly GPIO21 (GT911 INT); use GPIO27, DRAW_BUF_DIV=20, and export firmware/cyd_35r. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
82
include/wifi_prov.h
Normal file
82
include/wifi_prov.h
Normal file
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* 通用 WiFi 配网核心(无 LVGL 依赖)
|
||||
*
|
||||
* 流程:
|
||||
* 1. wifi_prov_begin() 读 NVS,有凭证则尝试 STA 连接
|
||||
* 2. 失败 / 无凭证 → 业务层开屏上 UI 或 SoftAP 门户
|
||||
* 3. wifi_prov_save() + wifi_prov_connect_to() 完成配网
|
||||
* 4. loop 里调用 wifi_prov_loop() 做断线重连与门户处理
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
#ifndef WIFI_PROV_AP_SSID
|
||||
#define WIFI_PROV_AP_SSID "CYD-Setup"
|
||||
#endif
|
||||
|
||||
#ifndef WIFI_PROV_CONNECT_TIMEOUT_MS
|
||||
#define WIFI_PROV_CONNECT_TIMEOUT_MS 20000u
|
||||
#endif
|
||||
|
||||
#ifndef WIFI_PROV_RECONNECT_MS
|
||||
#define WIFI_PROV_RECONNECT_MS 8000u
|
||||
#endif
|
||||
|
||||
static constexpr int WIFI_PROV_MAX_SCAN = 16;
|
||||
static constexpr size_t WIFI_PROV_SSID_MAX = 32;
|
||||
static constexpr size_t WIFI_PROV_PASS_MAX = 64;
|
||||
|
||||
struct WifiScanItem {
|
||||
char ssid[WIFI_PROV_SSID_MAX + 1];
|
||||
int32_t rssi;
|
||||
wifi_auth_mode_t auth;
|
||||
};
|
||||
|
||||
enum WifiProvState : uint8_t {
|
||||
WIFI_PROV_IDLE = 0,
|
||||
WIFI_PROV_CONNECTING,
|
||||
WIFI_PROV_CONNECTED,
|
||||
WIFI_PROV_FAILED,
|
||||
WIFI_PROV_PORTAL,
|
||||
};
|
||||
|
||||
using WifiProvStateCb = void (*)(WifiProvState state, void *user);
|
||||
|
||||
void wifi_prov_set_state_cb(WifiProvStateCb cb, void *user = nullptr);
|
||||
|
||||
/** 初始化 Preferences + WiFi STA;有凭证则异步开始连接。返回是否已有凭证。 */
|
||||
bool wifi_prov_begin();
|
||||
|
||||
bool wifi_prov_has_credentials();
|
||||
bool wifi_prov_is_connected();
|
||||
WifiProvState wifi_prov_state();
|
||||
|
||||
String wifi_prov_ssid();
|
||||
String wifi_prov_ip();
|
||||
int8_t wifi_prov_rssi();
|
||||
|
||||
void wifi_prov_save(const char *ssid, const char *password);
|
||||
void wifi_prov_clear();
|
||||
|
||||
/** 用已存凭证连接(异步,结果看 wifi_prov_loop / state) */
|
||||
void wifi_prov_connect_saved();
|
||||
|
||||
/** 连接指定网络并在成功后写入 NVS */
|
||||
void wifi_prov_connect_to(const char *ssid, const char *password);
|
||||
|
||||
/** 同步扫描,结果写入 out[],返回条数(≤ WIFI_PROV_MAX_SCAN) */
|
||||
int wifi_prov_scan(WifiScanItem *out, int max_items);
|
||||
|
||||
/**
|
||||
* SoftAP + 简易 Captive Portal(手机连 CYD-Setup → http://192.168.4.1)
|
||||
* 与屏上配网可并行;配网成功后会自动 stop。
|
||||
*/
|
||||
void wifi_prov_portal_start(const char *ap_ssid = WIFI_PROV_AP_SSID);
|
||||
void wifi_prov_portal_stop();
|
||||
bool wifi_prov_portal_active();
|
||||
|
||||
/** 每 loop 调用:重连、门户 HTTP、状态回调 */
|
||||
void wifi_prov_loop();
|
||||
Reference in New Issue
Block a user