Skip to content

Commit 127b607

Browse files
committed
BLE docs
1 parent 52fcaf8 commit 127b607

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

libs/bluetooth/jswrap_bluetooth.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,18 @@ static void advertising_init(void)
440440
/*JSON{
441441
"type": "class",
442442
"class" : "NRF"
443-
}*/
443+
}
444+
The NRF class is for controlling functionality of the Nordic nRF51/nRF52 chips. Currently these are only used in the [BBC micro:bit](/MicroBit).
445+
446+
The main part of this is control of Bluetooth Smart - both searching for devices, and changing advertising data.
447+
*/
444448
/*JSON{
445449
"type" : "object",
446450
"name" : "Bluetooth",
447451
"instanceof" : "Serial",
448452
"#ifdef" : "BLUETOOTH"
449453
}
450-
The USB Serial port
454+
The Bluetooth Serial port - used when data is sent or received over Bluetooth Smart on nRF51/nRF52 chips.
451455
*/
452456

453457
void jswrap_nrf_bluetooth_init(void) {
@@ -467,7 +471,9 @@ void jswrap_nrf_bluetooth_init(void) {
467471
"class" : "NRF",
468472
"name" : "sleep",
469473
"generate" : "jswrap_nrf_bluetooth_sleep"
470-
}*/
474+
}
475+
Disable Bluetooth communications
476+
*/
471477
void jswrap_nrf_bluetooth_sleep(void) {
472478
uint32_t err_code;
473479

@@ -488,7 +494,9 @@ void jswrap_nrf_bluetooth_sleep(void) {
488494
"class" : "NRF",
489495
"name" : "wake",
490496
"generate" : "jswrap_nrf_bluetooth_wake"
491-
}*/
497+
}
498+
Enable Bluetooth communications (they are enabled by default)
499+
*/
492500
void jswrap_nrf_bluetooth_wake(void) {
493501
NRF_RADIO->TASKS_DISABLE = (0UL);
494502
jswrap_nrf_bluetooth_startAdvertise();
@@ -541,8 +549,11 @@ JsVarFloat jswrap_nrf_bluetooth_getBattery(void) {
541549
["data","JsVar","The data to advertise as an object - see below for more info"]
542550
]
543551
}
552+
Change the data that Espruino advertises.
553+
554+
Data is of the form `{ UUID : data_as_byte_array }`. The UUID should be a [Bluetooth Service ID](https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx).
544555
545-
Data is of the form `{ UUID : data_as_byte_array }`. For example to return battery level at 95%, do:
556+
For example to return battery level at 95%, do:
546557
547558
```
548559
NRF.setAdvertising({
@@ -555,7 +566,7 @@ Or you could report the current temperature:
555566
```
556567
setInterval(function() {
557568
NRF.setAdvertising({
558-
0x1809 : [0|E.getTemperature()]
569+
0x1809 : [Math,round(E.getTemperature())]
559570
});
560571
}, 30000);
561572
```
@@ -603,7 +614,7 @@ void jswrap_nrf_bluetooth_setAdvertising(JsVar *data) {
603614
]
604615
}
605616
606-
Start/stop listening for BLE advertising packets within range...
617+
Start/stop listening for BLE advertising packets within range.
607618
608619
```
609620
// Start scanning

0 commit comments

Comments
 (0)