diff --git a/apps/bootgattbat/ChangeLog b/apps/bootgattbat/ChangeLog index 2a37193a3..df07f6ad0 100644 --- a/apps/bootgattbat/ChangeLog +++ b/apps/bootgattbat/ChangeLog @@ -1 +1,2 @@ 0.01: Initial release. +0.02: Handle the case where other apps have set bleAdvert to an array diff --git a/apps/bootgattbat/boot.js b/apps/bootgattbat/boot.js index d67b766b5..34d9f8d93 100644 --- a/apps/bootgattbat/boot.js +++ b/apps/bootgattbat/boot.js @@ -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); } diff --git a/apps/bootgattbat/metadata.json b/apps/bootgattbat/metadata.json index 95a521f47..f67b4507d 100644 --- a/apps/bootgattbat/metadata.json +++ b/apps/bootgattbat/metadata.json @@ -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",