增加电池信息电压 3313/2 3313/head
author1624952103 <pl@DESKTOP-EN9LKR5.localdomain>
Thu, 26 Mar 2026 10:40:58 +0000 (18:40 +0800)
committer1624952103 <pl@DESKTOP-EN9LKR5.localdomain>
Thu, 26 Mar 2026 10:40:58 +0000 (18:40 +0800)
code/sdk/zhihui/services/battery/service/battery_driver.cpp

index cbd01b5..fb9010b 100644 (file)
@@ -774,6 +774,32 @@ static int battery_get_percent_by_voltage(float voltage)
     // ======================================================================
     float temp_value = 0.0f;
 
+    // // ===================== 只打印当前使用的数组 =====================
+    static bool print_flag = false;
+    if(!print_flag)
+    {
+        print_flag = true;
+        printf("==== 当前使用的电池电压映射表 ====\n");
+        if(get_charge_stat())
+        {
+            printf("==== 充电模式 battery_charge_percent_map ====\n");
+        }
+        else
+        {
+            printf("==== 非充电模式 battery_percent_map ====\n");
+        }
+
+        for(int i=0; i<map_len; i++)
+        {
+            printf("[%2d] 电压: %.3f V → 电量: %d %%\n",
+                   i,
+                   battery_map[i][0],
+                   (int)battery_map[i][1]);
+        }
+        printf("=======================================\n");
+    }
+    // ===============================================================
+
     for (int i =0;i<map_len -1;i++)
     {
         //电压在前后两个之间
@@ -786,6 +812,16 @@ static int battery_get_percent_by_voltage(float voltage)
 
             percent =  (int)(temp_value + 0.5);
 
+            // ===================== 打印关键计算变量 =====================
+            printf("[电池计算] 当前电压=%.3fV | 区间[%d]%.3fV ~ [%d]%.3fV | r_div=%.3f | 计算电量=%.1f%% | 取整=%d%%\n",
+                   voltage,
+                   i, battery_map[i][0],
+                   i+1, battery_map[i+1][0],
+                   r_div,
+                   temp_value,
+                   percent);
+            // ============================================================
+
             if(get_charge_stat())
             {
                 // if(history_percent > percent && abs(history_percent - percent) < 10)
@@ -848,16 +884,15 @@ static int battery_get_percent_by_voltage(float voltage)
     if (voltage <= batteryservice_VOLTAGE_MIN)
         percent = 0;
 
-    if (voltage >= batteryservice_VOLTAGE_MAX) //电压大于4.3
+    if (voltage >= batteryservice_VOLTAGE_MAX)
     {
-        if(get_charge_stat() && history_percent < 100 && history_percent) //充电中则均匀增加
+        if(get_charge_stat() && history_percent < 100 && history_percent)
         {
             printf("111 history_percent:%d ,percent : %d ,voltage:%.3f \n",history_percent,percent,voltage);
-            // uapi_save_runtime_log(RUNTIME_LOG_BATTERY_MIN_UP);
             history_percent++;
             percent = history_percent;
         }
-        else if(!get_charge_stat() && history_percent) //未充电且history_percent不为0 则保持不变 
+        else if(!get_charge_stat() && history_percent)
         {
             printf("222 history_percent:%d ,percent : %d ,voltage:%.3f \n",history_percent,percent,voltage);
             percent = history_percent;
@@ -870,11 +905,9 @@ static int battery_get_percent_by_voltage(float voltage)
         }
     }
 
-
     return percent;
 }
 
-
 static uint32_t get_current_timestamp(void)
 {
     uint32_t timestamp = 0;