From 25d6aac1adf47e368ab5d9596b5a05e58544bbf0 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Sat, 9 Nov 2024 16:49:27 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E6=89=8B=E8=A1=A8=E9=87=8D?= =?utf8?q?=E5=90=AF=E8=B7=B3=E7=94=B5BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../battery/service/battery_driver.cpp | 32 ++++++++++++++++--- .../battery/service/battery_service.cpp | 2 +- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/code/sdk/application/battery/service/battery_driver.cpp b/code/sdk/application/battery/service/battery_driver.cpp index c2b20aa6b..0ae388b84 100644 --- a/code/sdk/application/battery/service/battery_driver.cpp +++ b/code/sdk/application/battery/service/battery_driver.cpp @@ -475,8 +475,23 @@ static int battery_get_percent_by_voltage(float voltage) if (voltage <= batteryservice_VOLTAGE_MIN) percent = 0; - if (voltage >= batteryservice_VOLTAGE_MAX) - percent = 100; + if (voltage >= batteryservice_VOLTAGE_MAX) //电压大于4.3 + { + if(get_charge_stat() && history_percent < 100) //充电中则均匀增加 + { + history_percent++; + percent = history_percent; + } + else if(history_percent) //未充电且history_percent不为0 则保持不变 + { + percent = history_percent; + } + else + { + percent = 100; + } + } + return percent; } @@ -587,9 +602,18 @@ static bool adc_get_sample_result(float *voltage, uint8_t channel) get_avg_voltage(voltage); if(percernt_installized) { - cur_percent = battery_get_percent_by_voltage(*voltage); + //历史电量不为0 则开机第一个电量为历史电量 + if(history_percent && !cur_percent && *voltage > batteryservice_VOLTAGE_MIN) + { + cur_percent = history_percent; + } + else + { + cur_percent = battery_get_percent_by_voltage(*voltage); + } + } - // PRINT("cur_percent : %d , history_percent : %d \n",cur_percent,history_percent); + // PRINT("cur_percent : %d , history_percent : %d *voltage : %f\n",cur_percent,history_percent,*voltage); } else if (channel == 0){ *voltage = adc_trans_systick_to_battery_ntc(stick); diff --git a/code/sdk/application/battery/service/battery_service.cpp b/code/sdk/application/battery/service/battery_service.cpp index d169d10c5..47a43d010 100644 --- a/code/sdk/application/battery/service/battery_service.cpp +++ b/code/sdk/application/battery/service/battery_service.cpp @@ -394,7 +394,6 @@ static void battery_check_task(void *arg) charger_plug_event_ui_sendmsg_toUI(0); }else if(mail.comm.event == BATTERY_CMD_FIRST_CHECK) { - battery_check_voltage(); battery_check_chargement(); }else if(mail.comm.event == BATTERY_CMD_SAVE_PERCENT) @@ -561,6 +560,7 @@ void uapi_battery_create_queue(void) #define BATTERY_TASK_SIZE 0x1C00 errcode_t uapi_battery_init(void) { + battery_check_voltage(); battery_percent_init(battery_get_percent_onstart()); //先读历史电量 app_task_definition_t taskcfg={0}; -- 2.17.1