Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 1 of 1

Thread: USB - wonderful! - treacherous!

  1. #1
    Senior Member Davidelvig's Avatar
    Join Date
    Aug 2015
    Location
    Wisconsin
    Posts
    310

    USB - wonderful! - treacherous!

    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 by Davidelvig; 12-29-2020 at 03:19 PM. Reason: Added environment info

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •