X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=protocol%2Fserial_mouse_mousesystems.c;h=cfe899621604657bad9fab03e8726a64a1582a67;hb=1b95b3c51a0eee5c8e47b189ece68ac55d7e4069;hp=68b2b5b3593081a3a7888a3815d3877c75ab7164;hpb=7dde35d4f7cc3cc1569a31e752ea4043133b1a72;p=max%2Ftmk_keyboard.git diff --git a/protocol/serial_mouse_mousesystems.c b/protocol/serial_mouse_mousesystems.c index 68b2b5b3..cfe89962 100644 --- a/protocol/serial_mouse_mousesystems.c +++ b/protocol/serial_mouse_mousesystems.c @@ -1,5 +1,5 @@ /* -Copyright 2011,2013 Jun Wako +Copyright 2014 Robin Haberkorn This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,16 +27,15 @@ along with this program. If not, see . #include "print.h" #include "debug.h" +#ifdef MAX +#undef MAX +#endif +#define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) + //#define SERIAL_MOUSE_CENTER_SCROLL static void print_usb_data(const report_mouse_t *report); -uint8_t serial_mouse_init(void) -{ - serial_init(); - return 0; -} - void serial_mouse_task(void) { /* 5 byte ring buffer */ @@ -73,20 +72,16 @@ void serial_mouse_task(void) #ifdef SERIAL_MOUSE_CENTER_SCROLL if ((buffer[0] & 0x7) == 0x5 && (buffer[1] || buffer[2])) { - report.h = (int8_t)buffer[1]; /* USB HID uses only values from -127 to 127 */ - report.h = report.h < -127 ? -127 : report.h; - report.v = (int8_t)buffer[2]; - report.v = report.v < -127 ? -127 : report.v; + report.h = MAX((int8_t)buffer[1], -127); + report.v = MAX((int8_t)buffer[2], -127); print_usb_data(&report); host_mouse_send(&report); if (buffer[3] || buffer[4]) { - report.h = (int8_t)buffer[3]; - report.h = report.h < -127 ? -127 : report.h; - report.v = (int8_t)buffer[4]; - report.v = report.v < -127 ? -127 : report.v; + report.h = MAX((int8_t)buffer[3], -127); + report.v = MAX((int8_t)buffer[4], -127); print_usb_data(&report); host_mouse_send(&report); @@ -109,20 +104,16 @@ void serial_mouse_task(void) if (!(buffer[0] & (1 << 0))) report.buttons |= MOUSE_BTN2; - report.x = (int8_t)buffer[1]; /* USB HID uses only values from -127 to 127 */ - report.x = report.x < -127 ? -127 : report.x; - report.y = -(int8_t)buffer[2]; - report.y = report.y < -127 ? -127 : report.y; + report.x = MAX((int8_t)buffer[1], -127); + report.y = MAX(-(int8_t)buffer[2], -127); print_usb_data(&report); host_mouse_send(&report); if (buffer[3] || buffer[4]) { - report.x = (int8_t)buffer[3]; - report.x = report.x < -127 ? -127 : report.x; - report.y = -(int8_t)buffer[4]; - report.y = report.y < -127 ? -127 : report.y; + report.x = MAX((int8_t)buffer[3], -127); + report.y = MAX(-(int8_t)buffer[4], -127); print_usb_data(&report); host_mouse_send(&report);