Baji_Rtc_Toy_Key/main/dzbj/device_mode.c
Rdzleo dbdd304905 代码初始化:
本项目为触摸版项目代码复制而来,基于此版本进行按键功能的适配!
2026-03-23 11:14:56 +08:00

38 lines
979 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "device_mode.h"
#include "nvs_flash.h"
#include "esp_log.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define TAG "DeviceMode"
#define NVS_NAMESPACE "device"
#define NVS_KEY "mode"
device_mode_t device_mode_get(void) {
nvs_handle_t h;
int32_t mode = DEVICE_MODE_AI;
if (nvs_open(NVS_NAMESPACE, NVS_READONLY, &h) == ESP_OK) {
nvs_get_i32(h, NVS_KEY, &mode);
nvs_close(h);
}
return (device_mode_t)mode;
}
void device_mode_set(device_mode_t mode) {
nvs_handle_t h;
if (nvs_open(NVS_NAMESPACE, NVS_READWRITE, &h) == ESP_OK) {
nvs_set_i32(h, NVS_KEY, (int32_t)mode);
nvs_commit(h);
nvs_close(h);
}
ESP_LOGI(TAG, "模式切换为 %s即将重启...",
mode == DEVICE_MODE_BADGE ? "吧唧" : "AI");
vTaskDelay(pdMS_TO_TICKS(500));
esp_restart();
}
bool device_mode_is_badge(void) {
return device_mode_get() == DEVICE_MODE_BADGE;
}