文件 system_app.h
cpp
#ifndef system_app_H
#define system_app_H
#include "system_app.h"
//#include "esp32_trans_app.h"
#include "system_app.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/event_groups.h"
#include "esp_timer.h"
#include "esp_sleep.h"
#include "system_storage.h"
extern EventGroupHandle_t sys_evt_group;
/**
系统APP托管功能:
1.屏幕背光
2.休眠息屏
3.时间
*/
#define system_rest_sec_default 300
#define nvs_storage_name "sys_app_datas"
#define nvs_version 1, 0, 0 // nvs版本号
#define software_version 1, 0, 9 // 固件版本号
#define software_version_release 1
/*电池信息结构体*/
typedef struct
{
uint8_t soc; // 当前电量 85%
uint8_t low_soc; // 电量≤20%时报警
uint16_t voltage;// 电压 3.85V
uint16_t rtt; // 内阻 120mΩ
} bat_info_t;
typedef struct
{
uint32_t screen_rest_sec; // 休眠时长
uint8_t screen_bringhtness; // 屏幕亮度
} system_eeprom_t;
/**
* @brief 系统参数
*/
typedef struct wifi_info_t
{
char name_str[128];
char password_str[128];
uint8_t save_cnt;//表示存储的 name_str 和 password_str ,如果只有其中一项 :例如只有password_str,则 save_cnt 等于 1,如果同时都保存了,则为2
} wifi_info_t , *p_wifi_info ;
typedef struct wifi_list_t
{
uint32_t r;
uint32_t w;
uint32_t len;
wifi_info_t *wifi_list_buf;
}wifi_list_t ,*p_wifi_list;
void wifi_list_init(p_wifi_list wifi_list, uint32_t len, wifi_info_t *wifi_list_buf);
int wifi_list_read(p_wifi_list wifi_list, wifi_info_t *wifi_list_item);
int wifi_list_write(p_wifi_list wifi_list, wifi_info_t wifi_list_item);
typedef struct
{
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t week;
uint8_t hour;
uint8_t min;
uint8_t sec;
} clock_time_t;
//气体
typedef struct
{
uint16_t hcho;
float tvoc;
uint16_t pm25;
} gas_info_t;
//温湿度
typedef struct
{
uint16_t temperature;
uint16_t humidity;
} temp_humi_info_t;
//天气
typedef struct
{
uint8_t icon[128];
uint8_t temperature;
} weather_info_t;
//空气质量
typedef struct
{
uint8_t air_quality;
} air_quality_info_t;
typedef struct
{
uint8_t chart_dat[1024];
bool is_show; // 是否显示聊天框
} chart_box_info_t;
enum
{
screen_always_on = 0xffffffff,
};
typedef enum
{
power_on = 0,
wake_up = 1
} system_wake_t;
typedef struct
{
chart_box_info_t chart_box_info; // 聊天框数据
p_wifi_list p_wifi_info_list;
uint8_t lcd_blk; // 背光亮度
uint8_t network_state; // 背光亮度
uint8_t network_state_cnt; //网络连接超时时间,超了就算是没网的状态 20秒
clock_time_t time; // 时间
gas_info_t gas_info; // 气体信息
temp_humi_info_t th_info; // 温湿度信息
weather_info_t weather_info; // 天气信息
air_quality_info_t air_info; // 空气质量信息
uint32_t screen_rest_count; // 休眠计数
bat_info_t bat_info; // 电池信息
uint8_t soft_version[3]; // 固件版本号
} system_data_t;
typedef struct
{
system_data_t data;
system_eeprom_t eeprom; // 存储数据
} system_paras_t;
/**
* @brief 系统初始化,初始化底层接口,初始化APP
*/
void system_init();
void system_deep_sleep_start();
void system_restart();
/**
* @brief 获取唤醒模式
*
* @return system_wake_t power_on(开机或重启) wake_up(休眠唤醒)
*/
system_wake_t system_get_power_on_mode();
//系统时间
void system_upload_time(clock_time_t time);
void system_get_time(clock_time_t *time);
void system_upload_time_hour_minute(uint8_t hour, uint8_t minute);
void system_upload_time_from_isr(clock_time_t time);
//息屏保存计数
void system_get_eeprom_screen_rest(uint32_t *rest_sec);
void system_save_eeprom_rest_time(void);
void system_upload_eeprom_rest_time(uint32_t rest_sec);
//息屏计数
void system_screen_rest_clr();
void system_upload_screen_rest_count(uint32_t count);
void system_upload_screen_rest_count_increase(uint32_t *count);//count 返回增加后的值
//背光
void system_upload_blk(uint8_t blk);
void system_get_blk(uint8_t *blk);
void system_upload_blk_rest(uint8_t blk); //可以等于0 亮度
void system_upload_eeprom_brightness(uint8_t brightness);
void system_save_eeprom_brightness(void);
void system_screen_resume_display(void) ;
void system_screen_resume_display_from_isr(void); //恢复亮屏
//电池
void system_upload_bat(bat_info_t *info);
void system_set_bat(uint8_t low_soc);
void system_get_bat(bat_info_t *info);
void system_upload_bat_from_isr(bat_info_t *info);
//版本
void system_get_soft_version(uint8_t *ver);
int strcmp_my(const char *str1, const char *str2);
uint8_t system_day_count_week(uint8_t year, uint8_t month, uint8_t day);
void sys_app_init(void *arg);
void system_upload_weather(weather_info_t weather);
void system_upload_weather_icon(weather_info_t weather);
void system_upload_weather_temperatrue(weather_info_t weather);
void system_upload_gas(gas_info_t gas);
void system_upload_air_quality(air_quality_info_t air_info);
void system_upload_screen_rest_count(uint32_t count);
void system_get_weather(weather_info_t *weather);
void system_get_gas(gas_info_t *gas);
void system_get_air_quality(air_quality_info_t *air_info);
int system_upload_add_wifi_item(wifi_info_t wifi_list_item);
int system_get_wifi_item(wifi_info_t *wifi_list_item);
int system_get_wifi_item_index(wifi_info_t *wifi_list_item, uint32_t index);
uint32_t system_get_wifi_list_len(void);
void system_upload_chat_box_info_chat_data(chart_box_info_t chart_box_info);
void system_upload_chat_box_info_is_chat(chart_box_info_t chart_box_info);
void system_get_chat_box_info(chart_box_info_t *chart_box_info);
//温湿度
void system_upload_temp_humi(temp_humi_info_t th_info);
void system_get_temp_humi(temp_humi_info_t *th_info);
void system_upload_temp(uint16_t temperature);
void system_upload_humi(uint16_t humidity);
void system_get_temp(uint16_t *temperature);
void system_get_humi(uint16_t *humidity);
extern QueueHandle_t trans_evt_queue;
extern EventGroupHandle_t trans_evt_group;
extern EventGroupHandle_t trans_evt_blk_group;
extern float test_tvoc;
extern uint16_t test_pm25;
extern uint16_t test_hcho;
extern uint16_t test_temperature;
extern uint16_t test_humidity;
extern float test_battery;
extern uint8_t battery_is_full;
#endif