Skip to content

Commit

Permalink
Expose the time of the last change to the LED state (qmk#17222)
Browse files Browse the repository at this point in the history
(Cherry-pick from: 0112938)
  • Loading branch information
yokada-code committed Aug 14, 2023
1 parent bc24935 commit 0bed569
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions quantum/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ void switch_events(uint8_t row, uint8_t col, bool pressed) {
#endif
}

static uint32_t last_led_modification_time = 0;
uint32_t last_led_activity_time(void) {
return last_led_modification_time;
}
uint32_t last_led_activity_elapsed(void) {
return timer_elapsed32(last_led_modification_time);
}

/** \brief Keyboard task: Do keyboard routine jobs
*
* Do routine keyboard jobs:
Expand Down Expand Up @@ -551,6 +559,7 @@ void keyboard_task(void) {
// update LED
if (led_status != host_keyboard_leds()) {
led_status = host_keyboard_leds();
last_led_modification_time = timer_read32();
keyboard_set_leds(led_status);
}
}
Expand Down
3 changes: 3 additions & 0 deletions quantum/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void led_set(uint8_t usb_led);

void led_init_ports(void);

uint32_t last_led_activity_time(void); // Timestamp of the LED activity
uint32_t last_led_activity_elapsed(void); // Number of milliseconds since the last LED activity

#ifdef __cplusplus
}
#endif

0 comments on commit 0bed569

Please sign in to comment.