summaryrefslogtreecommitdiff
path: root/common/lightbar.c
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2012-08-20 12:47:32 -0700
committerGerrit <chrome-bot@google.com>2012-08-20 15:44:50 -0700
commitede77d7cac6a9730f706cb110da414748b45379e (patch)
tree75b1fb4650154518798a615835fc0bbfe8775113 /common/lightbar.c
parentf229fabd8be499b45fbb801b1458f3dd2c58bd32 (diff)
downloadchrome-ec-ede77d7cac6a9730f706cb110da414748b45379e.tar.gz
Add "lightbar demo" mode for executive bikeshedding
I keep getting asked to build an EC image to manually control the lightbar patterns so that the Powers That Be can look at it. This change just makes it possible to turn that mode on and off for yourself. You'll need a root shell or the EC console to do it, though. BUG=chrome-os-partner:8039 BRANCH=link TEST=manual From the EC console, type lightbar demo 1 OR from the root shell run ectool lightbar demo 1 After that, these keys should change the lightbar appearance (transitions may be slow and subtle - that's intended): UP = battery is more fully charged DOWN = battery is less fully charged RIGHT = battery is charging LEFT = battery is discharging BRIGHT = increase lightbar brightness DIM = decrase lightbar brightness Note that this does not interfere with the normal function of any keys. It only adds some additional EC behavior. Change-Id: Ia1a9855188244d74b670f9dbfdf60e3ac0343460 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/30899
Diffstat (limited to 'common/lightbar.c')
-rw-r--r--common/lightbar.c98
1 files changed, 77 insertions, 21 deletions
diff --git a/common/lightbar.c b/common/lightbar.c
index 3b5f33279c..81d77ad1a7 100644
--- a/common/lightbar.c
+++ b/common/lightbar.c
@@ -24,6 +24,8 @@
#define CPUTS(outstr) cputs(CC_LIGHTBAR, outstr)
#define CPRINTF(format, args...) cprintf(CC_LIGHTBAR, format, ## args)
+#define CONSOLE_COMMAND_LIGHTBAR_HELP
+
/******************************************************************************/
/* How to talk to the controller */
/******************************************************************************/
@@ -130,7 +132,6 @@ static void lightbar_init_vals(void)
memset(current, 0, sizeof(current));
}
-
/* Helper function. */
static void setrgb(int led, int red, int green, int blue)
{
@@ -270,35 +271,75 @@ struct rgb_s {
uint8_t r, g, b;
};
enum {
- COLOR_RED, COLOR_YELLOW, COLOR_GREEN, COLOR_BLUE, COLOR_BLACK,
+ COLOR_LOW, COLOR_MEDIUM, COLOR_HIGH, COLOR_FULL, COLOR_BLACK,
};
static const struct rgb_s colors[] = {
- {0xff, 0x00, 0x00}, /* red */
- {0xff, 0xff, 0x00}, /* yellow */
- {0x00, 0xff, 0x00}, /* green */
- {0x00, 0x00, 0xff}, /* blue */
+ {0xff, 0x00, 0x00}, /* low = red */
+ {0xff, 0xff, 0x00}, /* med = yellow */
+ {0x00, 0x00, 0xff}, /* high = blue */
+ {0x00, 0xff, 0x00}, /* full = green */
{0x00, 0x00, 0x00}, /* black */
};
+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))
+ return;
+
+ st.battery_level += inc;
+
+ CPRINTF("[%T LB demo: battery_level=%d]\n", st.battery_level);
+}
+
+void demo_is_charging(int ischarge)
+{
+ if (!demo_mode)
+ return;
+ st.battery_is_charging = ischarge;
+ CPRINTF("[%T LB demo: battery_is_charging=%d]\n",
+ st.battery_is_charging);
+}
+
+void demo_brightness(int inc)
+{
+ int b;
+
+ if (!demo_mode)
+ return;
+
+ b = brightness + (inc * 16);
+ if (b > 0xff)
+ b = 0xff;
+ else if (b < 0)
+ b = 0;
+ lightbar_brightness(b);
+}
+
static int last_battery_is_charging;
static int last_battery_level;
static void get_battery_level(void)
{
-#ifdef CONFIG_TASK_POWERSTATE
- int pct = charge_get_percent();
-
- if (pct > LIGHTBAR_POWER_THRESHOLD_BLUE)
- st.battery_level = COLOR_BLUE;
- else if (pct > LIGHTBAR_POWER_THRESHOLD_GREEN)
- st.battery_level = COLOR_GREEN;
- else if (pct > LIGHTBAR_POWER_THRESHOLD_YELLOW)
- st.battery_level = COLOR_YELLOW;
- else
- st.battery_level = COLOR_RED;
+ int pct = 0;
+
+ if (demo_mode)
+ return;
- pct = charge_get_state();
+#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)
+ 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;
}
static struct {
@@ -391,8 +432,8 @@ static void pulse(timestamp_t now, int period_offset)
j = sini(i);
j = j * sini((int)i * 3 / 2) / 255;
j = j * sini((int)i * 16 / 10) / 255;
- /* Cut it down a bit */
- j = j / 2;
+ /* Cut it down a bit if we're plugged in. */
+ j = j / (1 + st.battery_is_charging);
/* Luminize current color using sinusoidal */
t = j + tmp_color.r;
@@ -453,7 +494,6 @@ static uint32_t sequence_S0(void)
/* Has something changed? */
if (st.battery_is_charging != last_battery_is_charging ||
st.battery_level != last_battery_level) {
-
/* yes */
for (i = 0; i < NUM_LEDS; i++) {
led_state[i].start_time.val = now.val +
@@ -1002,6 +1042,10 @@ static int lpc_cmd_lightbar(struct host_cmd_handler_args *args)
ptr->out.get_seq.num = st.cur_seq;
args->response_size = sizeof(struct ec_params_lightbar_cmd);
break;
+ case LIGHTBAR_CMD_DEMO:
+ demo_mode = ptr->in.demo.num ? 1 : 0;
+ CPRINTF("[%T LB_demo %d]\n", demo_mode);
+ break;
default:
CPRINTF("[%T LB bad cmd 0x%x]\n", ptr->in.cmd);
return EC_RES_INVALID_PARAM;
@@ -1034,6 +1078,7 @@ static int help(const char *cmd)
ccprintf(" %s CTRL REG VAL - set LED controller regs\n", cmd);
ccprintf(" %s LED RED GREEN BLUE - set color manually"
" (LED=4 for all)\n", cmd);
+ ccprintf(" %s demo [0|1] - turn demo mode on & off\n", cmd);
return EC_SUCCESS;
}
#endif
@@ -1097,6 +1142,17 @@ static int command_lightbar(int argc, char **argv)
return EC_SUCCESS;
}
+ if (argc == 3 && !strcasecmp(argv[1], "demo")) {
+ if (!strcasecmp(argv[2], "on") || argv[2][0] == '1')
+ demo_mode = 1;
+ else if (!strcasecmp(argv[2], "off") || argv[2][0] == '0')
+ demo_mode = 0;
+ else
+ return EC_ERROR_PARAM1;
+ ccprintf("demo mode is %s\n", demo_mode ? "on" : "off");
+ return EC_SUCCESS;
+ }
+
if (argc >= 2 && !strcasecmp(argv[1], "seq")) {
char *e;
uint8_t num;