]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/USBDevice/USBHID/USBMouseKeyboard.h
1 /* Copyright (c) 2010-2011 mbed.org, MIT License
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 * and associated documentation files (the "Software"), to deal in the Software without
5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7 * Software is furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in all copies or
10 * substantial portions of the Software.
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 #ifndef USBMOUSEKEYBOARD_H
20 #define USBMOUSEKEYBOARD_H
22 #define REPORT_ID_KEYBOARD 1
23 #define REPORT_ID_MOUSE 2
24 #define REPORT_ID_VOLUME 3
27 #include "USBKeyboard.h"
32 * USBMouseKeyboard example
36 * #include "USBMouseKeyboard.h"
38 * USBMouseKeyboard key_mouse;
44 * key_mouse.move(20, 0);
45 * key_mouse.printf("Hello From MBED\r\n");
55 * #include "USBMouseKeyboard.h"
57 * USBMouseKeyboard key_mouse(ABS_MOUSE);
63 * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2);
64 * key_mouse.printf("Hello from MBED\r\n");
70 class USBMouseKeyboard
: public USBHID
, public Stream
77 * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE)
78 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
79 * @param vendor_id Your vendor_id (default: 0x1234)
80 * @param product_id Your product_id (default: 0x0001)
81 * @param product_release Your preoduct_release (default: 0x0001)
84 USBMouseKeyboard(MOUSE_TYPE mouse_type
= REL_MOUSE
, uint16_t vendor_id
= 0x0021, uint16_t product_id
= 0x0011, uint16_t product_release
= 0x0001):
85 USBHID(0, 0, vendor_id
, product_id
, product_release
, false)
89 this->mouse_type
= mouse_type
;
94 * Write a state of the mouse
96 * @param x x-axis position
97 * @param y y-axis position
98 * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE)
99 * @param z wheel state (>0 to scroll down, <0 to scroll up)
100 * @returns true if there is no error, false otherwise
102 bool update(int16_t x
, int16_t y
, uint8_t buttons
, int8_t z
);
106 * Move the cursor to (x, y)
108 * @param x x-axis position
109 * @param y y-axis position
110 * @returns true if there is no error, false otherwise
112 bool move(int16_t x
, int16_t y
);
115 * Press one or several buttons
117 * @param button button state (ex: press(MOUSE_LEFT))
118 * @returns true if there is no error, false otherwise
120 bool press(uint8_t button
);
123 * Release one or several buttons
125 * @param button button state (ex: release(MOUSE_LEFT))
126 * @returns true if there is no error, false otherwise
128 bool release(uint8_t button
);
131 * Double click (MOUSE_LEFT)
133 * @returns true if there is no error, false otherwise
140 * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
141 * @returns true if there is no error, false otherwise
143 bool click(uint8_t button
);
148 * @param z value of the wheel (>0 to go down, <0 to go up)
149 * @returns true if there is no error, false otherwise
151 bool scroll(int8_t z
);
154 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
157 * //To send CTRL + s (save)
158 * keyboard.keyCode('s', KEY_CTRL);
161 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
162 * @param key character to send
163 * @returns true if there is no error, false otherwise
165 bool keyCode(uint8_t key
, uint8_t modifier
= 0);
170 * @param c character to be sent
171 * @returns true if there is no error, false otherwise
173 virtual int _putc(int c
);
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)
179 * @returns true if there is no error, false otherwise
181 bool mediaControl(MEDIA_KEY key
);
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:
185 * - First bit: NUM_LOCK
186 * - Second bit: CAPS_LOCK
187 * - Third bit: SCROLL_LOCK
189 * @returns status of lock keys
191 uint8_t lockStatus();
194 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
196 * @returns pointer to the report descriptor
198 virtual uint8_t * reportDesc();
201 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
203 * @returns if handle by subclass, return true
205 virtual bool EPINT_OUT_callback();
209 bool mouseWrite(int8_t x
, int8_t y
, uint8_t buttons
, int8_t z
);
210 MOUSE_TYPE mouse_type
;
212 bool mouseSend(int8_t x
, int8_t y
, uint8_t buttons
, int8_t z
);
216 //dummy otherwise it doesn't compile (we must define all methods of an abstract class)
217 virtual int _getc() { return -1;}