summaryrefslogtreecommitdiff
path: root/common/lightbar.c
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-09-28 10:12:49 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-10-06 22:57:08 -0700
commit852fb5d7f9aaf5ddefaddc2efe37ae8001b8158e (patch)
treeb3a42e5c2e1d405f4e8d11e942b96c4bb7561543 /common/lightbar.c
parent9669eeede24a9bae19cc000213265632a63e5d80 (diff)
downloadchrome-ec-852fb5d7f9aaf5ddefaddc2efe37ae8001b8158e.tar.gz
lightbar: fix battery level hysteresis bug
Fix bug in get_battery_level() where we attempt to apply hysteresis to the battery percentage when it jumps between levels. The problem is if the battery jumps up multiple levels, then it won't always update the battery level. For example, using level thresholds of {14, 40, 99}, if you jump from 0% to 99%, it won't update the battery level because it compares the new percentage, 99%, with the battery threshold for the new level + 1 (100%). BUG=chrome-os-partner:45878 BRANCH=smaug TEST=use the battfake console command to jump from 5% to 99% and verify that the lightbar goes from all red to google colors. note: without this CL, the lightbar stays all red. Change-Id: I5ae658c8c92469ebc7f516a04bda7b7fbcd32146 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/302684 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common/lightbar.c')
-rw-r--r--common/lightbar.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/common/lightbar.c b/common/lightbar.c
index 6298b9845f..3a2acb0e78 100644
--- a/common/lightbar.c
+++ b/common/lightbar.c
@@ -230,11 +230,9 @@ static void get_battery_level(void)
bl = quantize_battery_level(pct);
/* Use some hysteresis to avoid flickering */
- if (bl > st.battery_level
- && pct >= (st.p.battery_threshold[bl-1] + 1))
- st.battery_level = bl;
- else if (bl < st.battery_level &&
- pct <= (st.p.battery_threshold[bl] - 1))
+ if (bl < st.battery_level ||
+ (bl > st.battery_level
+ && pct >= (st.p.battery_threshold[st.battery_level] + 1)))
st.battery_level = bl;
#ifdef CONFIG_PWM_KBLIGHT