#include #include "FluxPower.h" #include "FluxWifi.h" #include "FluxSpifs.h" static const char *TAG = "POWER_IO"; /*电量变化引起的界面控件参数变化*/ extern lv_obj_t * ui_Batinfo_valueVoltage; extern lv_obj_t * ui_Batinfo_valueVolume; extern lv_obj_t * ui_Batinfo_SpinboxBAT; extern lv_obj_t * ui_Batinfo_BarBAT; extern lv_obj_t * ui_Home_LabelHeaderBatValue; extern lv_obj_t * ui_Home_SliderHeaderBat; /*没有返回值的电源管理任务*/ static int Bat_Adc_Value = 0; static adc_oneshot_unit_handle_t adc1_handle; static TaskHandle_t powerTaskHandle; /*定义变量存储电池电压值*/ static float Bat_Voltage_Value = 0; void powerTask(void) { /*初始化存储系统*/ spifs_init(); /*进行WIFI扫描 扫描后立即触发下拉菜单事件*/ wifi_scan(); lv_event_send(ui_wifiSet_wifiname,LV_EVENT_VALUE_CHANGED,NULL); while (1) { ESP_ERROR_CHECK(adc_oneshot_read(adc1_handle, EXAMPLE_ADC1_CHAN8, &Bat_Adc_Value)); /*根据采样值计算电池电压*/ Bat_Voltage_Value = 2 * (float)Bat_Adc_Value * 1.767 / 4095.0 + 2.3; vTaskDelay(pdMS_TO_TICKS(5000)); if (lv_scr_act() == ui_Batinfo) { /*配置电池信息页显示*/ lv_bar_set_value(ui_Batinfo_BarBAT,Bat_Adc_Value,LV_ANIM_ON); lv_spinbox_set_value(ui_Batinfo_SpinboxBAT,Bat_Adc_Value); lv_label_set_text_fmt(ui_Batinfo_valueVoltage,"%.2fV",Bat_Voltage_Value); lv_label_set_text_fmt(ui_Batinfo_valueVolume,"%.0fmAh",Bat_Voltage_Value/4.2*2500); } /*设置Home页的显示电量*/ lv_slider_set_value(ui_Home_SliderHeaderBat,Bat_Voltage_Value/4.2*100,LV_ANIM_ON); lv_label_set_text_fmt(ui_Home_LabelHeaderBatValue,"%.0f%%",Bat_Voltage_Value/4.2*100); } } void powerInit(void) { /*电源接口初始化*/ //-------------ADC1 Init---------------// adc_oneshot_unit_init_cfg_t init_config1 = { .unit_id = ADC_UNIT_1, }; ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &adc1_handle)); //-------------ADC1 Config---------------// adc_oneshot_chan_cfg_t config = { .bitwidth = ADC_BITWIDTH_12, .atten = ADC_ATTEN_DB_6, }; ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, EXAMPLE_ADC1_CHAN8, &config)); xTaskCreate(powerTask,"powerTask",4*1024, NULL, 2, &powerTaskHandle); }