Merge pull request #37 from 4yn/fix-dropped-mouse

Fix dropped mouse movement data
This commit is contained in:
Nick G
2022-08-13 01:47:54 -04:00
committed by GitHub
2 changed files with 20 additions and 21 deletions
Binary file not shown.
+20 -21
View File
@@ -121,32 +121,31 @@ void joy_mode() {
void key_mode() {
if (tud_hid_ready()) { // Wait for ready, updating mouse too fast hampers
// movement
/*------------- Keyboard -------------*/
uint8_t nkro_report[32] = {0};
for (int i = 0; i < SW_GPIO_SIZE; i++) {
if ((report.buttons >> i) % 2 == 1) {
uint8_t bit = SW_KEYCODE[i] % 8;
uint8_t byte = (SW_KEYCODE[i] / 8) + 1;
if (SW_KEYCODE[i] >= 240 && SW_KEYCODE[i] <= 247) {
nkro_report[0] |= (1 << bit);
} else if (byte > 0 && byte <= 31) {
nkro_report[byte] |= (1 << bit);
if (kbm_report) {
/*------------- Keyboard -------------*/
uint8_t nkro_report[32] = {0};
for (int i = 0; i < SW_GPIO_SIZE; i++) {
if ((report.buttons >> i) % 2 == 1) {
uint8_t bit = SW_KEYCODE[i] % 8;
uint8_t byte = (SW_KEYCODE[i] / 8) + 1;
if (SW_KEYCODE[i] >= 240 && SW_KEYCODE[i] <= 247) {
nkro_report[0] |= (1 << bit);
} else if (byte > 0 && byte <= 31) {
nkro_report[byte] |= (1 << bit);
}
}
}
}
/*------------- Mouse -------------*/
// find the delta between previous and current enc_val
int delta[ENC_GPIO_SIZE] = {0};
for (int i = 0; i < ENC_GPIO_SIZE; i++) {
delta[i] = (enc_val[i] - prev_enc_val[i]) * (ENC_REV[i] ? 1 : -1);
prev_enc_val[i] = enc_val[i];
}
if (kbm_report) {
tud_hid_n_report(0x00, REPORT_ID_KEYBOARD, &nkro_report,
sizeof(nkro_report));
} else {
/*------------- Mouse -------------*/
// find the delta between previous and current enc_val
int delta[ENC_GPIO_SIZE] = {0};
for (int i = 0; i < ENC_GPIO_SIZE; i++) {
delta[i] = (enc_val[i] - prev_enc_val[i]) * (ENC_REV[i] ? 1 : -1);
prev_enc_val[i] = enc_val[i];
}
tud_hid_mouse_report(REPORT_ID_MOUSE, 0x00, delta[0] * MOUSE_SENS,
delta[1] * MOUSE_SENS, 0, 0);
}