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
USBMouseKeyboard.h
00001 /* Copyright (c) 2010-2011 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #ifndef USBMOUSEKEYBOARD_H 00020 #define USBMOUSEKEYBOARD_H 00021 00022 #define REPORT_ID_KEYBOARD 1 00023 #define REPORT_ID_MOUSE 2 00024 #define REPORT_ID_VOLUME 3 00025 00026 #include "USBMouse.h" 00027 #include "USBKeyboard.h" 00028 #include "Stream.h" 00029 #include "USBHID.h" 00030 00031 /** 00032 * USBMouseKeyboard example 00033 * @code 00034 * 00035 * #include "mbed.h" 00036 * #include "USBMouseKeyboard.h" 00037 * 00038 * USBMouseKeyboard key_mouse; 00039 * 00040 * int main(void) 00041 * { 00042 * while(1) 00043 * { 00044 * key_mouse.move(20, 0); 00045 * key_mouse.printf("Hello From MBED\r\n"); 00046 * wait(1); 00047 * } 00048 * } 00049 * @endcode 00050 * 00051 * 00052 * @code 00053 * 00054 * #include "mbed.h" 00055 * #include "USBMouseKeyboard.h" 00056 * 00057 * USBMouseKeyboard key_mouse(ABS_MOUSE); 00058 * 00059 * int main(void) 00060 * { 00061 * while(1) 00062 * { 00063 * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2); 00064 * key_mouse.printf("Hello from MBED\r\n"); 00065 * wait(1); 00066 * } 00067 * } 00068 * @endcode 00069 */ 00070 class USBMouseKeyboard: public USBHID, public Stream 00071 { 00072 public: 00073 00074 /** 00075 * Constructor 00076 * 00077 * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE) 00078 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK 00079 * @param vendor_id Your vendor_id (default: 0x1234) 00080 * @param product_id Your product_id (default: 0x0001) 00081 * @param product_release Your preoduct_release (default: 0x0001) 00082 * 00083 */ 00084 USBMouseKeyboard(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x0021, uint16_t product_id = 0x0011, uint16_t product_release = 0x0001): 00085 USBHID(0, 0, vendor_id, product_id, product_release, false) 00086 { 00087 lock_status = 0; 00088 button = 0; 00089 this->mouse_type = mouse_type; 00090 //connect(); 00091 }; 00092 00093 /* 00094 * Connect a device 00095 * 00096 * @param blocking: block if not configured 00097 * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE) 00098 */ 00099 bool connect(MOUSE_TYPE mouse_type = REL_MOUSE, bool blocking = true); 00100 00101 /** 00102 * Write a state of the mouse 00103 * 00104 * @param x x-axis position 00105 * @param y y-axis position 00106 * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE) 00107 * @param z wheel state (>0 to scroll down, <0 to scroll up) 00108 * @returns true if there is no error, false otherwise 00109 */ 00110 bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z); 00111 00112 00113 /** 00114 * Move the cursor to (x, y) 00115 * 00116 * @param x x-axis position 00117 * @param y y-axis position 00118 * @returns true if there is no error, false otherwise 00119 */ 00120 bool move(int16_t x, int16_t y); 00121 00122 /** 00123 * Press one or several buttons 00124 * 00125 * @param button button state (ex: press(MOUSE_LEFT)) 00126 * @returns true if there is no error, false otherwise 00127 */ 00128 bool press(uint8_t button); 00129 00130 /** 00131 * Release one or several buttons 00132 * 00133 * @param button button state (ex: release(MOUSE_LEFT)) 00134 * @returns true if there is no error, false otherwise 00135 */ 00136 bool release(uint8_t button); 00137 00138 /** 00139 * Double click (MOUSE_LEFT) 00140 * 00141 * @returns true if there is no error, false otherwise 00142 */ 00143 bool doubleClick(); 00144 00145 /** 00146 * Click 00147 * 00148 * @param button state of the buttons ( ex: clic(MOUSE_LEFT)) 00149 * @returns true if there is no error, false otherwise 00150 */ 00151 bool click(uint8_t button); 00152 00153 /** 00154 * Scrolling 00155 * 00156 * @param z value of the wheel (>0 to go down, <0 to go up) 00157 * @returns true if there is no error, false otherwise 00158 */ 00159 bool scroll(int8_t z); 00160 00161 /** 00162 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key 00163 * 00164 * @code 00165 * //To send CTRL + s (save) 00166 * keyboard.keyCode('s', KEY_CTRL); 00167 * @endcode 00168 * 00169 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0) 00170 * @param key character to send 00171 * @returns true if there is no error, false otherwise 00172 */ 00173 bool keyCode(uint8_t key, uint8_t modifier = 0); 00174 00175 /** 00176 * Send a character 00177 * 00178 * @param c character to be sent 00179 * @returns true if there is no error, false otherwise 00180 */ 00181 virtual int _putc(int c); 00182 00183 /** 00184 * Control media keys 00185 * 00186 * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN) 00187 * @returns true if there is no error, false otherwise 00188 */ 00189 bool mediaControl(MEDIA_KEY key); 00190 00191 /** 00192 * 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: 00193 * - First bit: NUM_LOCK 00194 * - Second bit: CAPS_LOCK 00195 * - Third bit: SCROLL_LOCK 00196 * 00197 * @returns status of lock keys 00198 */ 00199 uint8_t lockStatus(); 00200 00201 /* 00202 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. 00203 * 00204 * @returns pointer to the report descriptor 00205 */ 00206 virtual uint8_t * reportDesc(); 00207 00208 /* 00209 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys 00210 * 00211 * @returns if handle by subclass, return true 00212 */ 00213 virtual bool EPINT_OUT_callback(); 00214 00215 00216 private: 00217 bool mouseWrite(int8_t x, int8_t y, uint8_t buttons, int8_t z); 00218 MOUSE_TYPE mouse_type; 00219 uint8_t button; 00220 bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z); 00221 00222 uint8_t lock_status; 00223 00224 //dummy otherwise it doesn't compile (we must define all methods of an abstract class) 00225 virtual int _getc() { return -1;} 00226 }; 00227 00228 #endif
Generated on Wed Jul 13 2022 08:27:09 by
1.7.2
