From 7de74ffd23c760f543e303cba595de20e92cbf33 Mon Sep 17 00:00:00 2001 From: lathoub Date: Wed, 24 Oct 2018 12:04:31 +0200 Subject: [PATCH] added noteOn --- src/Ble_esp32.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Ble_esp32.h b/src/Ble_esp32.h index b7fc176..4c214ba 100644 --- a/src/Ble_esp32.h +++ b/src/Ble_esp32.h @@ -15,6 +15,8 @@ protected: BLEAdvertising *pAdvertising; BLECharacteristic *pCharacteristic; + bool _connected; + public: void(*mConnectedCallback)(); void(*mDisconnectedCallback)(); @@ -31,11 +33,32 @@ public: } inline bool begin(const char* deviceName); + + inline void noteOn(int note, int velocity, int channel) { + + if (!_connected) return; + if (pCharacteristic == NULL) return; + + uint8_t midiPacket[] = { + 0x80, // header + 0x80, // timestamp, not implemented + 0x00, // status + 0x3c, // 0x3c == 60 == middle c + 0x00 // velocity + }; + + midiPacket[2] = note; // note, channel 0 + midiPacket[4] = velocity; // velocity + pCharacteristic->setValue(midiPacket, 5); // packet, length in bytes + pCharacteristic->notify(); + } inline void onConnected(void(*fptr)()) { + _connected = true; mConnectedCallback = fptr; } inline void onDisconnected(void(*fptr)()) { + _connected = false; mDisconnectedCallback = fptr; } };