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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

adk_barcode.ino 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**/
  2. /* A sketch demonstrating data exchange between two USB devices - a HID barcode scanner and ADK-compatible Android phone */
  3. /**/
  4. #include <adk.h>
  5. #include <hidboot.h>
  6. #include <usbhub.h>
  7. // Satisfy IDE, which only needs to see the include statment in the ino.
  8. #ifdef dobogusinclude
  9. #include <spi4teensy3.h>
  10. #include <SPI.h>
  11. #endif
  12. USB Usb;
  13. USBHub Hub1(&Usb);
  14. USBHub Hub2(&Usb);
  15. HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);
  16. ADK adk(&Usb,"Circuits@Home, ltd.",
  17. "USB Host Shield",
  18. "Arduino Terminal for Android",
  19. "1.0",
  20. "http://www.circuitsathome.com",
  21. "0000000000000001");
  22. class KbdRptParser : public KeyboardReportParser
  23. {
  24. protected:
  25. void OnKeyDown (uint8_t mod, uint8_t key);
  26. void OnKeyPressed(uint8_t key);
  27. };
  28. void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
  29. {
  30. uint8_t c = OemToAscii(mod, key);
  31. if (c)
  32. OnKeyPressed(c);
  33. }
  34. /* what to do when symbol arrives */
  35. void KbdRptParser::OnKeyPressed(uint8_t key)
  36. {
  37. const char* new_line = "\n";
  38. uint8_t rcode;
  39. uint8_t keylcl;
  40. if( adk.isReady() == false ) {
  41. return;
  42. }
  43. keylcl = key;
  44. if( keylcl == 0x13 ) {
  45. rcode = adk.SndData( strlen( new_line ), (uint8_t *)new_line );
  46. }
  47. else {
  48. rcode = adk.SndData( 1, &keylcl );
  49. }
  50. Serial.print((char) keylcl );
  51. Serial.print(" : ");
  52. Serial.println( keylcl, HEX );
  53. };
  54. KbdRptParser Prs;
  55. void setup()
  56. {
  57. Serial.begin(115200);
  58. #if !defined(__MIPSEL__)
  59. while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  60. #endif
  61. Serial.println("\r\nADK demo start");
  62. if (Usb.Init() == -1) {
  63. Serial.println("OSCOKIRQ failed to assert");
  64. while(1); //halt
  65. }//if (Usb.Init() == -1...
  66. Keyboard.SetReportParser(0, (HIDReportParser*)&Prs);
  67. delay( 200 );
  68. }
  69. void loop()
  70. {
  71. Usb.Task();
  72. }