diff options
Diffstat (limited to 'protocol')
| -rw-r--r-- | protocol/serial_mouse_microsoft.c | 9 | ||||
| -rw-r--r-- | protocol/serial_mouse_mousesystems.c | 29 |
2 files changed, 20 insertions, 18 deletions
diff --git a/protocol/serial_mouse_microsoft.c b/protocol/serial_mouse_microsoft.c index f83036a31..54fedae77 100644 --- a/protocol/serial_mouse_microsoft.c +++ b/protocol/serial_mouse_microsoft.c | |||
| @@ -27,6 +27,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 27 | #include "print.h" | 27 | #include "print.h" |
| 28 | #include "debug.h" | 28 | #include "debug.h" |
| 29 | 29 | ||
| 30 | #ifdef MAX | ||
| 31 | #undef MAX | ||
| 32 | #endif | ||
| 33 | #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) | ||
| 34 | |||
| 30 | static void print_usb_data(const report_mouse_t *report); | 35 | static void print_usb_data(const report_mouse_t *report); |
| 31 | 36 | ||
| 32 | void serial_mouse_task(void) | 37 | void serial_mouse_task(void) |
| @@ -91,8 +96,8 @@ void serial_mouse_task(void) | |||
| 91 | report.y = ((buffer[0] << 4) & 0xC0) | buffer[2]; | 96 | report.y = ((buffer[0] << 4) & 0xC0) | buffer[2]; |
| 92 | 97 | ||
| 93 | /* USB HID uses values from -127 to 127 only */ | 98 | /* USB HID uses values from -127 to 127 only */ |
| 94 | report.x = report.x < -127 ? -127 : report.x; | 99 | report.x = MAX(report.x, -127); |
| 95 | report.y = report.y < -127 ? -127 : report.y; | 100 | report.y = MAX(report.y, -127); |
| 96 | 101 | ||
| 97 | #if 0 | 102 | #if 0 |
| 98 | if (!report.buttons && !report.x && !report.y) { | 103 | if (!report.buttons && !report.x && !report.y) { |
diff --git a/protocol/serial_mouse_mousesystems.c b/protocol/serial_mouse_mousesystems.c index 36c67386f..c4ddbb845 100644 --- a/protocol/serial_mouse_mousesystems.c +++ b/protocol/serial_mouse_mousesystems.c | |||
| @@ -27,6 +27,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 27 | #include "print.h" | 27 | #include "print.h" |
| 28 | #include "debug.h" | 28 | #include "debug.h" |
| 29 | 29 | ||
| 30 | #ifdef MAX | ||
| 31 | #undef MAX | ||
| 32 | #endif | ||
| 33 | #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) | ||
| 34 | |||
| 30 | //#define SERIAL_MOUSE_CENTER_SCROLL | 35 | //#define SERIAL_MOUSE_CENTER_SCROLL |
| 31 | 36 | ||
| 32 | static void print_usb_data(const report_mouse_t *report); | 37 | static void print_usb_data(const report_mouse_t *report); |
| @@ -67,20 +72,16 @@ void serial_mouse_task(void) | |||
| 67 | 72 | ||
| 68 | #ifdef SERIAL_MOUSE_CENTER_SCROLL | 73 | #ifdef SERIAL_MOUSE_CENTER_SCROLL |
| 69 | if ((buffer[0] & 0x7) == 0x5 && (buffer[1] || buffer[2])) { | 74 | if ((buffer[0] & 0x7) == 0x5 && (buffer[1] || buffer[2])) { |
| 70 | report.h = (int8_t)buffer[1]; | ||
| 71 | /* USB HID uses only values from -127 to 127 */ | 75 | /* USB HID uses only values from -127 to 127 */ |
| 72 | report.h = report.h < -127 ? -127 : report.h; | 76 | report.h = MAX((int8_t)buffer[1], -127); |
| 73 | report.v = (int8_t)buffer[2]; | 77 | report.v = MAX((int8_t)buffer[2], -127); |
| 74 | report.v = report.v < -127 ? -127 : report.v; | ||
| 75 | 78 | ||
| 76 | print_usb_data(&report); | 79 | print_usb_data(&report); |
| 77 | host_mouse_send(&report); | 80 | host_mouse_send(&report); |
| 78 | 81 | ||
| 79 | if (buffer[3] || buffer[4]) { | 82 | if (buffer[3] || buffer[4]) { |
| 80 | report.h = (int8_t)buffer[3]; | 83 | report.h = MAX((int8_t)buffer[3], -127); |
| 81 | report.h = report.h < -127 ? -127 : report.h; | 84 | report.v = MAX((int8_t)buffer[4], -127); |
| 82 | report.v = (int8_t)buffer[4]; | ||
| 83 | report.v = report.v < -127 ? -127 : report.v; | ||
| 84 | 85 | ||
| 85 | print_usb_data(&report); | 86 | print_usb_data(&report); |
| 86 | host_mouse_send(&report); | 87 | host_mouse_send(&report); |
| @@ -103,20 +104,16 @@ void serial_mouse_task(void) | |||
| 103 | if (!(buffer[0] & (1 << 0))) | 104 | if (!(buffer[0] & (1 << 0))) |
| 104 | report.buttons |= MOUSE_BTN2; | 105 | report.buttons |= MOUSE_BTN2; |
| 105 | 106 | ||
| 106 | report.x = (int8_t)buffer[1]; | ||
| 107 | /* USB HID uses only values from -127 to 127 */ | 107 | /* USB HID uses only values from -127 to 127 */ |
| 108 | report.x = report.x < -127 ? -127 : report.x; | 108 | report.x = MAX((int8_t)buffer[1], -127); |
| 109 | report.y = -(int8_t)buffer[2]; | 109 | report.y = MAX(-(int8_t)buffer[2], -127); |
| 110 | report.y = report.y < -127 ? -127 : report.y; | ||
| 111 | 110 | ||
| 112 | print_usb_data(&report); | 111 | print_usb_data(&report); |
| 113 | host_mouse_send(&report); | 112 | host_mouse_send(&report); |
| 114 | 113 | ||
| 115 | if (buffer[3] || buffer[4]) { | 114 | if (buffer[3] || buffer[4]) { |
| 116 | report.x = (int8_t)buffer[3]; | 115 | report.x = MAX((int8_t)buffer[3], -127); |
| 117 | report.x = report.x < -127 ? -127 : report.x; | 116 | report.y = MAX(-(int8_t)buffer[4], -127); |
| 118 | report.y = -(int8_t)buffer[4]; | ||
| 119 | report.y = report.y < -127 ? -127 : report.y; | ||
| 120 | 117 | ||
| 121 | print_usb_data(&report); | 118 | print_usb_data(&report); |
| 122 | host_mouse_send(&report); | 119 | host_mouse_send(&report); |
