Add last activity functions for pointing device (#20079)
This commit is contained in:
parent
8686c527f7
commit
297779385f
6 changed files with 61 additions and 40 deletions
|
@ -139,10 +139,22 @@ void last_encoder_activity_trigger(void) {
|
||||||
last_encoder_modification_time = last_input_modification_time = sync_timer_read32();
|
last_encoder_modification_time = last_input_modification_time = sync_timer_read32();
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp) {
|
static uint32_t last_pointing_device_modification_time = 0;
|
||||||
last_matrix_modification_time = matrix_timestamp;
|
uint32_t last_pointing_device_activity_time(void) {
|
||||||
last_encoder_modification_time = encoder_timestamp;
|
return last_pointing_device_modification_time;
|
||||||
last_input_modification_time = MAX(matrix_timestamp, encoder_timestamp);
|
}
|
||||||
|
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
|
// 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. */
|
/** \brief Main task that is repeatedly called as fast as possible. */
|
||||||
void keyboard_task(void) {
|
void keyboard_task(void) {
|
||||||
const bool matrix_changed = matrix_task();
|
__attribute__((unused)) bool activity_has_occurred = false;
|
||||||
if (matrix_changed) {
|
if (matrix_task()) {
|
||||||
last_matrix_activity_trigger();
|
last_matrix_activity_trigger();
|
||||||
|
activity_has_occurred = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
quantum_task();
|
quantum_task();
|
||||||
|
@ -627,9 +640,16 @@ void keyboard_task(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENCODER_ENABLE
|
#ifdef ENCODER_ENABLE
|
||||||
const bool encoders_changed = encoder_read();
|
if (encoder_read()) {
|
||||||
if (encoders_changed) {
|
|
||||||
last_encoder_activity_trigger();
|
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
|
#endif
|
||||||
|
|
||||||
|
@ -637,11 +657,7 @@ void keyboard_task(void) {
|
||||||
oled_task();
|
oled_task();
|
||||||
# if OLED_TIMEOUT > 0
|
# if OLED_TIMEOUT > 0
|
||||||
// Wake up oled if user is using those fabulous keys or spinning those encoders!
|
// Wake up oled if user is using those fabulous keys or spinning those encoders!
|
||||||
# ifdef ENCODER_ENABLE
|
if (activity_has_occurred) oled_on();
|
||||||
if (matrix_changed || encoders_changed) oled_on();
|
|
||||||
# else
|
|
||||||
if (matrix_changed) oled_on();
|
|
||||||
# endif
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -649,11 +665,7 @@ void keyboard_task(void) {
|
||||||
st7565_task();
|
st7565_task();
|
||||||
# if ST7565_TIMEOUT > 0
|
# if ST7565_TIMEOUT > 0
|
||||||
// Wake up display if user is using those fabulous keys or spinning those encoders!
|
// Wake up display if user is using those fabulous keys or spinning those encoders!
|
||||||
# ifdef ENCODER_ENABLE
|
if (activity_has_occurred) st7565_on();
|
||||||
if (matrix_changed || encoders_changed) st7565_on();
|
|
||||||
# else
|
|
||||||
if (matrix_changed) st7565_on();
|
|
||||||
# endif
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -666,10 +678,6 @@ void keyboard_task(void) {
|
||||||
ps2_mouse_task();
|
ps2_mouse_task();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef POINTING_DEVICE_ENABLE
|
|
||||||
pointing_device_task();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MIDI_ENABLE
|
#ifdef MIDI_ENABLE
|
||||||
midi_task();
|
midi_task();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -111,8 +111,8 @@ void housekeeping_task(void); // To be executed by the main loop in each ba
|
||||||
void housekeeping_task_kb(void); // To be overridden by keyboard-level code
|
void housekeeping_task_kb(void); // To be overridden by keyboard-level code
|
||||||
void housekeeping_task_user(void); // To be overridden by user/keymap-level code
|
void housekeeping_task_user(void); // To be overridden by user/keymap-level code
|
||||||
|
|
||||||
uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder activity
|
uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder or pointing device activity
|
||||||
uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder activity
|
uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder or pointing device activity
|
||||||
|
|
||||||
uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity
|
uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity
|
||||||
uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity
|
uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity
|
||||||
|
@ -120,7 +120,10 @@ uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the
|
||||||
uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity
|
uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity
|
||||||
uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity
|
uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity
|
||||||
|
|
||||||
void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp); // Set the timestamps of the last matrix and encoder activity
|
uint32_t last_pointing_device_activity_time(void); // Timestamp of the last pointing device activity
|
||||||
|
uint32_t last_pointing_device_activity_elapsed(void); // Number of milliseconds since the last pointing device activity
|
||||||
|
|
||||||
|
void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp, uint32_t pointing_device_timestamp); // Set the timestamps of the last matrix and encoder activity
|
||||||
|
|
||||||
uint32_t get_matrix_scan_rate(void);
|
uint32_t get_matrix_scan_rate(void);
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,8 @@ uint16_t pointing_device_get_shared_cpi(void) {
|
||||||
|
|
||||||
#endif // defined(SPLIT_POINTING_ENABLE)
|
#endif // defined(SPLIT_POINTING_ENABLE)
|
||||||
|
|
||||||
static report_mouse_t local_mouse_report = {};
|
static report_mouse_t local_mouse_report = {};
|
||||||
|
static bool pointing_device_force_send = false;
|
||||||
|
|
||||||
extern const pointing_device_driver_t pointing_device_driver;
|
extern const pointing_device_driver_t pointing_device_driver;
|
||||||
|
|
||||||
|
@ -163,11 +164,11 @@ __attribute__((weak)) void pointing_device_init(void) {
|
||||||
* This sends the mouse report generated by pointing_device_task if changed since the last report. Once send zeros mouse report except buttons.
|
* This sends the mouse report generated by pointing_device_task if changed since the last report. Once send zeros mouse report except buttons.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
__attribute__((weak)) void pointing_device_send(void) {
|
__attribute__((weak)) bool pointing_device_send(void) {
|
||||||
static report_mouse_t old_report = {};
|
static report_mouse_t old_report = {};
|
||||||
|
bool should_send_report = has_mouse_report_changed(&local_mouse_report, &old_report);
|
||||||
|
|
||||||
// If you need to do other things, like debugging, this is the place to do it.
|
if (should_send_report) {
|
||||||
if (has_mouse_report_changed(&local_mouse_report, &old_report)) {
|
|
||||||
host_mouse_send(&local_mouse_report);
|
host_mouse_send(&local_mouse_report);
|
||||||
}
|
}
|
||||||
// send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device
|
// send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device
|
||||||
|
@ -175,6 +176,8 @@ __attribute__((weak)) void pointing_device_send(void) {
|
||||||
memset(&local_mouse_report, 0, sizeof(local_mouse_report));
|
memset(&local_mouse_report, 0, sizeof(local_mouse_report));
|
||||||
local_mouse_report.buttons = buttons;
|
local_mouse_report.buttons = buttons;
|
||||||
memcpy(&old_report, &local_mouse_report, sizeof(local_mouse_report));
|
memcpy(&old_report, &local_mouse_report, sizeof(local_mouse_report));
|
||||||
|
|
||||||
|
return should_send_report || buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -220,18 +223,18 @@ report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report) {
|
||||||
* It applies any optional configuration e.g. rotation or axis inversion and then initiates a send.
|
* It applies any optional configuration e.g. rotation or axis inversion and then initiates a send.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
__attribute__((weak)) void pointing_device_task(void) {
|
__attribute__((weak)) bool pointing_device_task(void) {
|
||||||
#if defined(SPLIT_POINTING_ENABLE)
|
#if defined(SPLIT_POINTING_ENABLE)
|
||||||
// Don't poll the target side pointing device.
|
// Don't poll the target side pointing device.
|
||||||
if (!is_keyboard_master()) {
|
if (!is_keyboard_master()) {
|
||||||
return;
|
return false;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (POINTING_DEVICE_TASK_THROTTLE_MS > 0)
|
#if (POINTING_DEVICE_TASK_THROTTLE_MS > 0)
|
||||||
static uint32_t last_exec = 0;
|
static uint32_t last_exec = 0;
|
||||||
if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) {
|
if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
last_exec = timer_read32();
|
last_exec = timer_read32();
|
||||||
#endif
|
#endif
|
||||||
|
@ -286,7 +289,11 @@ __attribute__((weak)) void pointing_device_task(void) {
|
||||||
report_mouse_t mousekey_report = mousekey_get_report();
|
report_mouse_t mousekey_report = mousekey_get_report();
|
||||||
local_mouse_report.buttons = local_mouse_report.buttons | mousekey_report.buttons;
|
local_mouse_report.buttons = local_mouse_report.buttons | mousekey_report.buttons;
|
||||||
#endif
|
#endif
|
||||||
pointing_device_send();
|
|
||||||
|
const bool send_report = pointing_device_send() || pointing_device_force_send;
|
||||||
|
pointing_device_force_send = false;
|
||||||
|
|
||||||
|
return send_report;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -304,7 +311,8 @@ report_mouse_t pointing_device_get_report(void) {
|
||||||
* @param[in] mouse_report
|
* @param[in] mouse_report
|
||||||
*/
|
*/
|
||||||
void pointing_device_set_report(report_mouse_t mouse_report) {
|
void pointing_device_set_report(report_mouse_t mouse_report) {
|
||||||
local_mouse_report = mouse_report;
|
pointing_device_force_send = has_mouse_report_changed(&local_mouse_report, &mouse_report);
|
||||||
|
memcpy(&local_mouse_report, &mouse_report, sizeof(local_mouse_report));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -97,8 +97,8 @@ typedef int16_t clamp_range_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void pointing_device_init(void);
|
void pointing_device_init(void);
|
||||||
void pointing_device_task(void);
|
bool pointing_device_task(void);
|
||||||
void pointing_device_send(void);
|
bool pointing_device_send(void);
|
||||||
report_mouse_t pointing_device_get_report(void);
|
report_mouse_t pointing_device_get_report(void);
|
||||||
void pointing_device_set_report(report_mouse_t mouse_report);
|
void pointing_device_set_report(report_mouse_t mouse_report);
|
||||||
uint16_t pointing_device_get_cpi(void);
|
uint16_t pointing_device_get_cpi(void);
|
||||||
|
|
|
@ -795,13 +795,14 @@ static void haptic_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla
|
||||||
static bool activity_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
|
static bool activity_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
|
||||||
static uint32_t last_update = 0;
|
static uint32_t last_update = 0;
|
||||||
split_slave_activity_sync_t activity_sync;
|
split_slave_activity_sync_t activity_sync;
|
||||||
activity_sync.matrix_timestamp = last_matrix_activity_time();
|
activity_sync.matrix_timestamp = last_matrix_activity_time();
|
||||||
activity_sync.encoder_timestamp = last_encoder_activity_time();
|
activity_sync.encoder_timestamp = last_encoder_activity_time();
|
||||||
|
activity_sync.pointing_device_timestamp = last_pointing_device_activity_time();
|
||||||
return send_if_data_mismatch(PUT_ACTIVITY, &last_update, &activity_sync, &split_shmem->activity_sync, sizeof(activity_sync));
|
return send_if_data_mismatch(PUT_ACTIVITY, &last_update, &activity_sync, &split_shmem->activity_sync, sizeof(activity_sync));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void activity_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
|
static void activity_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
|
||||||
set_activity_timestamps(split_shmem->activity_sync.matrix_timestamp, split_shmem->activity_sync.encoder_timestamp);
|
set_activity_timestamps(split_shmem->activity_sync.matrix_timestamp, split_shmem->activity_sync.encoder_timestamp, split_shmem->activity_sync.pointing_device_timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
|
@ -127,6 +127,7 @@ typedef struct _split_slave_haptic_sync_t {
|
||||||
typedef struct _split_slave_activity_sync_t {
|
typedef struct _split_slave_activity_sync_t {
|
||||||
uint32_t matrix_timestamp;
|
uint32_t matrix_timestamp;
|
||||||
uint32_t encoder_timestamp;
|
uint32_t encoder_timestamp;
|
||||||
|
uint32_t pointing_device_timestamp;
|
||||||
} split_slave_activity_sync_t;
|
} split_slave_activity_sync_t;
|
||||||
#endif // defined(SPLIT_ACTIVITY_ENABLE)
|
#endif // defined(SPLIT_ACTIVITY_ENABLE)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue