USBHost_t36 Connect/Disconnect callback / state?

I'm using the USBHost_t36 with a MIDIDevice. I'm wondering what the method is for detecting if a USB device has been disconnected or reconnected during runtime.

I'm looking (as a simple starting base), to just call a function that prints 'Disconnected' when the cable is unplugged from the device and then another that prints 'Connected' when the cable/device gets plugged back in.

Is there a callback I can set? Or some kind of status I can poll to read?
 
It seems that USBDriver has an operator overload for bool.

So as I only have one MIDIDevice being connected, I'm currently doing this check inside loop:

Code:
void loop() {
  myusb.Task();
  midiDevice.read();

  static bool prevActive = false;
  if (midiDevice != prevActive) {
    Serial.println(midiDevice ? "Connected" : "Disconnected");
    prevActive = midiDevice;
  }
}

Not sure if it's the best/correct way to be checking for this, but it seems to work so far!
 
That is what I have used in several of the examples.

It has been suggested that we add a callback or the like, but so far...
 
That is what I have used in several of the examples.

It has been suggested that we add a callback or the like, but so far...

Yes, I followed suit roughly from HIDDeviceInfo.ino when I went digging in the examples.

I do think a callback would be helpful, but then again... If the 'how to' is in the examples like this, then maybe it's not needed.
 
Back
Top