@@ -102,18 +102,15 @@ static mp_obj_t async_repeat_iterable = NULL;
102
102
static mp_obj_t async_iterator = NULL ;
103
103
// Record if an error occurs in async animation. Unfortunately there is no way to report this.
104
104
static bool async_error = false ;
105
+ static volatile bool wakeup_event = false ;
105
106
static uint16_t async_nonce = 0 ;
106
107
static mp_uint_t async_delay = 1000 ;
107
108
static mp_uint_t async_tick = 0 ;
108
109
109
- STATIC void wakeup_event () {
110
- // Wake up any fibers that were blocked on the animation (if any).
111
- MicroBitEvent event (MICROBIT_ID_ALERT, async_nonce);
112
- }
113
-
114
110
STATIC void wait_for_event () {
115
- async_nonce = uBit.MessageBus .nonce ();
116
- fiber_wait_for_event (MICROBIT_ID_ALERT, async_nonce);
111
+ while (!wakeup_event)
112
+ __WFI ();
113
+ wakeup_event = false ;
117
114
}
118
115
119
116
STATIC void async_stop (void ) {
@@ -125,7 +122,7 @@ STATIC void async_stop(void) {
125
122
MP_STATE_PORT (async_data)[0 ] = NULL ;
126
123
MP_STATE_PORT (async_data)[1 ] = NULL ;
127
124
MP_STATE_PORT (async_data)[2 ] = NULL ;
128
- wakeup_event () ;
125
+ wakeup_event = true ;
129
126
}
130
127
131
128
struct DisplayPoint {
@@ -250,6 +247,7 @@ static void microbit_display_update(void) {
250
247
case ASYNC_MODE_ANIMATION:
251
248
{
252
249
if (MP_STATE_PORT (async_data)[0 ] == NULL || MP_STATE_PORT (async_data)[1 ] == NULL ) {
250
+ async_stop ();
253
251
break ;
254
252
}
255
253
microbit_display_obj_t *display = (microbit_display_obj_t *)MP_STATE_PORT (async_data)[0 ];
@@ -314,6 +312,7 @@ void microbit_display_animate(microbit_display_obj_t *self, mp_obj_t iterable, m
314
312
async_repeat_iterable = iterable;
315
313
MP_STATE_PORT (async_data)[2 ] = iterable;
316
314
}
315
+ wakeup_event = false ;
317
316
async_mode = ASYNC_MODE_ANIMATION;
318
317
if (wait) {
319
318
wait_for_event ();
@@ -378,6 +377,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(microbit_display_scroll_obj, 1, microbit_display_scro
378
377
379
378
void microbit_display_clear (void ) {
380
379
// Reset repeat state, cancel animation and clear screen.
380
+ wakeup_event = false ;
381
381
async_mode = ASYNC_MODE_CLEAR;
382
382
async_tick = async_delay - FIBER_TICK_PERIOD_MS;
383
383
wait_for_event ();
@@ -461,9 +461,25 @@ microbit_display_obj_t microbit_display_obj = {
461
461
.strobe_mask = 0x20
462
462
};
463
463
464
+ extern bool compass_up_to_date;
465
+ extern bool accelerometer_up_to_date;
466
+
464
467
static void ticker (void ) {
465
- // Make sure we call the DAL ticker function.
466
- uBit.systemTick ();
468
+
469
+ // increment our real-time counter.
470
+ ticks += FIBER_TICK_PERIOD_MS;
471
+
472
+ if (uBit.compass .isCalibrating ()) {
473
+ uBit.compass .idleTick ();
474
+ }
475
+
476
+ compass_up_to_date = false ;
477
+ accelerometer_up_to_date = false ;
478
+
479
+ // Update buttons
480
+ uBit.buttonA .systemTick ();
481
+ uBit.buttonB .systemTick ();
482
+
467
483
// Update the display.
468
484
microbit_display_tick ();
469
485
}
0 commit comments