Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of USBDevice by
Revision 28:810d30880619, committed 2014-08-07
- Comitter:
- palheart
- Date:
- Thu Aug 07 08:36:37 2014 +0000
- Parent:
- 22:5b7d31d9d3f3
- Commit message:
- Renamed the whole thing in order to prevent messing up with the real library
Changed in this revision
USBHID/USBMouse.cpp | Show annotated file Show diff for this revision Revisions of this file |
USBHID/USBMouse.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/USBHID/USBMouse.cpp Wed Apr 02 21:00:41 2014 +0100 +++ b/USBHID/USBMouse.cpp Thu Aug 07 08:36:37 2014 +0000 @@ -20,51 +20,22 @@ #include "USBMouse.h" bool USBMouse::update(int16_t x, int16_t y, uint8_t button, int8_t z) { - switch (mouse_type) { - case REL_MOUSE: - while (x > 127) { - if (!mouseSend(127, 0, button, z)) return false; - x = x - 127; - } - while (x < -128) { - if (!mouseSend(-128, 0, button, z)) return false; - x = x + 128; - } - while (y > 127) { - if (!mouseSend(0, 127, button, z)) return false; - y = y - 127; - } - while (y < -128) { - if (!mouseSend(0, -128, button, z)) return false; - y = y + 128; - } - return mouseSend(x, y, button, z); - case ABS_MOUSE: - HID_REPORT report; + HID_REPORT report; - report.data[0] = x & 0xff; - report.data[1] = (x >> 8) & 0xff; - report.data[2] = y & 0xff; - report.data[3] = (y >> 8) & 0xff; - report.data[4] = -z; - report.data[5] = button & 0x07; + report.data[0] = x; + report.data[1] = y; - report.length = 6; + report.length = 2; + return send(&report); - return send(&report); - default: - return false; - } } bool USBMouse::mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z) { HID_REPORT report; - report.data[0] = buttons & 0x07; - report.data[1] = x; - report.data[2] = y; - report.data[3] = -z; // >0 to scroll down, <0 to scroll up + report.data[0] = x; + report.data[1] = y; - report.length = 4; + report.length = 2; return send(&report); } @@ -73,117 +44,29 @@ return update(x, y, button, 0); } -bool USBMouse::scroll(int8_t z) { - return update(0, 0, button, z); -} - - -bool USBMouse::doubleClick() { - if (!click(MOUSE_LEFT)) - return false; - wait(0.1); - return click(MOUSE_LEFT); -} - -bool USBMouse::click(uint8_t button) { - if (!update(0, 0, button, 0)) - return false; - wait(0.01); - return update(0, 0, 0, 0); -} - -bool USBMouse::press(uint8_t button_) { - button = button_ & 0x07; - return update(0, 0, button, 0); -} - -bool USBMouse::release(uint8_t button_) { - button = (button & (~button_)) & 0x07; - return update(0, 0, button, 0); -} - - uint8_t * USBMouse::reportDesc() { if (mouse_type == REL_MOUSE) { static uint8_t reportDescriptor[] = { USAGE_PAGE(1), 0x01, // Genric Desktop - USAGE(1), 0x02, // Mouse + USAGE(1), 0x05, // Mouse COLLECTION(1), 0x01, // Application USAGE(1), 0x01, // Pointer COLLECTION(1), 0x00, // Physical - - REPORT_COUNT(1), 0x03, - REPORT_SIZE(1), 0x01, - USAGE_PAGE(1), 0x09, // Buttons - USAGE_MINIMUM(1), 0x1, - USAGE_MAXIMUM(1), 0x3, - LOGICAL_MINIMUM(1), 0x00, - LOGICAL_MAXIMUM(1), 0x01, - INPUT(1), 0x02, - REPORT_COUNT(1), 0x01, - REPORT_SIZE(1), 0x05, - INPUT(1), 0x01, - - REPORT_COUNT(1), 0x03, - REPORT_SIZE(1), 0x08, - USAGE_PAGE(1), 0x01, USAGE(1), 0x30, // X USAGE(1), 0x31, // Y - USAGE(1), 0x38, // scroll - LOGICAL_MINIMUM(1), 0x81, - LOGICAL_MAXIMUM(1), 0x7f, - INPUT(1), 0x06, // Relative data - + LOGICAL_MINIMUM(1), 0x80, + LOGICAL_MAXIMUM(1), 0x7f, + REPORT_COUNT(1), 0x02, + REPORT_SIZE(1), 0x08, + INPUT(1), 0x02, // Input (Data, Variable, Absolute, No Null), END_COLLECTION(0), END_COLLECTION(0), }; reportLength = sizeof(reportDescriptor); return reportDescriptor; - } else if (mouse_type == ABS_MOUSE) { - static uint8_t reportDescriptor[] = { - - USAGE_PAGE(1), 0x01, // Generic Desktop - USAGE(1), 0x02, // Mouse - COLLECTION(1), 0x01, // Application - USAGE(1), 0x01, // Pointer - COLLECTION(1), 0x00, // Physical - - USAGE_PAGE(1), 0x01, // Generic Desktop - USAGE(1), 0x30, // X - USAGE(1), 0x31, // Y - LOGICAL_MINIMUM(1), 0x00, // 0 - LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767 - REPORT_SIZE(1), 0x10, - REPORT_COUNT(1), 0x02, - INPUT(1), 0x02, // Data, Variable, Absolute + } - USAGE_PAGE(1), 0x01, // Generic Desktop - USAGE(1), 0x38, // scroll - LOGICAL_MINIMUM(1), 0x81, // -127 - LOGICAL_MAXIMUM(1), 0x7f, // 127 - REPORT_SIZE(1), 0x08, - REPORT_COUNT(1), 0x01, - INPUT(1), 0x06, // Data, Variable, Relative - - USAGE_PAGE(1), 0x09, // Buttons - USAGE_MINIMUM(1), 0x01, - USAGE_MAXIMUM(1), 0x03, - LOGICAL_MINIMUM(1), 0x00, // 0 - LOGICAL_MAXIMUM(1), 0x01, // 1 - REPORT_COUNT(1), 0x03, - REPORT_SIZE(1), 0x01, - INPUT(1), 0x02, // Data, Variable, Absolute - REPORT_COUNT(1), 0x01, - REPORT_SIZE(1), 0x05, - INPUT(1), 0x01, // Constant - - END_COLLECTION(0), - END_COLLECTION(0) - }; - reportLength = sizeof(reportDescriptor); - return reportDescriptor; - } return NULL; } @@ -240,6 +123,7 @@ LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) 1, // bInterval (milliseconds) + }; return configurationDescriptor; }
--- a/USBHID/USBMouse.h Wed Apr 02 21:00:41 2014 +0100 +++ b/USBHID/USBMouse.h Thu Aug 07 08:36:37 2014 +0000 @@ -117,7 +117,7 @@ * @param product_release Your preoduct_release (default: 0x0001) * */ - USBMouse(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0001, uint16_t product_release = 0x0001): + USBMouse(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x2345, uint16_t product_id = 0x0001, uint16_t product_release = 0x0001): USBHID(0, 0, vendor_id, product_id, product_release, false) { button = 0; @@ -145,46 +145,7 @@ * @returns true if there is no error, false otherwise */ bool move(int16_t x, int16_t y); - - /** - * Press one or several buttons - * - * @param button button state (ex: press(MOUSE_LEFT)) - * @returns true if there is no error, false otherwise - */ - bool press(uint8_t button); - - /** - * Release one or several buttons - * - * @param button button state (ex: release(MOUSE_LEFT)) - * @returns true if there is no error, false otherwise - */ - bool release(uint8_t button); - - /** - * Double click (MOUSE_LEFT) - * - * @returns true if there is no error, false otherwise - */ - bool doubleClick(); - - /** - * Click - * - * @param button state of the buttons ( ex: clic(MOUSE_LEFT)) - * @returns true if there is no error, false otherwise - */ - bool click(uint8_t button); - - /** - * Scrolling - * - * @param z value of the wheel (>0 to go down, <0 to go up) - * @returns true if there is no error, false otherwise - */ - bool scroll(int8_t z); - + /* * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. *