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

accelerometer

Built-in accelerometer wrapped as a Devices.accelerometer.

board

Board-specific constants (see _board_module).

buttons

Button API (see _buttons_module).

gyro

Built-in gyroscope wrapped as a Devices.gyroscope.

i2c

Shared internal I2C bus (Grove + on-board devices). See _i2c.

imu

Fused IMU (see _imu_module).

lcd

LCD + LVGL control (see _lcd_module).

led

Built-in hub RGB LED.

log

Firmware log control.

ports

Hub ports (see _ports_module).

Functions

exit(→ NoReturn)

flush_output(→ None)

Flush any buffered framed stdout data as a #FR:OUT frame.

on(→ Callable[[_Handler], _Handler])

Event decorator injected by the program runner in fs/main.py.

powerOff(→ NoReturn)

Turn the hub off immediately. Does not return.

raw_write(→ int)

Write bytes to stdout bypassing the framing wrapper. Returns bytes written.

set_frame_sink(→ None)

Register a callback that mirrors framed and raw stdout bytes elsewhere.

set_framed_output(→ None)

Enable/disable C-level stdout framing (#FR:OUT <len>n<bytes>).

sleep(→ None)

sleep_ms(→ None)

Module Contents

hub.exit() NoReturn[source]
hub.flush_output() None[source]

Flush any buffered framed stdout data as a #FR:OUT frame.

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 hub runs from boot.py or the REPL.

name is "setup" (runs once) or "loop" (runs each tick).

hub.powerOff() NoReturn[source]

Turn the hub off immediately. Does not return.

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_strn under the GIL after every framed flush and every raw_write(). Used to forward the same byte stream to BLE NUS (since os.dupterm only exposes slot 0 = REPL on this port). Pass None to 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_strn call is wrapped so the host protocol parser can separate program output from binary frames. Used by the HubProtocol layer since sys.stdout is an immutable dummy in this build and can’t be replaced from Python.

hub.sleep(seconds: float) None[source]
hub.sleep_ms(ms: int) None[source]
hub.accelerometer: lpf2.devices.accelerometer[source]

Built-in accelerometer wrapped as a Devices.accelerometer.

hub.board: _board_module[source]

Board-specific constants (see _board_module).

hub.buttons: _buttons_module[source]

Button API (see _buttons_module).

hub.gyro: lpf2.devices.gyroscope[source]

Built-in gyroscope wrapped as a Devices.gyroscope.

hub.i2c: _i2c[source]

Shared internal I2C bus (Grove + on-board devices). See _i2c.

hub.imu: _imu_module[source]

Fused IMU (see _imu_module).

hub.lcd: _lcd_module[source]

LCD + LVGL control (see _lcd_module).

hub.led: lpf2.devices.hub_led[source]

Built-in hub RGB LED.

hub.log: _log_module[source]

Firmware log control.

hub.ports: _ports_module[source]

Hub ports (see _ports_module).