![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Kalibriersoftware Stromwerte
USBHID/USBMouseKeyboard.h@1:ea5f520dcdc1, 2015-11-28 (annotated)
- Committer:
- Racer01014
- Date:
- Sat Nov 28 13:50:31 2015 +0000
- Revision:
- 1:ea5f520dcdc1
- Parent:
- 0:5e35c180ed4a
-
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Racer01014 | 0:5e35c180ed4a | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
Racer01014 | 0:5e35c180ed4a | 2 | * |
Racer01014 | 0:5e35c180ed4a | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
Racer01014 | 0:5e35c180ed4a | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
Racer01014 | 0:5e35c180ed4a | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
Racer01014 | 0:5e35c180ed4a | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
Racer01014 | 0:5e35c180ed4a | 7 | * Software is furnished to do so, subject to the following conditions: |
Racer01014 | 0:5e35c180ed4a | 8 | * |
Racer01014 | 0:5e35c180ed4a | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
Racer01014 | 0:5e35c180ed4a | 10 | * substantial portions of the Software. |
Racer01014 | 0:5e35c180ed4a | 11 | * |
Racer01014 | 0:5e35c180ed4a | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
Racer01014 | 0:5e35c180ed4a | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
Racer01014 | 0:5e35c180ed4a | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
Racer01014 | 0:5e35c180ed4a | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Racer01014 | 0:5e35c180ed4a | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Racer01014 | 0:5e35c180ed4a | 17 | */ |
Racer01014 | 0:5e35c180ed4a | 18 | |
Racer01014 | 0:5e35c180ed4a | 19 | #ifndef USBMOUSEKEYBOARD_H |
Racer01014 | 0:5e35c180ed4a | 20 | #define USBMOUSEKEYBOARD_H |
Racer01014 | 0:5e35c180ed4a | 21 | |
Racer01014 | 0:5e35c180ed4a | 22 | #define REPORT_ID_KEYBOARD 1 |
Racer01014 | 0:5e35c180ed4a | 23 | #define REPORT_ID_MOUSE 2 |
Racer01014 | 0:5e35c180ed4a | 24 | #define REPORT_ID_VOLUME 3 |
Racer01014 | 0:5e35c180ed4a | 25 | |
Racer01014 | 0:5e35c180ed4a | 26 | #include "USBMouse.h" |
Racer01014 | 0:5e35c180ed4a | 27 | #include "USBKeyboard.h" |
Racer01014 | 0:5e35c180ed4a | 28 | #include "Stream.h" |
Racer01014 | 0:5e35c180ed4a | 29 | #include "USBHID.h" |
Racer01014 | 0:5e35c180ed4a | 30 | |
Racer01014 | 0:5e35c180ed4a | 31 | /** |
Racer01014 | 0:5e35c180ed4a | 32 | * USBMouseKeyboard example |
Racer01014 | 0:5e35c180ed4a | 33 | * @code |
Racer01014 | 0:5e35c180ed4a | 34 | * |
Racer01014 | 0:5e35c180ed4a | 35 | * #include "mbed.h" |
Racer01014 | 0:5e35c180ed4a | 36 | * #include "USBMouseKeyboard.h" |
Racer01014 | 0:5e35c180ed4a | 37 | * |
Racer01014 | 0:5e35c180ed4a | 38 | * USBMouseKeyboard key_mouse; |
Racer01014 | 0:5e35c180ed4a | 39 | * |
Racer01014 | 0:5e35c180ed4a | 40 | * int main(void) |
Racer01014 | 0:5e35c180ed4a | 41 | * { |
Racer01014 | 0:5e35c180ed4a | 42 | * while(1) |
Racer01014 | 0:5e35c180ed4a | 43 | * { |
Racer01014 | 0:5e35c180ed4a | 44 | * key_mouse.move(20, 0); |
Racer01014 | 0:5e35c180ed4a | 45 | * key_mouse.printf("Hello From MBED\r\n"); |
Racer01014 | 0:5e35c180ed4a | 46 | * wait(1); |
Racer01014 | 0:5e35c180ed4a | 47 | * } |
Racer01014 | 0:5e35c180ed4a | 48 | * } |
Racer01014 | 0:5e35c180ed4a | 49 | * @endcode |
Racer01014 | 0:5e35c180ed4a | 50 | * |
Racer01014 | 0:5e35c180ed4a | 51 | * |
Racer01014 | 0:5e35c180ed4a | 52 | * @code |
Racer01014 | 0:5e35c180ed4a | 53 | * |
Racer01014 | 0:5e35c180ed4a | 54 | * #include "mbed.h" |
Racer01014 | 0:5e35c180ed4a | 55 | * #include "USBMouseKeyboard.h" |
Racer01014 | 0:5e35c180ed4a | 56 | * |
Racer01014 | 0:5e35c180ed4a | 57 | * USBMouseKeyboard key_mouse(ABS_MOUSE); |
Racer01014 | 0:5e35c180ed4a | 58 | * |
Racer01014 | 0:5e35c180ed4a | 59 | * int main(void) |
Racer01014 | 0:5e35c180ed4a | 60 | * { |
Racer01014 | 0:5e35c180ed4a | 61 | * while(1) |
Racer01014 | 0:5e35c180ed4a | 62 | * { |
Racer01014 | 0:5e35c180ed4a | 63 | * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2); |
Racer01014 | 0:5e35c180ed4a | 64 | * key_mouse.printf("Hello from MBED\r\n"); |
Racer01014 | 0:5e35c180ed4a | 65 | * wait(1); |
Racer01014 | 0:5e35c180ed4a | 66 | * } |
Racer01014 | 0:5e35c180ed4a | 67 | * } |
Racer01014 | 0:5e35c180ed4a | 68 | * @endcode |
Racer01014 | 0:5e35c180ed4a | 69 | */ |
Racer01014 | 0:5e35c180ed4a | 70 | class USBMouseKeyboard: public USBHID, public Stream |
Racer01014 | 0:5e35c180ed4a | 71 | { |
Racer01014 | 0:5e35c180ed4a | 72 | public: |
Racer01014 | 0:5e35c180ed4a | 73 | |
Racer01014 | 0:5e35c180ed4a | 74 | /** |
Racer01014 | 0:5e35c180ed4a | 75 | * Constructor |
Racer01014 | 0:5e35c180ed4a | 76 | * |
Racer01014 | 0:5e35c180ed4a | 77 | * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE) |
Racer01014 | 0:5e35c180ed4a | 78 | * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK |
Racer01014 | 0:5e35c180ed4a | 79 | * @param vendor_id Your vendor_id (default: 0x1234) |
Racer01014 | 0:5e35c180ed4a | 80 | * @param product_id Your product_id (default: 0x0001) |
Racer01014 | 0:5e35c180ed4a | 81 | * @param product_release Your preoduct_release (default: 0x0001) |
Racer01014 | 0:5e35c180ed4a | 82 | * |
Racer01014 | 0:5e35c180ed4a | 83 | */ |
Racer01014 | 0:5e35c180ed4a | 84 | USBMouseKeyboard(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x0021, uint16_t product_id = 0x0011, uint16_t product_release = 0x0001): |
Racer01014 | 0:5e35c180ed4a | 85 | USBHID(0, 0, vendor_id, product_id, product_release, false) |
Racer01014 | 0:5e35c180ed4a | 86 | { |
Racer01014 | 0:5e35c180ed4a | 87 | lock_status = 0; |
Racer01014 | 0:5e35c180ed4a | 88 | button = 0; |
Racer01014 | 0:5e35c180ed4a | 89 | this->mouse_type = mouse_type; |
Racer01014 | 0:5e35c180ed4a | 90 | connect(); |
Racer01014 | 0:5e35c180ed4a | 91 | }; |
Racer01014 | 0:5e35c180ed4a | 92 | |
Racer01014 | 0:5e35c180ed4a | 93 | /** |
Racer01014 | 0:5e35c180ed4a | 94 | * Write a state of the mouse |
Racer01014 | 0:5e35c180ed4a | 95 | * |
Racer01014 | 0:5e35c180ed4a | 96 | * @param x x-axis position |
Racer01014 | 0:5e35c180ed4a | 97 | * @param y y-axis position |
Racer01014 | 0:5e35c180ed4a | 98 | * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE) |
Racer01014 | 0:5e35c180ed4a | 99 | * @param z wheel state (>0 to scroll down, <0 to scroll up) |
Racer01014 | 0:5e35c180ed4a | 100 | * @returns true if there is no error, false otherwise |
Racer01014 | 0:5e35c180ed4a | 101 | */ |
Racer01014 | 0:5e35c180ed4a | 102 | bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z); |
Racer01014 | 0:5e35c180ed4a | 103 | |
Racer01014 | 0:5e35c180ed4a | 104 | |
Racer01014 | 0:5e35c180ed4a | 105 | /** |
Racer01014 | 0:5e35c180ed4a | 106 | * Move the cursor to (x, y) |
Racer01014 | 0:5e35c180ed4a | 107 | * |
Racer01014 | 0:5e35c180ed4a | 108 | * @param x x-axis position |
Racer01014 | 0:5e35c180ed4a | 109 | * @param y y-axis position |
Racer01014 | 0:5e35c180ed4a | 110 | * @returns true if there is no error, false otherwise |
Racer01014 | 0:5e35c180ed4a | 111 | */ |
Racer01014 | 0:5e35c180ed4a | 112 | bool move(int16_t x, int16_t y); |
Racer01014 | 0:5e35c180ed4a | 113 | |
Racer01014 | 0:5e35c180ed4a | 114 | /** |
Racer01014 | 0:5e35c180ed4a | 115 | * Press one or several buttons |
Racer01014 | 0:5e35c180ed4a | 116 | * |
Racer01014 | 0:5e35c180ed4a | 117 | * @param button button state (ex: press(MOUSE_LEFT)) |
Racer01014 | 0:5e35c180ed4a | 118 | * @returns true if there is no error, false otherwise |
Racer01014 | 0:5e35c180ed4a | 119 | */ |
Racer01014 | 0:5e35c180ed4a | 120 | bool press(uint8_t button); |
Racer01014 | 0:5e35c180ed4a | 121 | |
Racer01014 | 0:5e35c180ed4a | 122 | /** |
Racer01014 | 0:5e35c180ed4a | 123 | * Release one or several buttons |
Racer01014 | 0:5e35c180ed4a | 124 | * |
Racer01014 | 0:5e35c180ed4a | 125 | * @param button button state (ex: release(MOUSE_LEFT)) |
Racer01014 | 0:5e35c180ed4a | 126 | * @returns true if there is no error, false otherwise |
Racer01014 | 0:5e35c180ed4a | 127 | */ |
Racer01014 | 0:5e35c180ed4a | 128 | bool release(uint8_t button); |
Racer01014 | 0:5e35c180ed4a | 129 | |
Racer01014 | 0:5e35c180ed4a | 130 | /** |
Racer01014 | 0:5e35c180ed4a | 131 | * Double click (MOUSE_LEFT) |
Racer01014 | 0:5e35c180ed4a | 132 | * |
Racer01014 | 0:5e35c180ed4a | 133 | * @returns true if there is no error, false otherwise |
Racer01014 | 0:5e35c180ed4a | 134 | */ |
Racer01014 | 0:5e35c180ed4a | 135 | bool doubleClick(); |
Racer01014 | 0:5e35c180ed4a | 136 | |
Racer01014 | 0:5e35c180ed4a | 137 | /** |
Racer01014 | 0:5e35c180ed4a | 138 | * Click |
Racer01014 | 0:5e35c180ed4a | 139 | * |
Racer01014 | 0:5e35c180ed4a | 140 | * @param button state of the buttons ( ex: clic(MOUSE_LEFT)) |
Racer01014 | 0:5e35c180ed4a | 141 | * @returns true if there is no error, false otherwise |
Racer01014 | 0:5e35c180ed4a | 142 | */ |
Racer01014 | 0:5e35c180ed4a | 143 | bool click(uint8_t button); |
Racer01014 | 0:5e35c180ed4a | 144 | |
Racer01014 | 0:5e35c180ed4a | 145 | /** |
Racer01014 | 0:5e35c180ed4a | 146 | * Scrolling |
Racer01014 | 0:5e35c180ed4a | 147 | * |
Racer01014 | 0:5e35c180ed4a | 148 | * @param z value of the wheel (>0 to go down, <0 to go up) |
Racer01014 | 0:5e35c180ed4a | 149 | * @returns true if there is no error, false otherwise |
Racer01014 | 0:5e35c180ed4a | 150 | */ |
Racer01014 | 0:5e35c180ed4a | 151 | bool scroll(int8_t z); |
Racer01014 | 0:5e35c180ed4a | 152 | |
Racer01014 | 0:5e35c180ed4a | 153 | /** |
Racer01014 | 0:5e35c180ed4a | 154 | * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key |
Racer01014 | 0:5e35c180ed4a | 155 | * |
Racer01014 | 0:5e35c180ed4a | 156 | * @code |
Racer01014 | 0:5e35c180ed4a | 157 | * //To send CTRL + s (save) |
Racer01014 | 0:5e35c180ed4a | 158 | * keyboard.keyCode('s', KEY_CTRL); |
Racer01014 | 0:5e35c180ed4a | 159 | * @endcode |
Racer01014 | 0:5e35c180ed4a | 160 | * |
Racer01014 | 0:5e35c180ed4a | 161 | * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0) |
Racer01014 | 0:5e35c180ed4a | 162 | * @param key character to send |
Racer01014 | 0:5e35c180ed4a | 163 | * @returns true if there is no error, false otherwise |
Racer01014 | 0:5e35c180ed4a | 164 | */ |
Racer01014 | 0:5e35c180ed4a | 165 | bool keyCode(uint8_t key, uint8_t modifier = 0); |
Racer01014 | 0:5e35c180ed4a | 166 | |
Racer01014 | 0:5e35c180ed4a | 167 | /** |
Racer01014 | 0:5e35c180ed4a | 168 | * Send a character |
Racer01014 | 0:5e35c180ed4a | 169 | * |
Racer01014 | 0:5e35c180ed4a | 170 | * @param c character to be sent |
Racer01014 | 0:5e35c180ed4a | 171 | * @returns true if there is no error, false otherwise |
Racer01014 | 0:5e35c180ed4a | 172 | */ |
Racer01014 | 0:5e35c180ed4a | 173 | virtual int _putc(int c); |
Racer01014 | 0:5e35c180ed4a | 174 | |
Racer01014 | 0:5e35c180ed4a | 175 | /** |
Racer01014 | 0:5e35c180ed4a | 176 | * Control media keys |
Racer01014 | 0:5e35c180ed4a | 177 | * |
Racer01014 | 0:5e35c180ed4a | 178 | * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN) |
Racer01014 | 0:5e35c180ed4a | 179 | * @returns true if there is no error, false otherwise |
Racer01014 | 0:5e35c180ed4a | 180 | */ |
Racer01014 | 0:5e35c180ed4a | 181 | bool mediaControl(MEDIA_KEY key); |
Racer01014 | 0:5e35c180ed4a | 182 | |
Racer01014 | 0:5e35c180ed4a | 183 | /** |
Racer01014 | 0:5e35c180ed4a | 184 | * Read status of lock keys. Useful to switch-on/off leds according to key pressed. Only the first three bits of the result is important: |
Racer01014 | 0:5e35c180ed4a | 185 | * - First bit: NUM_LOCK |
Racer01014 | 0:5e35c180ed4a | 186 | * - Second bit: CAPS_LOCK |
Racer01014 | 0:5e35c180ed4a | 187 | * - Third bit: SCROLL_LOCK |
Racer01014 | 0:5e35c180ed4a | 188 | * |
Racer01014 | 0:5e35c180ed4a | 189 | * @returns status of lock keys |
Racer01014 | 0:5e35c180ed4a | 190 | */ |
Racer01014 | 0:5e35c180ed4a | 191 | uint8_t lockStatus(); |
Racer01014 | 0:5e35c180ed4a | 192 | |
Racer01014 | 0:5e35c180ed4a | 193 | /* |
Racer01014 | 0:5e35c180ed4a | 194 | * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
Racer01014 | 0:5e35c180ed4a | 195 | * |
Racer01014 | 0:5e35c180ed4a | 196 | * @returns pointer to the report descriptor |
Racer01014 | 0:5e35c180ed4a | 197 | */ |
Racer01014 | 0:5e35c180ed4a | 198 | virtual uint8_t * reportDesc(); |
Racer01014 | 0:5e35c180ed4a | 199 | |
Racer01014 | 0:5e35c180ed4a | 200 | /* |
Racer01014 | 0:5e35c180ed4a | 201 | * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys |
Racer01014 | 0:5e35c180ed4a | 202 | * |
Racer01014 | 0:5e35c180ed4a | 203 | * @returns if handle by subclass, return true |
Racer01014 | 0:5e35c180ed4a | 204 | */ |
Racer01014 | 0:5e35c180ed4a | 205 | virtual bool EP1_OUT_callback(); |
Racer01014 | 0:5e35c180ed4a | 206 | |
Racer01014 | 0:5e35c180ed4a | 207 | |
Racer01014 | 0:5e35c180ed4a | 208 | private: |
Racer01014 | 0:5e35c180ed4a | 209 | bool mouseWrite(int8_t x, int8_t y, uint8_t buttons, int8_t z); |
Racer01014 | 0:5e35c180ed4a | 210 | MOUSE_TYPE mouse_type; |
Racer01014 | 0:5e35c180ed4a | 211 | uint8_t button; |
Racer01014 | 0:5e35c180ed4a | 212 | bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z); |
Racer01014 | 0:5e35c180ed4a | 213 | |
Racer01014 | 0:5e35c180ed4a | 214 | uint8_t lock_status; |
Racer01014 | 0:5e35c180ed4a | 215 | |
Racer01014 | 0:5e35c180ed4a | 216 | //dummy otherwise it doesn't compile (we must define all methods of an abstract class) |
Racer01014 | 0:5e35c180ed4a | 217 | virtual int _getc() { return -1;} |
Racer01014 | 0:5e35c180ed4a | 218 | }; |
Racer01014 | 0:5e35c180ed4a | 219 | |
Racer01014 | 0:5e35c180ed4a | 220 | #endif |