cleanup
This commit is contained in:
parent
ba7c598a52
commit
5f8a38a5b8
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue