Cache getSerial(); otherwise BLE information device initalization may crash

This commit is contained in:
Michal Moskal 2015-10-24 19:28:36 -07:00
parent 8924cab6da
commit 057158c9f3
2 changed files with 7 additions and 1 deletions

View file

@ -77,6 +77,7 @@ class MicroBit
void seedRandom();
uint32_t randomValue;
ManagedString serialCache;
public:

View file

@ -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;
}
/**