From 297779385fd53e93c33861e2d3107cb88efbde81 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Thu, 30 Mar 2023 18:27:39 -0700 Subject: Add last activity functions for pointing device (#20079) --- quantum/keyboard.c | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'quantum/keyboard.c') diff --git a/quantum/keyboard.c b/quantum/keyboard.c index 3f030d8845..6f1ad33b61 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -139,10 +139,22 @@ void last_encoder_activity_trigger(void) { last_encoder_modification_time = last_input_modification_time = sync_timer_read32(); } -void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp) { - last_matrix_modification_time = matrix_timestamp; - last_encoder_modification_time = encoder_timestamp; - last_input_modification_time = MAX(matrix_timestamp, encoder_timestamp); +static uint32_t last_pointing_device_modification_time = 0; +uint32_t last_pointing_device_activity_time(void) { + return last_pointing_device_modification_time; +} +uint32_t last_pointing_device_activity_elapsed(void) { + return sync_timer_elapsed32(last_pointing_device_modification_time); +} +void last_pointing_device_activity_trigger(void) { + last_pointing_device_modification_time = last_input_modification_time = sync_timer_read32(); +} + +void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp, uint32_t pointing_device_timestamp) { + last_matrix_modification_time = matrix_timestamp; + last_encoder_modification_time = encoder_timestamp; + last_pointing_device_modification_time = pointing_device_timestamp; + last_input_modification_time = MAX(matrix_timestamp, MAX(encoder_timestamp, pointing_device_timestamp)); } // Only enable this if console is enabled to print to @@ -598,9 +610,10 @@ void quantum_task(void) { /** \brief Main task that is repeatedly called as fast as possible. */ void keyboard_task(void) { - const bool matrix_changed = matrix_task(); - if (matrix_changed) { + __attribute__((unused)) bool activity_has_occurred = false; + if (matrix_task()) { last_matrix_activity_trigger(); + activity_has_occurred = true; } quantum_task(); @@ -627,9 +640,16 @@ void keyboard_task(void) { #endif #ifdef ENCODER_ENABLE - const bool encoders_changed = encoder_read(); - if (encoders_changed) { + if (encoder_read()) { last_encoder_activity_trigger(); + activity_has_occurred = true; + } +#endif + +#ifdef POINTING_DEVICE_ENABLE + if (pointing_device_task()) { + last_pointing_device_activity_trigger(); + activity_has_occurred = true; } #endif @@ -637,11 +657,7 @@ void keyboard_task(void) { oled_task(); # if OLED_TIMEOUT > 0 // Wake up oled if user is using those fabulous keys or spinning those encoders! -# ifdef ENCODER_ENABLE - if (matrix_changed || encoders_changed) oled_on(); -# else - if (matrix_changed) oled_on(); -# endif + if (activity_has_occurred) oled_on(); # endif #endif @@ -649,11 +665,7 @@ void keyboard_task(void) { st7565_task(); # if ST7565_TIMEOUT > 0 // Wake up display if user is using those fabulous keys or spinning those encoders! -# ifdef ENCODER_ENABLE - if (matrix_changed || encoders_changed) st7565_on(); -# else - if (matrix_changed) st7565_on(); -# endif + if (activity_has_occurred) st7565_on(); # endif #endif @@ -666,10 +678,6 @@ void keyboard_task(void) { ps2_mouse_task(); #endif -#ifdef POINTING_DEVICE_ENABLE - pointing_device_task(); -#endif - #ifdef MIDI_ENABLE midi_task(); #endif -- cgit v1.2.3