From 81d269dc004b6c7334e4e8eafbb2872e5b6fdcf1 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Thu, 22 Oct 2015 14:13:35 -0700 Subject: common: lightbar: Add histeresis to prevent flickering When ALS is enabled, if light is around one threshold (say 40 lux), the lightbar will flicker between readings. Add a histeresis to prevent the flickering. The current setting is: setting ^ (dim) 2 | ------+---->---+ 1 | +----<---+--->---+ (bright) 0 | +---<---+--------- +-------+--------+-------+--------> lux 20 40 60 BRANCH=smaug BUG=chrome-os-partner:44400 TEST=check in a dark room (30~40 lux) there is no flickering. Add unit test. Change-Id: I4018e2c2ed764abf9c9ed28e2d50a3e94a7d5f75 Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/308205 --- test/lightbar.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test_config.h | 1 + 2 files changed, 50 insertions(+) (limited to 'test') diff --git a/test/lightbar.c b/test/lightbar.c index 3aae1e71f3..8a21c1fc62 100644 --- a/test/lightbar.c +++ b/test/lightbar.c @@ -11,6 +11,7 @@ #include "timer.h" #include "util.h" + static int get_seq(void) { int rv; @@ -272,6 +273,53 @@ static int test_stable_states(void) return EC_SUCCESS; } +const struct lb_brightness_def lb_brightness_levels[] = { + { + /* regular brightness */ + .lux_up = 60, + .lux_down = 40, + }, + { + /* 25 - 50% brightness */ + .lux_up = 40, + .lux_down = 20, + }, + { + /* 0 .. 25% brightness */ + .lux_up = 0, + .lux_down = 0, + }, +}; +const unsigned int lb_brightness_levels_count = + ARRAY_SIZE(lb_brightness_levels); + +int lux_level_to_google_color(const int lux); +extern int google_color_id; + +int lid_is_open(void) +{ + return 1; +} + +static int test_als_lightbar(void) +{ + int lux_data[] = { 500, 100, 35, 15, 30, 35, 55, 70, 55, 100 }; + int exp_gcid[] = { 0, 0, 1, 2, 2, 2, 1, 0, 0, 0 }; + int exp_chg[] = { 0, 0, 1, 1, 0, 0, 1, 1, 0, 0 }; + int i; + + BUILD_ASSERT(ARRAY_SIZE(lux_data) == ARRAY_SIZE(exp_gcid)); + BUILD_ASSERT(ARRAY_SIZE(lux_data) == ARRAY_SIZE(exp_chg)); + + google_color_id = 0; + for (i = 0; i < ARRAY_SIZE(lux_data); i++) { + TEST_ASSERT(exp_chg[i] == + lux_level_to_google_color(lux_data[i])); + TEST_ASSERT(exp_gcid[i] == google_color_id); + } + return EC_SUCCESS; +} + void run_test(void) { RUN_TEST(test_stable_states); @@ -280,5 +328,6 @@ void run_test(void) RUN_TEST(test_stop_timeout); RUN_TEST(test_oneshots_norm_msg); RUN_TEST(test_double_oneshots); + RUN_TEST(test_als_lightbar); test_print_result(); } diff --git a/test/test_config.h b/test/test_config.h index f758d87410..1ef48eba69 100644 --- a/test/test_config.h +++ b/test/test_config.h @@ -109,6 +109,7 @@ int ncp15wb_calculate_temp(uint16_t adc); #ifdef TEST_LIGHTBAR #define CONFIG_I2C #define I2C_PORT_LIGHTBAR 0 +#define CONFIG_ALS_LIGHTBAR_DIMMING 0 #endif #ifdef TEST_USB_PD -- cgit v1.2.1