summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2012-10-12 17:58:11 -0700
committerRong Chang <rongchang@chromium.org>2012-10-16 01:01:32 -0700
commitacc3edba319151718205a497c011f422da7ae544 (patch)
treecdc002e3578f13e9383344b48220d5ca8d17d8ee
parentc9a9a719891a5bd8543f8b7bde02fca5db091732 (diff)
downloadchrome-ec-acc3edba319151718205a497c011f422da7ae544.tar.gz
Replace pulsing with sweeping.
BUG=chrome-os-partner:8039 BRANCH=Link TEST=none More cosmetic changes. Original-Change-Id: If33e39d3cea1e3930d630ad84a156e9afb4c57fd Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/35485 Reviewed-by: Randall Spangler <rspangler@chromium.org> (cherry picked from commit 814d0d227f599228761f5f95a618b4b63b05c66b) Change-Id: I0f8361efa206b66616d4bcfe62ec031af66c1c70 Reviewed-on: https://gerrit.chromium.org/gerrit/35678 Reviewed-by: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
-rw-r--r--common/lightbar.c38
1 files changed, 15 insertions, 23 deletions
diff --git a/common/lightbar.c b/common/lightbar.c
index 212b26aca5..93e1d2ec11 100644
--- a/common/lightbar.c
+++ b/common/lightbar.c
@@ -167,11 +167,9 @@ static struct p_state {
int battery_is_charging;
/* Pattern variables for state S0. */
- uint8_t w0; /* primary phase */
- uint8_t ramp; /* ramp-in for S3->S0 */
+ uint16_t w0; /* primary phase */
- uint8_t _pad0; /* next item is __packed */
- uint8_t _pad1; /* next item is __packed */
+ uint16_t _pad0; /* next item is __packed */
/* Tweakable parameters */
struct lightbar_params p;
@@ -181,7 +179,7 @@ static const struct lightbar_params default_params = {
.google_ramp_up = 2500,
.google_ramp_down = 10000,
.s3s0_ramp_up = 2000,
- .s0_tick_delay = { 45000, 30000 }, /* battery, AC */
+ .s0_tick_delay = { 5000, 3000 }, /* battery, AC */
.s0s3_ramp_down = 2000,
.s3_sleep_for = 15000000, /* between checks */
.s3_tick_delay = 15000,
@@ -238,7 +236,6 @@ static void lb_restore_state(void)
st.cur_seq = st.prev_seq = LIGHTBAR_S5;
st.battery_level = LB_BATTERY_LEVELS - 1;
st.w0 = 0;
- st.ramp = 0;
memcpy(&st.p, &default_params, sizeof(st.p));
CPRINTF("[%T LB state initialized]\n");
}
@@ -422,11 +419,12 @@ static inline float cycle_010(uint8_t i)
return i < 128 ? _ramp_table[i] : _ramp_table[256-i];
}
-/* This function provides a smooth oscillation between -0.5 and +0.5.
- * Zero starts at 0x00. */
-static inline float cycle_0P0N0(uint8_t i)
+/* This function provides a smooth oscillation between -0.5 and +0.5. */
+static inline float cycle_NPN(uint16_t i)
{
- return cycle_010(i+64) - 0.5f;
+ if ((i / 256) % 4)
+ return -0.5f;
+ return cycle_010(i) - 0.5f;
}
/******************************************************************************/
@@ -486,7 +484,7 @@ static uint32_t pulse_google_colors(void)
static uint32_t sequence_S3S0(void)
{
int w, r, g, b;
- float f, fmin, fmax, base_s0;
+ float f, fmin;
int ci;
uint32_t res;
@@ -497,18 +495,16 @@ static uint32_t sequence_S3S0(void)
if (res)
return res;
- /* Ramp up to base brightness, using S0 colors */
+ /* Ramp up to starting brightness, using S0 colors */
get_battery_level();
ci = st.p.s0_idx[st.battery_is_charging][st.battery_level];
if (ci >= ARRAY_SIZE(st.p.color))
ci = 0;
fmin = st.p.osc_min[st.battery_is_charging] / 255.0f;
- fmax = st.p.osc_max[st.battery_is_charging] / 255.0f;
- base_s0 = (fmax + fmin) * 0.5f;
for (w = 0; w <= 128; w++) {
- f = cycle_010(w) * base_s0;
+ f = cycle_010(w) * fmin;
r = st.p.color[ci].r * f;
g = st.p.color[ci].g * f;
b = st.p.color[ci].b * f;
@@ -518,7 +514,6 @@ static uint32_t sequence_S3S0(void)
/* Initial conditions */
st.w0 = 0;
- st.ramp = 0;
/* Ready for S0 */
return 0;
@@ -531,7 +526,8 @@ static uint32_t sequence_S0(void)
timestamp_t start, now;
uint32_t r, g, b;
int i, ci;
- uint8_t w, w_ofs;
+ uint8_t w_ofs;
+ uint16_t w;
float f, fmin, fmax, base_s0, osc_s0;
start = get_time();
@@ -563,8 +559,8 @@ static uint32_t sequence_S0(void)
osc_s0 = fmax - fmin;
for (i = 0; i < NUM_LEDS; i++) {
- w = st.w0 - i * w_ofs * st.ramp / 255;
- f = base_s0 + osc_s0 * cycle_0P0N0(w);
+ w = st.w0 - i * w_ofs;
+ f = base_s0 + osc_s0 * cycle_NPN(w);
r = st.p.color[ci].r * f;
g = st.p.color[ci].g * f;
b = st.p.color[ci].b * f;
@@ -577,10 +573,6 @@ static uint32_t sequence_S0(void)
else
st.w0++;
- /* Continue ramping in if needed */
- if (st.ramp < 0xff)
- st.ramp++;
-
WAIT_OR_RET(st.p.s0_tick_delay[st.battery_is_charging]);
}
return 0;