关机充电满电图标

2020-05-21  本文已影响0人  Letcos
platform:RK3399
OS:Android 7.1

概述

RK已经实现了关机充电图标动画显示的功能,在实际的使用过程中有一个问题:就算充满电了,充电动画图标仍然在,而没有一个满电图标显示.

满电图标显示

1.增加满电图标,目录如下

tools/resource_tool/resources/images/battery_fully.bmp

2.修改配置文件

tools/resource_tool/resources/images/battery_fully.bmp

 #reserve.
 bat_error=images/battery_fail.bmp

+#battery fully images
+bat_fully=images/battery_fully.bmp
+
 #num of level configs.
 levels=6

3.修改显示逻辑

diff --git a/common/cmd_charge.c b/common/cmd_charge.c
index 7d9acba..7e3599b 100755
--- a/common/cmd_charge.c
+++ b/common/cmd_charge.c
@@ -279,11 +279,13 @@ static anim_level_conf* level_confs = NULL;
 static int level_conf_num = 0;
 static int only_current_level = false;
 static char bat_err_path[MAX_INDEX_ENTRY_PATH_LEN];
+static char bat_fully_path[MAX_INDEX_ENTRY_PATH_LEN];
 
 #define OPT_CHARGE_ANIM_DELAY       "delay="
 #define OPT_CHARGE_ANIM_LOOP_CUR    "only_current_level="
 #define OPT_CHARGE_ANIM_LEVELS      "levels="
 #define OPT_CHARGE_ANIM_BAT_ERROR   "bat_error="
+#define OPT_CHARGE_ANIM_BAT_FULLY   "bat_fully="
 #define OPT_CHARGE_ANIM_LEVEL_CONF  "min_level="
 #define OPT_CHARGE_ANIM_LEVEL_NUM   "num="
 #define OPT_CHARGE_ANIM_LEVEL_PFX   "prefix="
@@ -435,6 +437,11 @@ static bool load_anim_desc(const char* desc_path, bool dump) {
            snprintf(bat_err_path, sizeof(bat_err_path), "%s",
                    arg + strlen(OPT_CHARGE_ANIM_BAT_ERROR));
            LOGD("Found battery error image:%s", bat_err_path);
+       } else if (!memcmp(arg, OPT_CHARGE_ANIM_BAT_FULLY,
+                   strlen(OPT_CHARGE_ANIM_BAT_FULLY))) {
+           snprintf(bat_fully_path, sizeof(bat_fully_path), "%s",
+                   arg + strlen(OPT_CHARGE_ANIM_BAT_FULLY));
+           LOGD("Found battery fully image:%s", bat_fully_path);
        } else {
            LOGE("Unknown arg:%s", arg);
            continue;
@@ -543,8 +550,12 @@ static void update_image(void) {
    int level = get_battery_capacity();
    int actual_conf = get_index_for_level(level);
    LOGD("level:%d, index:%d", level, actual_conf);
-
-   //step forward.
+   //battery full image  by hewy 2020/05/08
+   if(level >= 100) {
+       show_resource_image("images/battery_fully.bmp");
+       return;
+   }
+//step forward.
    current_index++;
 
    if (only_current_level) {

测试问题

修改过后测试发现,无论如何都无法显示满电图标.最后排查发现电量计cw2015是通过读取电压值判断是否满电的,实际上会有5%~10%的误差,导致一直检测到没有充满,但是实际上是充满了.可以改用电量来判断是否充满

--- a/drivers/power/fuel_gauge/fg_cw201x.c
+++ b/drivers/power/fuel_gauge/fg_cw201x.c
@@ -174,27 +174,20 @@ static int cw201x_check_charge(void)
 
 static int get_capcity(int volt)
 {
-   int i = 0;
-   int level0, level1;
-   int cap;
-   int step = 100 / (ARRAY_SIZE(volt_tab) -1);
+   int cw_capacity = 0;
+   int reg_val = 0;
 
+   reg_val = cw_read_word(REG_SOC);
 
-   for (i = 0 ; i < ARRAY_SIZE(volt_tab); i++) {
-       if (volt <= (volt_tab[i]))
-           break;
-   }
+   cw_capacity = reg_val>>8;
+   printf("CW2015[%d]: cw_capacity = %d\n", cw_capacity);
 
-   if (i == 0) 
-       return 0;
+   /*case 1 : avoid IC error, read SOC > 100*/
+   if ((cw_capacity < 0) || (cw_capacity > 100)) {
+       printf("Error:  cw_capacity = %d\n", cw_capacity);
+   }
    
-   level0 = volt_tab[i -1]; 
-   level1 = volt_tab[i];
-
-   cap = step * (i-1) + step *(volt - level0)/(level1 - level0);
-   /*printf("cap%d step:%d level0 %d level1 %d  diff %d\n",
-           cap, step, level0 ,level1, diff);*/
-   return cap;
+   return cw_capacity;
 }
 
 static int cw201x_update_battery(struct pmic *p, struct pmic *bat)

2020.06.16更新

经过充分测试,上述方式存在一个问题,当满电图标显示一段时间之后,按开机键无法开机。
错误原因:

failed to alloc 171600byte memory to display

实现方式存在问题,导致后来无法分配内存。
可以更换实现方式来解决这个问题:

diff --git a/tools/resource_tool/resources/charge_anim_desc.txt b/tools/resource_tool/resources/charge_anim_desc.txt
index 40faf88..9a8b86b 100644
--- a/tools/resource_tool/resources/charge_anim_desc.txt
+++ b/tools/resource_tool/resources/charge_anim_desc.txt
@@ -2,7 +2,7 @@
 delay=900
 
 #only show current level's pics.
-only_current_level=false
+only_current_level=true
 
 #reserve.
 bat_error=images/battery_fail.bmp
diff --git a/tools/resource_tool/resources/images/battery_5.bmp b/tools/resource_tool/resources/images/battery_5.bmp
index 9dce894..3aa52f1 100644
Binary files a/tools/resource_tool/resources/images/battery_5.bmp and b/tools/resource_tool/resources/images/battery_5.bmp differ
  1. 回退上面满电实现
  2. 将battery_5.bmp替换为battery_fully.bmp
  3. only_current_level=true
上一篇 下一篇

猜你喜欢

热点阅读