summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Collyer <scollyer@google.com>2017-06-15 16:41:43 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-06-16 17:24:27 -0700
commit28167cbc26015571eea3b9ed0344f03851acb4e4 (patch)
tree8e9beae0ccda86e56eb03abdb51440e9d96d8e45
parentdeeb0ac7de3774b50c8468dfe281e0b9f03d2d46 (diff)
downloadchrome-ec-28167cbc26015571eea3b9ed0344f03851acb4e4.tar.gz
eve: Make sure both LEDs are updated when charger is connected
When an external charger is connected, only the LED on the side the charger is connected should be on, the other side should be off. The existing LED behavior was incorrect in that only the side that was charging was being updated and the other side would remain in its previous state. This CL adds a fix so that if only one LED is being controlled, the other side is always turned off. In addition, the logic for double tap events was changed slightly so that if a double tap event is in progress and a charger is connected, the new state will be updated as soon as the charge state is changed instead of waiting for the double tap event to complete. BUG=b:62481906 BRANCH=eve TEST=Manual With battery level < 15% so that both LEDs are red when the charger isn't connected, connect charger and verified that the LED on the side the charger is connected turns white and the LED on the other side turns off. Change-Id: I7462629409496383adb43445e732dd6ca2f9f589 Signed-off-by: Scott Collyer <scollyer@google.com> Reviewed-on: https://chromium-review.googlesource.com/537960 Commit-Ready: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Duncan Laurie <dlaurie@google.com>
-rw-r--r--board/eve/led.c93
1 files changed, 47 insertions, 46 deletions
diff --git a/board/eve/led.c b/board/eve/led.c
index cdda42d07a..0687d61da6 100644
--- a/board/eve/led.c
+++ b/board/eve/led.c
@@ -243,7 +243,7 @@ static void eve_led_set_power_battery(void)
enum charge_state chg_state = charge_get_state();
int side;
int percent_chg;
- enum led_pattern pattern;
+ enum led_pattern pattern = led_pattern;
int tap = 0;
if (double_tap) {
@@ -262,55 +262,57 @@ static void eve_led_set_power_battery(void)
/* Get percent charge */
percent_chg = charge_get_percent();
- /*
- * If a double tap update is underway, let that complete before allowing
- * the pattern to change.
- */
- if (!double_tap_tick_count) {
- if (chg_state == PWR_STATE_CHARGE_NEAR_FULL ||
- ((chg_state == PWR_STATE_DISCHARGE_FULL)
- && extpower_is_present())) {
- pattern = SOLID_GREEN;
- } else if (chg_state == PWR_STATE_CHARGE) {
- pattern = SOLID_WHITE;
- } else {
- int i;
-
- /*
- * Not currently charging. Select the pattern based on
- * the battery charge level. If there is no double tap
- * event to process, then only the low battery patterns
- * are relevant.
- */
- for (i = 0; i < ARRAY_SIZE(pattern_tbl); i++) {
- if (percent_chg <= pattern_tbl[i].max) {
- pattern = pattern_tbl[i].pattern;
- break;
- }
+ if (chg_state == PWR_STATE_CHARGE_NEAR_FULL ||
+ ((chg_state == PWR_STATE_DISCHARGE_FULL)
+ && extpower_is_present())) {
+ pattern = SOLID_GREEN;
+ double_tap_tick_count = 0;
+ } else if (chg_state == PWR_STATE_CHARGE) {
+ pattern = SOLID_WHITE;
+ double_tap_tick_count = 0;
+ } else if (!double_tap_tick_count) {
+ int i;
+
+ /*
+ * Not currently charging. Select the pattern based on
+ * the battery charge level. If there is no double tap
+ * event to process, then only the low battery patterns
+ * are relevant.
+ */
+ for (i = 0; i < ARRAY_SIZE(pattern_tbl); i++) {
+ if (percent_chg <= pattern_tbl[i].max) {
+ pattern = pattern_tbl[i].pattern;
+ break;
}
- /*
- * The patterns used for double tap and for not charging
- * state are the same for low battery cases. But, if
- * battery charge is high enough to be above SOLID_RED,
- * then only display LED pattern if double tap has
- * occurred.
- */
- if (tap == 0 && pattern <= WHITE_RED)
- pattern = OFF;
- else
- /* Start double tap LED sequence */
- double_tap_tick_count = DOUBLE_TAP_TICK_LEN;
}
-
- /* If the LED pattern will change, then reset tick count and set
- * new pattern.
+ /*
+ * The patterns used for double tap and for not charging
+ * state are the same for low battery cases. But, if
+ * battery charge is high enough to be above SOLID_RED,
+ * then only display LED pattern if double tap has
+ * occurred.
*/
- if (pattern != led_pattern) {
- led_ticks = 0;
- led_pattern = pattern;
- }
+ if (tap == 0 && pattern <= WHITE_RED)
+ pattern = OFF;
+ else
+ /* Start double tap LED sequence */
+ double_tap_tick_count = DOUBLE_TAP_TICK_LEN;
}
+ /* If the LED pattern will change, then reset tick count and set
+ * new pattern.
+ */
+ if (pattern != led_pattern) {
+ led_ticks = 0;
+ led_pattern = pattern;
+ }
+ /*
+ * If external charger is connected, then make sure only the LED that's
+ * on the side with the charger is turned on.
+ */
+ if (side != LED_BOTH)
+ set_color(LED_OFF, side ^ 1);
+ /* Update LED pattern */
led_manage_pattern(side);
}
@@ -384,7 +386,6 @@ static int command_led(int argc, char **argv)
} else if (!strcasecmp(argv[1], "white")) {
set_color(LED_WHITE, side);
} else {
- /* maybe handle charger_discharge_on_ac() too? */
return EC_ERROR_PARAM1;
}
}