美文网首页
关机充电满电图标

关机充电满电图标

作者: Letcos | 来源:发表于2020-05-21 13:27 被阅读0次
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

相关文章

  • 关机充电满电图标

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

  • 2019-07-14

    带着满电的充电宝出门,居然还因没电关机失联!这是为啥?……充电宝带了,手机带了,充电线没带,TMD真倒霉!

  • 手机虚电

    手机存在虚电 手机存在虚电的意思,是你开机时显示满电状态,但你关机后再连上充电器,发现电量显示实际只有80%左右。...

  • 拍拍蛋小夜灯充电指示2018-12-13

    充电时:亮红灯; 充满电:灯熄灭

  • 撸羊毛的感觉,妙不可言

    免费的饭吃好,充电桩充满电,回家……

  • 被手机控制了

    今天下午三点半我就回家了。没别的事,就是手机没电自动关机了。早上忘记把手机充满电了,而自己单位又没有充电器。下午快...

  • 手机到底是关机充电好,还是开机充电好?了解完立马涨知识

    对于手机关机充电和开机充电哪个更好这个问题,网上有着各种各样的说法。那么,对于现在来说,手机关机充电和开机充电到底...

  • 停电

    接到通知,从晚上零点开始,停电24小时。赶紧给手机充满电,充电宝也充满电,冰箱关紧。 忽然发现,...

  • 停电前后

    从村里的用电微信群里得知,中午12点停电,直到傍晚。于是提前做好各项准备:给手机充满电;给充电宝充满电;给水壶灌满...

  • 充电

    手机需要充电,否则就会关机 机器需要通电,否则不能运转 人生需要充电,否则落后时代 吃饭为肌体充电 运动为健康充电...

网友评论

      本文标题:关机充电满电图标

      本文链接:https://www.haomeiwen.com/subject/bduzohtx.html