summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/keyboard.c24
-rw-r--r--common/lightbar.c98
-rw-r--r--include/battery.h11
-rw-r--r--include/ec_commands.h4
-rw-r--r--include/lightbar.h6
-rw-r--r--util/ectool.c15
-rw-r--r--util/lbplay.c2
7 files changed, 131 insertions, 29 deletions
diff --git a/common/keyboard.c b/common/keyboard.c
index e446b1c5aa..059e41b389 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -634,6 +634,30 @@ static void keyboard_special(uint16_t k)
static uint8_t s = 0;
static const uint16_t a[] = {0xe048, 0xe048, 0xe050, 0xe050, 0xe04b,
0xe04d, 0xe04b, 0xe04d, 0x0030, 0x001e};
+#ifdef CONFIG_TASK_LIGHTBAR
+ /* Lightbar demo mode: keyboard can fake the battery state */
+ switch (k) {
+ case 0xe048: /* up */
+ demo_battery_level(1);
+ break;
+ case 0xe050: /* down */
+ demo_battery_level(-1);
+ break;
+ case 0xe04b: /* left */
+ demo_is_charging(0);
+ break;
+ case 0xe04d: /* right */
+ demo_is_charging(1);
+ break;
+ case 0x0040: /* dim */
+ demo_brightness(-1);
+ break;
+ case 0x0041: /* bright */
+ demo_brightness(1);
+ break;
+ }
+#endif
+
if (k == a[s])
s++;
else if (k != 0xe048)
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;
diff --git a/include/battery.h b/include/battery.h
index 5644a22da2..b5b3909abe 100644
--- a/include/battery.h
+++ b/include/battery.h
@@ -19,12 +19,11 @@
/* Threshold for power led to turn green */
#define POWERLED_GREEN_THRESHOLD 90
-/* Define the lightbar thresholds, as though we care. */
-#define LIGHTBAR_POWER_THRESHOLD_BLUE 90
-#define LIGHTBAR_POWER_THRESHOLD_GREEN 40
-#define LIGHTBAR_POWER_THRESHOLD_YELLOW 10
-/* Red below 10% */
-
+/* Define the lightbar color thresholds */
+#define LIGHTBAR_POWER_THRESHOLD_FULL 99
+#define LIGHTBAR_POWER_THRESHOLD_HIGH 40
+#define LIGHTBAR_POWER_THRESHOLD_MEDIUM 10
+/* LOW is anything below MEDIUM */
#endif /* __CROS_EC_BATTERY_H */
diff --git a/include/ec_commands.h b/include/ec_commands.h
index cecf44e000..99d5bb90c3 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -612,7 +612,7 @@ struct ec_params_lightbar_cmd {
struct num {
uint8_t cmd;
uint8_t num;
- } brightness, seq;
+ } brightness, seq, demo;
struct reg {
uint8_t cmd;
@@ -636,7 +636,7 @@ struct ec_params_lightbar_cmd {
} get_seq;
struct {
/* no return params */
- } off, on, init, brightness, seq, reg, rgb;
+ } off, on, init, brightness, seq, reg, rgb, demo;
} out;
};
} __packed;
diff --git a/include/lightbar.h b/include/lightbar.h
index 395166191d..ea48314904 100644
--- a/include/lightbar.h
+++ b/include/lightbar.h
@@ -36,7 +36,13 @@ enum lightbar_command {
LIGHTBAR_CMD_REG,
LIGHTBAR_CMD_RGB,
LIGHTBAR_CMD_GET_SEQ,
+ LIGHTBAR_CMD_DEMO,
LIGHTBAR_NUM_CMDS
};
+/* These are used for demo purposes */
+extern void demo_battery_level(int inc);
+extern void demo_is_charging(int ischarge);
+extern void demo_brightness(int inc);
+
#endif /* __CROS_EC_LIGHTBAR_H */
diff --git a/util/ectool.c b/util/ectool.c
index 81b9f2a133..0b6fa089e4 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -1044,6 +1044,8 @@ static const struct {
sizeof(((struct ec_params_lightbar_cmd *)0)->out.rgb) },
{ sizeof(((struct ec_params_lightbar_cmd *)0)->in.get_seq),
sizeof(((struct ec_params_lightbar_cmd *)0)->out.get_seq) },
+ { sizeof(((struct ec_params_lightbar_cmd *)0)->in.demo),
+ sizeof(((struct ec_params_lightbar_cmd *)0)->out.demo) },
};
static int lb_help(const char *cmd)
@@ -1059,6 +1061,7 @@ static int lb_help(const char *cmd)
printf(" %s CTRL REG VAL - set LED controller regs\n", cmd);
printf(" %s LED RED GREEN BLUE - set color manually"
" (LED=4 for all)\n", cmd);
+ printf(" %s demo 0|1 - turn demo mode on & off\n", cmd);
return 0;
}
@@ -1131,6 +1134,18 @@ static int cmd_lightbar(int argc, char **argv)
return lb_do_cmd(LIGHTBAR_CMD_BRIGHTNESS, &param);
}
+ if (argc == 3 && !strcasecmp(argv[1], "demo")) {
+ if (!strcasecmp(argv[2], "on") || argv[2][0] == '1')
+ param.in.demo.num = 1;
+ else if (!strcasecmp(argv[2], "off") || argv[2][0] == '0')
+ param.in.demo.num = 0;
+ else {
+ fprintf(stderr, "Invalid arg\n");
+ return -1;
+ }
+ return lb_do_cmd(LIGHTBAR_CMD_DEMO, &param);
+ }
+
if (argc >= 2 && !strcasecmp(argv[1], "seq")) {
char *e;
uint8_t num;
diff --git a/util/lbplay.c b/util/lbplay.c
index 9121623f91..9acabaddfb 100644
--- a/util/lbplay.c
+++ b/util/lbplay.c
@@ -40,6 +40,8 @@ static const struct {
sizeof(((struct ec_params_lightbar_cmd *)0)->out.rgb) },
{ sizeof(((struct ec_params_lightbar_cmd *)0)->in.get_seq),
sizeof(((struct ec_params_lightbar_cmd *)0)->out.get_seq) },
+ { sizeof(((struct ec_params_lightbar_cmd *)0)->in.demo),
+ sizeof(((struct ec_params_lightbar_cmd *)0)->out.demo) },
};