88/*
99 This sketch example works with IMUBleNotification.ino
1010 IMUBleNotification.ino will send Notification to this sketch.
11- This sketch will receive the Notifications and out put the received data.
11+ This sketch will receive the Notifications and out put the received data in the serail monitor
1212*/
1313
1414#define MAX_IMU_RECORD 1
1515
16- ble_conn_param_t conn_param = {30.0 , // ms
17- 50.0 , // ms
18- 0 ,
19- 4000 // ms
16+ ble_conn_param_t conn_param = {30.0 , // minimum interval in ms 7.5 - 4000
17+ 50.0 , // maximum interval in ms 7.5 -
18+ 0 , // latency
19+ 4000 // timeout in ms 100 - 32000ms
2020 };
21+ // define a structure that will serve as buffer for holding IMU data
22+
2123typedef struct {
2224 int index;
2325 unsigned int slot[3 ];
@@ -30,28 +32,24 @@ BLEService bleImuService("F7580001-153E-D4F6-F26D-43D8D98EEB13");
3032BLECharacteristic bleImuChar (" F7580003-153E-D4F6-F26D-43D8D98EEB13" , // standard 128-bit characteristic UUID
3133 BLERead | BLENotify, sizeof (imuBuf)); // remote clients will be able to
3234 // get notifications if this characteristic changes
33-
35+ // function prototype for function that determines if the advertising data is found
3436bool adv_found (uint8_t type,
3537 const uint8_t *data,
3638 uint8_t data_len,
3739 void *user_data);
3840
3941void setup ()
4042{
41- Serial.begin (115200 ); // initialize serial communication
43+ // This is set to higher baud rate because accelrometer data changes very quickly
44+ Serial.begin (115200 ); // initialize serial communication
4245 pinMode (13 , OUTPUT); // initialize the LED on pin 13 to indicate when a central is connected
43-
46+ // set the event handeler function for the bleImuChar characteristic
4447 bleImuChar.setEventHandler (BLEWritten, bleImuCharacteristicWritten);
4548
46- /* Set a local name for the BLE device
47- This name will appear in advertising packets
48- and can be used by remote devices to identify this BLE device
49- The name can be changed but maybe be truncated based on space
50- left in advertisement packet */
5149 bleCentral.addAttribute (bleImuService); // Add the BLE IMU service
5250 bleCentral.addAttribute (bleImuChar); // Add the BLE IMU characteristic
5351
54- /* Setup callback */
52+ // Setup callback whenever a Peripheral advertising data is found)
5553 bleCentral.setAdvertiseHandler (adv_found);
5654 bleCentral.setEventHandler (BLEConnected, ble_connected);
5755
@@ -64,19 +62,24 @@ void setup()
6462
6563void loop ()
6664{
65+ // we put a 2 second delay
66+ // Even though this looks empty, since we setup 2 callbacks by setting the advertising handler adv_found
67+ // and event handler for BLEConnected, we basically are lsitening for advertising data and connected event.
68+
6769 delay (2000 );
6870}
6971
7072void ble_connected (BLEHelper &role)
7173{
74+ // since we are a central device we create a BLEPeripheralHelper peripheral
7275 BLEPeripheralHelper&peripheral = *(BLEPeripheralHelper*)(&role);
7376 Serial.println (" Connected" );
7477
7578 // Start discovery the profiles in peripheral device
7679 peripheral.discover ();
7780}
7881
79- void bleImuCharacteristicWritten (BLEHelper& central , BLECharacteristic& characteristic)
82+ void bleImuCharacteristicWritten (BLEHelper& peripheral , BLECharacteristic& characteristic)
8083{
8184 // Peripheral wrote new value to characteristic by Notification/Indication
8285 const unsigned char *cvalue = characteristic.value ();
@@ -103,7 +106,9 @@ bool adv_found(uint8_t type,
103106 Serial.print (type);
104107 Serial.print (" data_len " );
105108 Serial.println (data_len);
106-
109+ // Please see https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
110+ // To decode the data the central device cares.
111+ // This example use UUID as identity.
107112 switch (type)
108113 {
109114 case BT_DATA_UUID128_SOME:
0 commit comments