2011-11-05 04:37:26 +01:00
|
|
|
/**/
|
|
|
|
/* A sketch demonstrating data exchange between two USB devices - a HID barcode scanner and ADK-compatible Android phone */
|
|
|
|
/**/
|
|
|
|
#include <adk.h>
|
|
|
|
#include <hidboot.h>
|
2013-10-02 00:49:46 +02:00
|
|
|
#include <usbhub.h>
|
2015-03-03 19:08:39 +01:00
|
|
|
|
2014-11-10 07:35:13 +01:00
|
|
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
|
|
|
#ifdef dobogusinclude
|
|
|
|
#include <spi4teensy3.h>
|
|
|
|
#include <SPI.h>
|
|
|
|
#endif
|
2011-11-05 04:37:26 +01:00
|
|
|
|
|
|
|
USB Usb;
|
|
|
|
USBHub Hub1(&Usb);
|
2014-11-10 07:35:13 +01:00
|
|
|
USBHub Hub2(&Usb);
|
2015-05-23 15:49:46 +02:00
|
|
|
HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
|
2011-11-05 04:37:26 +01:00
|
|
|
|
|
|
|
ADK adk(&Usb,"Circuits@Home, ltd.",
|
|
|
|
"USB Host Shield",
|
|
|
|
"Arduino Terminal for Android",
|
|
|
|
"1.0",
|
|
|
|
"http://www.circuitsathome.com",
|
|
|
|
"0000000000000001");
|
|
|
|
|
|
|
|
|
|
|
|
class KbdRptParser : public KeyboardReportParser
|
|
|
|
{
|
2014-11-10 07:35:13 +01:00
|
|
|
|
2011-11-05 04:37:26 +01:00
|
|
|
protected:
|
2014-11-10 07:35:13 +01:00
|
|
|
void OnKeyDown (uint8_t mod, uint8_t key);
|
|
|
|
void OnKeyPressed(uint8_t key);
|
2011-11-05 04:37:26 +01:00
|
|
|
};
|
2014-11-10 07:35:13 +01:00
|
|
|
|
|
|
|
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
|
2011-11-05 04:37:26 +01:00
|
|
|
{
|
|
|
|
uint8_t c = OemToAscii(mod, key);
|
2014-11-10 07:35:13 +01:00
|
|
|
|
2011-11-05 04:37:26 +01:00
|
|
|
if (c)
|
|
|
|
OnKeyPressed(c);
|
|
|
|
}
|
2014-11-10 07:35:13 +01:00
|
|
|
|
2011-11-05 04:37:26 +01:00
|
|
|
/* what to do when symbol arrives */
|
2014-11-10 07:35:13 +01:00
|
|
|
void KbdRptParser::OnKeyPressed(uint8_t key)
|
2011-11-05 04:37:26 +01:00
|
|
|
{
|
|
|
|
const char* new_line = "\n";
|
|
|
|
uint8_t rcode;
|
|
|
|
uint8_t keylcl;
|
|
|
|
|
|
|
|
if( adk.isReady() == false ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-10 07:35:13 +01:00
|
|
|
|
2011-11-05 04:37:26 +01:00
|
|
|
keylcl = key;
|
2014-11-10 07:35:13 +01:00
|
|
|
|
2011-11-05 04:37:26 +01:00
|
|
|
if( keylcl == 0x13 ) {
|
|
|
|
rcode = adk.SndData( strlen( new_line ), (uint8_t *)new_line );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rcode = adk.SndData( 1, &keylcl );
|
2014-11-10 07:35:13 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 20:49:42 +01:00
|
|
|
Serial.print((char) keylcl );
|
2014-11-10 07:35:13 +01:00
|
|
|
Serial.print(" : ");
|
2011-11-05 04:37:26 +01:00
|
|
|
Serial.println( keylcl, HEX );
|
|
|
|
};
|
2014-11-10 07:35:13 +01:00
|
|
|
|
2011-11-05 04:37:26 +01:00
|
|
|
KbdRptParser Prs;
|
2014-11-10 07:35:13 +01:00
|
|
|
|
2011-11-05 04:37:26 +01:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
2014-11-10 07:35:13 +01:00
|
|
|
#if !defined(__MIPSEL__)
|
2013-10-21 19:58:03 +02:00
|
|
|
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
2014-11-10 07:35:13 +01:00
|
|
|
#endif
|
2011-11-05 04:37:26 +01:00
|
|
|
Serial.println("\r\nADK demo start");
|
2014-11-10 07:35:13 +01:00
|
|
|
|
2011-11-05 04:37:26 +01:00
|
|
|
if (Usb.Init() == -1) {
|
|
|
|
Serial.println("OSCOKIRQ failed to assert");
|
|
|
|
while(1); //halt
|
|
|
|
}//if (Usb.Init() == -1...
|
2014-11-10 07:35:13 +01:00
|
|
|
|
2015-05-23 15:49:46 +02:00
|
|
|
HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs);
|
2014-11-10 07:35:13 +01:00
|
|
|
|
2011-11-05 04:37:26 +01:00
|
|
|
delay( 200 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
Usb.Task();
|
|
|
|
}
|