summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-11-09 16:12:08 -0800
committerchrome-bot <chrome-bot@chromium.org>2015-11-13 01:00:39 -0800
commitb59fa8ca68ca20c60c9fbe099209a5e38ee5b99e (patch)
tree658af2830b74008daae2c3f95ea05d338def1fed
parent66a72f0b6e379edc3a2a52fa2e9b0f66c557a447 (diff)
downloadchrome-ec-b59fa8ca68ca20c60c9fbe099209a5e38ee5b99e.tar.gz
common: lightbar: update leds when needed
In S0 state, update leds only when needed: add a variable in get_battery_level to indicate the colors need to be changed. BRANCH=smaug BUG=b:25510300 TEST=Check the traffic on the i2c bus notice less traffic coming from lightbar task in S0. Change-Id: I22dce35edd794424f6fbb607a0dbb495eb308897 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/311756 Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r--common/lightbar.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/common/lightbar.c b/common/lightbar.c
index 97d0444396..2355067016 100644
--- a/common/lightbar.c
+++ b/common/lightbar.c
@@ -253,14 +253,17 @@ test_export_static int lux_level_to_google_color(const int lux)
}
#endif
-/* Update the known state. */
-static void get_battery_level(void)
+/*
+ * Update the known state.
+ * Return 1 if something changes.
+ */
+static int get_battery_level(void)
{
int pct = 0;
- int bl;
+ int bl, change = 0;
if (demo_mode)
- return;
+ return 0;
#ifdef HAS_TASK_CHARGER
st.battery_percent = pct = charge_get_percent();
@@ -274,8 +277,10 @@ static void get_battery_level(void)
/* Use some hysteresis to avoid flickering */
if (bl < st.battery_level ||
(bl > st.battery_level
- && pct >= (st.p.battery_threshold[st.battery_level] + 1)))
+ && pct >= (st.p.battery_threshold[st.battery_level] + 1))) {
st.battery_level = bl;
+ change = 1;
+ }
#ifdef CONFIG_PWM_KBLIGHT
/*
@@ -300,6 +305,7 @@ static void get_battery_level(void)
if (pct != last_backlight_level) {
last_backlight_level = pct;
lb_set_brightness(pct);
+ change = 1;
}
#endif
#ifdef CONFIG_ALS_LIGHTBAR_DIMMING
@@ -308,8 +314,10 @@ static void get_battery_level(void)
if (lux_level_to_google_color(MOTION_SENSE_LUX)) {
memcpy(st.p.color, lb_brightness_levels[google_color_id].color,
sizeof(lb_brightness_levels[google_color_id].color));
+ change = 1;
}
#endif
+ return change;
}
/* Forcing functions for demo mode, called by the keyboard task. */
@@ -586,7 +594,7 @@ static uint32_t sequence_S0(void)
static uint32_t sequence_S0(void)
{
int w, i, r, g, b;
- int f;
+ int f, change;
lb_set_rgb(NUM_LEDS, 0, 0, 0);
lb_on();
@@ -604,22 +612,23 @@ static uint32_t sequence_S0(void)
}
while (1) {
-
- get_battery_level();
-
- /* Not really low use google colors */
- if (st.battery_level) {
- for (i = 0; i < NUM_LEDS; i++) {
- r = st.p.color[i].r;
- g = st.p.color[i].g;
- b = st.p.color[i].b;
- lb_set_rgb(i, r, g, b);
+ change = get_battery_level();
+
+ if (change) {
+ /* Not really low use google colors */
+ if (st.battery_level) {
+ for (i = 0; i < NUM_LEDS; i++) {
+ r = st.p.color[i].r;
+ g = st.p.color[i].g;
+ b = st.p.color[i].b;
+ lb_set_rgb(i, r, g, b);
+ }
+ } else {
+ r = st.p.color[PRIMARY_RED].r;
+ g = st.p.color[PRIMARY_RED].g;
+ b = st.p.color[PRIMARY_RED].b;
+ lb_set_rgb(4, r, g, b);
}
- } else {
- r = st.p.color[PRIMARY_RED].r;
- g = st.p.color[PRIMARY_RED].g;
- b = st.p.color[PRIMARY_RED].b;
- lb_set_rgb(4, r, g, b);
}
WAIT_OR_RET(1 * SECOND);
@@ -673,9 +682,9 @@ static uint32_t sequence_S3(void)
lb_off();
lb_init(1);
lb_set_rgb(NUM_LEDS, 0, 0, 0);
+ get_battery_level();
while (1) {
WAIT_OR_RET(st.p.s3_sleep_for);
- get_battery_level();
/* only pulse if we've been given a valid color index */
ci = st.p.s3_idx[st.battery_is_charging][st.battery_level];
@@ -770,8 +779,8 @@ static uint32_t sequence_S5(void)
int initialized = 0;
uint32_t res = 0;
+ get_battery_level();
while (1) {
- get_battery_level();
if (!st.battery_is_power_on_prevented ||
!st.battery_is_charging)
break;