bootgattbat: handle bleAdvert array

pull/2956/head
Rob Pilling 2023-08-08 07:49:30 +01:00
parent 614c003eca
commit b86d2bd841
3 changed files with 19 additions and 2 deletions

View File

@ -1 +1,2 @@
0.01: Initial release.
0.02: Handle the case where other apps have set bleAdvert to an array

View File

@ -1,6 +1,22 @@
(() => {
function advertiseBattery() {
Bangle.bleAdvert[0x180F] = [E.getBattery()];
if(Array.isArray(Bangle.bleAdvert)){
// ensure we're in the cycle
var found = false;
for(var ad in Bangle.bleAdvert){
if(ad[0x180F]){
ad[0x180F] = [E.getBattery()];
found = true;
break;
}
}
if(!found)
Bangle.bleAdvert.push({ 0x180F: [E.getBattery()] });
}else{
// simple object
Bangle.bleAdvert[0x180F] = [E.getBattery()];
}
NRF.setAdvertising(Bangle.bleAdvert);
}

View File

@ -2,7 +2,7 @@
"id": "bootgattbat",
"name": "BLE GATT Battery Service",
"shortName": "BLE Battery Service",
"version": "0.01",
"version": "0.02",
"description": "Adds the GATT Battery Service to advertise the percentage of battery currently remaining over Bluetooth.\n",
"icon": "bluetooth.png",
"type": "bootloader",