Skip to content

Commit 65cdf4c

Browse files
committed
sys/bluetooth: add status update timer
This adds a timer to send status updates periodically in addition to when the status changes. Since there is no guarantee that notifications are received, we just keep sending them to be sure. In the future, we could consider sending an ack back to the hub indicate that the status change was received so that we don't have to do this. Issue: pybricks/support#287
1 parent 5de74c4 commit 65cdf4c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/pbio/sys/bluetooth.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ static void reset_all(void) {
189189
}
190190

191191
static PT_THREAD(pbsys_bluetooth_monitor_status(struct pt *pt)) {
192+
static struct etimer timer;
192193
static uint32_t old_status_flags, new_status_flags;
193194
static send_msg_t msg;
194195

@@ -198,9 +199,15 @@ static PT_THREAD(pbsys_bluetooth_monitor_status(struct pt *pt)) {
198199
// right after notifications are enabled.
199200
old_status_flags = ~0;
200201

202+
// Send status periodically as well in case a notification was missed due
203+
// to bad RF environment or bug like https://crbug.com/1195592
204+
etimer_set(&timer, clock_from_msec(500));
205+
201206
for (;;) {
202-
// wait for status to change
203-
PT_WAIT_UNTIL(pt, (new_status_flags = pbsys_status_get_flags()) != old_status_flags);
207+
// wait for status to change or timeout
208+
PT_WAIT_UNTIL(pt, (new_status_flags = pbsys_status_get_flags()) != old_status_flags || etimer_expired(&timer));
209+
210+
etimer_restart(&timer);
204211

205212
// send the message
206213
msg.context.size = pbio_pybricks_event_status_report(&msg.payload[0], new_status_flags);

0 commit comments

Comments
 (0)