From 7911d07477c6285b3699bb59fc7608f369e1368d Mon Sep 17 00:00:00 2001 From: demik Date: Thu, 2 Dec 2021 14:00:12 +0100 Subject: [PATCH] provides some slight acceleration and desceleration on bluetooth mouses --- ChangeLog.md | 3 +++ README.md | 2 +- main/blue.c | 49 +++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 1c8ada3..715357f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,6 @@ +## v1.4.3 +- provides some slight acceleration and desceleration on bluetooth mouses + ## v1.4.2 - added support for MicroSpeed MacTRAC 2.0 - fixed a BT led state when a device reconnect while scanning diff --git a/README.md b/README.md index 02035ce..4756a4a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ It include a custom PCB (EDA subfolder) with the accompanying firmware (code in ### Supported mouse conversions: Quack support the following conversions: -- ADB mouse to Macintosh 128/512/Plus +- ADB mouse to Macintosh 128/512/Plus or Apple Lisa - Bluetooth mouse to Macintosh 128/512/Plus or Apple Lisa ### Unsupported mouse conversions: diff --git a/main/blue.c b/main/blue.c index acc1cbf..1ed31da 100644 --- a/main/blue.c +++ b/main/blue.c @@ -375,6 +375,19 @@ void blue_h_input(esp_hidh_dev_t *dev, uint8_t *data, uint16_t length) { buttons = data[0]; + /* + * A friend of mine did this for a beer, it helps a little with high DPI mouses + * This is a precalculated table that looks like a squadhed arctan() + */ + + const unsigned char hid2quad[] = { + 0x01, 0x01, 0x02, 0x02, 0x03, 0x04, 0x05, 0x06, + 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0F, + 0x11, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x1A, 0x1C, 0x1D, 0x1E, 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x26, 0x27, 0x27, 0x28, 0x28 + }; + /* * Do some checks before parsing data. We sould't get anything wrong in theory, * but we sometimes to get shit from either mouse or bluetooth stack @@ -405,28 +418,44 @@ void blue_h_input(esp_hidh_dev_t *dev, uint8_t *data, uint16_t length) { blue_handle_button(buttons); - /* quadrature use 7 bits x/y offsets, bluetooth BOOT uses 8 bits */ + /* + * this try to help avoiding issues with high DPI mouses: + * - reduce bluetooth movement speed a little bit before 40 pixels per poll + * - go slower after 40 pixels per poll just to avoid too big jumps + */ + x = data[1]; y = data[2]; - /* reduce bluetooth movement speed as well before notifying */ if (x != 0) { - if (x == 1 || x == -1) { - xQueueSendToBack(q_qx, &x, 0); + if (x < 0) { + if (x < -40) + x = ((x + 40) / 2) - 40; + else + x = -1 * hid2quad[(x * -1) - 1]; } else { - x /= 2; - xQueueSendToBack(q_qx, &x, 0); + if (x > 40) + x = ((x - 40) / 2) + 40; + else + x = hid2quad[x - 1]; } + xQueueSendToBack(q_qx, &x, 0); } if (y != 0) { - if (y == 1 || y == -1) { - xQueueSendToBack(q_qy, &y, 0); + if (y < 0) { + if (y < -40) + y = ((y + 40) / 2) - 40; + else + y = -1 * hid2quad[(y * -1) - 1]; } else { - y /= 2; - xQueueSendToBack(q_qy, &y, 0); + if (y > 40) + y = ((y - 40) / 2) + 40; + else + y = hid2quad[y - 1]; } + xQueueSendToBack(q_qy, &y, 0); } }