howdy, diy friends. EDIT - i shouldn't say "mystery HID," because it's an
infinity in-usb-2 footpedal. it sends messages that are used for dictation software, but not keyboard characters or anything else that i can use as a joystick/input for REAPER - hence the mystery
originally, i was using this 3 button footswitch in REAPER via Bidule's HID-to-MIDI converter, but this sucks because it lost its association every time a different USB device was plugged in. the developer wasn't able to implement a solution to this issue, referencing system-level reasons that went over my head.
so, i decided to go DIY with it. i came into possession of an arduino with a usb host shield (
https://www.sparkfun.com/products/9947) and configured it to read the foot pedal.
using the most basic example from the library usbhid_desc, i am able to see a serial stream of data when i hit the 3 buttons (i'd paste it here but i bagged it up to take it to the local makerspace here in Dunth).
i'm able to run the demo of Bome's MIDI translator to capture and remap these serial messages to midi, and this is great, but i don't want to spend $70 on Bome's. i want to use the MIDI library to translate the received button presses to MIDI directly. definitely doable, but the usbhid_desc example code doesn't show me how to parse the actual messages being sent from the footpedal.
here's the sketch: note that everything is basically in setup, and that the printing of the messages appears to be done in Usb.Task(); ... i've looked everywhere for usb.task in the different libraries and their corresponding cpps, but i can't find it.
so, somewhere, there's a serial.print( ) with a mystery within the parentheses that i want to cut up, or use to trigger something else. whoever wrote this library/default sketch did such a good job obfuscating what's happening that i don't know how to dig in.
any tips?
Code:
#include <usbhid.h>
#include <hiduniversal.h>
#include <hidescriptorparser.h>
#include <usbhub.h>
#include "pgmstrings.h"
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
class HIDUniversal2 : public HIDUniversal
{
public:
HIDUniversal2(USB *usb) : HIDUniversal(usb) {};
protected:
uint8_t OnInitSuccessful();
};
uint8_t HIDUniversal2::OnInitSuccessful()
{
uint8_t rcode;
HexDumper<USBReadParser, uint16_t, uint16_t> Hex;
ReportDescParser Rpt;
if ((rcode = GetReportDescr(0, &Hex)))
goto FailGetReportDescr1;
if ((rcode = GetReportDescr(0, &Rpt)))
goto FailGetReportDescr2;
return 0;
FailGetReportDescr1:
USBTRACE("GetReportDescr1:");
goto Fail;
FailGetReportDescr2:
USBTRACE("GetReportDescr2:");
goto Fail;
Fail:
Serial.println(rcode, HEX);
Release();
return rcode;
}
USB Usb;
//USBHub Hub(&Usb);
HIDUniversal2 Hid(&Usb);
UniversalReportParser Uni;
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.");
delay( 200 );
if (!Hid.SetReportParser(0, &Uni))
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
}
void loop()
{
Usb.Task();
}