]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/adk/adk_barcode/adk_barcode.ino
lufa: usb-usb: Use LUFA startup instead of cusotom
[max/tmk_keyboard.git] / tmk_core / protocol / usb_hid / USB_Host_Shield_2.0 / examples / adk / adk_barcode / adk_barcode.ino
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
8 // Satisfy IDE, which only needs to see the include statment in the ino.
9 #ifdef dobogusinclude
10 #include <spi4teensy3.h>
11 #include <SPI.h>
12 #endif
13
14 USB Usb;
15 USBHub Hub1(&Usb);
16 USBHub Hub2(&Usb);
17 HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);
18
19 ADK adk(&Usb,"Circuits@Home, ltd.",
20             "USB Host Shield",
21             "Arduino Terminal for Android",
22             "1.0",
23             "http://www.circuitsathome.com",
24             "0000000000000001");
25
26
27 class KbdRptParser : public KeyboardReportParser
28 {
29
30 protected:
31         void OnKeyDown  (uint8_t mod, uint8_t key);
32         void OnKeyPressed(uint8_t key);
33 };
34
35 void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
36 {
37     uint8_t c = OemToAscii(mod, key);
38
39     if (c)
40         OnKeyPressed(c);
41 }
42
43 /* what to do when symbol arrives */
44 void KbdRptParser::OnKeyPressed(uint8_t key)
45 {
46 const char* new_line = "\n";
47 uint8_t rcode;
48 uint8_t keylcl;
49
50  if( adk.isReady() == false ) {
51    return;
52  }
53
54   keylcl = key;
55
56   if( keylcl == 0x13 ) {
57     rcode = adk.SndData( strlen( new_line ), (uint8_t *)new_line );
58   }
59   else {
60     rcode = adk.SndData( 1, &keylcl );
61   }
62
63   Serial.print((char) keylcl );
64   Serial.print(" : ");
65   Serial.println( keylcl, HEX );
66 };
67
68 KbdRptParser Prs;
69
70 void setup()
71 {
72   Serial.begin(115200);
73 #if !defined(__MIPSEL__)
74   while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
75 #endif
76   Serial.println("\r\nADK demo start");
77
78   if (Usb.Init() == -1) {
79     Serial.println("OSCOKIRQ failed to assert");
80     while(1); //halt
81   }//if (Usb.Init() == -1...
82
83   Keyboard.SetReportParser(0, (HIDReportParser*)&Prs);
84
85   delay( 200 );
86 }
87
88 void loop()
89 {
90   Usb.Task();
91 }