From 8fc80e86e4aa90dc88064edf135f6ccae374e647 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Tue, 14 Oct 2014 11:13:11 -0700 Subject: [PATCH] lightbar: bring the TAP sequence in gradually With only four LED segments, it's confusing to indicate a power percentage by dimming the top segment unless you can see the indicator smoothly ramping up from all-off. This does that. Kind of pretty, if I say so myself. BUG=chrome-os-partner:29041 BRANCH=ToT, Samus TEST=make buildall Run "ectool lightbar demo on", then press the T key to invoke the pattern and the arrow keys to fake the charge state. Change-Id: Ib6a56aea56078b8c1fc9edddda469d7f41735ff7 Signed-off-by: Bill Richardson Reviewed-on: https://chromium-review.googlesource.com/223300 Reviewed-by: Alec Berg --- common/lightbar.c | 18 ++++++++++++++++-- extra/lightbar/main.c | 1 + include/ec_commands.h | 1 + util/ectool.c | 2 ++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/common/lightbar.c b/common/lightbar.c index cd6595bb21..f8dce75c50 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -76,7 +76,8 @@ static const struct lightbar_params_v1 default_params = { .s3_ramp_up = 2500, .s3_ramp_down = 10000, .tap_tick_delay = 5000, /* oscillation step time */ - .tap_display_time = 5 * SECOND, /* total sequence time */ + .tap_gate_delay = 200 * MSEC, /* segment gating delay */ + .tap_display_time = 3 * SECOND, /* total sequence time */ .tap_pct_red = 10, /* below this is red */ .tap_pct_green = 97, /* above this is green */ @@ -804,8 +805,10 @@ static uint32_t sequence_TAP_inner(void) { enum { RED, YELLOW, GREEN } base_color; timestamp_t start, now; + uint32_t elapsed_time = 0; int i, ci, max_led; int f_min, f_delta, f_osc, f_power, f_mult; + int gi, gr, gate[NUM_LEDS] = {0, 0, 0, 0}; uint8_t w = 0; f_min = st.p.tap_seg_min_on * FP_SCALE / 100; @@ -826,6 +829,14 @@ static uint32_t sequence_TAP_inner(void) ci = st.p.tap_idx[base_color]; max_led = st.battery_percent / CUT; + /* Enable the segments gradually */ + gi = elapsed_time / st.p.tap_gate_delay; + gr = elapsed_time % st.p.tap_gate_delay; + if (gi < NUM_LEDS) + gate[gi] = FP_SCALE * gr / st.p.tap_gate_delay; + if (gi && gi <= NUM_LEDS) + gate[gi - 1] = FP_SCALE; + for (i = 0; i < NUM_LEDS; i++) { if (max_led > i) { @@ -849,6 +860,8 @@ static uint32_t sequence_TAP_inner(void) f_mult = f_min + f_power * f_delta / FP_SCALE; } + f_mult = f_mult * gate[i] / FP_SCALE; + /* Pulse when charging */ if (st.battery_is_charging) { int scale = (FP_SCALE - @@ -865,7 +878,8 @@ static uint32_t sequence_TAP_inner(void) /* Return after some time has elapsed */ now = get_time(); - if (now.le.lo - start.le.lo > st.p.tap_display_time) + elapsed_time = now.le.lo - start.le.lo; + if (elapsed_time > st.p.tap_display_time) break; } return 0; diff --git a/extra/lightbar/main.c b/extra/lightbar/main.c index a0da1a28ba..897a58d518 100644 --- a/extra/lightbar/main.c +++ b/extra/lightbar/main.c @@ -209,6 +209,7 @@ int lb_read_params_from_file(const char *filename, READ(1); p->s3_ramp_up = val[0]; READ(1); p->s3_ramp_down = val[0]; READ(1); p->tap_tick_delay = val[0]; + READ(1); p->tap_gate_delay = val[0]; READ(1); p->tap_display_time = val[0]; READ(1); p->tap_pct_red = val[0]; diff --git a/include/ec_commands.h b/include/ec_commands.h index 5987c46568..14abf48c09 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -1018,6 +1018,7 @@ struct lightbar_params_v1 { int32_t s3_ramp_up; int32_t s3_ramp_down; int32_t tap_tick_delay; + int32_t tap_gate_delay; int32_t tap_display_time; /* Tap-for-battery params */ diff --git a/util/ectool.c b/util/ectool.c index 7410c6f6db..b166e11f64 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -1951,6 +1951,7 @@ static int lb_read_params_v1_from_file(const char *filename, READ(1); p->s3_ramp_up = val[0]; READ(1); p->s3_ramp_down = val[0]; READ(1); p->tap_tick_delay = val[0]; + READ(1); p->tap_gate_delay = val[0]; READ(1); p->tap_display_time = val[0]; READ(1); p->tap_pct_red = val[0]; @@ -2049,6 +2050,7 @@ static void lb_show_params_v1(const struct lightbar_params_v1 *p) printf("%d\t\t# .s3_ramp_up\n", p->s3_ramp_up); printf("%d\t\t# .s3_ramp_down\n", p->s3_ramp_down); printf("%d\t\t# .tap_tick_delay\n", p->tap_tick_delay); + printf("%d\t\t# .tap_gate_delay\n", p->tap_gate_delay); printf("%d\t\t# .tap_display_time\n", p->tap_display_time); printf("%d\t\t# .tap_pct_red\n", p->tap_pct_red); printf("%d\t\t# .tap_pct_green\n", p->tap_pct_green);