修改电池温度自检间隔为40s
authorpenglei <1624952103@qq.com>
Mon, 1 Dec 2025 02:47:45 +0000 (10:47 +0800)
committerpenglei <1624952103@qq.com>
Mon, 1 Dec 2025 02:47:45 +0000 (10:47 +0800)
code/sdk/zhihui/services/battery/service/battery_driver.cpp
code/sdk/zhihui/services/battery/service/battery_service.cpp

index f43c00e..0364df7 100644 (file)
@@ -916,7 +916,7 @@ uint8_t batteryservice_get_battery_temp(float *temp)
     battery_info_t *current_battery_info = get_current_battery_info();
     *temp = current_battery_info->battery_ntc_temp;
     // PRINT("*temp : %.3f\n",*temp);
-    if(!*temp)
+    // if(!*temp)
     {
         batteryservice_get_voltage_by_channel(&current_battery_info->battery_ntc_temp,ADC_CHANNEL_BAT_TEMP);
         uapi_tcxo_delay_ms(20);   
index 701e3cf..e3871d5 100644 (file)
@@ -111,6 +111,34 @@ errcode_t charger_plug_event_ui_sendmsg_toUI(uint8_t plugged);
 static BATTERY_DATA_T *bat_t;
 static uint32_t len = 0;
 
+static uint32_t bat_check_time = 1;
+static uint32_t last_bat_check_time = 1;
+
+static void battery_check_timer_change(uint8_t percent) 
+{   
+    if(g_battery_timer && osTimerIsRunning(g_battery_timer))
+    {
+        if(percent >= 60)
+            bat_check_time = 4;
+        else if(percent >= 30 && percent < 60)
+            bat_check_time = 2;
+        else if(percent < 30)
+            bat_check_time = 1;
+
+        if(last_bat_check_time != bat_check_time)
+            last_bat_check_time = bat_check_time;
+        else
+            return;
+
+        printf("battery_check_timer_change percent:%d,bat_check_timer_ms:%ds\n",percent,bat_check_time);
+        int ret = osTimerStop(g_battery_timer);
+        // printf("osTimerStop ret : %d\n",ret);
+        ret = osTimerStart(g_battery_timer, bat_check_time * 1000);
+        // printf("osTimerStart ret : %d\n",ret);
+       
+    }
+}
+
 void battery_file_check(BATTERY_DATA_T newStruct, const char *filename) 
 {
     FILE *fp;
@@ -295,17 +323,17 @@ static void battery_check_voltage(void)
     batteryservice_get_voltage_by_channel(&current_battery_info->battery_voltage,ADC_CHANNEL_BAT_VOLTAGE);
     uapi_tcxo_delay_ms(20);
 
-    if(bat_temp_cnt >= 8) //5分钟左右检测一次电池温度
-    {
-        bat_temp_cnt = 0;
-        batteryservice_get_voltage_by_channel(&current_battery_info->battery_ntc_temp,ADC_CHANNEL_BAT_TEMP);
-        // printf("current_battery_info->battery_ntc_temp : %.3f \n",current_battery_info->battery_ntc_temp);
-        uapi_tcxo_delay_ms(20);
-    }
-    else
-    {
-        bat_temp_cnt ++;
-    }
+    // if(bat_temp_cnt >= 8) //5分钟左右检测一次电池温度
+    // {
+    //     bat_temp_cnt = 0;
+    //     batteryservice_get_voltage_by_channel(&current_battery_info->battery_ntc_temp,ADC_CHANNEL_BAT_TEMP);
+    //     // printf("current_battery_info->battery_ntc_temp : %.3f \n",current_battery_info->battery_ntc_temp);
+    //     uapi_tcxo_delay_ms(20);
+    // }
+    // else
+    // {
+    //     bat_temp_cnt ++;
+    // }
     // batteryservice_get_voltage_by_channel(&current_battery_info->pcb_ntc_temp,ADC_CHANNEL_PCB_TEMP);
     // uapi_tcxo_delay_ms(20);    
 }
@@ -329,6 +357,9 @@ static void battery_check_chargement(void)
     float bat_temp;
     //获取电量
     uint8_t percent = batteryservice_get_voltage(&voltage);
+
+    // battery_check_timer_change(percent);
+
     //获取电池温度
     batteryservice_get_battery_temp(&bat_temp);