Skip to content

Commit 62a42a4

Browse files
author
Josh Tsai
committed
Fix: auto brightness decrease curve not smooth enough while moving to a dark environment
We reduced the period to read ALS value, also modified the granularity to match the MS requriement. Signed-off-by: Josh Tsai <josh_tsai@compal.corp-partner.google.com>
1 parent 6b8f357 commit 62a42a4

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

board/hx30/board.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
/* Optional features */
161161
#define CONFIG_ALS
162162
#define CONFIG_CMD_ALS
163+
#define ALS_POLL_PERIOD (50 * MSEC)
163164

164165
#define CONFIG_BATTERY_CUT_OFF
165166
#define CONFIG_BATTERY_SMART

board/hx30/i2c_hid_mediakeys.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ static int als_polling_mode_count;
355355
void report_illuminance_value(void)
356356
{
357357
uint16_t newIlluminaceValue = *(uint16_t *)host_get_memmap(EC_MEMMAP_ALS);
358+
static int granularity;
358359

359360
/* We need to polling the ALS value at least 6 seconds */
360361
if (als_polling_mode_count <= 60) {
@@ -365,7 +366,7 @@ void report_illuminance_value(void)
365366
task_set_event(TASK_ID_HID, ((1 << HID_ALS_REPORT_LUX) |
366367
EVENT_REPORT_ILLUMINANCE_VALUE), 0);
367368
} else {
368-
if (ABS(als_sensor.illuminanceValue - newIlluminaceValue) > 5) {
369+
if (ABS(als_sensor.illuminanceValue - newIlluminaceValue) > granularity) {
369370
als_sensor.illuminanceValue = newIlluminaceValue;
370371
task_set_event(TASK_ID_HID, ((1 << HID_ALS_REPORT_LUX) |
371372
EVENT_REPORT_ILLUMINANCE_VALUE), 0);
@@ -374,6 +375,18 @@ void report_illuminance_value(void)
374375
}
375376
}
376377

378+
/**
379+
* To ensure the best experience the ALS should have a granularity of
380+
* at most 1 lux when the ambient light is below 25 lux and a granularity
381+
* of at most 4% of the ambient light when it is above 25 lux.
382+
* This enable the adaptive brightness algorithm to perform smooth screen
383+
* brightness transitions.
384+
*/
385+
if (newIlluminaceValue < 25)
386+
granularity = 1;
387+
else
388+
granularity = newIlluminaceValue*4/100;
389+
377390
}
378391
DECLARE_DEFERRED(report_illuminance_value);
379392

common/als.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
#define CPRINTS(format, args...) cprints(CC_ALS, format, ## args)
2323
#define CPRINTF(format, args...) cprintf(CC_ALS, format, ## args)
2424

25-
25+
#ifndef ALS_POLL_PERIOD
2626
#define ALS_POLL_PERIOD SECOND
27+
#endif
2728

2829
static int task_timeout = -1;
2930

0 commit comments

Comments
 (0)