Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check whether the USB connection is active #46

Open
tttapa opened this issue Jun 9, 2018 · 2 comments
Open

How to check whether the USB connection is active #46

tttapa opened this issue Jun 9, 2018 · 2 comments
Labels
help wanted Assistance from the community is especially welcome

Comments

@tttapa
Copy link

tttapa commented Jun 9, 2018

When the MIDI connection is not active on the PC-side, there's a 250 ms timeout that blocks the entire program every time you (try to) send MIDI messages.

Is there a way to check if the connection is active beforehand?
E.g. if (MidiUSB) MidiUSB.send(...);

The bool operator is declared in the header file, but it isn't yet implemented, and I couldn't find anything useful in the USB superclass that I could use.

Is there any way to resolve this issue?

Thanks,
Pieter

@facchinm facchinm added the help wanted Assistance from the community is especially welcome label Jun 11, 2018
@DanielRudrich
Copy link

I managed to solve this by adding a USB_Available call before sending:

Added a public method to the MIDI_ class:
int isAvailable();
implementation:
MIDI_::isAvailable() { return USB_Available(MIDI_TX);}

In my code:

if (MidiUSB.isAvailable() == 0)
{ 
// do send stuff
}
else
{
// port not ready
}
MidiUSB.flush(); // <- this somehow needs to be outside, no idea why

Can we have this method added to the class?

@warewolf
Copy link

I managed to solve this by adding a USB_Available call before sending:

Added a public method to the MIDI_ class: int isAvailable(); implementation: MIDI_::isAvailable() { return USB_Available(MIDI_TX);}

...snipped...

Can we have this method added to the class?

Came here because I'm having the same issue, and searched USBCDC on the Arudino Micro and essentially invented nearly the exact same code.

CDC.cpp in Arduino Core for USB CDC Serial exposes availableForWrite(), I would adopt that method name for consistency with arduino core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Assistance from the community is especially welcome
Projects
None yet
Development

No branches or pull requests

4 participants