USB - wonderful! - treacherous!

Status
Not open for further replies.

Davidelvig

Well-known member
I'm leveraging the Teensy-to-PC USB connection for more varied functions, and hitting some snags.
I've paid attention to this thread. I have what I hope are simple questions:

How to handle different streams of USB input.
USB MIDI: I've used this to code (polled in the mail loop) to read inbound MIDI messages
Code:
int handleInboundMIDI(bool echoMessages) {
    int msgs = 0;
    while (usbMIDI.read()) {
        msgs++;
        if (echoMessages) {
            Serial.printf("\nInbound message %d\n", msgs);
            Serial.printf("\tChan: %d\n", usbMIDI.getChannel());
            Serial.printf("\tType: %s (%2x)\n", dbMIDI::getMessageTypeName(usbMIDI.getType()), usbMIDI.getType());
            Serial.printf("\tDat1: %d\n", usbMIDI.getData1());
            Serial.printf("\tDat2: %d\n", usbMIDI.getData2());
            Serial.println();
        }
    }
    return(msgs);
}

and other, character-based Serial input, similarly polled:
Code:
void handleInboundSerial(void) {
    switch (Serial.peek()) {
        case 'a': case 'A':
            Serial.read();
            Serial.println("Do one thing");
            break;
        case 'b': case 'B':
            Serial.read();
            Serial.println("Do the other thing");
            break;
        default:
            break;   
    }
}

When polling both in the main loop, it gets confused. (USB MIDI out stops, for example)

My USB needs:
- USB MIDI in and out
- terminal in and out (Teensyduino Terminal)
- TyCmd upload BlahBlah.HEX
- TyCmd monitor --raw

What's a good strategy to leverage the many USB options without them stepping on each other?

Teensy 3.2, Mac OS Catalina, Arduino 1.8.13, Teensyduino 1.5.3
 
Last edited:
Status
Not open for further replies.
Back
Top