summaryrefslogtreecommitdiff
path: root/common/lightbar.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/lightbar.c')
-rw-r--r--common/lightbar.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/common/lightbar.c b/common/lightbar.c
index 3a1e005c9e..94e79fa43d 100644
--- a/common/lightbar.c
+++ b/common/lightbar.c
@@ -195,7 +195,7 @@ static void lightbar_restore_state(void)
static int last_backlight_level;
#endif
#ifdef CONFIG_ALS_LIGHTBAR_DIMMING
-static int last_google_color = -1;
+test_export_static int google_color_id;
#endif
static int demo_mode = DEMO_MODE_DEFAULT;
@@ -210,18 +210,37 @@ static int quantize_battery_level(int pct)
}
#ifdef CONFIG_ALS_LIGHTBAR_DIMMING
-static int lux_level_to_google_color(int lux)
+test_export_static int lux_level_to_google_color(const int lux)
{
int i;
- if (!lid_is_open())
+ if (!lid_is_open()) {
/* The lid shades the light sensor, use full brightness. */
- return 0;
+ if (google_color_id != 0) {
+ google_color_id = 0;
+ return 1;
+ } else {
+ return 0;
+ }
+ }
- for (i = 0; i < lb_brightness_levels_count ; i++)
- if (lux >= lb_brightness_levels[i].lux)
+ /* See if we need to decrease brightness */
+ for (i = google_color_id; i < lb_brightness_levels_count ; i++)
+ if (lux >= lb_brightness_levels[i].lux_down)
+ break;
+ if (i > google_color_id) {
+ google_color_id = i;
+ return 1;
+ }
+ /* See if we need to increase brightness */
+ for (i = google_color_id; i > 0; i--)
+ if (lux < lb_brightness_levels[i - 1].lux_up)
break;
- return i;
+ if (i < google_color_id) {
+ google_color_id = i;
+ return 1;
+ }
+ return 0;
}
#endif
@@ -230,9 +249,6 @@ static void get_battery_level(void)
{
int pct = 0;
int bl;
-#ifdef CONFIG_ALS_LIGHTBAR_DIMMING
- int color_id;
-#endif
if (demo_mode)
return;
@@ -282,12 +298,9 @@ static void get_battery_level(void)
#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));
+ if (lux_level_to_google_color(MOTION_SENSE_LUX)) {
+ memcpy(st.p.color, lb_brightness_levels[google_color_id].color,
+ sizeof(lb_brightness_levels[google_color_id].color));
}
#endif
}