Disable lighting after 5 minutes of inactivity
This commit is contained in:
parent
4ec0e833b9
commit
e65405c238
@ -81,15 +81,33 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
*/
|
||||
};
|
||||
|
||||
// Timer for activity tracking
|
||||
#define INACTIVITY_TIMER 300000 // milliseconds until considered inactive
|
||||
bool current_activation_state = 1;
|
||||
void update_activity_timer(void);
|
||||
uint32_t get_inactive_time(void);
|
||||
void set_lighting_after_inactivity(void);
|
||||
void reset_lighting_after_activity(void);
|
||||
uint32_t activity_timer;
|
||||
uint8_t old_led_lighting_mode;
|
||||
|
||||
// Runs just one time when the keyboard initializes.
|
||||
void matrix_init_user(void) {
|
||||
led_animation_direction = 1;
|
||||
led_animation_orientation = 1;
|
||||
led_animation_circular = 0;
|
||||
|
||||
update_activity_timer();
|
||||
};
|
||||
|
||||
// Runs constantly in the background, in a loop.
|
||||
void matrix_scan_user(void) {
|
||||
uint32_t inactive_time = get_inactive_time();
|
||||
if (inactive_time > INACTIVITY_TIMER && current_activation_state) {
|
||||
set_lighting_after_inactivity();
|
||||
} else if (inactive_time < 500 && !current_activation_state) {
|
||||
reset_lighting_after_activity();
|
||||
}
|
||||
};
|
||||
|
||||
// Function to test double shift caps toggle
|
||||
@ -99,6 +117,25 @@ void test_caps_toggle(void) {
|
||||
}
|
||||
};
|
||||
|
||||
void update_activity_timer(void) {
|
||||
activity_timer = timer_read32();
|
||||
}
|
||||
|
||||
void set_lighting_after_inactivity(void) {
|
||||
current_activation_state = 0;
|
||||
old_led_lighting_mode = led_lighting_mode;
|
||||
led_lighting_mode = LED_MODE_INDICATORS_ONLY;
|
||||
}
|
||||
|
||||
void reset_lighting_after_activity(void) {
|
||||
current_activation_state = 1;
|
||||
led_lighting_mode = old_led_lighting_mode;
|
||||
}
|
||||
|
||||
uint32_t get_inactive_time(void) {
|
||||
return timer_read32() - activity_timer;
|
||||
}
|
||||
|
||||
#define MODS_SHIFT (get_mods() & MOD_BIT(KC_LSHIFT) || get_mods() & MOD_BIT(KC_RSHIFT))
|
||||
#define MODS_CTRL (get_mods() & MOD_BIT(KC_LCTL) || get_mods() & MOD_BIT(KC_RCTRL))
|
||||
#define MODS_ALT (get_mods() & MOD_BIT(KC_LALT) || get_mods() & MOD_BIT(KC_RALT))
|
||||
@ -107,6 +144,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
static uint32_t key_timer;
|
||||
static uint8_t scroll_effect = 0;
|
||||
|
||||
update_activity_timer();
|
||||
|
||||
switch (keycode) {
|
||||
// Keyhandlers for double shift caps toggle
|
||||
case KC_LSFT:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user