@@ -355,6 +355,7 @@ static int als_polling_mode_count;
355355void 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}
378391DECLARE_DEFERRED (report_illuminance_value );
379392
0 commit comments