summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2012-09-21 16:36:05 -0700
committerGerrit <chrome-bot@google.com>2012-09-24 10:56:50 -0700
commit3c4f66648d74fea0937478042c26c4e729d47e58 (patch)
tree925ce1917e62b01b298733c973b49185f4cea0cc
parentef71b1a3e56efb86b888edc6c04240f3eb970bd2 (diff)
downloadchrome-ec-3c4f66648d74fea0937478042c26c4e729d47e58.tar.gz
Use two-color lightbar scheme, with KB backlight for brightness
Yet another set of tweaks to the lightbar patterns: At Startup or wake from sleep, Google colors cycle in. While running, > 25% power level in the battery: All blue, in a breathing effect (cycle up and down 30%). While running, <= 25% power level in battery: Same as above, but with red Shutting down, or going into sleep: Cycle out the Google colors (Note: the effect is only visible for S0->S3, because shutting down kills power to the lightbar before we can react). While sleeping: Similar to now, but only using Blue and red for battery indication as above. The EC doesn't have access to the ALS, so we use the keyboard backlight to control the lightbar brightness instead: If keyboard backlight is OFF (which it is when ambient is bright), use max brightness for lightbar. If keyboard backlight is ON, use keyboard backlight brightness. BUG=chrome-os-partner:13870 BRANCH=Link TEST=none This is an aesthetic change. Nothing to test, only artisitic criticism. Change-Id: Ib0b98eef18984945a83e988588c225025c4e8e52 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/33824 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--common/lightbar.c67
-rw-r--r--include/battery.h4
2 files changed, 52 insertions, 19 deletions
diff --git a/common/lightbar.c b/common/lightbar.c
index 25f15e6d19..6a1a12c820 100644
--- a/common/lightbar.c
+++ b/common/lightbar.c
@@ -15,6 +15,7 @@
#include "host_command.h"
#include "i2c.h"
#include "lightbar.h"
+#include "pwm.h"
#include "system.h"
#include "task.h"
#include "timer.h"
@@ -244,7 +245,7 @@ static void lb_restore_state(void)
memcpy(&st, old_state, size);
} else {
st.cur_seq = st.prev_seq = LIGHTBAR_S5;
- st.battery_level = 2;
+ st.battery_level = 3;
}
CPRINTF("[%T LB state: %d %d - %d/%d]\n",
st.cur_seq, st.prev_seq,
@@ -276,8 +277,8 @@ enum {
static const struct rgb_s colors[] = {
{0xff, 0x00, 0x00}, /* low = red */
{0xff, 0xff, 0x00}, /* med = yellow */
- {0x00, 0x00, 0xff}, /* high = blue */
- {0x00, 0xff, 0x00}, /* full = green */
+ {0x00, 0xff, 0x00}, /* high = green */
+ {0x00, 0x00, 0xff}, /* full = blue */
{0x00, 0x00, 0x00}, /* black */
};
@@ -285,12 +286,13 @@ static int demo_mode;
void demo_battery_level(int inc)
{
- if ((!demo_mode) ||
- (st.battery_level == COLOR_LOW && inc < 0) ||
- (st.battery_level == COLOR_FULL && inc > 0))
+ /* Only using two colors */
+ if (!demo_mode)
return;
-
- st.battery_level += inc;
+ if (inc > 0)
+ st.battery_level = 3;
+ else
+ st.battery_level = 0;
CPRINTF("[%T LB demo: battery_level=%d]\n", st.battery_level);
}
@@ -321,6 +323,10 @@ void demo_brightness(int inc)
static int last_battery_is_charging;
static int last_battery_level;
+#ifdef CONFIG_TASK_PWM
+static int last_backlight_level;
+#endif
+
static void get_battery_level(void)
{
int pct = 0;
@@ -328,16 +334,31 @@ static void get_battery_level(void)
if (demo_mode)
return;
+#ifdef CONFIG_TASK_PWM
+ /* With nothing else to go on, use the keyboard backlight level to
+ * set the brightness. If the keyboard backlight is OFF (which it is
+ * when ambient is bright), use max brightness for lightbar. If
+ * keyboard backlight is ON, use keyboard backlight brightness.
+ */
+ if (pwm_get_keyboard_backlight_enabled()) {
+ pct = pwm_get_keyboard_backlight();
+ if (pct != last_backlight_level) {
+ last_backlight_level = pct;
+ pct = (255 * pct) / 100;
+ lightbar_brightness(pct);
+ }
+ } else
+ lightbar_brightness(255);
+#endif
+
#ifdef CONFIG_TASK_POWERSTATE
pct = charge_get_percent();
st.battery_is_charging = (PWR_STATE_DISCHARGE != charge_get_state());
#endif
- if (pct > LIGHTBAR_POWER_THRESHOLD_FULL)
+
+ /* We're only using two of the four levels at the moment. */
+ if (pct > LIGHTBAR_POWER_THRESHOLD_MEDIUM)
st.battery_level = COLOR_FULL;
- else if (pct > LIGHTBAR_POWER_THRESHOLD_HIGH)
- st.battery_level = COLOR_HIGH;
- else if (pct > LIGHTBAR_POWER_THRESHOLD_MEDIUM)
- st.battery_level = COLOR_MEDIUM;
else
st.battery_level = COLOR_LOW;
}
@@ -557,11 +578,15 @@ static uint32_t sequence_S5S3(void)
static uint32_t sequence_S0S3(void)
{
int i;
- lightbar_on();
+ for (i = 0; i < NUM_LEDS; i++)
+ lightbar_setrgb(i, testy[i].r, testy[i].g, testy[i].b);
+
+ WAIT_OR_RET(200000);
for (i = 0; i < NUM_LEDS; i++) {
lightbar_setrgb(i, 0, 0, 0);
WAIT_OR_RET(200000);
}
+
return 0;
}
@@ -617,10 +642,18 @@ static uint32_t sequence_S3S0(void)
/* Sleep to off. */
static uint32_t sequence_S3S5(void)
{
- /* For now, do something to indicate this transition.
+ int i;
+ /* Go ahead and do something to indicate this transition.
* We might see it. */
- lightbar_off();
- WAIT_OR_RET(500000);
+ for (i = 0; i < NUM_LEDS; i++)
+ lightbar_setrgb(i, testy[i].r, testy[i].g, testy[i].b);
+
+ WAIT_OR_RET(200000);
+ for (i = 0; i < NUM_LEDS; i++) {
+ lightbar_setrgb(i, 0, 0, 0);
+ WAIT_OR_RET(200000);
+ }
+
return 0;
}
diff --git a/include/battery.h b/include/battery.h
index 9f3cb4cad7..f647a29bc0 100644
--- a/include/battery.h
+++ b/include/battery.h
@@ -21,10 +21,10 @@
/* Precharge only when state of charge is below this level */
#define PRE_CHARGE_THRESHOLD 25
-/* Define the lightbar color thresholds */
+/* Define the lightbar color thresholds, percentage */
#define LIGHTBAR_POWER_THRESHOLD_FULL 99
#define LIGHTBAR_POWER_THRESHOLD_HIGH 40
-#define LIGHTBAR_POWER_THRESHOLD_MEDIUM 10
+#define LIGHTBAR_POWER_THRESHOLD_MEDIUM 25
/* LOW is anything below MEDIUM */
#endif /* __CROS_EC_BATTERY_H */