// ======================================================================
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++)
{
//电压在前后两个之间
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)
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;
}
}
-
return percent;
}
-
static uint32_t get_current_timestamp(void)
{
uint32_t timestamp = 0;