From: 1624952103 Date: Mon, 2 Feb 2026 10:45:28 +0000 (+0800) Subject: 优化低温关机、停止充电,增加电池电压存储 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=f700c765746fa94e3fb94c1e69f62cb58a886b4d;p=mirrors%2FFD230.git 优化低温关机、停止充电,增加电池电压存储 --- diff --git a/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp b/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp index 9915c0570..1e21e8b1d 100644 --- a/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp @@ -221,14 +221,16 @@ namespace OHOS if(strcmp(view.GetViewId(),"shutdown") == 0) { // #ifdef FD230_650 - uapi_poweroff_device(); + // uapi_poweroff_device(); + shutdown_reboot_prejobs(SHUTDOWN_TYPE); // #endif return true; } if(strcmp(view.GetViewId(),"reset") == 0) { // #ifdef FD230_650 - uapi_reboot_device(); + // uapi_reboot_device(); + shutdown_reboot_prejobs(REBOOT_TYPE); // #endif return true; diff --git a/code/sdk/zhihui/services/battery/service/battery_driver.cpp b/code/sdk/zhihui/services/battery/service/battery_driver.cpp index 5482e48e8..ed64085bb 100644 --- a/code/sdk/zhihui/services/battery/service/battery_driver.cpp +++ b/code/sdk/zhihui/services/battery/service/battery_driver.cpp @@ -76,6 +76,24 @@ typedef enum { #ifdef ENABLE_HP4570 #include "hp4570.h" #endif +#include "custom_utils.h" + +#define AVG_VOLTAGE_COUNT 7 + +#pragma pack(1) +typedef struct +{ + // float avg_vol = 0; + float sum_vol = 0; + uint8_t vol_num = 0; + float history_data[AVG_VOLTAGE_COUNT] = {0}; + int left = 0; + int right = -1; + uint32_t time = 0; + // uint8_t percent = 0; +} BAT_VOL_T; +#pragma pack() + #define HAL_ADC_SAMPLE_NUMBER_CONFIG_0 10 /* Channel with buffer manual sample average number. */ #define HAL_ADC_SAMPLE_NUMBER_CONFIG_1 10 /* Channel without buffer manual sample average number. */ @@ -476,16 +494,17 @@ static uint32_t g_adc_sample_stick = 0; #define TESTADC_DISACRD_DELAY_MS 3 #define MINIMUM_VOLTAGE_RANGE 2 #define MAXIMUM_VOLTAGE_RANGE 17 -#define AVG_VOLTAGE_COUNT 7 + +static BAT_VOL_T bat_vol; static int history_percent = 0; -static float sum_vol = 0; -static int vol_num=0; +// static float sum_vol = 0; +// static int vol_num=0; -static float history_data[AVG_VOLTAGE_COUNT]={0}; -static int left = 0; -static int right = -1; +// static float history_data[AVG_VOLTAGE_COUNT]={0}; +// static int left = 0; +// static int right = -1; static uint32_t history_time = 0; static uint32_t sample_time = 0; @@ -497,6 +516,71 @@ static uint8_t percernt_installized = 0; static float test_temp = 0; +bool batteryservice_get_voltage_by_channel(float *voltage, uint8_t channel); + +void battery_save_vol(void) +{ + uint32_t time = 0; + uapi_get_timestampe_ss(&time); + for(int i = 0; i < bat_vol.vol_num;i++) + { + // printf("history_data[%d]:%.3f\n",i,bat_vol.history_data[i]); + if(bat_vol.history_data[i] < 3.3 || bat_vol.history_data[i] > 4.45) + bat_vol.history_data[i] = 0; + } + + bat_vol.time = time; + // bat_vol.percent = cur_percent; + uapi_save_file_data("/user/userdata/battery.bin",(uint8_t *)&bat_vol,sizeof(BAT_VOL_T),"wb"); + // uapi_save_file_data("/user/userdata/battery_time.bin",(uint8_t *)&time,sizeof(uint32_t),"wb"); +} + +void battery_restore_vol(void) +{ + // float cur_vol = 0; + uint32_t time = 0; + uint16_t len = sizeof(BAT_VOL_T); + + uapi_get_file_data("/user/userdata/battery.bin",(uint8_t *)&bat_vol,&len); + + uapi_get_timestampe_ss(&time); + + printf("time:%d,l_time:%d\n",time,bat_vol.time ); + if(time - bat_vol.time >= 24 * 60 * 60) + { + memset_s(&bat_vol,sizeof(BAT_VOL_T),0,sizeof(BAT_VOL_T)); + bat_vol.right = -1; + return; + } + + if(bat_vol.vol_num < 0 || bat_vol.vol_num > AVG_VOLTAGE_COUNT || + bat_vol.right < -1 || bat_vol.right >= AVG_VOLTAGE_COUNT || + bat_vol.left < -1 || bat_vol.left >= AVG_VOLTAGE_COUNT || + bat_vol.sum_vol < bat_vol.vol_num * 3.25 || bat_vol.sum_vol > (bat_vol.vol_num * 4.45)) + { + memset_s(&bat_vol,sizeof(BAT_VOL_T),0,sizeof(BAT_VOL_T)); + bat_vol.right = -1; + return; + } + + // batteryservice_get_voltage_by_channel(&cur_vol,ADC_CHANNEL_BAT_VOLTAGE); + + // if(bat_vol.percent > 0 && bat_vol.percent<=100 && (fabsf(cur_vol - bat_vol.avg_vol) < 0.15)) + // history_percent = bat_vol.percent; + // for(int i = 0; i < AVG_VOLTAGE_COUNT;i++) + // { + // printf("history_data[%d]:%.3f\n",i,bat_vol.history_data[i]); + // if(bat_vol.history_data[i] < 3.3 || bat_vol.history_data[i] > 4.45) + // { + // bat_vol.history_data[i] = 0; + // } + + // } + // printf("bat_vol.percent:%d,cur_vol:%.3f,bat_vol.avg_vol:%.3f\n",bat_vol.vol_num,cur_vol,bat_vol.avg_vol); + + // printf("vol_num:%d\n",bat_vol.vol_num); +} + void battery_percent_init(uint8_t percent) { percernt_installized = 1; @@ -763,43 +847,51 @@ static void get_avg_voltage(float *vol) sample_time = current_time - history_time; history_time = current_time; - if(sample_time >= 10) + if(sample_time >= 10 && *vol >= 3.25 && *vol <= 4.45) { sample_time = 0; - if(vol_num == AVG_VOLTAGE_COUNT) + if(bat_vol.vol_num == AVG_VOLTAGE_COUNT) { - sum_vol -= history_data[left]; - history_data[left] = 0; - left++; - left = left % AVG_VOLTAGE_COUNT; - vol_num--; + bat_vol.sum_vol -= bat_vol.history_data[bat_vol.left]; + bat_vol.history_data[bat_vol.left] = 0; + bat_vol.left++; + bat_vol.left = bat_vol.left % AVG_VOLTAGE_COUNT; + bat_vol.vol_num--; } - vol_num++; - right++; - right = right % AVG_VOLTAGE_COUNT; - history_data[right] = *vol; - sum_vol += history_data[right]; + bat_vol.vol_num++; + bat_vol.right++; + bat_vol.right = bat_vol.right % AVG_VOLTAGE_COUNT; + bat_vol.history_data[bat_vol.right] = *vol; + bat_vol.sum_vol += bat_vol.history_data[bat_vol.right]; // PRINT("history_data[right] : %.3f\n",history_data[right]); } - if(vol_num > 0) + + if(bat_vol.vol_num > 0) { - if(vol_num > 2) + if(bat_vol.vol_num > 2) { - min_vol = history_data[0]; - max_vol = history_data[0]; - for (int i = 0;i < vol_num; i++) + min_vol = bat_vol.history_data[0]; + max_vol = bat_vol.history_data[0]; + for (int i = 0;i < bat_vol.vol_num; i++) { - // PRINT("history_data[%d] : %.3f\n",i,history_data[i]); - if (history_data[i] < min_vol) - min_vol = history_data[i]; - if (history_data[i] > max_vol) - max_vol = history_data[i]; + + // PRINT("333history_data[%d] : %.3f\n",i,bat_vol.history_data[i]); + if (bat_vol.history_data[i] < min_vol) + min_vol = bat_vol.history_data[i]; + if (bat_vol.history_data[i] > max_vol) + max_vol = bat_vol.history_data[i]; } - *vol = (sum_vol - max_vol - min_vol) / (vol_num - 2); + + + // bat_vol.avg_vol = (bat_vol.sum_vol - max_vol - min_vol) / (bat_vol.vol_num - 2); + // printf("avg_vol : %.3f\n",bat_vol.avg_vol); + *vol = (bat_vol.sum_vol - max_vol - min_vol) / (bat_vol.vol_num - 2); + // printf("avg_vol : %.3f\n",*vol); } else - *vol = sum_vol / vol_num; + *vol = bat_vol.sum_vol / bat_vol.vol_num; + // bat_vol.avg_vol = bat_vol.sum_vol / bat_vol.vol_num; } } @@ -865,7 +957,7 @@ static bool adc_get_sample_result(float *voltage, uint8_t channel) int DecimalPart_1 = (int)(DecimalPart / 100); int DecimalPart_2 = (int)((DecimalPart % 100) / 10); int DecimalPart_3 = (int)(DecimalPart % 10); - // PRINT("*voltage : %.3f \n",*voltage); + // PRINT("222*voltage : %.3f \n",*voltage); // PRINT("DecimalPart_1 : %d , DecimalPart_2 : %d DecimalPart_3 : %d \n",DecimalPart_1,DecimalPart_2,DecimalPart_3); uint16_t value = DecimalPart_1 << 8 | DecimalPart_2 << 4 | DecimalPart_3 << 0; @@ -883,6 +975,7 @@ static bool adc_get_sample_result(float *voltage, uint8_t channel) } else { + // cur_percent = battery_get_percent_by_voltage(bat_vol.avg_vol); cur_percent = battery_get_percent_by_voltage(*voltage); } diff --git a/code/sdk/zhihui/services/battery/service/battery_service.cpp b/code/sdk/zhihui/services/battery/service/battery_service.cpp index 371c6ea3d..29bf842c5 100644 --- a/code/sdk/zhihui/services/battery/service/battery_service.cpp +++ b/code/sdk/zhihui/services/battery/service/battery_service.cpp @@ -103,7 +103,7 @@ static unsigned long g_app_queue = 0xFFFFFFFF; #else #define BATTERY_LOWPOWER_ALARM_SHUTDOWNLEVEL 5 #endif -#define BATTERY_DISABLE_CHARGE_HI_TEMP_VALUE (60.0f) //停止充电温度 +#define BATTERY_DISABLE_CHARGE_HI_TEMP_VALUE (45.0f) //停止充电温度 #define BATTERY_DISABLE_CHARGE_LOW_TEMP_VALUE (-10.0f) //停止充电温度 #define BATTERY_VOLTAGE_DEBOUNCE 2 @@ -371,7 +371,7 @@ static void battery_check_chargement(void) //获取电池温度 batteryservice_get_battery_temp(&bat_temp); - printf("bat_temp:%f\n",bat_temp); + // printf("bat_temp:%f\n",bat_temp); // bat_temp = -10; float charge_mA = 0; @@ -442,9 +442,9 @@ static void battery_check_chargement(void) if(bat_temp >= BATTERY_DISABLE_CHARGE_HI_TEMP_VALUE || bat_temp <= 0) { - PRINT("battery temp is too high : %.2f >= %.2f, disable charge!\n",bat_temp,BATTERY_DISABLE_CHARGE_HI_TEMP_VALUE); + PRINT("battery temp is too high or low : %.2f >= %.2f, disable charge! \n",bat_temp,BATTERY_DISABLE_CHARGE_HI_TEMP_VALUE); disable_charge(); - if(g_chargestatus != 0) + // if(g_chargestatus != 0) { printf("hp4570_set_ceb_en(false); \n"); #ifdef ENABLE_HP4570 @@ -641,6 +641,7 @@ static void battery_check_task(void *arg) }else if(mail.comm.event == BATTERY_CMD_SAVE_PERCENT) { // battery_save_percent(); + battery_save_vol(); } else if (mail.comm.event == BATTERY_CMD_START_AGING_TEST) { @@ -805,7 +806,7 @@ errcode_t uapi_battery_init(void) #ifdef ENABLE_HP4570 hp4570_init(HP4570N); #endif - + battery_restore_vol(); battery_check_voltage(); battery_percent_init(0); //先读历史电量 diff --git a/code/sdk/zhihui/services/battery/service/battery_service.h b/code/sdk/zhihui/services/battery/service/battery_service.h index 1e675e010..bfc3e85ba 100644 --- a/code/sdk/zhihui/services/battery/service/battery_service.h +++ b/code/sdk/zhihui/services/battery/service/battery_service.h @@ -63,6 +63,8 @@ void battery_get_data(void); void battery_save_data(void); void battery_get_data_t(BATTERY_DATA_T **data,uint16_t *length); uint8_t batteryservice_set_test_bat_temp(float temp); +void battery_save_vol(void); +void battery_restore_vol(void); #ifdef __cplusplus #if __cplusplus diff --git a/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c b/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c index 2488d304b..409cb4f33 100644 --- a/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c +++ b/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c @@ -931,7 +931,8 @@ void factorytest_protocol_common_decode(uint8_t submode,uint8_t testitem,uint8_t &send_data, 1); LOS_Mdelay(100); - uapi_poweroff_device(); + // uapi_poweroff_device(); + shutdown_reboot_prejobs(SHUTDOWN_TYPE); } else if(testitem == 0x03) { @@ -946,7 +947,8 @@ void factorytest_protocol_common_decode(uint8_t submode,uint8_t testitem,uint8_t LOS_Msleep(500); - uapi_reboot_device(); + // uapi_reboot_device(); + shutdown_reboot_prejobs(REBOOT_TYPE); } else if(testitem == 0x04) { @@ -2145,7 +2147,8 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint &send_data, 1); LOS_Mdelay(100); - uapi_poweroff_device(); + // uapi_poweroff_device(); + shutdown_reboot_prejobs(SHUTDOWN_TYPE); } break;