Add Serial.flush() option for MIDI examples

This commit is contained in:
Yuuichi Akagawa 2020-12-02 00:29:56 +09:00
parent 1ee088bcad
commit c43e08b445
3 changed files with 29 additions and 3 deletions

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
* USB-MIDI to Legacy Serial MIDI converter
* Copyright (C) 2012-2017 Yuuichi Akagawa
* Copyright (C) 2012-2020 Yuuichi Akagawa
*
* Idea from LPK25 USB-MIDI to Serial MIDI converter
* by Collin Cunningham - makezine.com, narbotic.com
@ -24,6 +24,11 @@
#else
#define _MIDI_SERIAL_PORT Serial
#endif
// Set to 1 if you want to wait for the Serial MIDI transmission to complete.
// For more information, see https://github.com/felis/USB_Host_Shield_2.0/issues/570
#define ENABLE_MIDI_SERIAL_FLUSH 0
//////////////////////////
// MIDI Pin assign
// 2 : GND
@ -68,6 +73,9 @@ void MIDI_poll()
if ( (size = Midi.RecvData(outBuf)) > 0 ) {
//MIDI Output
_MIDI_SERIAL_PORT.write(outBuf, size);
#if ENABLE_MIDI_SERIAL_FLUSH
_MIDI_SERIAL_PORT.flush();
#endif
}
} while (size > 0);
}

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
* USB-MIDI to Legacy Serial MIDI converter
* Copyright (C) 2012-2017 Yuuichi Akagawa
* Copyright (C) 2012-2020 Yuuichi Akagawa
*
* Idea from LPK25 USB-MIDI to Serial MIDI converter
* by Collin Cunningham - makezine.com, narbotic.com
@ -24,6 +24,11 @@
#else
#define _MIDI_SERIAL_PORT Serial
#endif
// Set to 1 if you want to wait for the Serial MIDI transmission to complete.
// For more information, see https://github.com/felis/USB_Host_Shield_2.0/issues/570
#define ENABLE_MIDI_SERIAL_FLUSH 0
//////////////////////////
// MIDI Pin assign
// 2 : GND
@ -73,6 +78,9 @@ void MIDI_poll(USBH_MIDI &Midi)
if ( (size = Midi.RecvData(outBuf)) > 0 ) {
//MIDI Output
_MIDI_SERIAL_PORT.write(outBuf, size);
#if ENABLE_MIDI_SERIAL_FLUSH
_MIDI_SERIAL_PORT.flush();
#endif
}
} while (size > 0);
}

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
* Legacy Serial MIDI and USB Host bidirectional converter
* Copyright (C) 2013-2017 Yuuichi Akagawa
* Copyright (C) 2013-2020 Yuuichi Akagawa
*
* for use with Arduino MIDI library
* https://github.com/FortySevenEffects/arduino_midi_library/
@ -32,6 +32,10 @@ MIDI_CREATE_DEFAULT_INSTANCE();
#define _MIDI_SERIAL_PORT Serial
#endif
// Set to 1 if you want to wait for the Serial MIDI transmission to complete.
// For more information, see https://github.com/felis/USB_Host_Shield_2.0/issues/570
#define ENABLE_MIDI_SERIAL_FLUSH 0
//////////////////////////
// MIDI Pin assign
// 2 : GND
@ -125,6 +129,9 @@ void MIDI_poll()
_MIDI_SERIAL_PORT.write(outbuf, rc);
p += 4;
}
#if ENABLE_MIDI_SERIAL_FLUSH
_MIDI_SERIAL_PORT.flush();
#endif
readPtr += 4;
}
#else
@ -133,6 +140,9 @@ void MIDI_poll()
if ( (size = Midi.RecvData(outBuf)) > 0 ) {
//MIDI Output
_MIDI_SERIAL_PORT.write(outBuf, size);
#if ENABLE_MIDI_SERIAL_FLUSH
_MIDI_SERIAL_PORT.flush();
#endif
}
} while (size > 0);
#endif