Python API summary#
Everything here is a method on Board. Each one sends a command and returns the board’s reply as a dictionary, or raises.
Connecting#
| Call | What it does |
|---|---|
Board.open(port=None) |
Open the board, auto-detecting the port |
board.close() |
Close it. Also happens on leaving a with block |
MockBoard() |
An in-process board, no hardware |
Identity and state#
| Call | Returns |
|---|---|
board.hello() |
Product, firmware version, serial, tile count, USB personality |
board.tiles() |
A list, one entry per tile: kind, firmware, state, keys currently down |
board.tile(addr) |
One tile’s entry, or None |
board.stats() |
Uptime, poll cycle time, fault state, LED power budget |
LEDs#
| Call | What it does |
|---|---|
board.led(btn, colour, fx=None, press=None) |
Set a logical button’s colour |
board.led_tile(addr, index, colour, fx=None) |
Set one LED by tile and position |
board.led_all(colour) |
Every LED on every tile |
board.led_reset() |
Back to the saved defaults |
board.led_layer() |
A diffing writer — see Your first script |
colour takes a name, "#RRGGBB", "RRGGBB", an (r, g, b) triple, an int, or None for off. fx is "solid", "blink", "fast" or "breathe". press turns the white press-flash on or off for that button.
LedLayer#
| Call | What it does |
|---|---|
layer.set(btn, colour, fx, press) |
Stage a colour |
layer.set_tile(addr, index, colour, fx) |
Stage a colour by tile and position |
layer.flush() |
Send what changed; returns how many commands went out |
layer.all(colour) / layer.reset() |
Send immediately and reset the diff |
layer.forget() |
Force the next flush() to resend everything |
Bindings#
| Call | What it does |
|---|---|
board.bind(btn, add=False) |
Wait for a key press and bind it. add=True joins a group |
board.bind_cancel() |
Stop waiting |
board.unbind(btn) |
Remove every key from a button |
board.unbind(btn, addr, key) |
Remove one key from a group |
board.map_get() / board.map_set(m) |
The whole configuration as a dictionary |
board.save() |
Write it to flash |
bind() blocks until someone presses a key, up to 30 seconds.
Encoders#
| Call | What it does |
|---|---|
board.bind_axis(n) |
Bind axis 1–8 to the next encoder turned. frc reports 1–4; 5–8 move only in sim |
board.unbind_axis(n) |
Remove it |
board.enc_zero(n=None) |
Zero one axis, or all of them |
Display tiles#
| Call | What it does |
|---|---|
board.screen(addr) |
A row-diffing writer for a display tile |
screen.text(row, s) / screen.bar(row, col, width, value) |
Stage a row |
screen.flush() |
Send changed rows and commit them together |
screen.clear() |
Blank the panel |
board.disp_store_image(addr, slot, file) |
Encode an image for the tile and store it in a slot |
board.disp_slot_show(addr, slot) |
Show a stored picture: one frame |
board.disp_slot_info(addr, slot) |
What a slot holds: None, or its fmt, attr, len and crc |
board.disp_slot_read(addr, slot) |
Read a stored picture back, checked against its CRC; seconds for a colour picture |
board.rumble_text_bind(code, addr, rows, attrs=None) |
Make a legend code write rows (up to 8 strings) to a display tile; attrs styles each row, e.g. "black on yellow" |
board.rumble_texts(code=None) / board.rumble_text_unbind(code, addr=None) |
List or remove those messages |
Drawing#
A disp2 can draw lines, rectangles and text anywhere on its 160 × 128 pixels. The tile does the drawing; the script sends end points, so a drawing that changes costs a few frames rather than a whole picture.
| Call | What it does |
|---|---|
board.canvas(addr, background="black") |
A drawing surface for a tile that draws. slot=n draws over a stored picture instead of a colour |
canvas.layer() |
A group of shapes that move together, drawn over the layers made before it |
layer.line(x0, y0, x1, y1, colour) / layer.poly(points, colour, closed=False) |
Lines |
layer.rect(x, y, w, h, colour) / layer.fill(x, y, w, h, colour) |
An outline, or a solid rectangle |
layer.box(cx, cy, w, h, degrees, colour) |
A rectangle about its centre, turned clockwise: a wheel, a robot |
layer.circle(cx, cy, r, colour) / layer.arrow(x0, y0, x1, y1, colour) |
A circle; a line with a head |
layer.text(x, y, s, fg, bg) |
Text at a pixel position, 12 × 16 pixels a character |
layer.clear() |
Empty the layer, to stage its shapes again |
canvas.flush() |
Send what changed; returns how many frames went out |
canvas.forget() |
Force the next flush() to clear the panel and redraw everything |
board.disp_show_image(addr, file) |
Send a two-colour picture straight to the panel, nothing stored |
canvas = board.canvas(6)
frame = canvas.layer().rect(40, 10, 80, 80, "white")
wheel = canvas.layer()
while True:
wheel.clear().box(40, 10, 9, 19, heading, "lime")
canvas.flush() # only what changed is sent
Colours are the ones LEDs take: a name, "#RRGGBB" or an (r, g, b) triple. Shapes that leave the panel are cut at its edge. The tile does not remember the drawing: the canvas works out what to erase, and after a tile has been unplugged call canvas.forget(). Drawing on a display explains it all, with three complete examples.
Drawing needs firmware 0.3.0 or newer on both the main module and the display tile. A tile that can draw reports "draw": true in board.tiles(). With no board, MockBoard() draws too: board.state.panel(6).save("out.png") writes what the panel would show.
Display tiles differ in size: disp1 is 21 columns × 4 rows, disp2 13 × 8 and screenkey1 10 × 8. Take the geometry from screen.cols / screen.rows, which come from the tile’s own descriptor, rather than hard-coding it. MockBoard() includes display tiles to develop against; MockBoard(display=False) behaves like firmware without display support, which answers unknown.
The board itself#
| Call | What it does |
|---|---|
board.usb(mode) |
Set the USB mode: "frc", "xinput", "desk", "midi" or "sim". Takes effect once saved and replugged. See USB modes |
board.power_budget(mA) |
Set the LED power budget |
board.test("walk", 250) / board.test("off") |
Report button presses with no tile involved |
board.reset() / board.reset(factory=True) |
Reboot, optionally erasing the configuration |
Events#
The board reports events such as a tile lost, a fault raised, or a key pressed during binding.
def on_tile(ev):
print(ev["addr"], ev["state"]) # 3 lost
unsubscribe = board.on("tile", on_tile)
Names are tile, fault, key, enc, stick, progress, player and rumble, plus lock in desk mode and midi in midi mode; "*" receives all of them.
Callbacks run on the library’s reader thread. Do not call board methods from inside one: the call blocks until it times out. Put the event on a queue and handle it in your loop.
Errors#
| Exception | When |
|---|---|
CommandError |
The board refused the command. .err is the reason code |
Timeout |
No reply in time |
NotConnected |
The port is closed or the cable went away |
NoBoardFound |
Auto-detection could not identify a board |
BoardError |
Base class for all of the above |