From 7340e804a1e3ffba2f1ffb9bf826a33b8b5fb19c Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Sun, 20 Sep 2015 14:04:03 -0700 Subject: common: Add lightbar dimming based on outside light. Unless the lid is closed, the ALS is used for lightbar dimming. Change the google colors depending on the light sensor result. BUG=chrome-os-partner:44400 BRANCH=smaug TEST=Check all 3 levels of brightness of the lightbar. Check value using "adb shell ectool lightbar" Check double tap color are not affected and is using full brightness. Change-Id: I7b5e2890c3557f1dd3ae719f5f82ffb5fe7b24fb Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/301216 Reviewed-by: Alec Berg --- common/lightbar.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'common/lightbar.c') diff --git a/common/lightbar.c b/common/lightbar.c index 103051214d..4e9179ad12 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -18,6 +18,8 @@ #include "host_command.h" #include "lb_common.h" #include "lightbar.h" +#include "lid_switch.h" +#include "motion_sense.h" #include "pwm.h" #include "system.h" #include "task.h" @@ -142,12 +144,6 @@ static const struct lightbar_params_v1 default_params = { }, .s5_idx = PRIMARY_RED, /* flash red */ .color = { -#if defined(BOARD_RYU) - {0x74, 0x58, 0xb4}, /* Segment0: Google blue */ - {0xd6, 0x40, 0x20}, /* Segment1: Google red */ - {0xfa, 0xe6, 0x20}, /* Segment2: Google yellow */ - {0x66, 0xb0, 0x50}, /* Segment3: Google green */ -#else /* * These values have been optically calibrated for the * Samus LEDs to best match the official colors, described at @@ -158,7 +154,6 @@ static const struct lightbar_params_v1 default_params = { {0xbc, 0x50, 0x2c}, /* 1: Google red */ {0xd0, 0xe0, 0x00}, /* 2: Google yellow */ {0x50, 0xa0, 0x40}, /* 3: Google green */ -#endif /* These are primary colors */ {0x00, 0x00, 0xff}, /* 4: full blue */ {0xff, 0x00, 0x00}, /* 5: full red */ @@ -208,6 +203,9 @@ static void lightbar_restore_state(void) #ifdef CONFIG_PWM_KBLIGHT static int last_backlight_level; #endif +#ifdef CONFIG_ALS_LIGHTBAR_DIMMING +static int last_google_color = -1; +#endif static int demo_mode = DEMO_MODE_DEFAULT; @@ -220,11 +218,30 @@ static int quantize_battery_level(int pct) return bl; } +#ifdef CONFIG_ALS_LIGHTBAR_DIMMING +static int lux_level_to_google_color(int lux) +{ + int i; + + if (!lid_is_open()) + /* The lid shades the light sensor, use full brightness. */ + return 0; + + for (i = 0; i < lb_brightness_levels_count ; i++) + if (lux >= lb_brightness_levels[i].lux) + break; + return i; +} +#endif + /* Update the known state. */ static void get_battery_level(void) { int pct = 0; int bl; +#ifdef CONFIG_ALS_LIGHTBAR_DIMMING + int color_id; +#endif if (demo_mode) return; @@ -269,6 +286,17 @@ static void get_battery_level(void) lb_set_brightness(pct); } #endif +#ifdef CONFIG_ALS_LIGHTBAR_DIMMING + /* Read last value (in lux) collected by the motion sensor. */ + /* Convert lux into brightness percentage */ + color_id = lux_level_to_google_color(MOTION_SENSE_LUX); + + if (color_id != last_google_color) { + last_google_color = pct; + memcpy(st.p.color, lb_brightness_levels[color_id].color, + sizeof(lb_brightness_levels[color_id].color)); + } +#endif } /* Forcing functions for demo mode, called by the keyboard task. */ -- cgit v1.2.1