I've got a Teensy 4.1, and I'm trying to adapt the File > Examples > USBHost_t36 > MIDI > Interface_16x16 example, using a sketch with the MIDIx4 USB type. It's working fine, but I want to be able to filter the USB MIDI devices connected to the 2nd USB port by their USB product name. For example, when I connect my Launchkey Mini MK3 to my PC, I see the following MIDI devices:
* "Launchkey Mini MK3 MIDI"
* "MIDIIN2 (Launchkey Mini MK3 MID"
* "MIDIOUT2 (Launchkey Mini MK3 MI"
But I can't figure out what I need to do in Teensy code. Is there a way to test that the USB product name of a connected MIDI device is a certain value? See the "if (SOMETHING.equals(MY_DEVICE_PRODUCT_NAME)) {" bit in my code.
Thanks!
* "Launchkey Mini MK3 MIDI"
* "MIDIIN2 (Launchkey Mini MK3 MID"
* "MIDIOUT2 (Launchkey Mini MK3 MI"
But I can't figure out what I need to do in Teensy code. Is there a way to test that the USB product name of a connected MIDI device is a certain value? See the "if (SOMETHING.equals(MY_DEVICE_PRODUCT_NAME)) {" bit in my code.
Code:
#include <USBHost_t36.h> // access to USB MIDI devices (plugged into 2nd USB port)
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
MIDIDevice midi01(myusb);
MIDIDevice midi02(myusb);
MIDIDevice midi03(myusb);
MIDIDevice midi04(myusb);
MIDIDevice * midilist[4] = {
&midi01, &midi02, &midi03, &midi04
};
void setup() {
myusb.begin();
}
String MY_DEVICE_PRODUCT_NAME = String("MIDIOUT2 (Launchkey Mini MK3 MI");
void loop() {
// Read messages arriving from the (up to) 4 USB devices plugged into the USB Host port
for (int port = 0; port < 4; port++) {
if (midilist[port]->read()) {
uint8_t type = midilist[port]->getType();
uint8_t data1 = midilist[port]->getData1();
uint8_t data2 = midilist[port]->getData2();
uint8_t channel = midilist[port]->getChannel();
const uint8_t *sys = midilist[port]->getSysExArray();
if (SOMETHING.equals(MY_DEVICE_PRODUCT_NAME)) {
doSomething();
}
}
}
// Read messages the PC (upstream host) sends and ignore them
while (usbMIDI.read());
}
Thanks!