1
+ /*
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2023 Micro:bit Educational Foundation
5
+ Copyright (c) 2023 Lancaster University
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a
8
+ copy of this software and associated documentation files (the "Software"),
9
+ to deal in the Software without restriction, including without limitation
10
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
+ and/or sell copies of the Software, and to permit persons to whom the
12
+ Software is furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
+ DEALINGS IN THE SOFTWARE.
24
+ */
1
25
#include " MicroBit.h"
2
26
#include " Synthesizer.h"
3
27
#include " StreamRecording.h"
@@ -302,6 +326,25 @@ static void onStart() {
302
326
uBit.display .print (HEART);
303
327
}
304
328
329
+ static void clearDataLoggingStorage () {
330
+ // This 32-bit word will be initially stored in flash as 0xffffffff
331
+ // On first run, it will be cleared to 0x00000000 in flash, to be able to
332
+ // use it as a flag to only erase the data logging storage once
333
+ static const uint32_t flash_original_value __ALIGNED (4 ) = 0xffffffff ;
334
+ uint32_t zero = 0x00000000 ;
335
+
336
+ NRF52FlashManager flashManager (0 , 128 , 4096 );
337
+
338
+ // Read the value currently in flash
339
+ uint32_t flash_current_value;
340
+ flashManager.read (&flash_current_value, (uint32_t )&flash_original_value, 1 );
341
+ if (flash_current_value) {
342
+ // Value is not cleared yet, so full erase data storage and clear the flag
343
+ uBit.log .clear (true );
344
+ flashManager.write ((uint32_t )&flash_original_value, &zero, 1 );
345
+ }
346
+ }
347
+
305
348
void out_of_box_experience () {
306
349
uBit.messageBus .listen (MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA);
307
350
uBit.messageBus .listen (MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB);
@@ -312,8 +355,11 @@ void out_of_box_experience() {
312
355
313
356
onStart ();
314
357
315
- // uBit.audio.rawSplitter->status |= DEVICE_COMPONENT_STATUS_SYSTEM_TICK;
316
- // uBit.audio.splitter->status |= DEVICE_COMPONENT_STATUS_SYSTEM_TICK;
358
+ // The Out of Box Experience is the default programme loaded to micro:bit from factory.
359
+ // It can be flashed to a micro:bit to resemble a "factory reset"
360
+ // For that, the data logging storage should be fully erased (by default it will do a quick erase)
361
+ // This process can take several seconds, so it is done in a separate fiber
362
+ create_fiber (clearDataLoggingStorage);
317
363
318
364
while (true ) {
319
365
uBit.sleep (1000 );
0 commit comments