diff --git a/examples/SysEx_Receive/SysEx_Receive.ino b/examples/SysEx_Receive/SysEx_Receive.ino new file mode 100644 index 0000000..52e3cf9 --- /dev/null +++ b/examples/SysEx_Receive/SysEx_Receive.ino @@ -0,0 +1,74 @@ +#include + +#include +//#include +//#include +//#include + +BLEMIDI_CREATE_DEFAULT_INSTANCE() + +bool isConnected = false; + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +void setup() +{ + Serial.begin(115200); + while (!Serial); + + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); + + BLEMIDI.setHandleConnected(OnConnected); + BLEMIDI.setHandleDisconnected(OnDisconnected); + + MIDI.setHandleSystemExclusive(OnMidiSysEx); + + // Listen for MIDI messages on channel 1 + MIDI.begin(); +} + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +void loop() +{ + // Listen to incoming notes + MIDI.read(); +} + +// ==================================================================================== +// Event handlers for incoming MIDI messages +// ==================================================================================== + +// ----------------------------------------------------------------------------- +// Device connected +// ----------------------------------------------------------------------------- +void OnConnected() { + isConnected = true; + digitalWrite(LED_BUILTIN, HIGH); +} + +// ----------------------------------------------------------------------------- +// Device disconnected +// ----------------------------------------------------------------------------- +void OnDisconnected() { + isConnected = false; + digitalWrite(LED_BUILTIN, LOW); +} + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +void OnMidiSysEx(byte* data, unsigned length) { + Serial.print(F("SYSEX: (")); + Serial.print(length); + Serial.print(F(" bytes) ")); + for (uint16_t i = 0; i < length; i++) + { + Serial.print(data[i], HEX); + Serial.print(" "); + } + Serial.println(); +} diff --git a/examples/SysEx_Send/SysEx_Send.ino b/examples/SysEx_Send/SysEx_Send.ino index 35490bc..67df0a0 100644 --- a/examples/SysEx_Send/SysEx_Send.ino +++ b/examples/SysEx_Send/SysEx_Send.ino @@ -41,13 +41,13 @@ bool isConnected = false; // ----------------------------------------------------------------------------- void setup() { - MIDI.begin(); - pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); BLEMIDI.setHandleConnected(OnConnected); BLEMIDI.setHandleDisconnected(OnDisconnected); + + MIDI.begin(); } // ----------------------------------------------------------------------------- @@ -84,4 +84,4 @@ void OnConnected() { void OnDisconnected() { isConnected = false; digitalWrite(LED_BUILTIN, LOW); -} +} \ No newline at end of file diff --git a/src/BLEMIDI.h b/src/BLEMIDI.h index eccf091..7ec29dd 100644 --- a/src/BLEMIDI.h +++ b/src/BLEMIDI.h @@ -27,7 +27,6 @@ private: char mDeviceName[24]; - bool mIsSysEx; uint8_t mTimestampLow; private: @@ -54,7 +53,7 @@ public: { getMidiTimestamp(&mTxBuffer[0], &mTxBuffer[1]); mTxIndex = 2; - mTimestampLow = mTxBuffer[1]; + mTimestampLow = mTxBuffer[1]; // or generate new ? return true; } @@ -72,21 +71,21 @@ public: void endTransmission() { - if (mTxBuffer[mTxIndex - 1] == 0xF7) - { - if (mTxIndex >= sizeof(mTxBuffer)) + if (mTxBuffer[mTxIndex - 1] == 0xF7) { - mBleClass.write(mTxBuffer, mTxIndex - 1); + if (mTxIndex >= sizeof(mTxBuffer)) + { + mBleClass.write(mTxBuffer, mTxIndex - 1); - mTxIndex = 1; // keep header - mTxBuffer[mTxIndex++] = mTimestampLow; + mTxIndex = 1; // keep header + mTxBuffer[mTxIndex++] = mTimestampLow; // or generate new ? + } + else + { + mTxBuffer[mTxIndex - 1] = mTimestampLow; // or generate new ? + } + mTxBuffer[mTxIndex++] = 0xF7; } - else - { - mTxBuffer[mTxIndex - 1] = mTimestampLow; - } - mTxBuffer[mTxIndex++] = 0xF7; - } mBleClass.write(mTxBuffer, mTxIndex); mTxIndex = 0;