spring: Update battery LED less frequently when charging

When the user uses about the same amount of power the charger provides
and the battery level is around 94%, the user might see the LED hop
between green and yellow. We should update LED color less frequently in
this case.

BUG=chrome-os-partner:20677
TEST=Hack a console command to fake battery charge level. Change battery
level between 93 and 94, and see LED color only change every 15 seconds.
BRANCH=Spring

Original-Change-Id: I55cda9aee5f79465e9094355a1f66666d018cddd
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/60851
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Signed-off-by: Vic Yang <victoryang@chromium.org>
(cherry picked from commit d03e35c42835e4b52779499d0a4b8ebdcb1074f2)

Change-Id: I51090418cdbb7a6fea0163e04d9a962b46268f34
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/61397
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Vic Yang
2013-07-03 14:59:15 +08:00
committed by ChromeBot
parent 56bd316488
commit a8e15b27bf

View File

@@ -13,10 +13,14 @@
#include "lp5562.h"
#include "pmu_tpschrome.h"
#include "smart_battery.h"
#include "timer.h"
#include "util.h"
#define GREEN_LED_THRESHOLD 94
/* Minimal interval between changing LED color to green and yellow. */
#define LED_WAIT_INTERVAL (15 * SECOND)
/* We use yellow LED instead of blue LED. Re-map colors here. */
#define LED_COLOR_NONE LP5562_COLOR_NONE
#define LED_COLOR_GREEN LP5562_COLOR_GREEN
@@ -121,6 +125,12 @@ static void battery_led_update(void)
static int led_power = -1;
int new_led_power;
/*
* The time before which we should not change LED
* color between green and yellow.
*/
static timestamp_t led_update_deadline = {.val = 0};
/* Determine LED power */
new_led_power = extpower_is_present();
if (new_led_power != led_power) {
@@ -129,6 +139,7 @@ static void battery_led_update(void)
} else {
rv = lp5562_poweroff();
set_led_color(LED_STATE_OFF);
led_update_deadline.val = 0;
}
if (!rv)
led_power = new_led_power;
@@ -178,6 +189,16 @@ static void battery_led_update(void)
break;
}
if (state == LED_STATE_SOLID_GREEN ||
state == LED_STATE_SOLID_YELLOW) {
if (!timestamp_expired(led_update_deadline, NULL))
return;
led_update_deadline.val =
get_time().val + LED_WAIT_INTERVAL;
} else {
led_update_deadline.val = 0;
}
set_led_color(state);
}
DECLARE_HOOK(HOOK_SECOND, battery_led_update, HOOK_PRIO_DEFAULT);