Cache getSerial(); otherwise BLE information device initalization may crash
This commit is contained in:
parent
8924cab6da
commit
057158c9f3
2 changed files with 7 additions and 1 deletions
|
@ -77,6 +77,7 @@ class MicroBit
|
|||
|
||||
void seedRandom();
|
||||
uint32_t randomValue;
|
||||
ManagedString serialCache;
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -221,6 +221,9 @@ ManagedString MicroBit::getName()
|
|||
*/
|
||||
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...
|
||||
int n1 = NRF_FICR->DEVICEID[1] & 0xffff;
|
||||
int n2 = (NRF_FICR->DEVICEID[1] >> 16) & 0xffff;
|
||||
|
@ -229,7 +232,9 @@ ManagedString MicroBit::getSerial()
|
|||
ManagedString s1 = ManagedString(n1);
|
||||
ManagedString s2 = ManagedString(n2);
|
||||
|
||||
return s1+s2;
|
||||
serialCache = s1 + s2;
|
||||
|
||||
return serialCache;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue