diff --git a/libraries/Bluefruit52Lib/examples/blemidi/blemidi.ino b/libraries/Bluefruit52Lib/examples/blemidi/blemidi.ino index d74ad8ab..6f77d553 100644 --- a/libraries/Bluefruit52Lib/examples/blemidi/blemidi.ino +++ b/libraries/Bluefruit52Lib/examples/blemidi/blemidi.ino @@ -36,10 +36,22 @@ void setup() bledis.setHardwareRev("Rev E"); bledis.setFirmwareRev("0.1.0"); bledis.start(); - - // Configure and Start BLE MIDI Service + + /* Start BLE MIDI + * Note: Apple requires BLE device must have min connection interval >= 20m + * ( The smaller the connection interval the faster we could send data). + * However for HID and MIDI device, Apple could accept min connection interval + * up to 11.25 ms. Therefore BLEMidi::start() will try to set the min and max + * connection interval to 11.25 ms and 15 ms respectively for best performance. + */ blemidi.start(); + /* Set connection interval (min, max) to your perferred value. + * Note: It is already set by BLEMidi::start() to 11.25ms - 15ms + * min = 9*1.25=11.25 ms, max = 12*1.25= 15 ms + */ + /* Bluefruit.setConnInterval(9, 12); */ + // Set up Advertising Packet setupAdv(); @@ -71,6 +83,8 @@ void loop() blemidi.send(0x90, current_note, 0x64); delay(500); + ledToggle(LED_BUILTIN); + // send note off blemidi.send(0x80, current_note, 0x64); delay(500); diff --git a/libraries/Bluefruit52Lib/src/services/BLEMidi.cpp b/libraries/Bluefruit52Lib/src/services/BLEMidi.cpp index 6e66ba51..bba16ac2 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEMidi.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEMidi.cpp @@ -49,7 +49,7 @@ const uint8_t BLEMIDI_UUID_SERVICE[] = const uint8_t BLEMIDI_UUID_CHR_IO[] = { 0xF3, 0x6B, 0x10, 0x9D, 0x66, 0xF2, 0xA9, 0xA1, - 0x12, 0x41, 0x68, 0x38, 0xD8, 0xE5, 0x72, 0x77 + 0x12, 0x41, 0x68, 0x38, 0xDB, 0xE5, 0x72, 0x77 }; /*------------------------------------------------------------------*/ @@ -122,12 +122,18 @@ BLEMidi::BLEMidi(void) void blemidi_write_cb(BLECharacteristic& chr, ble_gatts_evt_write_t* request) { - + if ( chr.handles().cccd_handle == request->handle ) + { + PRINT_LOCATION(); + }else if ( chr.handles().value_handle == request->handle ) + { + PRINT_LOCATION(); + } } bool BLEMidi::configured() { - return _io.notifyEnabled(); + return Bluefruit.connBonded() && _io.notifyEnabled(); } err_t BLEMidi::send(uint8_t data[]) @@ -149,7 +155,7 @@ err_t BLEMidi::send(uint8_t data[]) memcpy(event.data, data, 3); - VERIFY_STATUS( _io.notify(data, 3) ); + VERIFY_STATUS( _io.notify(&event, sizeof(event)) ); return ERROR_NONE; } @@ -171,5 +177,8 @@ err_t BLEMidi::start(void) VERIFY_STATUS( _io.start() ); + // Attempt to change the connection interval to 11.25-15 ms when starting HID + Bluefruit.setConnInterval(9, 12); + return ERROR_NONE; }