Skip to content

Commit

Permalink
[Core] Move has_mouse_report_changed function to report.c (qmk#16543
Browse files Browse the repository at this point in the history
)

* Move 'has_mouse_report_changed' checkto report.c

* change mousekeys to use memcpy

* fix linting issues
  • Loading branch information
drashna authored Mar 14, 2022
1 parent cc9a2ae commit 921b9da
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
24 changes: 14 additions & 10 deletions quantum/mousekey.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static uint8_t wheel_unit(void) {

void mousekey_task(void) {
// report cursor and scroll movement independently
report_mouse_t const tmpmr = mouse_report;
report_mouse_t tmpmr = mouse_report;

mouse_report.x = 0;
mouse_report.y = 0;
Expand Down Expand Up @@ -251,8 +251,10 @@ void mousekey_task(void) {
}
}

if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send();
mouse_report = tmpmr;
if (has_mouse_report_changed(&mouse_report, &tmpmr)) {
mousekey_send();
}
memcpy(&mouse_report, &tmpmr, sizeof(tmpmr));
}

void mousekey_on(uint8_t code) {
Expand Down Expand Up @@ -340,11 +342,11 @@ uint16_t w_intervals[mkspd_COUNT] = {MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0

void mousekey_task(void) {
// report cursor and scroll movement independently
report_mouse_t const tmpmr = mouse_report;
mouse_report.x = 0;
mouse_report.y = 0;
mouse_report.v = 0;
mouse_report.h = 0;
report_mouse_t tmpmr = mouse_report;
mouse_report.x = 0;
mouse_report.y = 0;
mouse_report.v = 0;
mouse_report.h = 0;

if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) {
mouse_report.x = tmpmr.x;
Expand All @@ -355,8 +357,10 @@ void mousekey_task(void) {
mouse_report.h = tmpmr.h;
}

if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send();
mouse_report = tmpmr;
if (has_mouse_report_changed(&mouse_report, &tmpmr)) {
mousekey_send();
}
memcpy(&mouse_report, &tmpmr, sizeof(tmpmr));
}

void adjust_speed(void) {
Expand Down
13 changes: 1 addition & 12 deletions quantum/pointing_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,6 @@ static report_mouse_t local_mouse_report = {};

extern const pointing_device_driver_t pointing_device_driver;

/**
* @brief Compares 2 mouse reports for difference and returns result
*
* @param[in] new_report report_mouse_t
* @param[in] old_report report_mouse_t
* @return bool result
*/
__attribute__((weak)) bool has_mouse_report_changed(report_mouse_t new_report, report_mouse_t old_report) {
return memcmp(&new_report, &old_report, sizeof(new_report));
}

/**
* @brief Keyboard level code pointing device initialisation
*
Expand Down Expand Up @@ -165,7 +154,7 @@ __attribute__((weak)) void pointing_device_send(void) {
static report_mouse_t old_report = {};

// If you need to do other things, like debugging, this is the place to do it.
if (has_mouse_report_changed(local_mouse_report, old_report)) {
if (has_mouse_report_changed(&local_mouse_report, &old_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
Expand Down
1 change: 0 additions & 1 deletion quantum/pointing_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ void pointing_device_task(void);
void pointing_device_send(void);
report_mouse_t pointing_device_get_report(void);
void pointing_device_set_report(report_mouse_t mouse_report);
bool has_mouse_report_changed(report_mouse_t new_report, report_mouse_t old_report);
uint16_t pointing_device_get_cpi(void);
void pointing_device_set_cpi(uint16_t cpi);

Expand Down
13 changes: 13 additions & 0 deletions tmk_core/protocol/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,16 @@ void clear_keys_from_report(report_keyboard_t* keyboard_report) {
#endif
memset(keyboard_report->keys, 0, sizeof(keyboard_report->keys));
}

#ifdef MOUSE_ENABLE
/**
* @brief Compares 2 mouse reports for difference and returns result
*
* @param[in] new_report report_mouse_t
* @param[in] old_report report_mouse_t
* @return bool result
*/
__attribute__((weak)) bool has_mouse_report_changed(report_mouse_t* new_report, report_mouse_t* old_report) {
return memcmp(new_report, old_report, sizeof(report_mouse_t));
}
#endif
4 changes: 4 additions & 0 deletions tmk_core/protocol/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key);
void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key);
void clear_keys_from_report(report_keyboard_t* keyboard_report);

#ifdef MOUSE_ENABLE
bool has_mouse_report_changed(report_mouse_t* new_report, report_mouse_t* old_report);
#endif

#ifdef __cplusplus
}
#endif

0 comments on commit 921b9da

Please sign in to comment.