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; BLEAdvertising *pAdvertising;
BLECharacteristic *pCharacteristic; BLECharacteristic *pCharacteristic;
bool _connected;
public: public:
void(*mConnectedCallback)(); void(*mConnectedCallback)();
void(*mDisconnectedCallback)(); void(*mDisconnectedCallback)();
@ -32,10 +34,31 @@ public:
inline bool begin(const char* deviceName); 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)()) { inline void onConnected(void(*fptr)()) {
_connected = true;
mConnectedCallback = fptr; mConnectedCallback = fptr;
} }
inline void onDisconnected(void(*fptr)()) { inline void onDisconnected(void(*fptr)()) {
_connected = false;
mDisconnectedCallback = fptr; mDisconnectedCallback = fptr;
} }
}; };