Odometry Pedometer using nRF51822 and ADXL345
Dependencies: ADXL345 BLE_API mbed nRF51822
Fork of BLE_CycleSpeedCadence by
Revision 52:6bbf62943106, committed 2014-11-21
- Comitter:
- rgrover1
- Date:
- Fri Nov 21 10:12:28 2014 +0000
- Parent:
- 51:cba5deb3b404
- Child:
- 53:06a74fd722b8
- Commit message:
- add some code to configure slower connection interval
Changed in this revision
--- a/BLE_API.lib Thu Nov 20 14:47:12 2014 +0200 +++ b/BLE_API.lib Fri Nov 21 10:12:28 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#fede41ce9407 +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#a7ded9ad83c8
--- 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;
--- a/nRF51822.lib Thu Nov 20 14:47:12 2014 +0200 +++ b/nRF51822.lib Fri Nov 21 10:12:28 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#61da91a52bd6 +http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#9a5ba2c5d53c
