diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2015-10-22 14:13:35 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-10-23 18:03:12 -0700 |
commit | 81d269dc004b6c7334e4e8eafbb2872e5b6fdcf1 (patch) | |
tree | 85829474533fddf3e030c2aa2c105bd621bb228d /test/lightbar.c | |
parent | 3fc374b7fd8b618d513db27d9f10c8200f603e15 (diff) | |
download | chrome-ec-81d269dc004b6c7334e4e8eafbb2872e5b6fdcf1.tar.gz |
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 <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/308205
Diffstat (limited to 'test/lightbar.c')
-rw-r--r-- | test/lightbar.c | 49 |
1 files changed, 49 insertions, 0 deletions
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(); } |