Remove caching of getSerial(); use temporary for BLE init
This commit is contained in:
parent
2877fd68f2
commit
59853855b0
|
@ -77,7 +77,6 @@ class MicroBit
|
||||||
|
|
||||||
void seedRandom();
|
void seedRandom();
|
||||||
uint32_t randomValue;
|
uint32_t randomValue;
|
||||||
ManagedString serialCache;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,9 @@ void MicroBit::init()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_ENABLED(MICROBIT_BLE_DEVICE_INFORMATION_SERVICE)
|
#if CONFIG_ENABLED(MICROBIT_BLE_DEVICE_INFORMATION_SERVICE)
|
||||||
DeviceInformationService ble_device_information_service (*ble, MICROBIT_BLE_MANUFACTURER, MICROBIT_BLE_MODEL, getSerial().toCharArray(), MICROBIT_BLE_HARDWARE_VERSION, MICROBIT_BLE_FIRMWARE_VERSION, MICROBIT_BLE_SOFTWARE_VERSION);
|
// Create a temporary, so that compiler doesn't delete the pointer before DeviceInformationService copies it
|
||||||
|
ManagedString tmp = getSerial();
|
||||||
|
DeviceInformationService ble_device_information_service (*ble, MICROBIT_BLE_MANUFACTURER, MICROBIT_BLE_MODEL, tmp.toCharArray(), MICROBIT_BLE_HARDWARE_VERSION, MICROBIT_BLE_FIRMWARE_VERSION, MICROBIT_BLE_SOFTWARE_VERSION);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_ENABLED(MICROBIT_BLE_EVENT_SERVICE)
|
#if CONFIG_ENABLED(MICROBIT_BLE_EVENT_SERVICE)
|
||||||
|
@ -221,9 +223,6 @@ ManagedString MicroBit::getName()
|
||||||
*/
|
*/
|
||||||
ManagedString MicroBit::getSerial()
|
ManagedString MicroBit::getSerial()
|
||||||
{
|
{
|
||||||
if (serialCache.length() > 0)
|
|
||||||
return serialCache;
|
|
||||||
|
|
||||||
// We take to 16 bit numbers here, as we want the full range of ID bits, but don't want negative numbers...
|
// We take to 16 bit numbers here, as we want the full range of ID bits, but don't want negative numbers...
|
||||||
int n1 = NRF_FICR->DEVICEID[1] & 0xffff;
|
int n1 = NRF_FICR->DEVICEID[1] & 0xffff;
|
||||||
int n2 = (NRF_FICR->DEVICEID[1] >> 16) & 0xffff;
|
int n2 = (NRF_FICR->DEVICEID[1] >> 16) & 0xffff;
|
||||||
|
@ -232,9 +231,7 @@ ManagedString MicroBit::getSerial()
|
||||||
ManagedString s1 = ManagedString(n1);
|
ManagedString s1 = ManagedString(n1);
|
||||||
ManagedString s2 = ManagedString(n2);
|
ManagedString s2 = ManagedString(n2);
|
||||||
|
|
||||||
serialCache = s1 + s2;
|
return s1 + s2;
|
||||||
|
|
||||||
return serialCache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue