Skip to content

Commit 5b27805

Browse files
committed
pbio/sys/status: Handle status change synchronously.
This was using broadcast, but there was ultimately only one receiver for this data. We can simplify this and avoid the risk of overrunning the event queue by calling it synchronously, which is safe for this event. After the refactoring in the previous commit, this is now a trivial change.
1 parent da6a32f commit 5b27805

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/pbio/sys/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ PROCESS_THREAD(pbsys_system_process, ev, data) {
3030

3131
for (;;) {
3232
PROCESS_WAIT_EVENT();
33-
pbsys_hmi_handle_status_change((pbsys_status_change_t)ev, (pbio_pybricks_status_t)data);
33+
3434
if (ev == PROCESS_EVENT_TIMER && etimer_expired(&timer)) {
3535
etimer_reset(&timer);
3636
pbsys_battery_poll();

lib/pbio/sys/status.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <pbdrv/clock.h>
1313
#include <pbsys/status.h>
1414

15+
#include "hmi.h"
16+
1517
static struct {
1618
/** Status indications as bit flags */
1719
uint32_t flags;
@@ -31,9 +33,11 @@ static void pbsys_status_update_flag(pbio_pybricks_status_t status, bool set) {
3133

3234
pbsys_status.flags = new_flags;
3335
pbsys_status.changed_time[status] = pbdrv_clock_get_ms();
34-
// REVISIT: this can drop events if event queue is full
35-
process_post(PROCESS_BROADCAST, set ? PBSYS_STATUS_CHANGE_SET : PBSYS_STATUS_CHANGE_CLEARED,
36-
(process_data_t)status);
36+
37+
// hmi is the only subscriber to status changes, so call its handler
38+
// directly. All other processes just poll the status as needed. If we ever
39+
// need more subscribers, we could register callbacks and call them here.
40+
pbsys_hmi_handle_status_change(set ? PBSYS_STATUS_CHANGE_SET : PBSYS_STATUS_CHANGE_CLEARED, status);
3741
}
3842

3943
/**

0 commit comments

Comments
 (0)