キーボードの長押しに対応。
Fork of USBDevice by
Embed:
(wiki syntax)
Show/hide line numbers
USBKeyboard.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 USBKEYBOARD_H 00020 #define USBKEYBOARD_H 00021 00022 #include "USBHID.h" 00023 #include "Stream.h" 00024 00025 /* Modifiers */ 00026 enum MODIFIER_KEY { 00027 KEY_CTRL = 1, 00028 KEY_SHIFT = 2, 00029 KEY_ALT = 4, 00030 }; 00031 00032 00033 enum MEDIA_KEY { 00034 KEY_NEXT_TRACK, /*!< next Track Button */ 00035 KEY_PREVIOUS_TRACK, /*!< Previous track Button */ 00036 KEY_STOP, /*!< Stop Button */ 00037 KEY_PLAY_PAUSE, /*!< Play/Pause Button */ 00038 KEY_MUTE, /*!< Mute Button */ 00039 KEY_VOLUME_UP, /*!< Volume Up Button */ 00040 KEY_VOLUME_DOWN, /*!< Volume Down Button */ 00041 }; 00042 00043 enum FUNCTION_KEY { 00044 KEY_F1 = 128, /* F1 key */ 00045 KEY_F2, /* F2 key */ 00046 KEY_F3, /* F3 key */ 00047 KEY_F4, /* F4 key */ 00048 KEY_F5, /* F5 key */ 00049 KEY_F6, /* F6 key */ 00050 KEY_F7, /* F7 key */ 00051 KEY_F8, /* F8 key */ 00052 KEY_F9, /* F9 key */ 00053 KEY_F10, /* F10 key */ 00054 KEY_F11, /* F11 key */ 00055 KEY_F12, /* F12 key */ 00056 00057 KEY_PRINT_SCREEN, /* Print Screen key */ 00058 KEY_SCROLL_LOCK, /* Scroll lock */ 00059 KEY_CAPS_LOCK, /* caps lock */ 00060 KEY_NUM_LOCK, /* num lock */ 00061 KEY_INSERT, /* Insert key */ 00062 KEY_HOME, /* Home key */ 00063 KEY_PAGE_UP, /* Page Up key */ 00064 KEY_PAGE_DOWN, /* Page Down key */ 00065 00066 RIGHT_ARROW, /* Right arrow */ 00067 LEFT_ARROW, /* Left arrow */ 00068 DOWN_ARROW, /* Down arrow */ 00069 UP_ARROW, /* Up arrow */ 00070 }; 00071 00072 /** 00073 * USBKeyboard example 00074 * @code 00075 * 00076 * #include "mbed.h" 00077 * #include "USBKeyboard.h" 00078 * 00079 * USBKeyboard key; 00080 * 00081 * int main(void) 00082 * { 00083 * while (1) 00084 * { 00085 * key.printf("Hello World\r\n"); 00086 * wait(1); 00087 * } 00088 * } 00089 * 00090 * @endcode 00091 */ 00092 class USBKeyboard: public USBHID, public Stream { 00093 public: 00094 00095 /** 00096 * コンストラクタ 00097 * 00098 * 00099 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK 00100 * @param vendor_id Your vendor_id (default: 0x1235) 00101 * @param product_id Your product_id (default: 0x0050) 00102 * @param product_release Your preoduct_release (default: 0x0001) 00103 * 00104 */ 00105 USBKeyboard(uint16_t vendor_id = 0x1235, uint16_t product_id = 0x0050, uint16_t product_release = 0x0001): 00106 USBHID(0, 0, vendor_id, product_id, product_release, false) { 00107 lock_status = 0; 00108 connect(); 00109 }; 00110 00111 /** 00112 * 修飾子(CTRL, SHIFT, ALT)とキーで定義された文字を送信します。 00113 * 00114 * @code 00115 * //To send CTRL + s (save) 00116 * keyboard.keyCode('s', KEY_CTRL); 00117 * @endcode 00118 * 00119 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0) 00120 * @param key 送信するキャラクタ 00121 * @returns true if there is no error, false otherwise 00122 */ 00123 /// 00124 /// キーコード 00125 /// 00126 bool keyCode(uint8_t key, uint8_t modifier = 0); 00127 00128 /// キーダウン /// 00129 bool keyDown(uint8_t key); 00130 00131 /// キーアップ /// 00132 bool keyUp(uint8_t); 00133 00134 /** 00135 * キャラクタを送信します。 00136 * 00137 * @param c 送信するキャラクタ 00138 * @returns エラーがない場合はtrueを返し、そうでない場合はfalseを返します。 00139 */ 00140 virtual int _putc(int c); 00141 00142 /** 00143 * メディアキーを制御する 00144 * 00145 * @param key 押されたメディアキー (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN) 00146 * @returns true if there is no error, false otherwise 00147 */ 00148 bool mediaControl(MEDIA_KEY key); 00149 00150 /* 00151 * レポート記述子を定義します。警告:このメソッドは、レポート記述子の長さをreportLengthに格納する必要があります。 00152 * 00153 * @returns レポート記述子へのポインタ 00154 */ 00155 virtual uint8_t * reportDesc(); 00156 00157 /* 00158 * OUTエンドポイントでデータが受信されたときに呼び出されます。LOCKキーのLEDをスイッチするのに便利です。 00159 * 00160 * @returns if handle by subclass, return true 00161 */ 00162 virtual bool EP1_OUT_callback(); 00163 00164 /** 00165 * ロックキーの状態を読み取ります。押されたキーに応じてLEDをスイッチオン/オフするのに便利です。 00166 * 結果の最初の3ビットのみが重要です。 00167 * - 最初のビット: NUM_LOCK 00168 * - 二番目のビット: CAPS_LOCK 00169 * - 三番目のビット: SCROLL_LOCK 00170 * 00171 * @returns ロックキーのステータス 00172 */ 00173 uint8_t lockStatus(); 00174 00175 protected: 00176 /* 00177 * 構成記述子を取得する。 00178 * 00179 * @returns 構成記述子へのポインタ 00180 */ 00181 virtual uint8_t * configurationDesc(); 00182 00183 private: 00184 // それ以外の場合は、それはコンパイルされません(抽象クラスのすべてのメソッドを定義する必要があります)。 00185 virtual int _getc() { 00186 return -1; 00187 }; 00188 00189 uint8_t lock_status; 00190 00191 }; 00192 00193 #endif
Generated on Tue Jul 12 2022 15:08:05 by 1.7.2