123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- /**
- * @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 60*24*30*3
- 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_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 *air_exhaust_first_vol = nvs_get_uint8(AIR_EXHAUST_FIRST_VOL);
- uint8_t *air_exhaust_second_vol = nvs_get_uint8(AIR_EXHAUST_SECOND_VOL);
- uint8_t *air_exhaust_third_vol = nvs_get_uint8(AIR_EXHAUST_THIRD_VOL);
- uint8_t *air_exhaust_fourth_vol = nvs_get_uint8(AIR_EXHAUST_FOURTH_VOL);
- uint8_t *air_exhaust_fifth_vol = nvs_get_uint8(AIR_EXHAUST_FIFTH_VOL);
- uint8_t *air_supply_first_vol = nvs_get_uint8(AIR_SUPPLY_FIRST_VOL);
- uint8_t *air_supply_second_vol = nvs_get_uint8(AIR_SUPPLY_SECOND_VOL);
- uint8_t *air_supply_third_vol = nvs_get_uint8(AIR_SUPPLY_THIRD_VOL);
- uint8_t *air_supply_fourth_vol = nvs_get_uint8(AIR_SUPPLY_FOURTH_VOL);
- uint8_t *air_supply_fifth_vol = nvs_get_uint8(AIR_SUPPLY_FIFTH_VOL);
- 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 *screen_off_minute = nvs_get_uint8(NVS_SCREEN_OFF_MINUTE_KEY);
- if (screen_off_minute == NULL) {
- nvs_set_uint8(10, NVS_SCREEN_OFF_MINUTE_KEY);
- setting->screen_off_minute = 10;
- } 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 (min_hum_valve == NULL) {
- nvs_set_uint8(DEFAULT_MIN_HUM, NVS_MIN_HUM);
- setting->exhaust_first_vol = DEFAULT_MIN_HUM;
- } else {
- setting->exhaust_first_vol = *min_hum_valve;
- }
- if (air_exhaust_first_vol == NULL) {
- nvs_set_uint32(air_fan_vol[0], AIR_EXHAUST_FIRST_VOL);
- setting->exhaust_first_vol = air_fan_vol[0];
- } else {
- setting->exhaust_first_vol = *air_exhaust_first_vol;
- }
- if (air_exhaust_second_vol == NULL) {
- nvs_set_uint32(air_fan_vol[1], AIR_EXHAUST_SECOND_VOL);
- setting->exhaust_second_vol = air_fan_vol[1];
- } else {
- setting->exhaust_second_vol = *air_exhaust_second_vol;
- }
- if (air_exhaust_third_vol == NULL) {
- nvs_set_uint32(air_fan_vol[2], AIR_EXHAUST_THIRD_VOL);
- setting->exhaust_third_vol = air_fan_vol[2];
- } else {
- setting->exhaust_third_vol = *air_exhaust_third_vol;
- }
- if (air_exhaust_fourth_vol == NULL) {
- nvs_set_uint32(air_fan_vol[3], AIR_EXHAUST_FOURTH_VOL);
- setting->exhaust_fourth_vol = air_fan_vol[3];
- } else {
- setting->exhaust_fourth_vol = *air_exhaust_fourth_vol;
- }
- if (air_exhaust_fifth_vol == NULL) {
- nvs_set_uint32(air_fan_vol[4], AIR_EXHAUST_FIFTH_VOL);
- setting->exhaust_fifth_vol = air_fan_vol[4];
- } else {
- setting->exhaust_fifth_vol =*air_exhaust_fifth_vol;
- }
- if (air_supply_first_vol == NULL) {
- nvs_set_uint32(air_fan_vol[0], AIR_SUPPLY_FIRST_VOL);
- setting->supply_first_vol = air_fan_vol[0];
- } else {
- setting->supply_first_vol = *air_supply_first_vol;
- }
- if (air_supply_second_vol == NULL) {
- nvs_set_uint32(air_fan_vol[1], AIR_SUPPLY_SECOND_VOL);
- setting->supply_second_vol = air_fan_vol[1];
- } else {
- setting->supply_second_vol = *air_supply_second_vol;
- }
- if (air_supply_third_vol == NULL) {
- nvs_set_uint32(air_fan_vol[2], AIR_SUPPLY_THIRD_VOL);
- setting->supply_third_vol = air_fan_vol[2];
- } else {
- setting->supply_third_vol = *air_supply_third_vol;
- }
- if (air_supply_fourth_vol == NULL) {
- nvs_set_uint32(air_fan_vol[3], AIR_SUPPLY_FOURTH_VOL);
- setting->supply_fourth_vol = air_fan_vol[3];
- } else {
- setting->supply_fourth_vol = *air_supply_fourth_vol;
- }
- if (air_supply_fifth_vol == NULL) {
- nvs_set_uint32(air_fan_vol[4], AIR_SUPPLY_FIFTH_VOL);
- setting->supply_fifth_vol = air_fan_vol[4];
- } else {
- setting->supply_fifth_vol = *air_supply_fifth_vol;
- }
- 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;
- }
- 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;
- }
- }
- void save_system_setting(system_setting_t *setting) {
- 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_uint32(setting->exhaust_first_vol, AIR_EXHAUST_FIRST_VOL);
- nvs_set_uint32(setting->exhaust_second_vol, AIR_EXHAUST_SECOND_VOL);
- nvs_set_uint32(setting->exhaust_third_vol, AIR_EXHAUST_THIRD_VOL);
- nvs_set_uint32(setting->exhaust_fourth_vol, AIR_EXHAUST_FOURTH_VOL);
- nvs_set_uint32(setting->exhaust_fifth_vol, AIR_EXHAUST_FIFTH_VOL);
- nvs_set_uint32(setting->supply_first_vol, AIR_SUPPLY_FIRST_VOL);
- nvs_set_uint32(setting->supply_second_vol, AIR_SUPPLY_SECOND_VOL);
- nvs_set_uint32(setting->supply_third_vol, AIR_SUPPLY_THIRD_VOL);
- nvs_set_uint32(setting->supply_fourth_vol, AIR_SUPPLY_FOURTH_VOL);
- nvs_set_uint32(setting->supply_fifth_vol, AIR_SUPPLY_FIFTH_VOL);
- 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);
- }
- 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);
- }
|