Skip to content

Commit 9acadbf

Browse files
authored
Merge pull request #445 from FrameworkComputer/hx30.change_als_report_mode
Add the algorithm to switch the ALS report mode
2 parents 162668e + fd636d5 commit 9acadbf

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

board/hx30/i2c_hid_mediakeys.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "timer.h"
1414
#include "chipset.h"
1515
#include "hwtimer.h"
16+
#include "math_util.h"
1617
#include "util.h"
1718
#include "i2c_hid.h"
1819
#include "i2c_hid_mediakeys.h"
@@ -350,16 +351,29 @@ void i2c_hid_als_init(void)
350351
als_sensor.illuminanceValue = 0x0000;
351352
}
352353

354+
static int als_polling_mode_count;
353355
void report_illuminance_value(void)
354356
{
355-
/* bypass the EC_MEMMAP_ALS value to input report */
356-
als_sensor.illuminanceValue = *(uint16_t *)host_get_memmap(EC_MEMMAP_ALS);
357+
uint16_t newIlluminaceValue = *(uint16_t *)host_get_memmap(EC_MEMMAP_ALS);
357358

358-
/* wait 6s to change mode from polling to threshold */
359+
/* We need to polling the ALS value at least 6 seconds */
360+
if (als_polling_mode_count <= 60) {
361+
als_polling_mode_count++; /* time base 100ms */
359362

363+
/* bypass the EC_MEMMAP_ALS value to input report */
364+
als_sensor.illuminanceValue = newIlluminaceValue;
365+
task_set_event(TASK_ID_HID, ((1 << HID_ALS_REPORT_LUX) |
366+
EVENT_REPORT_ILLUMINANCE_VALUE), 0);
367+
} else {
368+
if (ABS(als_sensor.illuminanceValue - newIlluminaceValue) > 5) {
369+
als_sensor.illuminanceValue = newIlluminaceValue;
370+
task_set_event(TASK_ID_HID, ((1 << HID_ALS_REPORT_LUX) |
371+
EVENT_REPORT_ILLUMINANCE_VALUE), 0);
372+
} else {
373+
task_set_event(TASK_ID_HID, EVENT_REPORT_ILLUMINANCE_VALUE, 0);
374+
}
375+
}
360376

361-
task_set_event(TASK_ID_HID, ((1 << HID_ALS_REPORT_LUX) |
362-
EVENT_REPORT_ILLUMINANCE_VALUE), 0);
363377
}
364378
DECLARE_DEFERRED(report_illuminance_value);
365379

@@ -380,6 +394,7 @@ static void als_report_control(uint8_t report_mode)
380394
} else {
381395
/* stop report als value */
382396
hook_call_deferred(&report_illuminance_value_data, -1);
397+
als_polling_mode_count = 0;
383398
}
384399
}
385400

0 commit comments

Comments
 (0)