This commit is contained in:
lathoub 2020-10-03 17:13:12 +02:00
parent ba7c598a52
commit 5f8a38a5b8
3 changed files with 90 additions and 17 deletions

View File

@ -0,0 +1,74 @@
#include <BLEMIDI.h>
#include <hardware/BLEMIDI_ESP32_NimBLE.h>
//#include <hardware/BLEMIDI_ESP32.h>
//#include <hardware/BLEMIDI_nRF52.h>
//#include <hardware/BLEMIDI_ArduinoBLE.h>
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();
}

View File

@ -41,13 +41,13 @@ bool isConnected = false;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void setup() void setup()
{ {
MIDI.begin();
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW); digitalWrite(LED_BUILTIN, LOW);
BLEMIDI.setHandleConnected(OnConnected); BLEMIDI.setHandleConnected(OnConnected);
BLEMIDI.setHandleDisconnected(OnDisconnected); BLEMIDI.setHandleDisconnected(OnDisconnected);
MIDI.begin();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -27,7 +27,6 @@ private:
char mDeviceName[24]; char mDeviceName[24];
bool mIsSysEx;
uint8_t mTimestampLow; uint8_t mTimestampLow;
private: private:
@ -54,7 +53,7 @@ public:
{ {
getMidiTimestamp(&mTxBuffer[0], &mTxBuffer[1]); getMidiTimestamp(&mTxBuffer[0], &mTxBuffer[1]);
mTxIndex = 2; mTxIndex = 2;
mTimestampLow = mTxBuffer[1]; mTimestampLow = mTxBuffer[1]; // or generate new ?
return true; return true;
} }
@ -79,11 +78,11 @@ public:
mBleClass.write(mTxBuffer, mTxIndex - 1); mBleClass.write(mTxBuffer, mTxIndex - 1);
mTxIndex = 1; // keep header mTxIndex = 1; // keep header
mTxBuffer[mTxIndex++] = mTimestampLow; mTxBuffer[mTxIndex++] = mTimestampLow; // or generate new ?
} }
else else
{ {
mTxBuffer[mTxIndex - 1] = mTimestampLow; mTxBuffer[mTxIndex - 1] = mTimestampLow; // or generate new ?
} }
mTxBuffer[mTxIndex++] = 0xF7; mTxBuffer[mTxIndex++] = 0xF7;
} }