From 839f89af9339030262e6465c41dc75a862f8b2c3 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 28 Feb 2017 15:20:29 +0700 Subject: [PATCH] auto change connection interval to 11.25 - 15ms when starting BLEHidAdafruit --- cores/nRF5/common_func.h | 2 +- .../examples/hid_keyboard/hid_keyboard.ino | 16 +++++++++++++--- .../src/services/BLEHidAdafruit.cpp | 7 ++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/cores/nRF5/common_func.h b/cores/nRF5/common_func.h index 81b84420..04cfe9ef 100644 --- a/cores/nRF5/common_func.h +++ b/cores/nRF5/common_func.h @@ -101,7 +101,7 @@ int cprintf(const char * format, ...); #define PRINT_HEX(x) \ do {\ - cprintf("%s: %d: " #x " = ", __PRETTY_FUNCTION__, __LINE__);\ + cprintf("%s: %d: " #x " = 0x", __PRETTY_FUNCTION__, __LINE__);\ char fmt[] = "%00X\n";\ fmt[2] += 2*sizeof(x); /* Hex with correct size */\ cprintf(fmt, (x) );\ diff --git a/libraries/Bluefruit52Lib/examples/hid_keyboard/hid_keyboard.ino b/libraries/Bluefruit52Lib/examples/hid_keyboard/hid_keyboard.ino index a38ac657..b507b439 100644 --- a/libraries/Bluefruit52Lib/examples/hid_keyboard/hid_keyboard.ino +++ b/libraries/Bluefruit52Lib/examples/hid_keyboard/hid_keyboard.ino @@ -26,8 +26,6 @@ void setup() Serial.println("Bluefruit52 HID Keyboard Example"); Bluefruit.begin(); - // HID Device can have a min connection interval of 9*1.25 = 11.25 ms - Bluefruit.setConnInterval(9, 16); // min = 9*1.25=11.25 ms, max = 16*1.25=20ms Bluefruit.setName("Bluefruit52"); // Configure and Start Device Information Service @@ -40,9 +38,21 @@ void setup() // Configure and Start BLE Uart Service bleuart.start(); - // BLE HID + /* Start BLE HID + * 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 BLEHidAdafruit::start() will try to set the min and max + * connection interval to 11.25 ms and 15 ms respectively for best performance. + */ blehid.start(); + /* Set connection interval (min, max) to your perferred value. + * Note: It is already set by BLEHidAdafruit::start() to 11.25ms - 15ms + * min = 9*1.25=11.25 ms, max = 12*1.25= 15 ms + */ + /* Bluefruit.setConnInterval(9, 12); */ + // Setup Advertising Packet setupAdv(); diff --git a/libraries/Bluefruit52Lib/src/services/BLEHidAdafruit.cpp b/libraries/Bluefruit52Lib/src/services/BLEHidAdafruit.cpp index f9f67834..50cd9884 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEHidAdafruit.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEHidAdafruit.cpp @@ -213,7 +213,12 @@ err_t BLEHidAdafruit::start(void) enableBootProtocol(true, true); setReportMap(hid_report_descriptor, sizeof(hid_report_descriptor)); - return BLEHidGeneric::start(); + VERIFY_STATUS( BLEHidGeneric::start() ); + + // Attemp to change the connection interval to 11.25-15 ms when starting HID + Bluefruit.setConnInterval(9, 12); + + return ERROR_NONE; } /*------------------------------------------------------------------*/