Skip to content

Add event service for gestures, button actions, and raw message bus events#124

Merged
microbit-matt-hillsdon merged 1 commit intoappsfrom
event-service3
Mar 27, 2026
Merged

Add event service for gestures, button actions, and raw message bus events#124
microbit-matt-hillsdon merged 1 commit intoappsfrom
event-service3

Conversation

@microbit-matt-hillsdon
Copy link
Copy Markdown
Contributor

Pin events can be added as a high-level feature later if there's demand. They make much less sense for a general purpose "control/monitor the micro:bit over BLE" program. Though maybe useful for digital twin projects as they can observe pins without changing the pin mode (but can't read values, just transitions).

For now they're accessible via the numeric API with CODAL/DAL constants in the user program.

I do slightly wonder what the point of the button service is now...

@microbit-matt-hillsdon
Copy link
Copy Markdown
Contributor Author

For discussion/experimentation rather than a quick review + merge.

@microbit-grace
Copy link
Copy Markdown
Contributor

microbit-grace commented Mar 26, 2026

Had a play and it looks good.

It was a bit unexpected that the Gestures section would affect the Raw Events section. Listening to gestures would cause it to stream raw events, and stopping listening to the gestures would not stop gesture raw events, but after some thought, it makes sense because gestures get subscribed.

Also, not sure if there is a root for getting the touch logo press event as well.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 26, 2026

Deploying microbit-connection with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8455a6a
Status:🚫  Build failed.

View logs

@microbit-matt-hillsdon
Copy link
Copy Markdown
Contributor Author

I've tried to separate out the notifications so you only get low level ones if you ask for them.

I've added the logo as a button and it seems to work well.

I also added detail to the demo about what requires what service as otherwise the split of the button-related behaviours is inexplicable (similar to JSDoc already added).

Copy link
Copy Markdown
Contributor

@microbit-grace microbit-grace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, glad adding logo press was straightforward!

…bus events

Expose the micro:bit's BLE Event Service as high-level typed events
(gesturechanged, buttonaaction, buttonbaction, buttonabaction, logoaction)
and a low-level microbitevent channel for arbitrary message bus traffic
via subscribeToEvent/sendEvent.

Named events demux incoming notifications by source ID (V1 DAL / V2
CODAL) so listeners receive structured data without needing to know
the underlying message bus layout. The raw microbitevent channel is
opt-in: only events matching explicit subscribeToEvent registrations
are dispatched, keeping it isolated from the named event traffic.

Client requirements and BLE notification subscriptions are replayed
on reconnect so the micro:bit re-registers its event forwarding.

Adds an Events tab to the demo app for interactive testing.
@microbit-matt-hillsdon
Copy link
Copy Markdown
Contributor Author

Thanks. Pushed a rebase with a better message but otherwise unchanged. Will merge once built in CI.

@microbit-matt-hillsdon microbit-matt-hillsdon merged commit 12ea250 into apps Mar 27, 2026
3 of 4 checks passed
@microbit-matt-hillsdon microbit-matt-hillsdon deleted the event-service3 branch March 27, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants