2016-03-10 09:30:43 +01:00
|
|
|
#include <hidcomposite.h>
|
|
|
|
#include <usbhub.h>
|
|
|
|
|
|
|
|
// Satisfy the IDE, which needs to see the include statment in the ino too.
|
|
|
|
#ifdef dobogusinclude
|
|
|
|
#include <spi4teensy3.h>
|
|
|
|
#endif
|
2017-08-14 09:39:38 +02:00
|
|
|
#include <SPI.h>
|
2016-03-10 09:30:43 +01:00
|
|
|
|
2016-03-21 19:54:30 +01:00
|
|
|
// Override HIDComposite to be able to select which interface we want to hook into
|
2016-03-10 09:30:43 +01:00
|
|
|
class HIDSelector : public HIDComposite
|
|
|
|
{
|
|
|
|
public:
|
2016-04-19 11:34:04 +02:00
|
|
|
HIDSelector(USB *p) : HIDComposite(p) {};
|
2016-03-10 09:30:43 +01:00
|
|
|
|
|
|
|
protected:
|
2016-04-19 11:34:04 +02:00
|
|
|
void ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf); // Called by the HIDComposite library
|
|
|
|
bool SelectInterface(uint8_t iface, uint8_t proto);
|
2016-03-10 09:30:43 +01:00
|
|
|
};
|
|
|
|
|
2016-03-21 19:54:30 +01:00
|
|
|
// Return true for the interface we want to hook into
|
2016-03-10 09:30:43 +01:00
|
|
|
bool HIDSelector::SelectInterface(uint8_t iface, uint8_t proto)
|
|
|
|
{
|
2016-04-19 11:34:04 +02:00
|
|
|
if (proto != 0)
|
2016-03-10 09:30:43 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-21 19:54:30 +01:00
|
|
|
// Will be called for all HID data received from the USB interface
|
2016-03-10 09:51:04 +01:00
|
|
|
void HIDSelector::ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf) {
|
2016-03-10 09:30:43 +01:00
|
|
|
#if 1
|
2016-04-19 11:34:04 +02:00
|
|
|
if (len && buf) {
|
|
|
|
Notify(PSTR("\r\n"), 0x80);
|
|
|
|
for (uint8_t i = 0; i < len; i++) {
|
|
|
|
D_PrintHex<uint8_t > (buf[i], 0x80);
|
|
|
|
Notify(PSTR(" "), 0x80);
|
|
|
|
}
|
|
|
|
}
|
2016-03-10 09:30:43 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
USB Usb;
|
|
|
|
//USBHub Hub(&Usb);
|
|
|
|
HIDSelector hidSelector(&Usb);
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin( 115200 );
|
|
|
|
#if !defined(__MIPSEL__)
|
|
|
|
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
|
|
|
#endif
|
|
|
|
Serial.println("Start");
|
|
|
|
|
|
|
|
if (Usb.Init() == -1)
|
|
|
|
Serial.println("OSC did not start.");
|
|
|
|
|
|
|
|
// Set this to higher values to enable more debug information
|
|
|
|
// minimum 0x00, maximum 0xff, default 0x80
|
|
|
|
UsbDEBUGlvl = 0xff;
|
|
|
|
|
|
|
|
delay( 200 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
Usb.Task();
|
|
|
|
}
|