Pinscape Controller version 1 fork. This is a fork to allow for ongoing bug fixes to the original controller version, from before the major changes for the expansion board project.
Dependencies: FastIO FastPWM SimpleDMA mbed
Fork of Pinscape_Controller by
USBDevice/USBHID/USBMouse.h@68:edfecf67a931, 2016-02-15 (annotated)
- Committer:
- mjr
- Date:
- Mon Feb 15 23:03:55 2016 +0000
- Revision:
- 68:edfecf67a931
- Parent:
- 52:63f0a9b45f0c
Finalize USB library updates to fix compatibility problems introduced in USBHAL_KL25Z overhaul.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mjr | 52:63f0a9b45f0c | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
mjr | 52:63f0a9b45f0c | 2 | * |
mjr | 52:63f0a9b45f0c | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
mjr | 52:63f0a9b45f0c | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
mjr | 52:63f0a9b45f0c | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
mjr | 52:63f0a9b45f0c | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
mjr | 52:63f0a9b45f0c | 7 | * Software is furnished to do so, subject to the following conditions: |
mjr | 52:63f0a9b45f0c | 8 | * |
mjr | 52:63f0a9b45f0c | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
mjr | 52:63f0a9b45f0c | 10 | * substantial portions of the Software. |
mjr | 52:63f0a9b45f0c | 11 | * |
mjr | 52:63f0a9b45f0c | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
mjr | 52:63f0a9b45f0c | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
mjr | 52:63f0a9b45f0c | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
mjr | 52:63f0a9b45f0c | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
mjr | 52:63f0a9b45f0c | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
mjr | 52:63f0a9b45f0c | 17 | */ |
mjr | 52:63f0a9b45f0c | 18 | |
mjr | 52:63f0a9b45f0c | 19 | #ifndef USBMOUSE_H |
mjr | 52:63f0a9b45f0c | 20 | #define USBMOUSE_H |
mjr | 52:63f0a9b45f0c | 21 | |
mjr | 52:63f0a9b45f0c | 22 | #include "USBHID.h" |
mjr | 52:63f0a9b45f0c | 23 | |
mjr | 52:63f0a9b45f0c | 24 | #define REPORT_ID_MOUSE 2 |
mjr | 52:63f0a9b45f0c | 25 | |
mjr | 52:63f0a9b45f0c | 26 | /* Common usage */ |
mjr | 52:63f0a9b45f0c | 27 | |
mjr | 52:63f0a9b45f0c | 28 | enum MOUSE_BUTTON |
mjr | 52:63f0a9b45f0c | 29 | { |
mjr | 52:63f0a9b45f0c | 30 | MOUSE_LEFT = 1, |
mjr | 52:63f0a9b45f0c | 31 | MOUSE_RIGHT = 2, |
mjr | 52:63f0a9b45f0c | 32 | MOUSE_MIDDLE = 4, |
mjr | 52:63f0a9b45f0c | 33 | }; |
mjr | 52:63f0a9b45f0c | 34 | |
mjr | 52:63f0a9b45f0c | 35 | /* X and Y limits */ |
mjr | 52:63f0a9b45f0c | 36 | /* These values do not directly map to screen pixels */ |
mjr | 52:63f0a9b45f0c | 37 | /* Zero may be interpreted as meaning 'no movement' */ |
mjr | 52:63f0a9b45f0c | 38 | #define X_MIN_ABS (1) /*!< Minimum value on x-axis */ |
mjr | 52:63f0a9b45f0c | 39 | #define Y_MIN_ABS (1) /*!< Minimum value on y-axis */ |
mjr | 52:63f0a9b45f0c | 40 | #define X_MAX_ABS (0x7fff) /*!< Maximum value on x-axis */ |
mjr | 52:63f0a9b45f0c | 41 | #define Y_MAX_ABS (0x7fff) /*!< Maximum value on y-axis */ |
mjr | 52:63f0a9b45f0c | 42 | |
mjr | 52:63f0a9b45f0c | 43 | #define X_MIN_REL (-127) /*!< The maximum value that we can move to the left on the x-axis */ |
mjr | 52:63f0a9b45f0c | 44 | #define Y_MIN_REL (-127) /*!< The maximum value that we can move up on the y-axis */ |
mjr | 52:63f0a9b45f0c | 45 | #define X_MAX_REL (127) /*!< The maximum value that we can move to the right on the x-axis */ |
mjr | 52:63f0a9b45f0c | 46 | #define Y_MAX_REL (127) /*!< The maximum value that we can move down on the y-axis */ |
mjr | 52:63f0a9b45f0c | 47 | |
mjr | 52:63f0a9b45f0c | 48 | enum MOUSE_TYPE |
mjr | 52:63f0a9b45f0c | 49 | { |
mjr | 52:63f0a9b45f0c | 50 | ABS_MOUSE, |
mjr | 52:63f0a9b45f0c | 51 | REL_MOUSE, |
mjr | 52:63f0a9b45f0c | 52 | }; |
mjr | 52:63f0a9b45f0c | 53 | |
mjr | 52:63f0a9b45f0c | 54 | /** |
mjr | 52:63f0a9b45f0c | 55 | * |
mjr | 52:63f0a9b45f0c | 56 | * USBMouse example |
mjr | 52:63f0a9b45f0c | 57 | * @code |
mjr | 52:63f0a9b45f0c | 58 | * #include "mbed.h" |
mjr | 52:63f0a9b45f0c | 59 | * #include "USBMouse.h" |
mjr | 52:63f0a9b45f0c | 60 | * |
mjr | 52:63f0a9b45f0c | 61 | * USBMouse mouse; |
mjr | 52:63f0a9b45f0c | 62 | * |
mjr | 52:63f0a9b45f0c | 63 | * int main(void) |
mjr | 52:63f0a9b45f0c | 64 | * { |
mjr | 52:63f0a9b45f0c | 65 | * while (1) |
mjr | 52:63f0a9b45f0c | 66 | * { |
mjr | 52:63f0a9b45f0c | 67 | * mouse.move(20, 0); |
mjr | 52:63f0a9b45f0c | 68 | * wait(0.5); |
mjr | 52:63f0a9b45f0c | 69 | * } |
mjr | 52:63f0a9b45f0c | 70 | * } |
mjr | 52:63f0a9b45f0c | 71 | * |
mjr | 52:63f0a9b45f0c | 72 | * @endcode |
mjr | 52:63f0a9b45f0c | 73 | * |
mjr | 52:63f0a9b45f0c | 74 | * |
mjr | 52:63f0a9b45f0c | 75 | * @code |
mjr | 52:63f0a9b45f0c | 76 | * #include "mbed.h" |
mjr | 52:63f0a9b45f0c | 77 | * #include "USBMouse.h" |
mjr | 52:63f0a9b45f0c | 78 | * #include <math.h> |
mjr | 52:63f0a9b45f0c | 79 | * |
mjr | 52:63f0a9b45f0c | 80 | * USBMouse mouse(ABS_MOUSE); |
mjr | 52:63f0a9b45f0c | 81 | * |
mjr | 52:63f0a9b45f0c | 82 | * int main(void) |
mjr | 52:63f0a9b45f0c | 83 | * { |
mjr | 52:63f0a9b45f0c | 84 | * uint16_t x_center = (X_MAX_ABS - X_MIN_ABS)/2; |
mjr | 52:63f0a9b45f0c | 85 | * uint16_t y_center = (Y_MAX_ABS - Y_MIN_ABS)/2; |
mjr | 52:63f0a9b45f0c | 86 | * uint16_t x_screen = 0; |
mjr | 52:63f0a9b45f0c | 87 | * uint16_t y_screen = 0; |
mjr | 52:63f0a9b45f0c | 88 | * |
mjr | 52:63f0a9b45f0c | 89 | * uint32_t x_origin = x_center; |
mjr | 52:63f0a9b45f0c | 90 | * uint32_t y_origin = y_center; |
mjr | 52:63f0a9b45f0c | 91 | * uint32_t radius = 5000; |
mjr | 52:63f0a9b45f0c | 92 | * uint32_t angle = 0; |
mjr | 52:63f0a9b45f0c | 93 | * |
mjr | 52:63f0a9b45f0c | 94 | * while (1) |
mjr | 52:63f0a9b45f0c | 95 | * { |
mjr | 52:63f0a9b45f0c | 96 | * x_screen = x_origin + cos((double)angle*3.14/180.0)*radius; |
mjr | 52:63f0a9b45f0c | 97 | * y_screen = y_origin + sin((double)angle*3.14/180.0)*radius; |
mjr | 52:63f0a9b45f0c | 98 | * |
mjr | 52:63f0a9b45f0c | 99 | * mouse.move(x_screen, y_screen); |
mjr | 52:63f0a9b45f0c | 100 | * angle += 3; |
mjr | 52:63f0a9b45f0c | 101 | * wait(0.01); |
mjr | 52:63f0a9b45f0c | 102 | * } |
mjr | 52:63f0a9b45f0c | 103 | * } |
mjr | 52:63f0a9b45f0c | 104 | * |
mjr | 52:63f0a9b45f0c | 105 | * @endcode |
mjr | 52:63f0a9b45f0c | 106 | */ |
mjr | 52:63f0a9b45f0c | 107 | class USBMouse: public USBHID |
mjr | 52:63f0a9b45f0c | 108 | { |
mjr | 52:63f0a9b45f0c | 109 | public: |
mjr | 52:63f0a9b45f0c | 110 | |
mjr | 52:63f0a9b45f0c | 111 | /** |
mjr | 52:63f0a9b45f0c | 112 | * Constructor |
mjr | 52:63f0a9b45f0c | 113 | * |
mjr | 52:63f0a9b45f0c | 114 | * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE) |
mjr | 52:63f0a9b45f0c | 115 | * @param vendor_id Your vendor_id (default: 0x1234) |
mjr | 52:63f0a9b45f0c | 116 | * @param product_id Your product_id (default: 0x0001) |
mjr | 52:63f0a9b45f0c | 117 | * @param product_release Your preoduct_release (default: 0x0001) |
mjr | 52:63f0a9b45f0c | 118 | * |
mjr | 52:63f0a9b45f0c | 119 | */ |
mjr | 52:63f0a9b45f0c | 120 | USBMouse(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0001, uint16_t product_release = 0x0001): |
mjr | 52:63f0a9b45f0c | 121 | USBHID(0, 0, vendor_id, product_id, product_release, false) |
mjr | 52:63f0a9b45f0c | 122 | { |
mjr | 52:63f0a9b45f0c | 123 | button = 0; |
mjr | 52:63f0a9b45f0c | 124 | this->mouse_type = mouse_type; |
mjr | 52:63f0a9b45f0c | 125 | connect(); |
mjr | 52:63f0a9b45f0c | 126 | }; |
mjr | 52:63f0a9b45f0c | 127 | |
mjr | 52:63f0a9b45f0c | 128 | /** |
mjr | 52:63f0a9b45f0c | 129 | * Write a state of the mouse |
mjr | 52:63f0a9b45f0c | 130 | * |
mjr | 52:63f0a9b45f0c | 131 | * @param x x-axis position |
mjr | 52:63f0a9b45f0c | 132 | * @param y y-axis position |
mjr | 52:63f0a9b45f0c | 133 | * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE) |
mjr | 52:63f0a9b45f0c | 134 | * @param z wheel state (>0 to scroll down, <0 to scroll up) |
mjr | 52:63f0a9b45f0c | 135 | * @returns true if there is no error, false otherwise |
mjr | 52:63f0a9b45f0c | 136 | */ |
mjr | 52:63f0a9b45f0c | 137 | bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z); |
mjr | 52:63f0a9b45f0c | 138 | |
mjr | 52:63f0a9b45f0c | 139 | |
mjr | 52:63f0a9b45f0c | 140 | /** |
mjr | 52:63f0a9b45f0c | 141 | * Move the cursor to (x, y) |
mjr | 52:63f0a9b45f0c | 142 | * |
mjr | 52:63f0a9b45f0c | 143 | * @param x-axis position |
mjr | 52:63f0a9b45f0c | 144 | * @param y-axis position |
mjr | 52:63f0a9b45f0c | 145 | * @returns true if there is no error, false otherwise |
mjr | 52:63f0a9b45f0c | 146 | */ |
mjr | 52:63f0a9b45f0c | 147 | bool move(int16_t x, int16_t y); |
mjr | 52:63f0a9b45f0c | 148 | |
mjr | 52:63f0a9b45f0c | 149 | /** |
mjr | 52:63f0a9b45f0c | 150 | * Press one or several buttons |
mjr | 52:63f0a9b45f0c | 151 | * |
mjr | 52:63f0a9b45f0c | 152 | * @param button button state (ex: press(MOUSE_LEFT)) |
mjr | 52:63f0a9b45f0c | 153 | * @returns true if there is no error, false otherwise |
mjr | 52:63f0a9b45f0c | 154 | */ |
mjr | 52:63f0a9b45f0c | 155 | bool press(uint8_t button); |
mjr | 52:63f0a9b45f0c | 156 | |
mjr | 52:63f0a9b45f0c | 157 | /** |
mjr | 52:63f0a9b45f0c | 158 | * Release one or several buttons |
mjr | 52:63f0a9b45f0c | 159 | * |
mjr | 52:63f0a9b45f0c | 160 | * @param button button state (ex: release(MOUSE_LEFT)) |
mjr | 52:63f0a9b45f0c | 161 | * @returns true if there is no error, false otherwise |
mjr | 52:63f0a9b45f0c | 162 | */ |
mjr | 52:63f0a9b45f0c | 163 | bool release(uint8_t button); |
mjr | 52:63f0a9b45f0c | 164 | |
mjr | 52:63f0a9b45f0c | 165 | /** |
mjr | 52:63f0a9b45f0c | 166 | * Double click (MOUSE_LEFT) |
mjr | 52:63f0a9b45f0c | 167 | * |
mjr | 52:63f0a9b45f0c | 168 | * @returns true if there is no error, false otherwise |
mjr | 52:63f0a9b45f0c | 169 | */ |
mjr | 52:63f0a9b45f0c | 170 | bool doubleClick(); |
mjr | 52:63f0a9b45f0c | 171 | |
mjr | 52:63f0a9b45f0c | 172 | /** |
mjr | 52:63f0a9b45f0c | 173 | * Click |
mjr | 52:63f0a9b45f0c | 174 | * |
mjr | 52:63f0a9b45f0c | 175 | * @param button state of the buttons ( ex: clic(MOUSE_LEFT)) |
mjr | 52:63f0a9b45f0c | 176 | * @returns true if there is no error, false otherwise |
mjr | 52:63f0a9b45f0c | 177 | */ |
mjr | 52:63f0a9b45f0c | 178 | bool click(uint8_t button); |
mjr | 52:63f0a9b45f0c | 179 | |
mjr | 52:63f0a9b45f0c | 180 | /** |
mjr | 52:63f0a9b45f0c | 181 | * Scrolling |
mjr | 52:63f0a9b45f0c | 182 | * |
mjr | 52:63f0a9b45f0c | 183 | * @param z value of the wheel (>0 to go down, <0 to go up) |
mjr | 52:63f0a9b45f0c | 184 | * @returns true if there is no error, false otherwise |
mjr | 52:63f0a9b45f0c | 185 | */ |
mjr | 52:63f0a9b45f0c | 186 | bool scroll(int8_t z); |
mjr | 52:63f0a9b45f0c | 187 | |
mjr | 52:63f0a9b45f0c | 188 | /* |
mjr | 52:63f0a9b45f0c | 189 | * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
mjr | 52:63f0a9b45f0c | 190 | * |
mjr | 52:63f0a9b45f0c | 191 | * @returns pointer to the report descriptor |
mjr | 52:63f0a9b45f0c | 192 | */ |
mjr | 52:63f0a9b45f0c | 193 | virtual uint8_t * reportDesc(); |
mjr | 52:63f0a9b45f0c | 194 | |
mjr | 52:63f0a9b45f0c | 195 | protected: |
mjr | 52:63f0a9b45f0c | 196 | /* |
mjr | 52:63f0a9b45f0c | 197 | * Get configuration descriptor |
mjr | 52:63f0a9b45f0c | 198 | * |
mjr | 52:63f0a9b45f0c | 199 | * @returns pointer to the configuration descriptor |
mjr | 52:63f0a9b45f0c | 200 | */ |
mjr | 52:63f0a9b45f0c | 201 | virtual uint8_t * configurationDesc(); |
mjr | 52:63f0a9b45f0c | 202 | |
mjr | 52:63f0a9b45f0c | 203 | private: |
mjr | 52:63f0a9b45f0c | 204 | MOUSE_TYPE mouse_type; |
mjr | 52:63f0a9b45f0c | 205 | uint8_t button; |
mjr | 52:63f0a9b45f0c | 206 | bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z); |
mjr | 52:63f0a9b45f0c | 207 | }; |
mjr | 52:63f0a9b45f0c | 208 | |
mjr | 52:63f0a9b45f0c | 209 | #endif |