Skip to content

Commit c5b6840

Browse files
committed
Fix Jira 676 and Jira 685
1. Jira 676 Review Edit Update BLE User Manual with China Flex 2. Jira 685 BLE Peripheral sketches shall state which associated Central sketch to use
1 parent 09c43be commit c5b6840

File tree

9 files changed

+102
-53
lines changed

9 files changed

+102
-53
lines changed

libraries/CurieBLE/examples/BatteryMonitor/BatteryMonitor.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're pr
1515
BLEService batteryService("180F"); // BLE Battery Service
1616

1717
// BLE Battery Level Characteristic"
18-
BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID
18+
BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID defined in the URL above
1919
BLERead | BLENotify); // remote clients will be able to
20-
// get notifications if this characteristic changes
20+
// get notifications if this characteristic changes
2121

2222
int oldBatteryLevel = 0; // last battery level reading from analog input
2323
long previousMillis = 0; // last time the battery level was checked, in ms

libraries/CurieBLE/examples/ButtonLED/ButtonLED.ino

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ const int ledPin = 13; // set ledPin to on-board LED
99
const int buttonPin = 4; // set buttonPin to digital pin 4
1010

1111
BLEPeripheral blePeripheral; // create peripheral instance
12-
BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service
12+
BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service with a 128-bit UUID (32 characters exclusive of dashes).
13+
// Long UUID denote custom user created UUID
1314

1415

1516
// create switch characteristic and allow remote device to read and write
1617
BLECharCharacteristic ledCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
1718
// create button characteristic and allow remote device to get notifications
1819
BLECharCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); // allows remote device to get notifications
20+
// Note use of Typed Characteristics. These previous 2 characeristics are of the type char
1921

2022
void setup() {
2123
Serial.begin(9600);
@@ -32,6 +34,7 @@ void setup() {
3234
blePeripheral.addAttribute(ledCharacteristic);
3335
blePeripheral.addAttribute(buttonCharacteristic);
3436

37+
// set initial values for led and button characteristic
3538
ledCharacteristic.setValue(0);
3639
buttonCharacteristic.setValue(0);
3740

@@ -59,10 +62,13 @@ void loop() {
5962

6063
if (ledCharacteristic.written() || buttonChanged) {
6164
// update LED, either central has written to characteristic or button state has changed
65+
// if you are using a phone or a BLE central device that is aware of this characteristic, writing a value of 0x40 for example
66+
// Will be interpreted as written
6267
if (ledCharacteristic.value()) {
6368
Serial.println("LED on");
6469
digitalWrite(ledPin, HIGH);
6570
} else {
71+
// If central writes a 0 value then it is interpreted as no value and turns off the LED
6672
Serial.println("LED off");
6773
digitalWrite(ledPin, LOW);
6874
}

libraries/CurieBLE/examples/CallbackLED/CallbackLED.ino

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22
* Copyright (c) 2016 Intel Corporation. All rights reserved.
33
* See the bottom of this file for the license terms.
44
*/
5+
6+
// This example can work with LEDCentral
7+
//
8+
// This example demonstartes the use of Callback or event Handlers responding to events
9+
// BLECoonected, BLEDisconnected and BLEWritten are events.
10+
// To Test use a Phone app lie nrf Controller (Android) or Light Blue (iOS)
11+
// Connect to BLE device named LEDCB and explore characteristic with UUID 19B10001-E8F2-537E-4F6C-D104768A1214
12+
// Writing a byte value suck as 0x40 should turn on the LED
13+
// Writng a byte value of 0x00 should turn off the LED
514

615
#include <CurieBLE.h>
716

817
const int ledPin = 13; // set ledPin to use on-board LED
918
BLEPeripheral blePeripheral; // create peripheral instance
1019

11-
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service
20+
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service with a 128-bit UUID (32 characters exclusive of dashes).
21+
// Long UUID denote custom user created UUID
1222

1323
// create switch characteristic and allow remote device to read and write
1424
BLECharCharacteristic switchChar("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
@@ -45,6 +55,9 @@ void loop() {
4555
blePeripheral.poll();
4656
}
4757

58+
// The function parameter (BLEHelper& central) is for peripheral devices
59+
// This enable us to have access to the central's data like its bluetooth address
60+
4861
void blePeripheralConnectHandler(BLEHelper& central) {
4962
// central connected event handler
5063
Serial.print("Connected event, central: ");
@@ -57,6 +70,8 @@ void blePeripheralDisconnectHandler(BLEHelper& central) {
5770
Serial.println(central.address());
5871
}
5972

73+
// In addtion to the BLECentral& central parameter, we also have to have to BLECharacteristic& characteristic parameter
74+
6075
void switchCharacteristicWritten(BLEHelper& central, BLECharacteristic& characteristic) {
6176
// central wrote new value to characteristic, update LED
6277
Serial.print("Characteristic event, written: ");

libraries/CurieBLE/examples/IMUBleCentral/IMUBleCentral.ino

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@
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+
2123
typedef struct {
2224
int index;
2325
unsigned int slot[3];
@@ -30,28 +32,24 @@ BLEService bleImuService("F7580001-153E-D4F6-F26D-43D8D98EEB13");
3032
BLECharacteristic 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
3436
bool adv_found(uint8_t type,
3537
const uint8_t *data,
3638
uint8_t data_len,
3739
void *user_data);
3840

3941
void 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

6563
void 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

7072
void 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:

libraries/CurieBLE/examples/IMUBleNotification/IMUBleNotification.ino

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typedef struct {
1919
unsigned int slot[3];
2020
} imuFrameType;
2121

22+
// Buffer to hold IMU data
2223
imuFrameType imuBuf[MAX_IMU_RECORD];
2324

2425
unsigned seqNum = 0;
@@ -40,20 +41,21 @@ void setup()
4041
The name can be changed but maybe be truncated based on space left in advertisement packet */
4142
blePeripheral.setLocalName("Imu");
4243
blePeripheral.setAdvertisedServiceUuid(bleImuService.uuid()); // add the service UUID
43-
blePeripheral.addAttribute(bleImuService); // Add the BLE Battery service
44-
blePeripheral.addAttribute(bleImuChar); // add the battery level characteristic
44+
blePeripheral.addAttribute(bleImuService); // Add the Imu service
45+
blePeripheral.addAttribute(bleImuChar); // add the Imu characteristic
4546

4647
/* Now activate the BLE device. It will start continuously transmitting BLE
4748
advertising packets and will be visible to remote BLE central devices
4849
until it receives a new connection */
4950
blePeripheral.begin();
50-
51+
// Start the IMU
5152
CurieIMU.begin();
5253
}
5354

5455
void loop()
5556
{
5657
// listen for BLE peripherals to connect:
58+
// Since we are a peripheral we need a central object to connect to
5759
BLECentralHelper central = blePeripheral.central();
5860

5961
// if a central is connected to peripheral:
@@ -82,7 +84,7 @@ void loop()
8284
sentTime = millis();
8385
bleImuChar.setValue((unsigned char *)&(imuBuf[0]), sizeof(imuBuf));
8486
}
85-
} // while
87+
} // end of while loop
8688

8789
// when the central disconnects, turn off the LED:
8890
digitalWrite(13, LOW);
@@ -91,6 +93,7 @@ void loop()
9193
}
9294
}
9395

96+
// This function records the IMU data that we send to the central
9497
void recordImuData(int index)
9598
{
9699
/* Read IMU data.
@@ -100,7 +103,8 @@ void recordImuData(int index)
100103

101104
imuBuf[index].index = seqNum++;
102105
CurieIMU.readMotionSensor(ax, ay, az, gx, gy, gz);
103-
106+
107+
// Encode the data into the buffer
104108
imuBuf[index].slot[0] = (unsigned int)((ax << 16) | (ay & 0x0FFFF));
105109
imuBuf[index].slot[1] = (unsigned int)((az << 16) | (gx & 0x0FFFF));
106110
imuBuf[index].slot[2] = (unsigned int)((gy << 16) | (gz & 0x0FFFF));

libraries/CurieBLE/examples/LED/LED.ino

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22
* Copyright (c) 2016 Intel Corporation. All rights reserved.
33
* See the bottom of this file for the license terms.
44
*/
5-
5+
6+
// This example can work with LEDCentral
7+
//
8+
// This example is similar to CallbackLED example in functionality
9+
// It does not use callbacks. In the loop it interogates the connection state with central
10+
// Checks if the characteristic is wriiten and turns of the LED accordingly
11+
// To Test use a Phone app lie nrf Controller (Android) or Light Blue (iOS)
12+
// Connect to BLE device named LEDCB and explore characteristic with UUID 19B10001-E8F2-537E-4F6C-D104768A1214
13+
// Writing a byte value suck as 0x40 should turn on the LED
14+
// Writng a byte value of 0x00 should turn off the LED
15+
616
#include <CurieBLE.h>
717

818
BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're programming)

libraries/CurieBLE/examples/LEDCentral/LEDCentral.ino

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@
66
#include <CurieBLE.h>
77

88
/*
9-
This example can work with CallbackLED
10-
to show the profile read/write operation in central
9+
This example can work with CallbackLED and LED
10+
to show how a central device can do charcteristic read and write operations.
11+
A third party serial terminal is recommended to see outputs from central and peripheral device
1112
*/
1213

13-
ble_conn_param_t conn_param = {30.0, //ms
14-
50.0, //ms
15-
0,
16-
4000 //ms
14+
// set up connection params
15+
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
1720
};
1821

1922
const int ledPin = 13; // set ledPin to use on-board LED
2023
BLECentral bleCentral; // create central instance
2124
BLEPeripheralHelper *blePeripheral1 = NULL;
2225

23-
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service
26+
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service with a 128-bit UUID (32 characters exclusive of dashes).
27+
// Long UUID denote custom user created UUID
2428
BLECharCharacteristic switchChar("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);// create switch characteristic and allow remote device to read and write
2529

30+
// function prototype for function that determines if the advertising data is found
2631
bool adv_found(uint8_t type,
2732
const uint8_t *data,
2833
uint8_t data_len,

libraries/CurieBLE/examples/MIDIBLE/MIDIBLE.ino

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
Towards the bottom of advanced, you will see 'Bluetooth MIDI devices'.
2626
You should see your Arduino 101 advertising in the list. Connect to
2727
your device and it should be available to all other iOS MIDI apps you have.
28+
29+
If you do not have iOS, you can still use a BLE app on Android and just subscribe
30+
to the midiChar charcteristic and see the updates.
2831
2932
To send data, you use the following line: char.setValue(d, n); where char is
3033
the BLE characteristic (in our case, midiCha), d is the data, and n is the
@@ -98,6 +101,21 @@ void setup() {
98101
Serial.println(("Bluetooth device active, waiting for connections..."));
99102
}
100103

104+
void loop() {
105+
106+
/*Simple randome note player to test MIDI output
107+
Plays random note every 400ms
108+
*/
109+
int note = random(0, 127);
110+
//readMIDI();
111+
noteOn(0, note, 127); //loads up midiData buffer
112+
midiChar.setValue(midiData, 5);//midiData); //posts 5 bytes
113+
delay(200);
114+
noteOff(0, note);
115+
midiChar.setValue(midiData, 5);//midiData); //posts 5 bytes
116+
delay(200);
117+
}
118+
101119
void BLESetup()
102120
{
103121
// set the local name peripheral advertises
@@ -124,22 +142,6 @@ void BLESetup()
124142
midiDevice.begin();
125143
}
126144

127-
void loop() {
128-
129-
/*Simple randome note player to test MIDI output
130-
Plays random note every 400ms
131-
*/
132-
int note = random(0, 127);
133-
//readMIDI();
134-
noteOn(0, note, 127); //loads up midiData buffer
135-
midiChar.setValue(midiData, 5);//midiData); //posts 5 bytes
136-
delay(200);
137-
noteOff(0, note);
138-
midiChar.setValue(midiData, 5);//midiData); //posts 5 bytes
139-
delay(200);
140-
}
141-
142-
143145
void midiDeviceConnectHandler(BLEHelper& central) {
144146
// central connected event handler
145147
Serial.print("Connected event, central: ");

libraries/CurieBLE/examples/Scanning/Scanning.ino

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
The list will refresh every 3s
1212
*/
1313

14-
#define BLE_SCANING_DEVICE_MAX_CNT 5
14+
15+
const int bleScanMaxCnt = 5;
1516

1617
typedef struct{
1718
char macaddr[32]; // BLE MAC address.
1819
char loacalname[22]; // Device's name
1920
}ble_device_info_t;
2021

21-
ble_device_info_t device_list[BLE_SCANING_DEVICE_MAX_CNT];
22+
ble_device_info_t device_list[bleScanMaxCnt];
2223
uint8_t list_index = 0;
2324

2425
BLECentral bleCentral; // BLE Central Device (the board you're programming)
@@ -64,9 +65,10 @@ void loop()
6465
adv_list_clear();
6566
}
6667

68+
// Add the scanned BLE device into the global variables.
6769
bool adv_list_add(ble_device_info_t &device)
6870
{
69-
if (list_index >= BLE_SCANING_DEVICE_MAX_CNT)
71+
if (list_index >= bleScanMaxCnt)
7072
{
7173
return false;
7274
}
@@ -115,7 +117,7 @@ bool adv_found(uint8_t type,
115117
ble_device_info_t device;
116118
bt_addr_le_to_str (addr, device.macaddr, sizeof (device.macaddr));
117119
memcpy(device.loacalname, " -NA-", sizeof(" -NA-"));
118-
120+
// Please see https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
119121
switch (type) {
120122
case BT_DATA_NAME_SHORTENED:
121123
case BT_DATA_NAME_COMPLETE:

0 commit comments

Comments
 (0)