hub
Board-provided hub module.
Exposes the on-device peripherals: LPF2 ports (hub.ports), hub LED, IMU (hub.imu), buttons, LCD (LVGL), status log and power-off. Objects here are singletons created by the C firmware — this module is a stub; the real implementation lives in the ESP32 port.
Attributes
Built-in accelerometer wrapped as a Devices.accelerometer. |
|
Board-specific constants (see |
|
Button API (see |
|
Built-in gyroscope wrapped as a Devices.gyroscope. |
|
Shared internal I2C bus (Grove + on-board devices). See |
|
Fused IMU (see |
|
LCD + LVGL control (see |
|
Built-in hub RGB LED. |
|
Firmware log control. |
|
Hub ports (see |
Functions
|
|
|
Flush any buffered framed stdout data as a #FR:OUT frame. |
|
Event decorator injected by the program runner in |
|
Turn the hub off immediately. Does not return. |
|
Write bytes to stdout bypassing the framing wrapper. Returns bytes written. |
|
Register a callback that mirrors framed and raw stdout bytes elsewhere. |
|
Enable/disable C-level stdout framing (#FR:OUT <len>n<bytes>). |
|
|
|
Module Contents
- hub.on(name: _HandlerName) Callable[[_Handler], _Handler][source]
Event decorator injected by the program runner in
fs/main.py.Only available when a script is launched from the on-device menu; not present when
import hubruns fromboot.pyor the REPL.nameis"setup"(runs once) or"loop"(runs each tick).
- hub.raw_write(buf: bytes) int[source]
Write bytes to stdout bypassing the framing wrapper. Returns bytes written.
Flushes any pending framed output first so raw bytes never interleave inside a framed payload.
- hub.set_frame_sink(cb: Callable[[bytes], None] | None) None[source]
Register a callback that mirrors framed and raw stdout bytes elsewhere.
Called from
mp_hal_stdout_tx_strnunder the GIL after every framed flush and everyraw_write(). Used to forward the same byte stream to BLE NUS (sinceos.duptermonly exposes slot 0 = REPL on this port). PassNoneto detach. Exceptions inside the callback are swallowed.
- hub.set_framed_output(enabled: bool) None[source]
Enable/disable C-level stdout framing (#FR:OUT <len>n<bytes>).
When enabled, every
mp_hal_stdout_tx_strncall is wrapped so the host protocol parser can separate program output from binary frames. Used by the HubProtocol layer sincesys.stdoutis an immutable dummy in this build and can’t be replaced from Python.
- hub.accelerometer: lpf2.devices.accelerometer[source]
Built-in accelerometer wrapped as a Devices.accelerometer.
- hub.gyro: lpf2.devices.gyroscope[source]
Built-in gyroscope wrapped as a Devices.gyroscope.
- hub.led: lpf2.devices.hub_led[source]
Built-in hub RGB LED.