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 <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223300
Reviewed-by: Alec Berg <alecaberg@chromium.org>
This commit is contained in:
Bill Richardson
2014-10-14 11:13:11 -07:00
committed by chrome-internal-fetch
parent 9a2afe9f78
commit 8fc80e86e4
4 changed files with 20 additions and 2 deletions

View File

@@ -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;

View File

@@ -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];

View File

@@ -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 */

View File

@@ -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);