summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-09-20 14:04:03 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-05-01 21:16:43 +0000
commit62aaabefade879e7925abaa0fedaeeb0d57ba888 (patch)
treea18262301f447ffc06fcc436fefc36faf9d54819
parent2dc01bb3a1491d67be8f2f4b8a052c08b5f217dc (diff)
downloadchrome-ec-62aaabefade879e7925abaa0fedaeeb0d57ba888.tar.gz
BACKPORT: 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, b:27849483, b:36973851 BRANCH=smaug, cyan, ultima 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. Reviewed-on: https://chromium-review.googlesource.com/301216 Reviewed-by: Alec Berg <alecaberg@chromium.org> (cherry picked from commit 7340e804a1e3ffba2f1ffb9bf826a33b8b5fb19c) Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/359391 Reviewed-on: https://chromium-review.googlesource.com/409478 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit 4b09db60502503a7c7d823c56e512129ea114175) Change-Id: I7b5e2890c3557f1dd3ae719f5f82ffb5fe7b24fb Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/489751
-rw-r--r--common/lightbar.c35
-rw-r--r--include/config.h3
-rw-r--r--include/lightbar.h18
-rw-r--r--include/motion_sense.h4
4 files changed, 60 insertions, 0 deletions
diff --git a/common/lightbar.c b/common/lightbar.c
index 879da25531..3a1e005c9e 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"
@@ -192,6 +194,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;
@@ -204,11 +209,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;
@@ -255,6 +279,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. */
diff --git a/include/config.h b/include/config.h
index 13d902a565..0af953bd68 100644
--- a/include/config.h
+++ b/include/config.h
@@ -97,6 +97,9 @@
#undef CONFIG_ALS_ISL29035
#undef CONFIG_ALS_OPT3001
+/* Define which ALS sensor is used for dimming the lightbar when dark */
+#undef CONFIG_ALS_LIGHTBAR_DIMMING
+
/* Support AP hang detection host command and state machine */
#undef CONFIG_AP_HANG_DETECT
diff --git a/include/lightbar.h b/include/lightbar.h
index 293eeb2ab2..8648e3f3bd 100644
--- a/include/lightbar.h
+++ b/include/lightbar.h
@@ -34,6 +34,24 @@ enum lb_control {
LB_CONT_MAX
};
+#ifdef CONFIG_ALS_LIGHTBAR_DIMMING
+/*
+ * For dimming the lightbar in the dark, we define an array to
+ * describe the expected colors:
+ * if luminosity is more than 'lux', the color defined will be used.
+ * The last entry must have lux == 0.
+ * Defining brightness is not enough to prevent washed color in low
+ * lux setting.
+ */
+struct lb_brightness_def {
+ uint16_t lux;
+ struct rgb_s color[4];
+};
+
+extern struct lb_brightness_def lb_brightness_levels[];
+extern const unsigned lb_brightness_levels_count;
+#endif
+
/* Request a preset sequence from the lightbar task. */
void lightbar_sequence_f(enum lightbar_sequence num, const char *f);
#define lightbar_sequence(A) lightbar_sequence_f(A, __func__)
diff --git a/include/motion_sense.h b/include/motion_sense.h
index 86d3e87ab8..ed24f232fd 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -185,4 +185,8 @@ void motion_sense_fifo_add_unit(struct ec_response_motion_sensor_data *data,
#else
#define ALL_MOTION_SENSORS motion_sensor_count
#endif
+
+#ifdef CONFIG_ALS_LIGHTBAR_DIMMING
+#define MOTION_SENSE_LUX motion_sensors[CONFIG_ALS_LIGHTBAR_DIMMING].raw_xyz[0]
+#endif
#endif /* __CROS_EC_MOTION_SENSE_H */