优化了NVS使用,改为/platform_storage.c统一处理
|
After Width: | Height: | Size: 283 KiB |
|
After Width: | Height: | Size: 283 KiB |
|
After Width: | Height: | Size: 284 KiB |
|
After Width: | Height: | Size: 283 KiB |
|
After Width: | Height: | Size: 285 KiB |
|
After Width: | Height: | Size: 287 KiB |
|
After Width: | Height: | Size: 289 KiB |
|
After Width: | Height: | Size: 286 KiB |
|
After Width: | Height: | Size: 285 KiB |
|
After Width: | Height: | Size: 283 KiB |
|
After Width: | Height: | Size: 285 KiB |
|
After Width: | Height: | Size: 286 KiB |
|
After Width: | Height: | Size: 283 KiB |
|
After Width: | Height: | Size: 284 KiB |
|
After Width: | Height: | Size: 285 KiB |
|
After Width: | Height: | Size: 283 KiB |
|
After Width: | Height: | Size: 282 KiB |
|
After Width: | Height: | Size: 282 KiB |
|
After Width: | Height: | Size: 291 KiB |
|
After Width: | Height: | Size: 283 KiB |
|
After Width: | Height: | Size: 294 KiB |
|
After Width: | Height: | Size: 281 KiB |
|
After Width: | Height: | Size: 287 KiB |
|
After Width: | Height: | Size: 271 KiB |
|
After Width: | Height: | Size: 290 KiB |
|
After Width: | Height: | Size: 281 KiB |
|
After Width: | Height: | Size: 374 KiB |
|
After Width: | Height: | Size: 281 KiB |
@@ -173,12 +173,16 @@ void platform_console_write_line(const char *line);
|
||||
* - `erase`: removing an absent key is treated as success (idempotent).
|
||||
*/
|
||||
esp_err_t platform_storage_set_blob(const char *ns, const char *key, const void *data, size_t len);
|
||||
esp_err_t platform_storage_set_string(const char *ns, const char *key, const char *value);
|
||||
esp_err_t platform_storage_set_u8(const char *ns, const char *key, uint8_t value);
|
||||
esp_err_t platform_storage_set_i8(const char *ns, const char *key, int8_t value);
|
||||
esp_err_t platform_storage_get_blob(const char *ns,
|
||||
const char *key,
|
||||
void *out,
|
||||
size_t out_len,
|
||||
size_t *out_len_actual);
|
||||
esp_err_t platform_storage_get_u8(const char *ns, const char *key, uint8_t *out);
|
||||
esp_err_t platform_storage_get_i8(const char *ns, const char *key, int8_t *out);
|
||||
esp_err_t platform_storage_get_u32(const char *ns, const char *key, uint32_t *out);
|
||||
esp_err_t platform_storage_get_u64(const char *ns, const char *key, uint64_t *out);
|
||||
esp_err_t platform_storage_get_string(const char *ns,
|
||||
|
||||
@@ -56,6 +56,78 @@ esp_err_t platform_storage_set_blob(const char *ns, const char *key, const void
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t platform_storage_set_string(const char *ns, const char *key, const char *value)
|
||||
{
|
||||
if (ns == NULL || key == NULL || value == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = nvs_open(ns, NVS_READWRITE, &handle);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = nvs_set_str(handle, key, value);
|
||||
if (err == ESP_OK) {
|
||||
err = nvs_commit(handle);
|
||||
}
|
||||
|
||||
nvs_close(handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Persist string %s/%s failed (%s)", ns, key, esp_err_to_name(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t platform_storage_set_u8(const char *ns, const char *key, uint8_t value)
|
||||
{
|
||||
if (ns == NULL || key == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = nvs_open(ns, NVS_READWRITE, &handle);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = nvs_set_u8(handle, key, value);
|
||||
if (err == ESP_OK) {
|
||||
err = nvs_commit(handle);
|
||||
}
|
||||
|
||||
nvs_close(handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Persist u8 %s/%s failed (%s)", ns, key, esp_err_to_name(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t platform_storage_set_i8(const char *ns, const char *key, int8_t value)
|
||||
{
|
||||
if (ns == NULL || key == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = nvs_open(ns, NVS_READWRITE, &handle);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = nvs_set_i8(handle, key, value);
|
||||
if (err == ESP_OK) {
|
||||
err = nvs_commit(handle);
|
||||
}
|
||||
|
||||
nvs_close(handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Persist i8 %s/%s failed (%s)", ns, key, esp_err_to_name(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t platform_storage_get_blob(const char *ns,
|
||||
const char *key,
|
||||
void *out,
|
||||
@@ -111,6 +183,23 @@ esp_err_t platform_storage_get_u8(const char *ns, const char *key, uint8_t *out)
|
||||
return normalize_missing_key(err);
|
||||
}
|
||||
|
||||
esp_err_t platform_storage_get_i8(const char *ns, const char *key, int8_t *out)
|
||||
{
|
||||
if (ns == NULL || key == NULL || out == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = open_storage_readonly(ns, &handle);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = nvs_get_i8(handle, key, out);
|
||||
nvs_close(handle);
|
||||
return normalize_missing_key(err);
|
||||
}
|
||||
|
||||
esp_err_t platform_storage_get_u32(const char *ns, const char *key, uint32_t *out)
|
||||
{
|
||||
if (ns == NULL || key == NULL || out == NULL) {
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/task.h"
|
||||
#include "platform.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "ssid_manager.h"
|
||||
#include "wifi_manager.h"
|
||||
#include "wifi_storage_hooks.h"
|
||||
|
||||
static const char *TAG = "wifi_portal";
|
||||
|
||||
@@ -40,8 +42,29 @@ static wifi_portal_behavior_hooks_t s_behavior_hooks = {};
|
||||
|
||||
static esp_err_t apply_sta_stability_policy(void);
|
||||
|
||||
static void install_wifi_storage_hooks(void)
|
||||
{
|
||||
static bool s_installed;
|
||||
if (s_installed) {
|
||||
return;
|
||||
}
|
||||
|
||||
const wifi_storage_hooks_t hooks = {
|
||||
.set_string = platform_storage_set_string,
|
||||
.get_string = platform_storage_get_string,
|
||||
.set_u8 = platform_storage_set_u8,
|
||||
.get_u8 = platform_storage_get_u8,
|
||||
.set_i8 = platform_storage_set_i8,
|
||||
.get_i8 = platform_storage_get_i8,
|
||||
.erase = platform_storage_erase,
|
||||
};
|
||||
wifi_storage_set_hooks(&hooks);
|
||||
s_installed = true;
|
||||
}
|
||||
|
||||
static void log_saved_wifi_candidates(const char *context)
|
||||
{
|
||||
install_wifi_storage_hooks();
|
||||
const auto &ssid_list = SsidManager::GetInstance().GetSsidList();
|
||||
ESP_LOGI(TAG,
|
||||
"%s: %u saved Wi-Fi credential candidate(s)",
|
||||
@@ -141,6 +164,7 @@ static void wifi_manager_event_callback(WifiEvent event, const std::string &data
|
||||
|
||||
static esp_err_t ensure_wifi_manager_initialized(void)
|
||||
{
|
||||
install_wifi_storage_hooks();
|
||||
if (s_wifi_manager_initialized) {
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -162,6 +186,7 @@ static esp_err_t ensure_wifi_manager_initialized(void)
|
||||
|
||||
static void seed_default_credentials(const char *ssid, const char *password)
|
||||
{
|
||||
install_wifi_storage_hooks();
|
||||
auto &manager = SsidManager::GetInstance();
|
||||
const auto saved_count = manager.GetSsidList().size();
|
||||
|
||||
@@ -227,6 +252,7 @@ esp_err_t wifi_portal_init_defaults(const char *seed_ssid, const char *seed_pass
|
||||
|
||||
bool wifi_portal_has_saved_credentials(void)
|
||||
{
|
||||
install_wifi_storage_hooks();
|
||||
return !SsidManager::GetInstance().GetSsidList().empty();
|
||||
}
|
||||
|
||||
@@ -295,6 +321,7 @@ esp_err_t wifi_portal_connect_sta(int timeout_ms)
|
||||
|
||||
esp_err_t wifi_portal_save_credentials(const char *ssid, const char *password)
|
||||
{
|
||||
install_wifi_storage_hooks();
|
||||
ESP_RETURN_ON_ERROR(wifi_portal_lock(), TAG, "Failed to lock Wi-Fi portal");
|
||||
PortalUnlockGuard guard;
|
||||
|
||||
@@ -315,6 +342,7 @@ esp_err_t wifi_portal_save_credentials(const char *ssid, const char *password)
|
||||
|
||||
esp_err_t wifi_portal_clear_saved_credentials(void)
|
||||
{
|
||||
install_wifi_storage_hooks();
|
||||
ESP_RETURN_ON_ERROR(wifi_portal_lock(), TAG, "Failed to lock Wi-Fi portal");
|
||||
PortalUnlockGuard guard;
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import os
|
||||
import re
|
||||
import struct
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
LCD_ROOT = Path(r"D:\Code\chaowan\lcd\main")
|
||||
OUT_DIR = ROOT / "components" / "platform" / "assets" / "lcd"
|
||||
|
||||
IMAGE_SOURCES = {
|
||||
"qianzhiwuxing": ["qianzhiwuxing0"],
|
||||
"shui": ["shui1", "shui2"],
|
||||
"mu": ["mu1", "mu2"],
|
||||
"huo": ["huo1", "huo2"],
|
||||
"tu": ["tu1", "tu2"],
|
||||
"jin": ["jin1", "jin2"],
|
||||
"caiwei": ["bei0", "dongbei0", "dong0", "dongnan0", "nan0", "xinan0", "xi0", "xibei0"],
|
||||
"chouqian_qianzhi": ["chouqianqianzhi0", "chouqianqianzhi1", "chouqianqianzhi2"],
|
||||
"chouqian_buyun": ["shangshangqian0", "buyunqian1", "buyunqian2"],
|
||||
"chouqian_heping": [None, "hepingqian1", "hepingqian2"],
|
||||
"chouqian_shangshang": [None, "shangshangqian1", "shangshangqian2"],
|
||||
"chouqian_xiaoji": [None, "xiaojiqian1", "xiaojiqian2"],
|
||||
"chouqian_zhongshang": [None, "zhongshangqian1", "zhongshangqian2"],
|
||||
}
|
||||
|
||||
|
||||
def extract_arrays(source_text):
|
||||
arrays = {}
|
||||
pattern = re.compile(
|
||||
r"static\s+const\s+(?:rle_structure_t|eye_image_frame_t)\s+([A-Za-z0-9_]+)\[\]\s*=\s*\{",
|
||||
re.MULTILINE,
|
||||
)
|
||||
for match in pattern.finditer(source_text):
|
||||
name = match.group(1)
|
||||
cursor = match.end()
|
||||
depth = 1
|
||||
while cursor < len(source_text) and depth > 0:
|
||||
if source_text[cursor] == "{":
|
||||
depth += 1
|
||||
elif source_text[cursor] == "}":
|
||||
depth -= 1
|
||||
cursor += 1
|
||||
arrays[name] = source_text[match.end(): cursor - 1]
|
||||
return arrays
|
||||
|
||||
|
||||
def parse_runs(body):
|
||||
runs = []
|
||||
for color, count in re.findall(r"\{\s*0x([0-9A-Fa-f]+)\s*,\s*(\d+)\s*\}", body):
|
||||
runs.append((int(color, 16), int(count)))
|
||||
if not runs:
|
||||
raise ValueError("no runs parsed")
|
||||
return runs
|
||||
|
||||
|
||||
def write_rle(path, runs):
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with path.open("wb") as f:
|
||||
for color, count in runs:
|
||||
f.write(struct.pack("<HH", color, count))
|
||||
|
||||
|
||||
def main():
|
||||
eye_arrays = extract_arrays((LCD_ROOT / "eye_image.c").read_text(encoding="utf-8"))
|
||||
OUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
for asset_dir, frames in IMAGE_SOURCES.items():
|
||||
for index, array_name in enumerate(frames):
|
||||
if array_name is None:
|
||||
continue
|
||||
write_rle(OUT_DIR / f"{asset_dir}{index}.rle", parse_runs(eye_arrays[array_name]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||