cycle speed and cadence service
Dependencies: BLE_API mbed nRF51822
Fork of Bluetooth_Heart_Rate_Monitor_dummy by
Diff: main.cpp
- Revision:
- 52:6bbf62943106
- Parent:
- 50:477004d54431
- Child:
- 53:06a74fd722b8
--- a/main.cpp Thu Nov 20 14:47:12 2014 +0200 +++ b/main.cpp Fri Nov 21 10:12:28 2014 +0000 @@ -20,6 +20,12 @@ #include "BatteryService.h" #include "DeviceInformationService.h" +/* Enable the following if you need to throttle the connection interval. This has + * the effect of reducing energy consumption after a connection is made; + * particularly for applications where the central may want a fast connection + * interval.*/ +#define UPDATE_PARAMS_FOR_LONGER_CONNECTION_INTERVAL 0 + BLEDevice ble; DigitalOut led1(LED1); @@ -34,6 +40,28 @@ ble.startAdvertising(); // restart advertising } +void onConnectionCallback(Gap::Handle_t handle, Gap::addr_type_t peerAddrType, const Gap::address_t peerAddr, const Gap::ConnectionParams_t *params) +{ + #if UPDATE_PARAMS_FOR_LONGER_CONNECTION_INTERVAL + /* Updating connection parameters can be attempted only after a connection has been + * established. Please note that the ble-Central is still the final arbiter for + * the effective parameters; the peripheral can only hope that the request is + * honored. Please also be mindful of the constraints that might be enforced by + * the BLE stack on the underlying controller.*/ + #define MIN_CONN_INTERVAL 250 /**< Minimum connection interval (250 ms) */ + #define MAX_CONN_INTERVAL 350 /**< Maximum connection interval (350 ms). */ + #define CONN_SUP_TIMEOUT 6000 /**< Connection supervisory timeout (6 seconds). */ + #define SLAVE_LATENCY 4 + + Gap::ConnectionParams_t gap_conn_params; + gap_conn_params.minConnectionInterval = Gap::MSEC_TO_GAP_DURATION_UNITS(MIN_CONN_INTERVAL); + gap_conn_params.maxConnectionInterval = Gap::MSEC_TO_GAP_DURATION_UNITS(MAX_CONN_INTERVAL); + gap_conn_params.connectionSupervisionTimeout = Gap::MSEC_TO_GAP_DURATION_UNITS(CONN_SUP_TIMEOUT); + gap_conn_params.slaveLatency = SLAVE_LATENCY; + ble.updateConnectionParams(handle, &gap_conn_params); + #endif /* #if UPDATE_PARAMS_FOR_LONGER_CONNECTION_INTERVAL */ +} + void periodicCallback(void) { led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */ @@ -51,6 +79,9 @@ ble.init(); ble.onDisconnection(disconnectionCallback); +#if UPDATE_PARAMS_FOR_LONGER_CONNECTION_INTERVAL + ble.onConnection(onConnectionCallback); +#endif /* #if UPDATE_PARAMS_FOR_LONGER_CONNECTION_INTERVAL */ /* Setup primary service. */ uint8_t hrmCounter = 100;