|
| 1 | +/* |
| 2 | + Mouse.cpp |
| 3 | +
|
| 4 | + Copyright (c) 2015, Arduino LLC |
| 5 | + Original code (pre-library): Copyright (c) 2011, Peter Barrett |
| 6 | +
|
| 7 | + This library is free software; you can redistribute it and/or |
| 8 | + modify it under the terms of the GNU Lesser General Public |
| 9 | + License as published by the Free Software Foundation; either |
| 10 | + version 2.1 of the License, or (at your option) any later version. |
| 11 | +
|
| 12 | + This library is distributed in the hope that it will be useful, |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | + Lesser General Public License for more details. |
| 16 | +
|
| 17 | + You should have received a copy of the GNU Lesser General Public |
| 18 | + License along with this library; if not, write to the Free Software |
| 19 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | +*/ |
| 21 | + |
| 22 | +#if 1 //defined(USBCON) |
| 23 | + |
| 24 | +#include "Mouse.h" |
| 25 | + |
| 26 | +const u8 _hidReportDescriptor[] PROGMEM = { |
| 27 | + |
| 28 | + // Mouse |
| 29 | + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 |
| 30 | + 0x09, 0x02, // USAGE (Mouse) |
| 31 | + 0xa1, 0x01, // COLLECTION (Application) |
| 32 | + 0x09, 0x01, // USAGE (Pointer) |
| 33 | + 0xa1, 0x00, // COLLECTION (Physical) |
| 34 | + 0x85, 0x01, // REPORT_ID (1) |
| 35 | + 0x05, 0x09, // USAGE_PAGE (Button) |
| 36 | + 0x19, 0x01, // USAGE_MINIMUM (Button 1) |
| 37 | + 0x29, 0x03, // USAGE_MAXIMUM (Button 3) |
| 38 | + 0x15, 0x00, // LOGICAL_MINIMUM (0) |
| 39 | + 0x25, 0x01, // LOGICAL_MAXIMUM (1) |
| 40 | + 0x95, 0x03, // REPORT_COUNT (3) |
| 41 | + 0x75, 0x01, // REPORT_SIZE (1) |
| 42 | + 0x81, 0x02, // INPUT (Data,Var,Abs) |
| 43 | + 0x95, 0x01, // REPORT_COUNT (1) |
| 44 | + 0x75, 0x05, // REPORT_SIZE (5) |
| 45 | + 0x81, 0x03, // INPUT (Cnst,Var,Abs) |
| 46 | + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) |
| 47 | + 0x09, 0x30, // USAGE (X) |
| 48 | + 0x09, 0x31, // USAGE (Y) |
| 49 | + 0x09, 0x38, // USAGE (Wheel) |
| 50 | + 0x15, 0x81, // LOGICAL_MINIMUM (-127) |
| 51 | + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) |
| 52 | + 0x75, 0x08, // REPORT_SIZE (8) |
| 53 | + 0x95, 0x03, // REPORT_COUNT (3) |
| 54 | + 0x81, 0x06, // INPUT (Data,Var,Rel) |
| 55 | + 0xc0, // END_COLLECTION |
| 56 | + 0xc0, // END_COLLECTION |
| 57 | +}; |
| 58 | + |
| 59 | +size_t getsizeof_hidReportDescriptor() { |
| 60 | + return sizeof(_hidReportDescriptor); |
| 61 | +} |
| 62 | + |
| 63 | +Mouse_ Mouse; |
| 64 | + |
| 65 | +//================================================================================ |
| 66 | +//================================================================================ |
| 67 | +// Mouse |
| 68 | + |
| 69 | +Mouse_::Mouse_(void) : _buttons(0) |
| 70 | +{ |
| 71 | +} |
| 72 | + |
| 73 | +void Mouse_::begin(void) |
| 74 | +{ |
| 75 | +} |
| 76 | + |
| 77 | +void Mouse_::end(void) |
| 78 | +{ |
| 79 | +} |
| 80 | + |
| 81 | +void Mouse_::click(uint8_t b) |
| 82 | +{ |
| 83 | + _buttons = b; |
| 84 | + move(0,0,0); |
| 85 | + _buttons = 0; |
| 86 | + move(0,0,0); |
| 87 | +} |
| 88 | + |
| 89 | +void Mouse_::move(signed char x, signed char y, signed char wheel) |
| 90 | +{ |
| 91 | + u8 m[4]; |
| 92 | + m[0] = _buttons; |
| 93 | + m[1] = x; |
| 94 | + m[2] = y; |
| 95 | + m[3] = wheel; |
| 96 | + HID_SendReport(1,m,4); |
| 97 | +} |
| 98 | + |
| 99 | +void Mouse_::buttons(uint8_t b) |
| 100 | +{ |
| 101 | + if (b != _buttons) |
| 102 | + { |
| 103 | + _buttons = b; |
| 104 | + move(0,0,0); |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +void Mouse_::press(uint8_t b) |
| 109 | +{ |
| 110 | + buttons(_buttons | b); |
| 111 | +} |
| 112 | + |
| 113 | +void Mouse_::release(uint8_t b) |
| 114 | +{ |
| 115 | + buttons(_buttons & ~b); |
| 116 | +} |
| 117 | + |
| 118 | +bool Mouse_::isPressed(uint8_t b) |
| 119 | +{ |
| 120 | + if ((b & _buttons) > 0) |
| 121 | + return true; |
| 122 | + return false; |
| 123 | +} |
| 124 | + |
| 125 | +#endif |
0 commit comments