Old 12-11-2018, 06:42 AM   #1
mccrabney
Human being with feelings
 
mccrabney's Avatar
 
Join Date: Aug 2015
Location: Nawtonomy, Alabamistan
Posts: 1,831
Default mystery HID to MIDI (arduino, host shield, etc)

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();
}
__________________
° striving for a loop-based, controller-centric midi recording/editing workflow.
° desiring to control all quantise parameters from control surface.
° using REAPER to make modern sample-based beat music

Last edited by mccrabney; 12-11-2018 at 06:52 AM.
mccrabney is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:58 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.