Add battery changed callbacks (#25207)
This commit is contained in:
parent
11c8b2841e
commit
5611a40064
3 changed files with 44 additions and 0 deletions
|
@ -17,11 +17,21 @@ void battery_init(void) {
|
|||
last_bat_level = battery_driver_sample_percent();
|
||||
}
|
||||
|
||||
__attribute__((weak)) void battery_percent_changed_user(uint8_t level) {}
|
||||
__attribute__((weak)) void battery_percent_changed_kb(uint8_t level) {}
|
||||
|
||||
static void handle_percent_changed(void) {
|
||||
battery_percent_changed_user(last_bat_level);
|
||||
battery_percent_changed_kb(last_bat_level);
|
||||
}
|
||||
|
||||
void battery_task(void) {
|
||||
static uint32_t bat_timer = 0;
|
||||
if (timer_elapsed32(bat_timer) > BATTERY_SAMPLE_INTERVAL) {
|
||||
last_bat_level = battery_driver_sample_percent();
|
||||
|
||||
handle_percent_changed();
|
||||
|
||||
bat_timer = timer_read32();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,4 +31,16 @@ void battery_task(void);
|
|||
*/
|
||||
uint8_t battery_get_percent(void);
|
||||
|
||||
/**
|
||||
* \brief user hook called when battery level changed.
|
||||
*
|
||||
*/
|
||||
void battery_percent_changed_user(uint8_t level);
|
||||
|
||||
/**
|
||||
* \brief keyboard hook called when battery level changed.
|
||||
*
|
||||
*/
|
||||
void battery_percent_changed_kb(uint8_t level);
|
||||
|
||||
/** \} */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue