PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

604 lines
26KB

  1. // Simple test of USB Host Mouse/Keyboard
  2. //
  3. // This example is in the public domain
  4. #include "USBHost_t36.h"
  5. int mousex, mousey;
  6. USBHost myusb;
  7. USBHub hub1(myusb);
  8. USBHub hub2(myusb);
  9. KeyboardController keyboard1(myusb);
  10. KeyboardController keyboard2(myusb);
  11. USBHIDParser hid1(myusb);
  12. USBHIDParser hid2(myusb);
  13. USBHIDParser hid3(myusb);
  14. USBHIDParser hid4(myusb);
  15. USBHIDParser hid5(myusb);
  16. DigitizerController digi1(myusb);
  17. JoystickController joystick1(myusb);
  18. //BluetoothController bluet(myusb, true, "0000"); // Version does pairing to device
  19. BluetoothController bluet(myusb); // version assumes it already was paired
  20. int user_axis[64];
  21. uint8_t digi_axis[64];
  22. uint32_t buttons_prev = 0;
  23. //RawHIDController rawhid1(myusb);
  24. RawHIDController rawhid2(myusb, 0xff000080);
  25. USBDriver *drivers[] = {&hub1, &hub2,&keyboard1, &keyboard2, &joystick1, &bluet, &hid1, &hid2, &hid3, &hid4, &hid5};
  26. #define CNT_DEVICES (sizeof(drivers)/sizeof(drivers[0]))
  27. const char * driver_names[CNT_DEVICES] = {"Hub1","Hub2", "KB1", "KB2", "JOY1D", "Bluet", "HID1" , "HID2", "HID3", "HID4", "HID5"};
  28. bool driver_active[CNT_DEVICES] = {false, false, false, false};
  29. // Lets also look at HID Input devices
  30. USBHIDInput *hiddrivers[] = {&digi1, &joystick1, &rawhid2};
  31. #define CNT_HIDDEVICES (sizeof(hiddrivers)/sizeof(hiddrivers[0]))
  32. const char * hid_driver_names[CNT_DEVICES] = {"digi1", "Joystick1", "RawHid2"};
  33. bool hid_driver_active[CNT_DEVICES] = {false, false};
  34. bool show_changed_only = false;
  35. uint8_t joystick_left_trigger_value = 0;
  36. uint8_t joystick_right_trigger_value = 0;
  37. uint64_t joystick_full_notify_mask = (uint64_t) - 1;
  38. void setup()
  39. {
  40. Serial1.begin(2000000);
  41. while (!Serial) ; // wait for Arduino Serial Monitor
  42. Serial.println("\n\nUSB Host Testing");
  43. Serial.println(sizeof(USBHub), DEC);
  44. myusb.begin();
  45. keyboard1.attachPress(OnPress);
  46. keyboard2.attachPress(OnPress);
  47. keyboard1.attachExtrasPress(OnHIDExtrasPress);
  48. keyboard1.attachExtrasRelease(OnHIDExtrasRelease);
  49. keyboard2.attachExtrasPress(OnHIDExtrasPress);
  50. keyboard2.attachExtrasRelease(OnHIDExtrasRelease);
  51. // The below forceBootProtocol will force which ever
  52. // next keyboard that attaches to this device to be in boot protocol
  53. // Only try this if you run into keyboard with issues. If this is a combined
  54. // device like wireless mouse and keyboard this can cause mouse problems.
  55. //keyboard1.forceBootProtocol();
  56. //rawhid1.attachReceive(OnReceiveHidData);
  57. rawhid2.attachReceive(OnReceiveHidData);
  58. }
  59. void loop()
  60. {
  61. myusb.Task();
  62. if (Serial.available()) {
  63. int ch = Serial.read(); // get the first char.
  64. while (Serial.read() != -1) ;
  65. if ((ch == 'b') || (ch == 'B')) {
  66. Serial.println("Only notify on Basic Axis changes");
  67. joystick1.axisChangeNotifyMask(0x3ff);
  68. } else if ((ch == 'f') || (ch == 'F')) {
  69. Serial.println("Only notify on Full Axis changes");
  70. joystick1.axisChangeNotifyMask(joystick_full_notify_mask);
  71. } else {
  72. if (show_changed_only) {
  73. show_changed_only = false;
  74. Serial.println("\n*** Show All fields mode ***");
  75. } else {
  76. show_changed_only = true;
  77. Serial.println("\n*** Show only changed fields mode ***");
  78. }
  79. }
  80. }
  81. for (uint8_t i = 0; i < CNT_DEVICES; i++) {
  82. if (*drivers[i] != driver_active[i]) {
  83. if (driver_active[i]) {
  84. Serial.printf("*** Device %s - disconnected ***\n", driver_names[i]);
  85. driver_active[i] = false;
  86. } else {
  87. Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
  88. driver_active[i] = true;
  89. const uint8_t *psz = drivers[i]->manufacturer();
  90. if (psz && *psz) Serial.printf(" manufacturer: %s\n", psz);
  91. psz = drivers[i]->product();
  92. if (psz && *psz) Serial.printf(" product: %s\n", psz);
  93. psz = drivers[i]->serialNumber();
  94. if (psz && *psz) Serial.printf(" Serial: %s\n", psz);
  95. // Note: with some keyboards there is an issue that they don't output in boot protocol mode
  96. // and may not work. The above code can try to force the keyboard into boot mode, but there
  97. // are issues with doing this blindly with combo devices like wireless keyboard/mouse, which
  98. // may cause the mouse to not work. Note: the above id is in the builtin list of
  99. // vendor IDs that are already forced
  100. if (drivers[i] == &keyboard1) {
  101. if (keyboard1.idVendor() == 0x04D9) {
  102. Serial.println("Gigabyte vendor: force boot protocol");
  103. // Gigabyte keyboard
  104. keyboard1.forceBootProtocol();
  105. }
  106. }
  107. }
  108. }
  109. }
  110. for (uint8_t i = 0; i < CNT_HIDDEVICES; i++) {
  111. if (*hiddrivers[i] != hid_driver_active[i]) {
  112. if (hid_driver_active[i]) {
  113. Serial.printf("*** HID Device %s - disconnected ***\n", hid_driver_names[i]);
  114. hid_driver_active[i] = false;
  115. } else {
  116. Serial.printf("*** HID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
  117. hid_driver_active[i] = true;
  118. const uint8_t *psz = hiddrivers[i]->manufacturer();
  119. if (psz && *psz) Serial.printf(" manufacturer: %s\n", psz);
  120. psz = hiddrivers[i]->product();
  121. if (psz && *psz) Serial.printf(" product: %s\n", psz);
  122. psz = hiddrivers[i]->serialNumber();
  123. if (psz && *psz) Serial.printf(" Serial: %s\n", psz);
  124. }
  125. }
  126. }
  127. if (digi1.available()) {
  128. Serial.print("Mouse: buttons = ");
  129. Serial.print(digi1.getButtons());
  130. Serial.print(", mouseX = ");
  131. Serial.print(digi1.getMouseX());
  132. Serial.print(", mouseY = ");
  133. Serial.print(digi1.getMouseY());
  134. Serial.print(", wheel = ");
  135. Serial.print(digi1.getWheel());
  136. Serial.print(", wheelH = ");
  137. Serial.print(digi1.getWheelH());
  138. Serial.println();
  139. digi1.digitizerDataClear();
  140. for (uint8_t i = 0; i<10; i++) {
  141. Serial.printf(" %d:%d", i, digi1.getAxis(i));
  142. }
  143. Serial.println();
  144. }
  145. if (joystick1.available()) {
  146. uint64_t axis_mask = joystick1.axisMask();
  147. uint64_t axis_changed_mask = joystick1.axisChangedMask();
  148. Serial.print("Joystick: buttons = ");
  149. uint32_t buttons = joystick1.getButtons();
  150. Serial.print(buttons, HEX);
  151. //Serial.printf(" AMasks: %x %x:%x", axis_mask, (uint32_t)(user_axis_mask >> 32), (uint32_t)(user_axis_mask & 0xffffffff));
  152. //Serial.printf(" M: %lx %lx", axis_mask, joystick1.axisChangedMask());
  153. if (show_changed_only) {
  154. for (uint8_t i = 0; axis_changed_mask != 0; i++, axis_changed_mask >>= 1) {
  155. if (axis_changed_mask & 1) {
  156. Serial.printf(" %d:%d", i, joystick1.getAxis(i));
  157. }
  158. }
  159. } else {
  160. for (uint8_t i = 0; axis_mask != 0; i++, axis_mask >>= 1) {
  161. if (axis_mask & 1) {
  162. Serial.printf(" %d:%d", i, joystick1.getAxis(i));
  163. }
  164. }
  165. }
  166. uint8_t ltv;
  167. uint8_t rtv;
  168. switch (joystick1.joystickType()) {
  169. default:
  170. break;
  171. case JoystickController::PS4:
  172. ltv = joystick1.getAxis(3);
  173. rtv = joystick1.getAxis(4);
  174. if ((ltv != joystick_left_trigger_value) || (rtv != joystick_right_trigger_value)) {
  175. joystick_left_trigger_value = ltv;
  176. joystick_right_trigger_value = rtv;
  177. joystick1.setRumble(ltv, rtv);
  178. }
  179. break;
  180. case JoystickController::PS3:
  181. ltv = joystick1.getAxis(18);
  182. rtv = joystick1.getAxis(19);
  183. if ((ltv != joystick_left_trigger_value) || (rtv != joystick_right_trigger_value)) {
  184. joystick_left_trigger_value = ltv;
  185. joystick_right_trigger_value = rtv;
  186. joystick1.setRumble(ltv, rtv, 50);
  187. }
  188. break;
  189. case JoystickController::XBOXONE:
  190. case JoystickController::XBOX360:
  191. ltv = joystick1.getAxis(4);
  192. rtv = joystick1.getAxis(5);
  193. if ((ltv != joystick_left_trigger_value) || (rtv != joystick_right_trigger_value)) {
  194. joystick_left_trigger_value = ltv;
  195. joystick_right_trigger_value = rtv;
  196. joystick1.setRumble(ltv, rtv);
  197. Serial.printf(" Set Rumble %d %d", ltv, rtv);
  198. }
  199. break;
  200. }
  201. if (buttons != buttons_prev) {
  202. if (joystick1.joystickType() == JoystickController::PS3) {
  203. joystick1.setLEDs((buttons >> 12) & 0xf); // try to get to TRI/CIR/X/SQuare
  204. } else {
  205. uint8_t lr = (buttons & 1) ? 0xff : 0;
  206. uint8_t lg = (buttons & 2) ? 0xff : 0;
  207. uint8_t lb = (buttons & 4) ? 0xff : 0;
  208. joystick1.setLEDs(lr, lg, lb);
  209. }
  210. buttons_prev = buttons;
  211. }
  212. Serial.println();
  213. joystick1.joystickDataClear();
  214. }
  215. // See if we have some RAW data
  216. /* if (rawhid1) {
  217. int ch;
  218. uint8_t buffer[64];
  219. uint8_t count_chars = 0;
  220. memset(buffer, 0, sizeof(buffer));
  221. if (Serial.available()) {
  222. while (((ch = Serial.read()) != -1) && (count_chars < sizeof(buffer))) {
  223. buffer[count_chars++] = ch;
  224. }
  225. rawhid1.sendPacket(buffer);
  226. }
  227. }
  228. */
  229. }
  230. void OnPress(int key)
  231. {
  232. Serial.print("key '");
  233. switch (key) {
  234. case KEYD_UP : Serial.print("UP"); break;
  235. case KEYD_DOWN : Serial.print("DN"); break;
  236. case KEYD_LEFT : Serial.print("LEFT"); break;
  237. case KEYD_RIGHT : Serial.print("RIGHT"); break;
  238. case KEYD_INSERT : Serial.print("Ins"); break;
  239. case KEYD_DELETE : Serial.print("Del"); break;
  240. case KEYD_PAGE_UP : Serial.print("PUP"); break;
  241. case KEYD_PAGE_DOWN: Serial.print("PDN"); break;
  242. case KEYD_HOME : Serial.print("HOME"); break;
  243. case KEYD_END : Serial.print("END"); break;
  244. case KEYD_F1 : Serial.print("F1"); break;
  245. case KEYD_F2 : Serial.print("F2"); break;
  246. case KEYD_F3 : Serial.print("F3"); break;
  247. case KEYD_F4 : Serial.print("F4"); break;
  248. case KEYD_F5 : Serial.print("F5"); break;
  249. case KEYD_F6 : Serial.print("F6"); break;
  250. case KEYD_F7 : Serial.print("F7"); break;
  251. case KEYD_F8 : Serial.print("F8"); break;
  252. case KEYD_F9 : Serial.print("F9"); break;
  253. case KEYD_F10 : Serial.print("F10"); break;
  254. case KEYD_F11 : Serial.print("F11"); break;
  255. case KEYD_F12 : Serial.print("F12"); break;
  256. default: Serial.print((char)key); break;
  257. }
  258. Serial.print("' ");
  259. Serial.print(key);
  260. Serial.print(" MOD: ");
  261. if (keyboard1) {
  262. Serial.print(keyboard1.getModifiers(), HEX);
  263. Serial.print(" OEM: ");
  264. Serial.print(keyboard1.getOemKey(), HEX);
  265. Serial.print(" LEDS: ");
  266. Serial.println(keyboard1.LEDS(), HEX);
  267. } else {
  268. Serial.print(keyboard2.getModifiers(), HEX);
  269. Serial.print(" OEM: ");
  270. Serial.print(keyboard2.getOemKey(), HEX);
  271. Serial.print(" LEDS: ");
  272. Serial.println(keyboard2.LEDS(), HEX);
  273. }
  274. //Serial.print("key ");
  275. //Serial.print((char)keyboard1.getKey());
  276. //Serial.print(" ");
  277. //Serial.print((char)keyboard2.getKey());
  278. //Serial.println();
  279. }
  280. void OnHIDExtrasPress(uint32_t top, uint16_t key)
  281. {
  282. Serial.print("HID (");
  283. Serial.print(top, HEX);
  284. Serial.print(") key press:");
  285. Serial.print(key, HEX);
  286. if (top == 0xc0000) {
  287. switch (key) {
  288. case 0x20 : Serial.print(" - +10"); break;
  289. case 0x21 : Serial.print(" - +100"); break;
  290. case 0x22 : Serial.print(" - AM/PM"); break;
  291. case 0x30 : Serial.print(" - Power"); break;
  292. case 0x31 : Serial.print(" - Reset"); break;
  293. case 0x32 : Serial.print(" - Sleep"); break;
  294. case 0x33 : Serial.print(" - Sleep After"); break;
  295. case 0x34 : Serial.print(" - Sleep Mode"); break;
  296. case 0x35 : Serial.print(" - Illumination"); break;
  297. case 0x36 : Serial.print(" - Function Buttons"); break;
  298. case 0x40 : Serial.print(" - Menu"); break;
  299. case 0x41 : Serial.print(" - Menu Pick"); break;
  300. case 0x42 : Serial.print(" - Menu Up"); break;
  301. case 0x43 : Serial.print(" - Menu Down"); break;
  302. case 0x44 : Serial.print(" - Menu Left"); break;
  303. case 0x45 : Serial.print(" - Menu Right"); break;
  304. case 0x46 : Serial.print(" - Menu Escape"); break;
  305. case 0x47 : Serial.print(" - Menu Value Increase"); break;
  306. case 0x48 : Serial.print(" - Menu Value Decrease"); break;
  307. case 0x60 : Serial.print(" - Data On Screen"); break;
  308. case 0x61 : Serial.print(" - Closed Caption"); break;
  309. case 0x62 : Serial.print(" - Closed Caption Select"); break;
  310. case 0x63 : Serial.print(" - VCR/TV"); break;
  311. case 0x64 : Serial.print(" - Broadcast Mode"); break;
  312. case 0x65 : Serial.print(" - Snapshot"); break;
  313. case 0x66 : Serial.print(" - Still"); break;
  314. case 0x80 : Serial.print(" - Selection"); break;
  315. case 0x81 : Serial.print(" - Assign Selection"); break;
  316. case 0x82 : Serial.print(" - Mode Step"); break;
  317. case 0x83 : Serial.print(" - Recall Last"); break;
  318. case 0x84 : Serial.print(" - Enter Channel"); break;
  319. case 0x85 : Serial.print(" - Order Movie"); break;
  320. case 0x86 : Serial.print(" - Channel"); break;
  321. case 0x87 : Serial.print(" - Media Selection"); break;
  322. case 0x88 : Serial.print(" - Media Select Computer"); break;
  323. case 0x89 : Serial.print(" - Media Select TV"); break;
  324. case 0x8A : Serial.print(" - Media Select WWW"); break;
  325. case 0x8B : Serial.print(" - Media Select DVD"); break;
  326. case 0x8C : Serial.print(" - Media Select Telephone"); break;
  327. case 0x8D : Serial.print(" - Media Select Program Guide"); break;
  328. case 0x8E : Serial.print(" - Media Select Video Phone"); break;
  329. case 0x8F : Serial.print(" - Media Select Games"); break;
  330. case 0x90 : Serial.print(" - Media Select Messages"); break;
  331. case 0x91 : Serial.print(" - Media Select CD"); break;
  332. case 0x92 : Serial.print(" - Media Select VCR"); break;
  333. case 0x93 : Serial.print(" - Media Select Tuner"); break;
  334. case 0x94 : Serial.print(" - Quit"); break;
  335. case 0x95 : Serial.print(" - Help"); break;
  336. case 0x96 : Serial.print(" - Media Select Tape"); break;
  337. case 0x97 : Serial.print(" - Media Select Cable"); break;
  338. case 0x98 : Serial.print(" - Media Select Satellite"); break;
  339. case 0x99 : Serial.print(" - Media Select Security"); break;
  340. case 0x9A : Serial.print(" - Media Select Home"); break;
  341. case 0x9B : Serial.print(" - Media Select Call"); break;
  342. case 0x9C : Serial.print(" - Channel Increment"); break;
  343. case 0x9D : Serial.print(" - Channel Decrement"); break;
  344. case 0x9E : Serial.print(" - Media Select SAP"); break;
  345. case 0xA0 : Serial.print(" - VCR Plus"); break;
  346. case 0xA1 : Serial.print(" - Once"); break;
  347. case 0xA2 : Serial.print(" - Daily"); break;
  348. case 0xA3 : Serial.print(" - Weekly"); break;
  349. case 0xA4 : Serial.print(" - Monthly"); break;
  350. case 0xB0 : Serial.print(" - Play"); break;
  351. case 0xB1 : Serial.print(" - Pause"); break;
  352. case 0xB2 : Serial.print(" - Record"); break;
  353. case 0xB3 : Serial.print(" - Fast Forward"); break;
  354. case 0xB4 : Serial.print(" - Rewind"); break;
  355. case 0xB5 : Serial.print(" - Scan Next Track"); break;
  356. case 0xB6 : Serial.print(" - Scan Previous Track"); break;
  357. case 0xB7 : Serial.print(" - Stop"); break;
  358. case 0xB8 : Serial.print(" - Eject"); break;
  359. case 0xB9 : Serial.print(" - Random Play"); break;
  360. case 0xBA : Serial.print(" - Select DisC"); break;
  361. case 0xBB : Serial.print(" - Enter Disc"); break;
  362. case 0xBC : Serial.print(" - Repeat"); break;
  363. case 0xBD : Serial.print(" - Tracking"); break;
  364. case 0xBE : Serial.print(" - Track Normal"); break;
  365. case 0xBF : Serial.print(" - Slow Tracking"); break;
  366. case 0xC0 : Serial.print(" - Frame Forward"); break;
  367. case 0xC1 : Serial.print(" - Frame Back"); break;
  368. case 0xC2 : Serial.print(" - Mark"); break;
  369. case 0xC3 : Serial.print(" - Clear Mark"); break;
  370. case 0xC4 : Serial.print(" - Repeat From Mark"); break;
  371. case 0xC5 : Serial.print(" - Return To Mark"); break;
  372. case 0xC6 : Serial.print(" - Search Mark Forward"); break;
  373. case 0xC7 : Serial.print(" - Search Mark Backwards"); break;
  374. case 0xC8 : Serial.print(" - Counter Reset"); break;
  375. case 0xC9 : Serial.print(" - Show Counter"); break;
  376. case 0xCA : Serial.print(" - Tracking Increment"); break;
  377. case 0xCB : Serial.print(" - Tracking Decrement"); break;
  378. case 0xCD : Serial.print(" - Pause/Continue"); break;
  379. case 0xE0 : Serial.print(" - Volume"); break;
  380. case 0xE1 : Serial.print(" - Balance"); break;
  381. case 0xE2 : Serial.print(" - Mute"); break;
  382. case 0xE3 : Serial.print(" - Bass"); break;
  383. case 0xE4 : Serial.print(" - Treble"); break;
  384. case 0xE5 : Serial.print(" - Bass Boost"); break;
  385. case 0xE6 : Serial.print(" - Surround Mode"); break;
  386. case 0xE7 : Serial.print(" - Loudness"); break;
  387. case 0xE8 : Serial.print(" - MPX"); break;
  388. case 0xE9 : Serial.print(" - Volume Up"); break;
  389. case 0xEA : Serial.print(" - Volume Down"); break;
  390. case 0xF0 : Serial.print(" - Speed Select"); break;
  391. case 0xF1 : Serial.print(" - Playback Speed"); break;
  392. case 0xF2 : Serial.print(" - Standard Play"); break;
  393. case 0xF3 : Serial.print(" - Long Play"); break;
  394. case 0xF4 : Serial.print(" - Extended Play"); break;
  395. case 0xF5 : Serial.print(" - Slow"); break;
  396. case 0x100: Serial.print(" - Fan Enable"); break;
  397. case 0x101: Serial.print(" - Fan Speed"); break;
  398. case 0x102: Serial.print(" - Light"); break;
  399. case 0x103: Serial.print(" - Light Illumination Level"); break;
  400. case 0x104: Serial.print(" - Climate Control Enable"); break;
  401. case 0x105: Serial.print(" - Room Temperature"); break;
  402. case 0x106: Serial.print(" - Security Enable"); break;
  403. case 0x107: Serial.print(" - Fire Alarm"); break;
  404. case 0x108: Serial.print(" - Police Alarm"); break;
  405. case 0x150: Serial.print(" - Balance Right"); break;
  406. case 0x151: Serial.print(" - Balance Left"); break;
  407. case 0x152: Serial.print(" - Bass Increment"); break;
  408. case 0x153: Serial.print(" - Bass Decrement"); break;
  409. case 0x154: Serial.print(" - Treble Increment"); break;
  410. case 0x155: Serial.print(" - Treble Decrement"); break;
  411. case 0x160: Serial.print(" - Speaker System"); break;
  412. case 0x161: Serial.print(" - Channel Left"); break;
  413. case 0x162: Serial.print(" - Channel Right"); break;
  414. case 0x163: Serial.print(" - Channel Center"); break;
  415. case 0x164: Serial.print(" - Channel Front"); break;
  416. case 0x165: Serial.print(" - Channel Center Front"); break;
  417. case 0x166: Serial.print(" - Channel Side"); break;
  418. case 0x167: Serial.print(" - Channel Surround"); break;
  419. case 0x168: Serial.print(" - Channel Low Frequency Enhancement"); break;
  420. case 0x169: Serial.print(" - Channel Top"); break;
  421. case 0x16A: Serial.print(" - Channel Unknown"); break;
  422. case 0x170: Serial.print(" - Sub-channel"); break;
  423. case 0x171: Serial.print(" - Sub-channel Increment"); break;
  424. case 0x172: Serial.print(" - Sub-channel Decrement"); break;
  425. case 0x173: Serial.print(" - Alternate Audio Increment"); break;
  426. case 0x174: Serial.print(" - Alternate Audio Decrement"); break;
  427. case 0x180: Serial.print(" - Application Launch Buttons"); break;
  428. case 0x181: Serial.print(" - AL Launch Button Configuration Tool"); break;
  429. case 0x182: Serial.print(" - AL Programmable Button Configuration"); break;
  430. case 0x183: Serial.print(" - AL Consumer Control Configuration"); break;
  431. case 0x184: Serial.print(" - AL Word Processor"); break;
  432. case 0x185: Serial.print(" - AL Text Editor"); break;
  433. case 0x186: Serial.print(" - AL Spreadsheet"); break;
  434. case 0x187: Serial.print(" - AL Graphics Editor"); break;
  435. case 0x188: Serial.print(" - AL Presentation App"); break;
  436. case 0x189: Serial.print(" - AL Database App"); break;
  437. case 0x18A: Serial.print(" - AL Email Reader"); break;
  438. case 0x18B: Serial.print(" - AL Newsreader"); break;
  439. case 0x18C: Serial.print(" - AL Voicemail"); break;
  440. case 0x18D: Serial.print(" - AL Contacts/Address Book"); break;
  441. case 0x18E: Serial.print(" - AL Calendar/Schedule"); break;
  442. case 0x18F: Serial.print(" - AL Task/Project Manager"); break;
  443. case 0x190: Serial.print(" - AL Log/Journal/Timecard"); break;
  444. case 0x191: Serial.print(" - AL Checkbook/Finance"); break;
  445. case 0x192: Serial.print(" - AL Calculator"); break;
  446. case 0x193: Serial.print(" - AL A/V Capture/Playback"); break;
  447. case 0x194: Serial.print(" - AL Local Machine Browser"); break;
  448. case 0x195: Serial.print(" - AL LAN/WAN Browser"); break;
  449. case 0x196: Serial.print(" - AL Internet Browser"); break;
  450. case 0x197: Serial.print(" - AL Remote Networking/ISP Connect"); break;
  451. case 0x198: Serial.print(" - AL Network Conference"); break;
  452. case 0x199: Serial.print(" - AL Network Chat"); break;
  453. case 0x19A: Serial.print(" - AL Telephony/Dialer"); break;
  454. case 0x19B: Serial.print(" - AL Logon"); break;
  455. case 0x19C: Serial.print(" - AL Logoff"); break;
  456. case 0x19D: Serial.print(" - AL Logon/Logoff"); break;
  457. case 0x19E: Serial.print(" - AL Terminal Lock/Screensaver"); break;
  458. case 0x19F: Serial.print(" - AL Control Panel"); break;
  459. case 0x1A0: Serial.print(" - AL Command Line Processor/Run"); break;
  460. case 0x1A1: Serial.print(" - AL Process/Task Manager"); break;
  461. case 0x1A2: Serial.print(" - AL Select Tast/Application"); break;
  462. case 0x1A3: Serial.print(" - AL Next Task/Application"); break;
  463. case 0x1A4: Serial.print(" - AL Previous Task/Application"); break;
  464. case 0x1A5: Serial.print(" - AL Preemptive Halt Task/Application"); break;
  465. case 0x200: Serial.print(" - Generic GUI Application Controls"); break;
  466. case 0x201: Serial.print(" - AC New"); break;
  467. case 0x202: Serial.print(" - AC Open"); break;
  468. case 0x203: Serial.print(" - AC Close"); break;
  469. case 0x204: Serial.print(" - AC Exit"); break;
  470. case 0x205: Serial.print(" - AC Maximize"); break;
  471. case 0x206: Serial.print(" - AC Minimize"); break;
  472. case 0x207: Serial.print(" - AC Save"); break;
  473. case 0x208: Serial.print(" - AC Print"); break;
  474. case 0x209: Serial.print(" - AC Properties"); break;
  475. case 0x21A: Serial.print(" - AC Undo"); break;
  476. case 0x21B: Serial.print(" - AC Copy"); break;
  477. case 0x21C: Serial.print(" - AC Cut"); break;
  478. case 0x21D: Serial.print(" - AC Paste"); break;
  479. case 0x21E: Serial.print(" - AC Select All"); break;
  480. case 0x21F: Serial.print(" - AC Find"); break;
  481. case 0x220: Serial.print(" - AC Find and Replace"); break;
  482. case 0x221: Serial.print(" - AC Search"); break;
  483. case 0x222: Serial.print(" - AC Go To"); break;
  484. case 0x223: Serial.print(" - AC Home"); break;
  485. case 0x224: Serial.print(" - AC Back"); break;
  486. case 0x225: Serial.print(" - AC Forward"); break;
  487. case 0x226: Serial.print(" - AC Stop"); break;
  488. case 0x227: Serial.print(" - AC Refresh"); break;
  489. case 0x228: Serial.print(" - AC Previous Link"); break;
  490. case 0x229: Serial.print(" - AC Next Link"); break;
  491. case 0x22A: Serial.print(" - AC Bookmarks"); break;
  492. case 0x22B: Serial.print(" - AC History"); break;
  493. case 0x22C: Serial.print(" - AC Subscriptions"); break;
  494. case 0x22D: Serial.print(" - AC Zoom In"); break;
  495. case 0x22E: Serial.print(" - AC Zoom Out"); break;
  496. case 0x22F: Serial.print(" - AC Zoom"); break;
  497. case 0x230: Serial.print(" - AC Full Screen View"); break;
  498. case 0x231: Serial.print(" - AC Normal View"); break;
  499. case 0x232: Serial.print(" - AC View Toggle"); break;
  500. case 0x233: Serial.print(" - AC Scroll Up"); break;
  501. case 0x234: Serial.print(" - AC Scroll Down"); break;
  502. case 0x235: Serial.print(" - AC Scroll"); break;
  503. case 0x236: Serial.print(" - AC Pan Left"); break;
  504. case 0x237: Serial.print(" - AC Pan Right"); break;
  505. case 0x238: Serial.print(" - AC Pan"); break;
  506. case 0x239: Serial.print(" - AC New Window"); break;
  507. case 0x23A: Serial.print(" - AC Tile Horizontally"); break;
  508. case 0x23B: Serial.print(" - AC Tile Vertically"); break;
  509. case 0x23C: Serial.print(" - AC Format"); break;
  510. }
  511. }
  512. Serial.println();
  513. }
  514. void OnHIDExtrasRelease(uint32_t top, uint16_t key)
  515. {
  516. Serial.print("HID (");
  517. Serial.print(top, HEX);
  518. Serial.print(") key release:");
  519. Serial.println(key, HEX);
  520. }
  521. bool OnReceiveHidData(uint32_t usage, const uint8_t *data, uint32_t len) {
  522. // Called for maybe both HIDS for rawhid basic test. One is for the Teensy
  523. // to output to Serial. while still having Raw Hid...
  524. if (usage == 0xffc90004) {
  525. // Lets trim off trailing null characters.
  526. while ((len > 0) && (data[len - 1] == 0)) {
  527. len--;
  528. }
  529. if (len) {
  530. Serial.print("RawHid Serial: ");
  531. Serial.write(data, len);
  532. }
  533. } else {
  534. Serial.print("RawHIDx data: ");
  535. Serial.println(usage, HEX);
  536. uint8_t len1 = len;
  537. for(int j = 0; j < len; j++){
  538. user_axis[j] = data[j];
  539. }
  540. /*
  541. while (len) {
  542. uint8_t cb = (len > 16) ? 16 : len;
  543. const uint8_t *p = data;
  544. uint8_t i;
  545. for (i = 0; i < cb; i++) {
  546. Serial.printf("%02x ", *p++);
  547. }
  548. Serial.print(": ");
  549. for (i = 0; i < cb; i++) {
  550. Serial.write(((*data >= ' ') && (*data <= '~')) ? *data : '.');
  551. data++;
  552. }
  553. len -= cb;
  554. Serial.println();
  555. }
  556. */
  557. }
  558. for (uint8_t i = 0; i<9; i++) {
  559. Serial.printf(" %d:%d", i, user_axis[i]);
  560. }
  561. Serial.println();
  562. Serial.print("Mouse: buttons = ");
  563. Serial.print(user_axis[3]);
  564. Serial.print(", mouseX = ");
  565. Serial.print(user_axis[4]);
  566. Serial.print(", mouseY = ");
  567. Serial.print(user_axis[5]);
  568. Serial.println();
  569. return true;
  570. }