platform:RK3399
OS:Android 7.1
概述
RK已經(jīng)實(shí)現(xiàn)了關(guān)機(jī)充電圖標(biāo)動(dòng)畫顯示的功能,在實(shí)際的使用過程中有一個(gè)問題:就算充滿電了,充電動(dòng)畫圖標(biāo)仍然在,而沒有一個(gè)滿電圖標(biāo)顯示.
滿電圖標(biāo)顯示
1.增加滿電圖標(biāo),目錄如下
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) {
測試問題
修改過后測試發(fā)現(xiàn),無論如何都無法顯示滿電圖標(biāo).最后排查發(fā)現(xiàn)電量計(jì)cw2015是通過讀取電壓值判斷是否滿電的,實(shí)際上會(huì)有5%~10%的誤差,導(dǎo)致一直檢測到?jīng)]有充滿,但是實(shí)際上是充滿了.可以改用電量來判斷是否充滿
--- 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更新
經(jīng)過充分測試,上述方式存在一個(gè)問題,當(dāng)滿電圖標(biāo)顯示一段時(shí)間之后,按開機(jī)鍵無法開機(jī)。
錯(cuò)誤原因:
failed to alloc 171600byte memory to display
實(shí)現(xiàn)方式存在問題,導(dǎo)致后來無法分配內(nèi)存。
可以更換實(shí)現(xiàn)方式來解決這個(gè)問題:
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
- 回退上面滿電實(shí)現(xiàn)
- 將battery_5.bmp替換為battery_fully.bmp
- only_current_level=true