From 8c3a58e0d7b8eff1062b6f89f411d3386ed27ad4 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Fri, 24 May 2024 17:33:20 +0100 Subject: [PATCH] NRF: getAddress(1) returns the current BLE address --- libs/bluetooth/jswrap_bluetooth.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/bluetooth/jswrap_bluetooth.c b/libs/bluetooth/jswrap_bluetooth.c index 788874f511..093b0c5984 100644 --- a/libs/bluetooth/jswrap_bluetooth.c +++ b/libs/bluetooth/jswrap_bluetooth.c @@ -707,14 +707,20 @@ void jswrap_ble_eraseBonds() { "class" : "NRF", "name" : "getAddress", "generate" : "jswrap_ble_getAddress", + "params" : [ + ["current", "JsVar", "If true, return the current address rather than the default"] + ], "return" : ["JsVar", "MAC address - a string of the form 'aa:bb:cc:dd:ee:ff'" ] } -Get this device's default Bluetooth MAC address. +Get this device's default or current Bluetooth MAC address. For Puck.js, the last 5 characters of this (e.g. `ee:ff`) are used in the device's advertised Bluetooth name. */ -JsVar *jswrap_ble_getAddress() { +JsVar *jswrap_ble_getAddress(JsVar *current) { + if (jsvGetBool(current)) { + return jsvObjectGetChildIfExists(execInfo.hiddenRoot, BLE_NAME_MAC_ADDRESS); + } #ifdef NRF5X uint32_t addr0 = NRF_FICR->DEVICEADDR[0]; uint32_t addr1 = NRF_FICR->DEVICEADDR[1];