Skip to content

Latest commit

 

History

History
436 lines (307 loc) · 23.1 KB

CANVAS.md

File metadata and controls

436 lines (307 loc) · 23.1 KB

canvas mode

canvas is the third base scene of the custom runtime — the right-hand button on the device, or PUT /api/v1/scene {"base":"canvas"}. it is the one scene nothing on the device draws by itself: an integration pushes a document of drawing primitives and the device renders it, so the integration can send data rather than 2,496 bytes of raw rgb.

every picture on this page is a photograph of the panel. they were captured off GET /screen by runtime/tools/tc002-canvas-docs.py, which drives the device through this same catalogue — so the documents below and the images of them cannot drift apart. the panel is 52 × 16 pixels; the images are scaled six times, nearest-neighbour, so a panel pixel is a visible square.

for the api itself — routes, fields, limits, the patch format, what is stored and when — see the canvas section of RUNTIME.md. this page is the visual counterpart: what the primitives actually look like on the glass.


the shape of a document

a document is a list of elements. push it once, then send only the values that change:

curl -sX PUT http://10.0.0.111/api/v1/canvas -H "Authorization: Bearer $ADMIN" -d '{
  "elements": [
    {"type":"text","at":[0,0],"font":"mini","colour":"506070","text":"amsterdam"},
    {"id":"t","type":"text","at":[0,5],"font":"block","colour":"ffffff","text":"9"},
    {"id":"g","type":"sparkline","at":[28,11],"size":[24,5],"style":"bars","colour":"205070",
     "min":0,"max":100,"data":[40,45,50,60,55,50,45]}
  ]}'

# and afterwards, only the readings — no pixels, no layout
curl -sX PATCH http://10.0.0.111/api/v1/canvas -H "Authorization: Bearer $CONTROL" \
  -d '{"values":[{"id":"t","text":"11"},{"id":"g","data":[45,50,60,70,65,60,55]}]}'

a weather dashboard: the city in the smallest face, a large 9, the word deg, and a small bar chart of the day's history

that layout is 361 bytes sent once; each update after it is about 70. the elements that change carry an id, and the ones that never change do not need one.


text

the four hand-drawn faces

small is 5 × 7 and has every printable character. mini is 3 × 5 and carries letters and digits — it is the face the device's own menus use. block (6 × 10) and big (10 × 14) carry digits and a colon only, for a number you read across a room. twenty more, imported from pixel fonts made for led matrices and old pcs, are in imported faces below.

the mini face spelling mini 3x5 abc above the small face spelling small, with 5x7 beside it

face size characters a full line
small 5 × 7 all printable ascii 8 characters
mini 3 × 5 letters, digits and : / . % ? - 13 characters
block 6 × 10 digits and : 7 characters
big 10 × 14 digits and : are what it is for, but it falls back to the 5 × 7 face doubled, so letters do render 4 characters

a character costs its width plus one pixel of gap (two for big), so "a full line" above is how many fit across 52 pixels. anything longer is clipped — or scrolled.

the small face showing abcdefgh above the punctuation row the mini face showing abcdefghijkl above mnopqrstuvwx

numerals

the small face showing 01234567 above 89 the mini face showing 0123456789 above 12:34

block and big exist for one job: a reading that has to be legible from across the room. they carry 0–9 and : and nothing else, so a deg or a kW beside them comes from small or mini.

the block face showing 12:34 in blue the big face showing 21 in amber with the word deg beside it in the small face

imported faces

twenty more faces, imported from pixel fonts drawn for led matrices and old pcs. they are proportional (the int10h ones are monospaced at 8 columns), they carry far more than ascii, and text in them is utf-8: "text":"20°C" draws a degree sign. a \n in any text starts a new line under the last, one row apart (a tile's label and value stay one line each, so there it is a space). name one as font anywhere a font is taken — a text element, a plain notification, the clock, a berry script, and (the short ones) the device menus.

each face's height is trimmed to the rows its letters, digits and latin-1 actually use, so a 16-row text-mode cell whose ink sits in rows 2–12 is an 11-row face here. a glyph reaching outside those rows — the box-drawing set and the full blocks of the cp437 faces — is cut to them.

matrix fonts by trip5 (Matrix-Fonts, mit): latin, greek and cyrillic, drawn for 8-row led clocks. the x variants drop the descender row and use the full height for capitals; the 8x6 ones are wider, at most six columns a glyph.

face rows glyphs a full line of lowercase
chunky6 chunky6x light6 light6x 6 441 12–13 characters
chunky8 chunky8x light8 light8x 8 731 12–13 characters
chunky8x6 light8x6 8 463 8 characters

the chunky6 face showing Hello° over 12:34 the chunky6x face showing Hello° over 12:34 the light6 face showing Hello° over 12:34 the light6x face showing Hello° over 12:34 the chunky8 face showing Ab12°é the chunky8x face showing Ab12°é the chunky8x6 face showing Hello° over 12:34 the light8 face showing Ab12°é the light8x face showing Ab12°é the light8x6 face showing Hello° over 12:34

tiny5 by stefan schmidt (font_tiny5, ofl-1.1; on google fonts): capitals five rows tall, with latin, greek, cyrillic and armenian. tiny5-duo doubles the vertical strokes and tiny5-mono is monospaced. its accented capitals and descenders make the trimmed face 11 rows.

face rows glyphs a full line of lowercase
tiny5 11 1,941 13 characters
tiny5-duo 11 1,941 9 characters
tiny5-mono 11 2,286 8 characters

the tiny5 face showing Ab12°é the tiny5-duo face showing Ab12°é the tiny5-mono face showing Ab12°é

int10h — vileR's ultimate oldschool pc font pack (cc by-sa 4.0): bios and text-mode fonts of real machines, the full cp437 set with its smileys, card suits, arrows, box drawing and greek; ibm-vga is the extended (pxplus) version, with latin, greek and cyrillic beyond cp437. eight columns a glyph, so six characters across, and too wide for seconds on the clock.

face from rows glyphs
phoenix the phoenix bios 8×8 8 255
phoenix-2y the same, doubled in height 16 255
phoenix-8x14 phoenix's vga 8×14 14 255
ibm-iso8 ibm pc dos's iso 8×16, one-pixel strokes 15 255
apricot-xenc the apricot xen-c 14 255
robotron-a7100 the robotron a7100 11 255
ibm-vga the ibm vga 8×16, pxplus 15 787

the phoenix face showing Ab12° and a smiley the phoenix-2y face showing Ab12° and a smiley the phoenix-8x14 face showing Ab12° and a smiley the ibm-iso8 face showing Ab12° and a smiley the apricot-xenc face showing Ab12° and a smiley the robotron-a7100 face showing Ab12° and a smiley the ibm-vga face showing Ab12° and a smiley

a character a face does not have draws as the face's replacement glyph if it has one, and as ? if it does not: cp437 has no cyrillic, so phoenix draws Ж as ? where ibm-vga has it.

phoenix drawing Ж as a question mark beside ibm-vga drawing Ж

the hand-drawn faces know ascii and one more character: small and mini draw a degree sign, so 21.4°C reads as a temperature in a tile. anything else they lack is one ?.

alignment

give a text element a size and it becomes a box: align places the string inside it, and anything that does not fit is cut off at the box edge rather than running over its neighbour.

three lines in the smallest face, one left-aligned in red, one centred in green, one right-aligned in blue


the drawing primitives

rect

filled decides between an outline and a solid block. without a size a rect takes the rest of the panel.

a blue rectangle outline beside a solid orange one

line

at is one end, to is the other. lines are drawn with a bresenham walk, so a steep line is a line rather than two dots.

six lines fanning out from the bottom-left corner in red, orange, yellow, green, blue and violet

circle

at is the centre and r the radius; filled again decides between a ring and a disc.

a blue circle outline, a solid white disc and a small pink ring

pixel

one lit point. the primitive everything else is made of, and occasionally the one you want.

twenty scattered single pixels in assorted colours

bar

a value from 0 to 100 in its box, with an optional background for the empty part. vertical fills from the bottom, which is where a level belongs.

a bar can instead watch a transfer the device measures for itself: "watch":"staging" (the staging directory an in-place update copies the next build into, every file in it summed) or "watch":"image" (the image a flash copies to /data), with "bytes" the size it will reach. the renderer measures it every 100 ms while the bar is on the panel and eases to each reading over 400 ms, so the bar moves as one continuous motion with what has actually arrived. a moving bar (watching or gliding) is filled to a fraction of a pixel: its leading pixel lights by how far the fill has got into it, so each new pixel fades in instead of switching on. the watch is one of those two names, never a path. a renderer that cannot measure (the console's preview) gets no readings and draws the bar empty; value is ignored while a bar watches. this is the bar under the update tools' Updating..., Flashing... and Working....

three horizontal bars labelled cpu, mem and disk at 25, 60 and 93 percent in green, amber and red seven vertical bars rising in steps from ten to a hundred percent

sparkline

up to 52 samples — one per panel column. three styles, and the same data in each:

a sine wave drawn as a thin joined line in mint green the same wave as vertical bars in blue the same wave filled solid in violet

with no min and max a sparkline scales to whatever its samples span, so a flat line is flat. give it a range and two charts become comparable. a threshold recolours the samples that cross it:

a bar sparkline where three spikes above the threshold are drawn in red against blue

data is a list of numbers. samples can also be sent as data_hex, which costs two characters each instead of up to four; a json string given as data is refused and told to use data_hex, because reading "1,2,3" as bytes would draw a wrong picture without saying so.

icon

sixty-one 8 × 8 glyphs built into the runtime. they are monochrome and take the element's colour, which is why they suit a panel where the palette belongs to the document rather than to the artwork. GET /api/v1/icons lists them on the device.

five weather icons sun moon cloud cloud-rain cloud-snow
storm, fog, thermometer, droplet and flame storm fog thermometer droplet flame
snowflake, fan, bulb and two battery levels snowflake fan bulb battery-full battery-half
low and empty batteries, a plug and two wifi strengths battery-low battery-empty plug wifi wifi-low
bluetooth, signal bars, a house, a door and a clock bluetooth signal house door clock
a calendar, envelope, phone, person and pet calendar envelope phone person pet
a car, train, bus and a closed and open padlock car train bus lock unlock
a bell, a silenced bell, a star, a heart and a flag bell bell-off star heart flag
a tick, a cross, a warning triangle, an info mark and a question mark check cross warning info question
play, pause, stop, next and previous transport controls play pause stop next previous
a speaker, a muted speaker and up, down and left arrows volume mute up down left
a right arrow, a rising and a falling trend, a plus and a minus right up-trend down-trend plus minus
a single dot dot

sprite

anything that needs colours of its own is a sprite: 8 × 8 or 16 × 16 of raw rgb888, uploaded as octets to PUT /api/v1/sprites/<id> and drawn by id. black is transparent, so a sprite can sit over something else. eight slots, and they survive a renderer restart.

a magenta ring, a warm gradient square, a cool gradient square and a yellow smiley face a shaded blue globe at sixteen by sixteen, filling the panel's full height

the ring is the one to look at: the panel shows through its middle because those pixels are black.

tile

the composite an integration reaches for first, and the one place the device makes a layout decision for you. a tile is a glyph, a label and a reading. given room it puts the glyph on the left with the label over the value; where there is not room the label is dropped rather than squeezed or cut off, and the reading — the half worth keeping — stays.

a full-width tile: a thermometer on the left, the word lounge above the reading 21.4°C three tiles across the panel, each an icon above a number, with no room for labels two stacked tiles, each a glyph beside a temperature, too short for labels

a PATCH value replaces a tile's reading and never its label: the reading is the part that changes, the label is layout.


placement

at: [x, y] and size: [w, h] are pixels from the top-left. tile: n, of: m divides the panel into columns and row: n, of: m into rows — the device does the rounding, so the pieces meet exactly with no gap and no overlap (52 does not divide by three).

four coloured columns filling the panel edge to edge four coloured rows filling the panel top to bottom

a box is not only a position: it aligns what is inside it and cuts off what is not.

two boxes side by side, one with the word centre centred in it, the other with a longer string cut off at its edge

elements draw in the order they are given, so the last one wins where they meet. that is what lets a document build up in layers — ground, then chart, then labels on top.

a red, a green and a blue rectangle overlapping in that order a dark ground, a dim area chart over it, and the words load and 90% on top

anything may be placed off the panel and what fits is drawn. that is deliberate: it is what lets an element be animated in from outside.


animations

an animation is declared per element, so a document pays for motion only where it asked for it — a scene of static elements asks the renderer for no frames at all once it has settled. ms is the period, and phase (0–100) offsets an element within it, so a row of things does not move in lockstep.

hue

the colour walks the wheel from whatever the element was given as its starting point.

two words in the small face cycling through the colour wheel, half a period apart

pulse

brightness rides up and down, never quite to nothing.

the word breathe in blue, brightening and dimming

blink

on for its duty cycle, dark for the rest. amount is the duty as a percentage.

the words one, two and three blinking out of step with each other

bounce

up and down by amount pixels, or across with axis: "x".

the words up, and, down bouncing vertically one after another the word side sliding left and right

scramble

the flipboard: each character settles out of flipping glyphs, left to right, and then stops. an arrival animation — it runs once when the value arrives rather than forever.

the word SCRAMBLE resolving out of randomly flipping letters

typewriter

a character at a time, then it holds. also an arrival animation.

the words typing and one by one appearing a letter at a time

scroll

for text too wide for its box: a pixel every ms, wrapping once it has left.

a long sentence scrolling right to left across the panel

sweep

a sparkline draws itself in from the left, and starts again whenever its data changes.

an area chart drawing itself in from the left edge

glide

a bar whose value changes eases to it from wherever it was drawn: quickly at first, settling gently, over ms (1,000 unless given). a new value arriving mid-glide sets off from the point the bar had reached, so a stream of patches — a download, a progress count — moves it smoothly rather than in jumps. a bar that appears gliding grows from empty. a renderer that only knows a document's published ages (the console after a reload) draws a gliding bar at its value.

together

each element runs on its own clock, so a document mixes them freely.

five elements animating at once: a hue cycle, a blink, a pulse, a scramble settling and a bouncing word

matching the phase elsewhere

the device starts a document's animations when it installs it, and a document says nothing about when it was said. so GET /canvas publishes an age_ms for the document and for each element — a PATCH restarts only the elements whose value actually changed — and a second renderer of the same document back-dates its own install by those ages to draw the phase the panel is drawing. the console's preview does exactly that.


as a notification

every document on this page can also be a notification: POST /notify with elements instead of text draws it under the notification's lifecycle — a duration or hold, a name to dismiss it by, stack to queue it behind the current one — and its arrival animations start the moment it is shown, not when it was queued. the base scene comes back when it leaves, and a restart drops it, because notifications live in the renderer's memory and never on flash. tc002 notify --data @doc.json sends one; the console's canvas builder has a "send as notification" button; the Updating... the update tools show is one of these, white tiny5 pulsing over a gliding bar of how much has been copied, held until the new runtime is up.

posting a document under the name of the one showing updates it in place: no transition, its continuous animations keep their phase, and an element whose value changed starts its arrival again — a gliding bar easing to the new value. that is how the update tools drive their bar: the same notice, posted again with the bar's new value, a few times a second. a document that should show without being saved but is not a notification is a PUT /canvas with "persist": false.

trying it

the demo reels in runtime/tools/ play every one of these on the device, and print what each step costs:

runtime/tools/tc002-demo-shapes.py     -s 10.0.0.111 --token-file tokens
runtime/tools/tc002-demo-text.py       -s 10.0.0.111 --token-file tokens
runtime/tools/tc002-demo-charts.py     -s 10.0.0.111 --token-file tokens
runtime/tools/tc002-demo-icons.py      -s 10.0.0.111 --token-file tokens
runtime/tools/tc002-demo-images.py     -s 10.0.0.111 --token-file tokens
runtime/tools/tc002-demo-layout.py     -s 10.0.0.111 --token-file tokens
runtime/tools/tc002-demo-tiles.py      -s 10.0.0.111 --token-file tokens
runtime/tools/tc002-demo-dashboard.py  -s 10.0.0.111 --token-file tokens

each takes --hold, --only, --list and --loop, and each puts back the scene and the canvas it found. tc002-demo-lint.py checks every document all eight would send — the limits, the fields, and where the ink actually lands — without a device.

to regenerate every image on this page:

runtime/tools/tc002-canvas-docs.py -s 10.0.0.111 --token-file tokens

it needs ffmpeg on the machine running it, for the gifs only — the stills go through a twenty-line png encoder at the bottom of that file. that is the one tradeoff here: quantising a hue sweep to a 256-colour palette by hand would be a worse use of the repository than a dependency in a documentation script.