Transistor Gijutsu, October 2014, Special Features Chapter 8,Software of the thermistor thermometer of 0.001 ° resolution, トランジスタ技術2014年10月号 特集第8章のソフトウェア 0.001℃分解能で気配もキャッチ「超敏感肌温度計」

Dependencies:   USBDevice mbed

Information

tg_201410s8_AD7714 トランジスタ技術 2014年 10月号 第8章のソフトウェア

Program for Section 8 in October. 2014 issue of the Transistor Gijutsu
(Japanese electronics magazine)

概要

このプログラムは、サーミスタの抵抗値変化をAD7714(24bitADC)で測定し、抵抗値を温度値に変換することで、0.001℃程度の分解能で温度変化を測定します。

ファイル

このソフトウエアは、次のファイルから構成されています。

  • AD7714.cpp - AD7714の内部レジスタを設定
  • Thermistor.cpp - サーミスタの抵抗値から温度値に変換
  • ExpAvr.cpp - 指数平均によるソフトウエアLPF
  • main.cpp - main()関数

詳細については、10月号の記事および上記ファイル中のコメントを参照してください。

Committer:
Dance
Date:
Fri Aug 29 08:38:36 2014 +0000
Revision:
0:de885a6da962
Transistor Gijutsu, October 2014, Special Features Chapter 8; ????????2014?10??????8????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Dance 0:de885a6da962 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Dance 0:de885a6da962 2 *
Dance 0:de885a6da962 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Dance 0:de885a6da962 4 * and associated documentation files (the "Software"), to deal in the Software without
Dance 0:de885a6da962 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Dance 0:de885a6da962 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Dance 0:de885a6da962 7 * Software is furnished to do so, subject to the following conditions:
Dance 0:de885a6da962 8 *
Dance 0:de885a6da962 9 * The above copyright notice and this permission notice shall be included in all copies or
Dance 0:de885a6da962 10 * substantial portions of the Software.
Dance 0:de885a6da962 11 *
Dance 0:de885a6da962 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Dance 0:de885a6da962 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Dance 0:de885a6da962 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Dance 0:de885a6da962 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Dance 0:de885a6da962 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Dance 0:de885a6da962 17 */
Dance 0:de885a6da962 18
Dance 0:de885a6da962 19 #include "stdint.h"
Dance 0:de885a6da962 20 #include "USBMouseKeyboard.h"
Dance 0:de885a6da962 21
Dance 0:de885a6da962 22 typedef struct {
Dance 0:de885a6da962 23 unsigned char usage;
Dance 0:de885a6da962 24 unsigned char modifier;
Dance 0:de885a6da962 25 } KEYMAP;
Dance 0:de885a6da962 26
Dance 0:de885a6da962 27 #ifdef US_KEYBOARD
Dance 0:de885a6da962 28 /* US keyboard (as HID standard) */
Dance 0:de885a6da962 29 #define KEYMAP_SIZE (152)
Dance 0:de885a6da962 30 const KEYMAP keymap[KEYMAP_SIZE] = {
Dance 0:de885a6da962 31 {0, 0}, /* NUL */
Dance 0:de885a6da962 32 {0, 0}, /* SOH */
Dance 0:de885a6da962 33 {0, 0}, /* STX */
Dance 0:de885a6da962 34 {0, 0}, /* ETX */
Dance 0:de885a6da962 35 {0, 0}, /* EOT */
Dance 0:de885a6da962 36 {0, 0}, /* ENQ */
Dance 0:de885a6da962 37 {0, 0}, /* ACK */
Dance 0:de885a6da962 38 {0, 0}, /* BEL */
Dance 0:de885a6da962 39 {0x2a, 0}, /* BS */ /* Keyboard Delete (Backspace) */
Dance 0:de885a6da962 40 {0x2b, 0}, /* TAB */ /* Keyboard Tab */
Dance 0:de885a6da962 41 {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */
Dance 0:de885a6da962 42 {0, 0}, /* VT */
Dance 0:de885a6da962 43 {0, 0}, /* FF */
Dance 0:de885a6da962 44 {0, 0}, /* CR */
Dance 0:de885a6da962 45 {0, 0}, /* SO */
Dance 0:de885a6da962 46 {0, 0}, /* SI */
Dance 0:de885a6da962 47 {0, 0}, /* DEL */
Dance 0:de885a6da962 48 {0, 0}, /* DC1 */
Dance 0:de885a6da962 49 {0, 0}, /* DC2 */
Dance 0:de885a6da962 50 {0, 0}, /* DC3 */
Dance 0:de885a6da962 51 {0, 0}, /* DC4 */
Dance 0:de885a6da962 52 {0, 0}, /* NAK */
Dance 0:de885a6da962 53 {0, 0}, /* SYN */
Dance 0:de885a6da962 54 {0, 0}, /* ETB */
Dance 0:de885a6da962 55 {0, 0}, /* CAN */
Dance 0:de885a6da962 56 {0, 0}, /* EM */
Dance 0:de885a6da962 57 {0, 0}, /* SUB */
Dance 0:de885a6da962 58 {0, 0}, /* ESC */
Dance 0:de885a6da962 59 {0, 0}, /* FS */
Dance 0:de885a6da962 60 {0, 0}, /* GS */
Dance 0:de885a6da962 61 {0, 0}, /* RS */
Dance 0:de885a6da962 62 {0, 0}, /* US */
Dance 0:de885a6da962 63 {0x2c, 0}, /* */
Dance 0:de885a6da962 64 {0x1e, KEY_SHIFT}, /* ! */
Dance 0:de885a6da962 65 {0x34, KEY_SHIFT}, /* " */
Dance 0:de885a6da962 66 {0x20, KEY_SHIFT}, /* # */
Dance 0:de885a6da962 67 {0x21, KEY_SHIFT}, /* $ */
Dance 0:de885a6da962 68 {0x22, KEY_SHIFT}, /* % */
Dance 0:de885a6da962 69 {0x24, KEY_SHIFT}, /* & */
Dance 0:de885a6da962 70 {0x34, 0}, /* ' */
Dance 0:de885a6da962 71 {0x26, KEY_SHIFT}, /* ( */
Dance 0:de885a6da962 72 {0x27, KEY_SHIFT}, /* ) */
Dance 0:de885a6da962 73 {0x25, KEY_SHIFT}, /* * */
Dance 0:de885a6da962 74 {0x2e, KEY_SHIFT}, /* + */
Dance 0:de885a6da962 75 {0x36, 0}, /* , */
Dance 0:de885a6da962 76 {0x2d, 0}, /* - */
Dance 0:de885a6da962 77 {0x37, 0}, /* . */
Dance 0:de885a6da962 78 {0x38, 0}, /* / */
Dance 0:de885a6da962 79 {0x27, 0}, /* 0 */
Dance 0:de885a6da962 80 {0x1e, 0}, /* 1 */
Dance 0:de885a6da962 81 {0x1f, 0}, /* 2 */
Dance 0:de885a6da962 82 {0x20, 0}, /* 3 */
Dance 0:de885a6da962 83 {0x21, 0}, /* 4 */
Dance 0:de885a6da962 84 {0x22, 0}, /* 5 */
Dance 0:de885a6da962 85 {0x23, 0}, /* 6 */
Dance 0:de885a6da962 86 {0x24, 0}, /* 7 */
Dance 0:de885a6da962 87 {0x25, 0}, /* 8 */
Dance 0:de885a6da962 88 {0x26, 0}, /* 9 */
Dance 0:de885a6da962 89 {0x33, KEY_SHIFT}, /* : */
Dance 0:de885a6da962 90 {0x33, 0}, /* ; */
Dance 0:de885a6da962 91 {0x36, KEY_SHIFT}, /* < */
Dance 0:de885a6da962 92 {0x2e, 0}, /* = */
Dance 0:de885a6da962 93 {0x37, KEY_SHIFT}, /* > */
Dance 0:de885a6da962 94 {0x38, KEY_SHIFT}, /* ? */
Dance 0:de885a6da962 95 {0x1f, KEY_SHIFT}, /* @ */
Dance 0:de885a6da962 96 {0x04, KEY_SHIFT}, /* A */
Dance 0:de885a6da962 97 {0x05, KEY_SHIFT}, /* B */
Dance 0:de885a6da962 98 {0x06, KEY_SHIFT}, /* C */
Dance 0:de885a6da962 99 {0x07, KEY_SHIFT}, /* D */
Dance 0:de885a6da962 100 {0x08, KEY_SHIFT}, /* E */
Dance 0:de885a6da962 101 {0x09, KEY_SHIFT}, /* F */
Dance 0:de885a6da962 102 {0x0a, KEY_SHIFT}, /* G */
Dance 0:de885a6da962 103 {0x0b, KEY_SHIFT}, /* H */
Dance 0:de885a6da962 104 {0x0c, KEY_SHIFT}, /* I */
Dance 0:de885a6da962 105 {0x0d, KEY_SHIFT}, /* J */
Dance 0:de885a6da962 106 {0x0e, KEY_SHIFT}, /* K */
Dance 0:de885a6da962 107 {0x0f, KEY_SHIFT}, /* L */
Dance 0:de885a6da962 108 {0x10, KEY_SHIFT}, /* M */
Dance 0:de885a6da962 109 {0x11, KEY_SHIFT}, /* N */
Dance 0:de885a6da962 110 {0x12, KEY_SHIFT}, /* O */
Dance 0:de885a6da962 111 {0x13, KEY_SHIFT}, /* P */
Dance 0:de885a6da962 112 {0x14, KEY_SHIFT}, /* Q */
Dance 0:de885a6da962 113 {0x15, KEY_SHIFT}, /* R */
Dance 0:de885a6da962 114 {0x16, KEY_SHIFT}, /* S */
Dance 0:de885a6da962 115 {0x17, KEY_SHIFT}, /* T */
Dance 0:de885a6da962 116 {0x18, KEY_SHIFT}, /* U */
Dance 0:de885a6da962 117 {0x19, KEY_SHIFT}, /* V */
Dance 0:de885a6da962 118 {0x1a, KEY_SHIFT}, /* W */
Dance 0:de885a6da962 119 {0x1b, KEY_SHIFT}, /* X */
Dance 0:de885a6da962 120 {0x1c, KEY_SHIFT}, /* Y */
Dance 0:de885a6da962 121 {0x1d, KEY_SHIFT}, /* Z */
Dance 0:de885a6da962 122 {0x2f, 0}, /* [ */
Dance 0:de885a6da962 123 {0x31, 0}, /* \ */
Dance 0:de885a6da962 124 {0x30, 0}, /* ] */
Dance 0:de885a6da962 125 {0x23, KEY_SHIFT}, /* ^ */
Dance 0:de885a6da962 126 {0x2d, KEY_SHIFT}, /* _ */
Dance 0:de885a6da962 127 {0x35, 0}, /* ` */
Dance 0:de885a6da962 128 {0x04, 0}, /* a */
Dance 0:de885a6da962 129 {0x05, 0}, /* b */
Dance 0:de885a6da962 130 {0x06, 0}, /* c */
Dance 0:de885a6da962 131 {0x07, 0}, /* d */
Dance 0:de885a6da962 132 {0x08, 0}, /* e */
Dance 0:de885a6da962 133 {0x09, 0}, /* f */
Dance 0:de885a6da962 134 {0x0a, 0}, /* g */
Dance 0:de885a6da962 135 {0x0b, 0}, /* h */
Dance 0:de885a6da962 136 {0x0c, 0}, /* i */
Dance 0:de885a6da962 137 {0x0d, 0}, /* j */
Dance 0:de885a6da962 138 {0x0e, 0}, /* k */
Dance 0:de885a6da962 139 {0x0f, 0}, /* l */
Dance 0:de885a6da962 140 {0x10, 0}, /* m */
Dance 0:de885a6da962 141 {0x11, 0}, /* n */
Dance 0:de885a6da962 142 {0x12, 0}, /* o */
Dance 0:de885a6da962 143 {0x13, 0}, /* p */
Dance 0:de885a6da962 144 {0x14, 0}, /* q */
Dance 0:de885a6da962 145 {0x15, 0}, /* r */
Dance 0:de885a6da962 146 {0x16, 0}, /* s */
Dance 0:de885a6da962 147 {0x17, 0}, /* t */
Dance 0:de885a6da962 148 {0x18, 0}, /* u */
Dance 0:de885a6da962 149 {0x19, 0}, /* v */
Dance 0:de885a6da962 150 {0x1a, 0}, /* w */
Dance 0:de885a6da962 151 {0x1b, 0}, /* x */
Dance 0:de885a6da962 152 {0x1c, 0}, /* y */
Dance 0:de885a6da962 153 {0x1d, 0}, /* z */
Dance 0:de885a6da962 154 {0x2f, KEY_SHIFT}, /* { */
Dance 0:de885a6da962 155 {0x31, KEY_SHIFT}, /* | */
Dance 0:de885a6da962 156 {0x30, KEY_SHIFT}, /* } */
Dance 0:de885a6da962 157 {0x35, KEY_SHIFT}, /* ~ */
Dance 0:de885a6da962 158 {0,0}, /* DEL */
Dance 0:de885a6da962 159
Dance 0:de885a6da962 160 {0x3a, 0}, /* F1 */
Dance 0:de885a6da962 161 {0x3b, 0}, /* F2 */
Dance 0:de885a6da962 162 {0x3c, 0}, /* F3 */
Dance 0:de885a6da962 163 {0x3d, 0}, /* F4 */
Dance 0:de885a6da962 164 {0x3e, 0}, /* F5 */
Dance 0:de885a6da962 165 {0x3f, 0}, /* F6 */
Dance 0:de885a6da962 166 {0x40, 0}, /* F7 */
Dance 0:de885a6da962 167 {0x41, 0}, /* F8 */
Dance 0:de885a6da962 168 {0x42, 0}, /* F9 */
Dance 0:de885a6da962 169 {0x43, 0}, /* F10 */
Dance 0:de885a6da962 170 {0x44, 0}, /* F11 */
Dance 0:de885a6da962 171 {0x45, 0}, /* F12 */
Dance 0:de885a6da962 172
Dance 0:de885a6da962 173 {0x46, 0}, /* PRINT_SCREEN */
Dance 0:de885a6da962 174 {0x47, 0}, /* SCROLL_LOCK */
Dance 0:de885a6da962 175 {0x39, 0}, /* CAPS_LOCK */
Dance 0:de885a6da962 176 {0x53, 0}, /* NUM_LOCK */
Dance 0:de885a6da962 177 {0x49, 0}, /* INSERT */
Dance 0:de885a6da962 178 {0x4a, 0}, /* HOME */
Dance 0:de885a6da962 179 {0x4b, 0}, /* PAGE_UP */
Dance 0:de885a6da962 180 {0x4e, 0}, /* PAGE_DOWN */
Dance 0:de885a6da962 181
Dance 0:de885a6da962 182 {0x4f, 0}, /* RIGHT_ARROW */
Dance 0:de885a6da962 183 {0x50, 0}, /* LEFT_ARROW */
Dance 0:de885a6da962 184 {0x51, 0}, /* DOWN_ARROW */
Dance 0:de885a6da962 185 {0x52, 0}, /* UP_ARROW */
Dance 0:de885a6da962 186 };
Dance 0:de885a6da962 187
Dance 0:de885a6da962 188 #else
Dance 0:de885a6da962 189 /* UK keyboard */
Dance 0:de885a6da962 190 #define KEYMAP_SIZE (152)
Dance 0:de885a6da962 191 const KEYMAP keymap[KEYMAP_SIZE] = {
Dance 0:de885a6da962 192 {0, 0}, /* NUL */
Dance 0:de885a6da962 193 {0, 0}, /* SOH */
Dance 0:de885a6da962 194 {0, 0}, /* STX */
Dance 0:de885a6da962 195 {0, 0}, /* ETX */
Dance 0:de885a6da962 196 {0, 0}, /* EOT */
Dance 0:de885a6da962 197 {0, 0}, /* ENQ */
Dance 0:de885a6da962 198 {0, 0}, /* ACK */
Dance 0:de885a6da962 199 {0, 0}, /* BEL */
Dance 0:de885a6da962 200 {0x2a, 0}, /* BS */ /* Keyboard Delete (Backspace) */
Dance 0:de885a6da962 201 {0x2b, 0}, /* TAB */ /* Keyboard Tab */
Dance 0:de885a6da962 202 {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */
Dance 0:de885a6da962 203 {0, 0}, /* VT */
Dance 0:de885a6da962 204 {0, 0}, /* FF */
Dance 0:de885a6da962 205 {0, 0}, /* CR */
Dance 0:de885a6da962 206 {0, 0}, /* SO */
Dance 0:de885a6da962 207 {0, 0}, /* SI */
Dance 0:de885a6da962 208 {0, 0}, /* DEL */
Dance 0:de885a6da962 209 {0, 0}, /* DC1 */
Dance 0:de885a6da962 210 {0, 0}, /* DC2 */
Dance 0:de885a6da962 211 {0, 0}, /* DC3 */
Dance 0:de885a6da962 212 {0, 0}, /* DC4 */
Dance 0:de885a6da962 213 {0, 0}, /* NAK */
Dance 0:de885a6da962 214 {0, 0}, /* SYN */
Dance 0:de885a6da962 215 {0, 0}, /* ETB */
Dance 0:de885a6da962 216 {0, 0}, /* CAN */
Dance 0:de885a6da962 217 {0, 0}, /* EM */
Dance 0:de885a6da962 218 {0, 0}, /* SUB */
Dance 0:de885a6da962 219 {0, 0}, /* ESC */
Dance 0:de885a6da962 220 {0, 0}, /* FS */
Dance 0:de885a6da962 221 {0, 0}, /* GS */
Dance 0:de885a6da962 222 {0, 0}, /* RS */
Dance 0:de885a6da962 223 {0, 0}, /* US */
Dance 0:de885a6da962 224 {0x2c, 0}, /* */
Dance 0:de885a6da962 225 {0x1e, KEY_SHIFT}, /* ! */
Dance 0:de885a6da962 226 {0x1f, KEY_SHIFT}, /* " */
Dance 0:de885a6da962 227 {0x32, 0}, /* # */
Dance 0:de885a6da962 228 {0x21, KEY_SHIFT}, /* $ */
Dance 0:de885a6da962 229 {0x22, KEY_SHIFT}, /* % */
Dance 0:de885a6da962 230 {0x24, KEY_SHIFT}, /* & */
Dance 0:de885a6da962 231 {0x34, 0}, /* ' */
Dance 0:de885a6da962 232 {0x26, KEY_SHIFT}, /* ( */
Dance 0:de885a6da962 233 {0x27, KEY_SHIFT}, /* ) */
Dance 0:de885a6da962 234 {0x25, KEY_SHIFT}, /* * */
Dance 0:de885a6da962 235 {0x2e, KEY_SHIFT}, /* + */
Dance 0:de885a6da962 236 {0x36, 0}, /* , */
Dance 0:de885a6da962 237 {0x2d, 0}, /* - */
Dance 0:de885a6da962 238 {0x37, 0}, /* . */
Dance 0:de885a6da962 239 {0x38, 0}, /* / */
Dance 0:de885a6da962 240 {0x27, 0}, /* 0 */
Dance 0:de885a6da962 241 {0x1e, 0}, /* 1 */
Dance 0:de885a6da962 242 {0x1f, 0}, /* 2 */
Dance 0:de885a6da962 243 {0x20, 0}, /* 3 */
Dance 0:de885a6da962 244 {0x21, 0}, /* 4 */
Dance 0:de885a6da962 245 {0x22, 0}, /* 5 */
Dance 0:de885a6da962 246 {0x23, 0}, /* 6 */
Dance 0:de885a6da962 247 {0x24, 0}, /* 7 */
Dance 0:de885a6da962 248 {0x25, 0}, /* 8 */
Dance 0:de885a6da962 249 {0x26, 0}, /* 9 */
Dance 0:de885a6da962 250 {0x33, KEY_SHIFT}, /* : */
Dance 0:de885a6da962 251 {0x33, 0}, /* ; */
Dance 0:de885a6da962 252 {0x36, KEY_SHIFT}, /* < */
Dance 0:de885a6da962 253 {0x2e, 0}, /* = */
Dance 0:de885a6da962 254 {0x37, KEY_SHIFT}, /* > */
Dance 0:de885a6da962 255 {0x38, KEY_SHIFT}, /* ? */
Dance 0:de885a6da962 256 {0x34, KEY_SHIFT}, /* @ */
Dance 0:de885a6da962 257 {0x04, KEY_SHIFT}, /* A */
Dance 0:de885a6da962 258 {0x05, KEY_SHIFT}, /* B */
Dance 0:de885a6da962 259 {0x06, KEY_SHIFT}, /* C */
Dance 0:de885a6da962 260 {0x07, KEY_SHIFT}, /* D */
Dance 0:de885a6da962 261 {0x08, KEY_SHIFT}, /* E */
Dance 0:de885a6da962 262 {0x09, KEY_SHIFT}, /* F */
Dance 0:de885a6da962 263 {0x0a, KEY_SHIFT}, /* G */
Dance 0:de885a6da962 264 {0x0b, KEY_SHIFT}, /* H */
Dance 0:de885a6da962 265 {0x0c, KEY_SHIFT}, /* I */
Dance 0:de885a6da962 266 {0x0d, KEY_SHIFT}, /* J */
Dance 0:de885a6da962 267 {0x0e, KEY_SHIFT}, /* K */
Dance 0:de885a6da962 268 {0x0f, KEY_SHIFT}, /* L */
Dance 0:de885a6da962 269 {0x10, KEY_SHIFT}, /* M */
Dance 0:de885a6da962 270 {0x11, KEY_SHIFT}, /* N */
Dance 0:de885a6da962 271 {0x12, KEY_SHIFT}, /* O */
Dance 0:de885a6da962 272 {0x13, KEY_SHIFT}, /* P */
Dance 0:de885a6da962 273 {0x14, KEY_SHIFT}, /* Q */
Dance 0:de885a6da962 274 {0x15, KEY_SHIFT}, /* R */
Dance 0:de885a6da962 275 {0x16, KEY_SHIFT}, /* S */
Dance 0:de885a6da962 276 {0x17, KEY_SHIFT}, /* T */
Dance 0:de885a6da962 277 {0x18, KEY_SHIFT}, /* U */
Dance 0:de885a6da962 278 {0x19, KEY_SHIFT}, /* V */
Dance 0:de885a6da962 279 {0x1a, KEY_SHIFT}, /* W */
Dance 0:de885a6da962 280 {0x1b, KEY_SHIFT}, /* X */
Dance 0:de885a6da962 281 {0x1c, KEY_SHIFT}, /* Y */
Dance 0:de885a6da962 282 {0x1d, KEY_SHIFT}, /* Z */
Dance 0:de885a6da962 283 {0x2f, 0}, /* [ */
Dance 0:de885a6da962 284 {0x64, 0}, /* \ */
Dance 0:de885a6da962 285 {0x30, 0}, /* ] */
Dance 0:de885a6da962 286 {0x23, KEY_SHIFT}, /* ^ */
Dance 0:de885a6da962 287 {0x2d, KEY_SHIFT}, /* _ */
Dance 0:de885a6da962 288 {0x35, 0}, /* ` */
Dance 0:de885a6da962 289 {0x04, 0}, /* a */
Dance 0:de885a6da962 290 {0x05, 0}, /* b */
Dance 0:de885a6da962 291 {0x06, 0}, /* c */
Dance 0:de885a6da962 292 {0x07, 0}, /* d */
Dance 0:de885a6da962 293 {0x08, 0}, /* e */
Dance 0:de885a6da962 294 {0x09, 0}, /* f */
Dance 0:de885a6da962 295 {0x0a, 0}, /* g */
Dance 0:de885a6da962 296 {0x0b, 0}, /* h */
Dance 0:de885a6da962 297 {0x0c, 0}, /* i */
Dance 0:de885a6da962 298 {0x0d, 0}, /* j */
Dance 0:de885a6da962 299 {0x0e, 0}, /* k */
Dance 0:de885a6da962 300 {0x0f, 0}, /* l */
Dance 0:de885a6da962 301 {0x10, 0}, /* m */
Dance 0:de885a6da962 302 {0x11, 0}, /* n */
Dance 0:de885a6da962 303 {0x12, 0}, /* o */
Dance 0:de885a6da962 304 {0x13, 0}, /* p */
Dance 0:de885a6da962 305 {0x14, 0}, /* q */
Dance 0:de885a6da962 306 {0x15, 0}, /* r */
Dance 0:de885a6da962 307 {0x16, 0}, /* s */
Dance 0:de885a6da962 308 {0x17, 0}, /* t */
Dance 0:de885a6da962 309 {0x18, 0}, /* u */
Dance 0:de885a6da962 310 {0x19, 0}, /* v */
Dance 0:de885a6da962 311 {0x1a, 0}, /* w */
Dance 0:de885a6da962 312 {0x1b, 0}, /* x */
Dance 0:de885a6da962 313 {0x1c, 0}, /* y */
Dance 0:de885a6da962 314 {0x1d, 0}, /* z */
Dance 0:de885a6da962 315 {0x2f, KEY_SHIFT}, /* { */
Dance 0:de885a6da962 316 {0x64, KEY_SHIFT}, /* | */
Dance 0:de885a6da962 317 {0x30, KEY_SHIFT}, /* } */
Dance 0:de885a6da962 318 {0x32, KEY_SHIFT}, /* ~ */
Dance 0:de885a6da962 319 {0,0}, /* DEL */
Dance 0:de885a6da962 320
Dance 0:de885a6da962 321 {0x3a, 0}, /* F1 */
Dance 0:de885a6da962 322 {0x3b, 0}, /* F2 */
Dance 0:de885a6da962 323 {0x3c, 0}, /* F3 */
Dance 0:de885a6da962 324 {0x3d, 0}, /* F4 */
Dance 0:de885a6da962 325 {0x3e, 0}, /* F5 */
Dance 0:de885a6da962 326 {0x3f, 0}, /* F6 */
Dance 0:de885a6da962 327 {0x40, 0}, /* F7 */
Dance 0:de885a6da962 328 {0x41, 0}, /* F8 */
Dance 0:de885a6da962 329 {0x42, 0}, /* F9 */
Dance 0:de885a6da962 330 {0x43, 0}, /* F10 */
Dance 0:de885a6da962 331 {0x44, 0}, /* F11 */
Dance 0:de885a6da962 332 {0x45, 0}, /* F12 */
Dance 0:de885a6da962 333
Dance 0:de885a6da962 334 {0x46, 0}, /* PRINT_SCREEN */
Dance 0:de885a6da962 335 {0x47, 0}, /* SCROLL_LOCK */
Dance 0:de885a6da962 336 {0x39, 0}, /* CAPS_LOCK */
Dance 0:de885a6da962 337 {0x53, 0}, /* NUM_LOCK */
Dance 0:de885a6da962 338 {0x49, 0}, /* INSERT */
Dance 0:de885a6da962 339 {0x4a, 0}, /* HOME */
Dance 0:de885a6da962 340 {0x4b, 0}, /* PAGE_UP */
Dance 0:de885a6da962 341 {0x4e, 0}, /* PAGE_DOWN */
Dance 0:de885a6da962 342
Dance 0:de885a6da962 343 {0x4f, 0}, /* RIGHT_ARROW */
Dance 0:de885a6da962 344 {0x50, 0}, /* LEFT_ARROW */
Dance 0:de885a6da962 345 {0x51, 0}, /* DOWN_ARROW */
Dance 0:de885a6da962 346 {0x52, 0}, /* UP_ARROW */
Dance 0:de885a6da962 347 };
Dance 0:de885a6da962 348 #endif
Dance 0:de885a6da962 349
Dance 0:de885a6da962 350
Dance 0:de885a6da962 351 uint8_t * USBMouseKeyboard::reportDesc() {
Dance 0:de885a6da962 352 if (mouse_type == REL_MOUSE) {
Dance 0:de885a6da962 353 static uint8_t reportDescriptor[] = {
Dance 0:de885a6da962 354 // Keyboard
Dance 0:de885a6da962 355 USAGE_PAGE(1), 0x01,
Dance 0:de885a6da962 356 USAGE(1), 0x06,
Dance 0:de885a6da962 357 COLLECTION(1), 0x01,
Dance 0:de885a6da962 358 REPORT_ID(1), REPORT_ID_KEYBOARD,
Dance 0:de885a6da962 359 USAGE_PAGE(1), 0x07,
Dance 0:de885a6da962 360 USAGE_MINIMUM(1), 0xE0,
Dance 0:de885a6da962 361 USAGE_MAXIMUM(1), 0xE7,
Dance 0:de885a6da962 362 LOGICAL_MINIMUM(1), 0x00,
Dance 0:de885a6da962 363 LOGICAL_MAXIMUM(1), 0x01,
Dance 0:de885a6da962 364 REPORT_SIZE(1), 0x01,
Dance 0:de885a6da962 365 REPORT_COUNT(1), 0x08,
Dance 0:de885a6da962 366 INPUT(1), 0x02,
Dance 0:de885a6da962 367 REPORT_COUNT(1), 0x01,
Dance 0:de885a6da962 368 REPORT_SIZE(1), 0x08,
Dance 0:de885a6da962 369 INPUT(1), 0x01,
Dance 0:de885a6da962 370 REPORT_COUNT(1), 0x05,
Dance 0:de885a6da962 371 REPORT_SIZE(1), 0x01,
Dance 0:de885a6da962 372 USAGE_PAGE(1), 0x08,
Dance 0:de885a6da962 373 USAGE_MINIMUM(1), 0x01,
Dance 0:de885a6da962 374 USAGE_MAXIMUM(1), 0x05,
Dance 0:de885a6da962 375 OUTPUT(1), 0x02,
Dance 0:de885a6da962 376 REPORT_COUNT(1), 0x01,
Dance 0:de885a6da962 377 REPORT_SIZE(1), 0x03,
Dance 0:de885a6da962 378 OUTPUT(1), 0x01,
Dance 0:de885a6da962 379 REPORT_COUNT(1), 0x06,
Dance 0:de885a6da962 380 REPORT_SIZE(1), 0x08,
Dance 0:de885a6da962 381 LOGICAL_MINIMUM(1), 0x00,
Dance 0:de885a6da962 382 LOGICAL_MAXIMUM(2), 0xff, 0x00,
Dance 0:de885a6da962 383 USAGE_PAGE(1), 0x07,
Dance 0:de885a6da962 384 USAGE_MINIMUM(1), 0x00,
Dance 0:de885a6da962 385 USAGE_MAXIMUM(2), 0xff, 0x00,
Dance 0:de885a6da962 386 INPUT(1), 0x00,
Dance 0:de885a6da962 387 END_COLLECTION(0),
Dance 0:de885a6da962 388
Dance 0:de885a6da962 389 // Mouse
Dance 0:de885a6da962 390 USAGE_PAGE(1), 0x01, // Generic Desktop
Dance 0:de885a6da962 391 USAGE(1), 0x02, // Mouse
Dance 0:de885a6da962 392 COLLECTION(1), 0x01, // Application
Dance 0:de885a6da962 393 USAGE(1), 0x01, // Pointer
Dance 0:de885a6da962 394 COLLECTION(1), 0x00, // Physical
Dance 0:de885a6da962 395 REPORT_ID(1), REPORT_ID_MOUSE,
Dance 0:de885a6da962 396 REPORT_COUNT(1), 0x03,
Dance 0:de885a6da962 397 REPORT_SIZE(1), 0x01,
Dance 0:de885a6da962 398 USAGE_PAGE(1), 0x09, // Buttons
Dance 0:de885a6da962 399 USAGE_MINIMUM(1), 0x1,
Dance 0:de885a6da962 400 USAGE_MAXIMUM(1), 0x3,
Dance 0:de885a6da962 401 LOGICAL_MINIMUM(1), 0x00,
Dance 0:de885a6da962 402 LOGICAL_MAXIMUM(1), 0x01,
Dance 0:de885a6da962 403 INPUT(1), 0x02,
Dance 0:de885a6da962 404 REPORT_COUNT(1), 0x01,
Dance 0:de885a6da962 405 REPORT_SIZE(1), 0x05,
Dance 0:de885a6da962 406 INPUT(1), 0x01,
Dance 0:de885a6da962 407 REPORT_COUNT(1), 0x03,
Dance 0:de885a6da962 408 REPORT_SIZE(1), 0x08,
Dance 0:de885a6da962 409 USAGE_PAGE(1), 0x01,
Dance 0:de885a6da962 410 USAGE(1), 0x30, // X
Dance 0:de885a6da962 411 USAGE(1), 0x31, // Y
Dance 0:de885a6da962 412 USAGE(1), 0x38, // scroll
Dance 0:de885a6da962 413 LOGICAL_MINIMUM(1), 0x81,
Dance 0:de885a6da962 414 LOGICAL_MAXIMUM(1), 0x7f,
Dance 0:de885a6da962 415 INPUT(1), 0x06,
Dance 0:de885a6da962 416 END_COLLECTION(0),
Dance 0:de885a6da962 417 END_COLLECTION(0),
Dance 0:de885a6da962 418
Dance 0:de885a6da962 419
Dance 0:de885a6da962 420 // Media Control
Dance 0:de885a6da962 421 USAGE_PAGE(1), 0x0C,
Dance 0:de885a6da962 422 USAGE(1), 0x01,
Dance 0:de885a6da962 423 COLLECTION(1), 0x01,
Dance 0:de885a6da962 424 REPORT_ID(1), REPORT_ID_VOLUME,
Dance 0:de885a6da962 425 USAGE_PAGE(1), 0x0C,
Dance 0:de885a6da962 426 LOGICAL_MINIMUM(1), 0x00,
Dance 0:de885a6da962 427 LOGICAL_MAXIMUM(1), 0x01,
Dance 0:de885a6da962 428 REPORT_SIZE(1), 0x01,
Dance 0:de885a6da962 429 REPORT_COUNT(1), 0x07,
Dance 0:de885a6da962 430 USAGE(1), 0xB5, // Next Track
Dance 0:de885a6da962 431 USAGE(1), 0xB6, // Previous Track
Dance 0:de885a6da962 432 USAGE(1), 0xB7, // Stop
Dance 0:de885a6da962 433 USAGE(1), 0xCD, // Play / Pause
Dance 0:de885a6da962 434 USAGE(1), 0xE2, // Mute
Dance 0:de885a6da962 435 USAGE(1), 0xE9, // Volume Up
Dance 0:de885a6da962 436 USAGE(1), 0xEA, // Volume Down
Dance 0:de885a6da962 437 INPUT(1), 0x02, // Input (Data, Variable, Absolute)
Dance 0:de885a6da962 438 REPORT_COUNT(1), 0x01,
Dance 0:de885a6da962 439 INPUT(1), 0x01,
Dance 0:de885a6da962 440 END_COLLECTION(0),
Dance 0:de885a6da962 441 };
Dance 0:de885a6da962 442 reportLength = sizeof(reportDescriptor);
Dance 0:de885a6da962 443 return reportDescriptor;
Dance 0:de885a6da962 444 } else if (mouse_type == ABS_MOUSE) {
Dance 0:de885a6da962 445 static uint8_t reportDescriptor[] = {
Dance 0:de885a6da962 446
Dance 0:de885a6da962 447 // Keyboard
Dance 0:de885a6da962 448 USAGE_PAGE(1), 0x01,
Dance 0:de885a6da962 449 USAGE(1), 0x06,
Dance 0:de885a6da962 450 COLLECTION(1), 0x01,
Dance 0:de885a6da962 451 REPORT_ID(1), REPORT_ID_KEYBOARD,
Dance 0:de885a6da962 452 USAGE_PAGE(1), 0x07,
Dance 0:de885a6da962 453 USAGE_MINIMUM(1), 0xE0,
Dance 0:de885a6da962 454 USAGE_MAXIMUM(1), 0xE7,
Dance 0:de885a6da962 455 LOGICAL_MINIMUM(1), 0x00,
Dance 0:de885a6da962 456 LOGICAL_MAXIMUM(1), 0x01,
Dance 0:de885a6da962 457 REPORT_SIZE(1), 0x01,
Dance 0:de885a6da962 458 REPORT_COUNT(1), 0x08,
Dance 0:de885a6da962 459 INPUT(1), 0x02,
Dance 0:de885a6da962 460 REPORT_COUNT(1), 0x01,
Dance 0:de885a6da962 461 REPORT_SIZE(1), 0x08,
Dance 0:de885a6da962 462 INPUT(1), 0x01,
Dance 0:de885a6da962 463 REPORT_COUNT(1), 0x05,
Dance 0:de885a6da962 464 REPORT_SIZE(1), 0x01,
Dance 0:de885a6da962 465 USAGE_PAGE(1), 0x08,
Dance 0:de885a6da962 466 USAGE_MINIMUM(1), 0x01,
Dance 0:de885a6da962 467 USAGE_MAXIMUM(1), 0x05,
Dance 0:de885a6da962 468 OUTPUT(1), 0x02,
Dance 0:de885a6da962 469 REPORT_COUNT(1), 0x01,
Dance 0:de885a6da962 470 REPORT_SIZE(1), 0x03,
Dance 0:de885a6da962 471 OUTPUT(1), 0x01,
Dance 0:de885a6da962 472 REPORT_COUNT(1), 0x06,
Dance 0:de885a6da962 473 REPORT_SIZE(1), 0x08,
Dance 0:de885a6da962 474 LOGICAL_MINIMUM(1), 0x00,
Dance 0:de885a6da962 475 LOGICAL_MAXIMUM(2), 0xff, 0x00,
Dance 0:de885a6da962 476 USAGE_PAGE(1), 0x07,
Dance 0:de885a6da962 477 USAGE_MINIMUM(1), 0x00,
Dance 0:de885a6da962 478 USAGE_MAXIMUM(2), 0xff, 0x00,
Dance 0:de885a6da962 479 INPUT(1), 0x00,
Dance 0:de885a6da962 480 END_COLLECTION(0),
Dance 0:de885a6da962 481
Dance 0:de885a6da962 482 // Mouse
Dance 0:de885a6da962 483 USAGE_PAGE(1), 0x01, // Generic Desktop
Dance 0:de885a6da962 484 USAGE(1), 0x02, // Mouse
Dance 0:de885a6da962 485 COLLECTION(1), 0x01, // Application
Dance 0:de885a6da962 486 USAGE(1), 0x01, // Pointer
Dance 0:de885a6da962 487 COLLECTION(1), 0x00, // Physical
Dance 0:de885a6da962 488 REPORT_ID(1), REPORT_ID_MOUSE,
Dance 0:de885a6da962 489
Dance 0:de885a6da962 490 USAGE_PAGE(1), 0x01, // Generic Desktop
Dance 0:de885a6da962 491 USAGE(1), 0x30, // X
Dance 0:de885a6da962 492 USAGE(1), 0x31, // Y
Dance 0:de885a6da962 493 LOGICAL_MINIMUM(1), 0x00, // 0
Dance 0:de885a6da962 494 LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767
Dance 0:de885a6da962 495 REPORT_SIZE(1), 0x10,
Dance 0:de885a6da962 496 REPORT_COUNT(1), 0x02,
Dance 0:de885a6da962 497 INPUT(1), 0x02, // Data, Variable, Absolute
Dance 0:de885a6da962 498
Dance 0:de885a6da962 499 USAGE_PAGE(1), 0x01, // Generic Desktop
Dance 0:de885a6da962 500 USAGE(1), 0x38, // scroll
Dance 0:de885a6da962 501 LOGICAL_MINIMUM(1), 0x81, // -127
Dance 0:de885a6da962 502 LOGICAL_MAXIMUM(1), 0x7f, // 127
Dance 0:de885a6da962 503 REPORT_SIZE(1), 0x08,
Dance 0:de885a6da962 504 REPORT_COUNT(1), 0x01,
Dance 0:de885a6da962 505 INPUT(1), 0x06, // Data, Variable, Relative
Dance 0:de885a6da962 506
Dance 0:de885a6da962 507 USAGE_PAGE(1), 0x09, // Buttons
Dance 0:de885a6da962 508 USAGE_MINIMUM(1), 0x01,
Dance 0:de885a6da962 509 USAGE_MAXIMUM(1), 0x03,
Dance 0:de885a6da962 510 LOGICAL_MINIMUM(1), 0x00, // 0
Dance 0:de885a6da962 511 LOGICAL_MAXIMUM(1), 0x01, // 1
Dance 0:de885a6da962 512 REPORT_COUNT(1), 0x03,
Dance 0:de885a6da962 513 REPORT_SIZE(1), 0x01,
Dance 0:de885a6da962 514 INPUT(1), 0x02, // Data, Variable, Absolute
Dance 0:de885a6da962 515 REPORT_COUNT(1), 0x01,
Dance 0:de885a6da962 516 REPORT_SIZE(1), 0x05,
Dance 0:de885a6da962 517 INPUT(1), 0x01, // Constant
Dance 0:de885a6da962 518
Dance 0:de885a6da962 519 END_COLLECTION(0),
Dance 0:de885a6da962 520 END_COLLECTION(0),
Dance 0:de885a6da962 521
Dance 0:de885a6da962 522 // Media Control
Dance 0:de885a6da962 523 USAGE_PAGE(1), 0x0C,
Dance 0:de885a6da962 524 USAGE(1), 0x01,
Dance 0:de885a6da962 525 COLLECTION(1), 0x01,
Dance 0:de885a6da962 526 REPORT_ID(1), REPORT_ID_VOLUME,
Dance 0:de885a6da962 527 USAGE_PAGE(1), 0x0C,
Dance 0:de885a6da962 528 LOGICAL_MINIMUM(1), 0x00,
Dance 0:de885a6da962 529 LOGICAL_MAXIMUM(1), 0x01,
Dance 0:de885a6da962 530 REPORT_SIZE(1), 0x01,
Dance 0:de885a6da962 531 REPORT_COUNT(1), 0x07,
Dance 0:de885a6da962 532 USAGE(1), 0xB5, // Next Track
Dance 0:de885a6da962 533 USAGE(1), 0xB6, // Previous Track
Dance 0:de885a6da962 534 USAGE(1), 0xB7, // Stop
Dance 0:de885a6da962 535 USAGE(1), 0xCD, // Play / Pause
Dance 0:de885a6da962 536 USAGE(1), 0xE2, // Mute
Dance 0:de885a6da962 537 USAGE(1), 0xE9, // Volume Up
Dance 0:de885a6da962 538 USAGE(1), 0xEA, // Volume Down
Dance 0:de885a6da962 539 INPUT(1), 0x02, // Input (Data, Variable, Absolute)
Dance 0:de885a6da962 540 REPORT_COUNT(1), 0x01,
Dance 0:de885a6da962 541 INPUT(1), 0x01,
Dance 0:de885a6da962 542 END_COLLECTION(0),
Dance 0:de885a6da962 543 };
Dance 0:de885a6da962 544 reportLength = sizeof(reportDescriptor);
Dance 0:de885a6da962 545 return reportDescriptor;
Dance 0:de885a6da962 546 }
Dance 0:de885a6da962 547
Dance 0:de885a6da962 548 return NULL;
Dance 0:de885a6da962 549 }
Dance 0:de885a6da962 550
Dance 0:de885a6da962 551 bool USBMouseKeyboard::EP1_OUT_callback() {
Dance 0:de885a6da962 552 uint32_t bytesRead = 0;
Dance 0:de885a6da962 553 uint8_t led[65];
Dance 0:de885a6da962 554 USBDevice::readEP(EPINT_OUT, led, &bytesRead, MAX_HID_REPORT_SIZE);
Dance 0:de885a6da962 555
Dance 0:de885a6da962 556 // we take led[1] because led[0] is the report ID
Dance 0:de885a6da962 557 lock_status = led[1] & 0x07;
Dance 0:de885a6da962 558
Dance 0:de885a6da962 559 // We activate the endpoint to be able to recceive data
Dance 0:de885a6da962 560 if (!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
Dance 0:de885a6da962 561 return false;
Dance 0:de885a6da962 562 return true;
Dance 0:de885a6da962 563 }
Dance 0:de885a6da962 564
Dance 0:de885a6da962 565 uint8_t USBMouseKeyboard::lockStatus() {
Dance 0:de885a6da962 566 return lock_status;
Dance 0:de885a6da962 567 }
Dance 0:de885a6da962 568
Dance 0:de885a6da962 569 bool USBMouseKeyboard::update(int16_t x, int16_t y, uint8_t button, int8_t z) {
Dance 0:de885a6da962 570 switch (mouse_type) {
Dance 0:de885a6da962 571 case REL_MOUSE:
Dance 0:de885a6da962 572 while (x > 127) {
Dance 0:de885a6da962 573 if (!mouseSend(127, 0, button, z)) return false;
Dance 0:de885a6da962 574 x = x - 127;
Dance 0:de885a6da962 575 }
Dance 0:de885a6da962 576 while (x < -128) {
Dance 0:de885a6da962 577 if (!mouseSend(-128, 0, button, z)) return false;
Dance 0:de885a6da962 578 x = x + 128;
Dance 0:de885a6da962 579 }
Dance 0:de885a6da962 580 while (y > 127) {
Dance 0:de885a6da962 581 if (!mouseSend(0, 127, button, z)) return false;
Dance 0:de885a6da962 582 y = y - 127;
Dance 0:de885a6da962 583 }
Dance 0:de885a6da962 584 while (y < -128) {
Dance 0:de885a6da962 585 if (!mouseSend(0, -128, button, z)) return false;
Dance 0:de885a6da962 586 y = y + 128;
Dance 0:de885a6da962 587 }
Dance 0:de885a6da962 588 return mouseSend(x, y, button, z);
Dance 0:de885a6da962 589 case ABS_MOUSE:
Dance 0:de885a6da962 590 HID_REPORT report;
Dance 0:de885a6da962 591
Dance 0:de885a6da962 592 report.data[0] = REPORT_ID_MOUSE;
Dance 0:de885a6da962 593 report.data[1] = x & 0xff;
Dance 0:de885a6da962 594 report.data[2] = (x >> 8) & 0xff;
Dance 0:de885a6da962 595 report.data[3] = y & 0xff;
Dance 0:de885a6da962 596 report.data[4] = (y >> 8) & 0xff;
Dance 0:de885a6da962 597 report.data[5] = -z;
Dance 0:de885a6da962 598 report.data[6] = button & 0x07;
Dance 0:de885a6da962 599
Dance 0:de885a6da962 600 report.length = 7;
Dance 0:de885a6da962 601
Dance 0:de885a6da962 602 return send(&report);
Dance 0:de885a6da962 603 default:
Dance 0:de885a6da962 604 return false;
Dance 0:de885a6da962 605 }
Dance 0:de885a6da962 606 }
Dance 0:de885a6da962 607
Dance 0:de885a6da962 608 bool USBMouseKeyboard::mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z) {
Dance 0:de885a6da962 609 HID_REPORT report;
Dance 0:de885a6da962 610 report.data[0] = REPORT_ID_MOUSE;
Dance 0:de885a6da962 611 report.data[1] = buttons & 0x07;
Dance 0:de885a6da962 612 report.data[2] = x;
Dance 0:de885a6da962 613 report.data[3] = y;
Dance 0:de885a6da962 614 report.data[4] = -z; // >0 to scroll down, <0 to scroll up
Dance 0:de885a6da962 615
Dance 0:de885a6da962 616 report.length = 5;
Dance 0:de885a6da962 617
Dance 0:de885a6da962 618 return send(&report);
Dance 0:de885a6da962 619 }
Dance 0:de885a6da962 620
Dance 0:de885a6da962 621 bool USBMouseKeyboard::move(int16_t x, int16_t y) {
Dance 0:de885a6da962 622 return update(x, y, button, 0);
Dance 0:de885a6da962 623 }
Dance 0:de885a6da962 624
Dance 0:de885a6da962 625 bool USBMouseKeyboard::scroll(int8_t z) {
Dance 0:de885a6da962 626 return update(0, 0, button, z);
Dance 0:de885a6da962 627 }
Dance 0:de885a6da962 628
Dance 0:de885a6da962 629 bool USBMouseKeyboard::doubleClick() {
Dance 0:de885a6da962 630 if (!click(MOUSE_LEFT))
Dance 0:de885a6da962 631 return false;
Dance 0:de885a6da962 632 wait(0.1);
Dance 0:de885a6da962 633 return click(MOUSE_LEFT);
Dance 0:de885a6da962 634 }
Dance 0:de885a6da962 635
Dance 0:de885a6da962 636 bool USBMouseKeyboard::click(uint8_t button) {
Dance 0:de885a6da962 637 if (!update(0, 0, button, 0))
Dance 0:de885a6da962 638 return false;
Dance 0:de885a6da962 639 wait(0.01);
Dance 0:de885a6da962 640 return update(0, 0, 0, 0);
Dance 0:de885a6da962 641 }
Dance 0:de885a6da962 642
Dance 0:de885a6da962 643 bool USBMouseKeyboard::press(uint8_t button_) {
Dance 0:de885a6da962 644 button = button_ & 0x07;
Dance 0:de885a6da962 645 return update(0, 0, button, 0);
Dance 0:de885a6da962 646 }
Dance 0:de885a6da962 647
Dance 0:de885a6da962 648 bool USBMouseKeyboard::release(uint8_t button_) {
Dance 0:de885a6da962 649 button = (button & (~button_)) & 0x07;
Dance 0:de885a6da962 650 return update(0, 0, button, 0);
Dance 0:de885a6da962 651 }
Dance 0:de885a6da962 652
Dance 0:de885a6da962 653 int USBMouseKeyboard::_putc(int c) {
Dance 0:de885a6da962 654 return keyCode(c, keymap[c].modifier);
Dance 0:de885a6da962 655 }
Dance 0:de885a6da962 656
Dance 0:de885a6da962 657 bool USBMouseKeyboard::keyCode(uint8_t key, uint8_t modifier) {
Dance 0:de885a6da962 658 // Send a simulated keyboard keypress. Returns true if successful.
Dance 0:de885a6da962 659
Dance 0:de885a6da962 660 HID_REPORT report;
Dance 0:de885a6da962 661
Dance 0:de885a6da962 662 report.data[0] = REPORT_ID_KEYBOARD;
Dance 0:de885a6da962 663 report.data[1] = modifier;
Dance 0:de885a6da962 664 report.data[2] = 0;
Dance 0:de885a6da962 665 report.data[3] = keymap[key].usage;
Dance 0:de885a6da962 666 report.data[4] = 0;
Dance 0:de885a6da962 667 report.data[5] = 0;
Dance 0:de885a6da962 668 report.data[6] = 0;
Dance 0:de885a6da962 669 report.data[7] = 0;
Dance 0:de885a6da962 670 report.data[8] = 0;
Dance 0:de885a6da962 671
Dance 0:de885a6da962 672 report.length = 9;
Dance 0:de885a6da962 673
Dance 0:de885a6da962 674 if (!send(&report)) {
Dance 0:de885a6da962 675 return false;
Dance 0:de885a6da962 676 }
Dance 0:de885a6da962 677
Dance 0:de885a6da962 678 report.data[1] = 0;
Dance 0:de885a6da962 679 report.data[3] = 0;
Dance 0:de885a6da962 680
Dance 0:de885a6da962 681 if (!send(&report)) {
Dance 0:de885a6da962 682 return false;
Dance 0:de885a6da962 683 }
Dance 0:de885a6da962 684
Dance 0:de885a6da962 685 return true;
Dance 0:de885a6da962 686
Dance 0:de885a6da962 687 }
Dance 0:de885a6da962 688
Dance 0:de885a6da962 689
Dance 0:de885a6da962 690 bool USBMouseKeyboard::mediaControl(MEDIA_KEY key) {
Dance 0:de885a6da962 691 HID_REPORT report;
Dance 0:de885a6da962 692
Dance 0:de885a6da962 693 report.data[0] = REPORT_ID_VOLUME;
Dance 0:de885a6da962 694 report.data[1] = (1 << key) & 0x7f;
Dance 0:de885a6da962 695
Dance 0:de885a6da962 696 report.length = 2;
Dance 0:de885a6da962 697
Dance 0:de885a6da962 698 send(&report);
Dance 0:de885a6da962 699
Dance 0:de885a6da962 700 report.data[0] = REPORT_ID_VOLUME;
Dance 0:de885a6da962 701 report.data[1] = 0;
Dance 0:de885a6da962 702
Dance 0:de885a6da962 703 report.length = 2;
Dance 0:de885a6da962 704
Dance 0:de885a6da962 705 return send(&report);
Dance 0:de885a6da962 706 }