added noteOn

This commit is contained in:
lathoub 2018-10-24 12:04:31 +02:00
parent bf0ae6be04
commit 7de74ffd23
1 changed files with 23 additions and 0 deletions

View File

@ -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;
}
};