| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- /**
- * @Author: 李建
- * @Date: 2025/5/2 11:48
- * Description: 系统设置功能
- * Copyright: Copyright (©) 2025 永续绿建. All rights reserved.
- */
- #include <esp_log.h>
- #include <esp_timer.h>
- #include "setting.h"
- #include "lvgl.h"
- #include "system/miscellaneous_interface.h"
- #include "lcd_st7701.h"
- #include "gui_guider.h"
- #define DEFAULT_REPORT_DURATION 30
- #define DEFAULT_MIN_HUM 30
- #define FILTER_LIFE_TIME_VALVE 51840//六个月,每五分钟计数加一(4320个小时)
- static const char *TAG = "system_setting";
- lv_timer_t * screen_timer;
- static uint8_t screen_on_off_status;// 当前屏幕亮或灭的状态
- void read_system_setting(system_setting_t *setting) {
- uint8_t air_exhaust_fan_vol[5]={75,77,79,81,85};
- uint8_t air_supply_fan_vol[5]={30,35,40,45,50};
- uint8_t *min_hum_valve = nvs_get_uint8(NVS_MIN_HUM);
- uint32_t *filter_life_time_valve = nvs_get_uint32(FILTER_LIFE_TIME);
- uint8_t *report_duration = nvs_get_uint8(NVS_REPORT_DATA_DURATION);
- uint8_t *screen_auto_off = nvs_get_uint8(NVS_SCREEN_AUTO_OFF_KEY);
- if (screen_auto_off == NULL) {
- nvs_set_uint8(1, NVS_SCREEN_AUTO_OFF_KEY);
- setting->screen_auto_off = 1;
- } else {
- setting->screen_auto_off = *screen_auto_off;
- }
- uint8_t *_mould_proof_runtime = nvs_get_uint8(NVS_MOULD_PROOF_RUNTIME);
- if (_mould_proof_runtime == NULL) {
- nvs_set_uint8(1, NVS_MOULD_PROOF_RUNTIME);
- // setting->mould_proof_runtime = 1;//测试
- setting->mould_proof_runtime = 60;
- } else {
- setting->mould_proof_runtime = *_mould_proof_runtime;
- }
- uint8_t *screen_off_minute = nvs_get_uint8(NVS_SCREEN_OFF_MINUTE_KEY);
- if (screen_off_minute == NULL) {
- nvs_set_uint8(1, NVS_SCREEN_OFF_MINUTE_KEY);
- setting->screen_off_minute = 1;
- } else {
- setting->screen_off_minute = *screen_off_minute;
- }
- uint8_t *sound_on_off = nvs_get_uint8(NVS_SOUND_ON_OFF_KEY);
- if (sound_on_off == NULL) {
- nvs_set_uint8(1, NVS_SOUND_ON_OFF_KEY);
- setting->sound_on_off = 1;
- } else {
- setting->sound_on_off = *sound_on_off;
- }
- uint8_t *sound_volume = nvs_get_uint8(NVS_SOUND_VOLUME_KEY);
- if (sound_volume == NULL) {
- nvs_set_uint8(50, NVS_SOUND_VOLUME_KEY);
- setting->sound_volume = 50;
- } else {
- setting->sound_volume = *sound_volume;
- }
- if (filter_life_time_valve == NULL) {
- nvs_set_uint32(FILTER_LIFE_TIME_VALVE, FILTER_LIFE_TIME);
- setting->filter_life_time = FILTER_LIFE_TIME_VALVE;
- } else {
- setting->filter_life_time = *filter_life_time_valve;
- }
- setting->filter_life_time = FILTER_LIFE_TIME_VALVE;
- if (report_duration == NULL) {
- nvs_set_uint8(DEFAULT_REPORT_DURATION, NVS_REPORT_DATA_DURATION);
- setting->report_data_duration = DEFAULT_REPORT_DURATION;
- } else {
- setting->report_data_duration = *report_duration;
- }
- uint8_t *devic_type = nvs_get_uint8(NVS_SLAVE_ADDR);
- if (devic_type == NULL) {
- nvs_set_uint8(0, NVS_SLAVE_ADDR);
- setting->devic_type = 0;
- } else {
- setting->devic_type = *devic_type;
- }
- uint8_t *slave_addr = nvs_get_uint8(NVS_DEVIC_TYPE);
- if (devic_type == NULL) {
- nvs_set_uint8(0, NVS_DEVIC_TYPE);
- setting->slave_addr = 0;
- } else {
- setting->slave_addr = *slave_addr;
- }
- }
- void save_system_setting(system_setting_t *setting) {
- setting->set_min_hum=30;
- nvs_set_uint16(setting->set_min_hum, NVS_MIN_HUM);
- nvs_set_uint32(setting->filter_life_time, FILTER_LIFE_TIME);
- nvs_set_uint8(setting->report_data_duration, NVS_REPORT_DATA_DURATION);
- nvs_set_uint8(setting->sound_on_off, NVS_SOUND_ON_OFF_KEY);
- nvs_set_uint8(setting->sound_volume, NVS_SOUND_VOLUME_KEY);
- nvs_set_uint8(setting->screen_auto_off, NVS_SCREEN_AUTO_OFF_KEY);
- nvs_set_uint8(setting->screen_off_minute, NVS_SCREEN_OFF_MINUTE_KEY);
- nvs_set_uint8(setting->mould_proof_runtime, NVS_MOULD_PROOF_RUNTIME);
- }
- static uint8_t set_bits(uint8_t num, uint8_t bit, uint8_t value) {
- if (bit > 7)
- return num;
- if (value)
- return num | (1 << bit);
- else
- return num & ~(1 << bit);
- }
- static void screen_off_timer_cb(lv_timer_t * timer) {
- lcd_st7701_backlight_off();
- lv_screen_load_anim(guider_ui.screen_main, LV_SCR_LOAD_ANIM_MOVE_RIGHT, 100, 0, false);
- screen_on_off_status = 0;
- nvs_set_uint8(1, NVS_SCREEN_ON_OFF);
- lv_timer_pause(screen_timer);
- }
- bool reset_screen_off(){
- if(screen_timer==NULL)return false;
- lv_timer_reset(screen_timer);
- if(screen_on_off_status==0)
- {
- lcd_st7701_backlight_on();
- nvs_set_uint8(0, NVS_SCREEN_ON_OFF);
- screen_on_off_status = 1;
- lv_timer_resume(screen_timer);
- return true;
- }
- return false;
- }
- void screen_off_timer_init(system_setting_t* setting) {
- ESP_LOGD(TAG, "screen_off_timer_init");
- screen_timer = lv_timer_create(screen_off_timer_cb, 1000 * 60 * setting->screen_off_minute, NULL);
- }
|