commit ec314bc5a6904f52276642a5c6f8c0bd17e5a115 Author: Richard Kacerek Date: Thu Oct 22 12:55:21 2026 +0200 docs: design for second-screen (Casio weather clock + server stats views) Co-Authored-By: Claude Sonnet 5.5 diff --git a/docs/reference/casio_spike.py b/docs/reference/casio_spike.py new file mode 100644 index 0000000..6c64dbe --- /dev/null +++ b/docs/reference/casio_spike.py @@ -0,0 +1,187 @@ +"""THROWAWAY SPIKE: Casio-style clock mockup (static weather). Not production code.""" +import os +import sys +from datetime import datetime + +from PIL import Image, ImageDraw, ImageFont + +W, H = 480, 320 +BG = (170, 184, 154) +INK = (28, 36, 24) +GHOST = (158, 172, 143) # unlit segments, barely darker than the background +SLANT = 0.14 + +# mock forecast (spike): rain probability % for the next 12 h, and mm per hour +RAIN = [0, 0, 10, 20, 40, 70, 60, 50, 30, 20, 10, 0] +MM = [0, 0, 0, 0.1, 0.4, 1.2, 0.9, 0.5, 0.1, 0, 0, 0] + +SEGS = { + "0": "abcdef", "1": "bc", "2": "abdeg", "3": "abcdg", "4": "bcfg", + "5": "acdfg", "6": "acdefg", "7": "abc", "8": "abcdefg", "9": "abcdfg", +} + + +def slant(pts, base_y): + return [(x + SLANT * (base_y - y), y) for x, y in pts] + + +def hexseg(horizontal, c0, c1, c, t): + if horizontal: + pts = [(c0, c), (c0 + t / 2, c - t / 2), (c1 - t / 2, c - t / 2), + (c1, c), (c1 - t / 2, c + t / 2), (c0 + t / 2, c + t / 2)] + else: + pts = [(c, c0), (c + t / 2, c0 + t / 2), (c + t / 2, c1 - t / 2), + (c, c1), (c - t / 2, c1 - t / 2), (c - t / 2, c0 + t / 2)] + return pts + + +def digit(d, x, y, w, h, t, ch, ghost=True): + g = 1.5 + top, mid, bot = y + t / 2, y + h / 2, y + h - t / 2 + left, right = x + t / 2, x + w - t / 2 + geo = { + "a": hexseg(True, left + g, right - g, top, t), + "g": hexseg(True, left + g, right - g, mid, t), + "d": hexseg(True, left + g, right - g, bot, t), + "f": hexseg(False, top + g, mid - g, left, t), + "b": hexseg(False, top + g, mid - g, right, t), + "e": hexseg(False, mid + g, bot - g, left, t), + "c": hexseg(False, mid + g, bot - g, right, t), + } + on = SEGS.get(ch, "") + for name, pts in geo.items(): + lit = name in on + if lit or ghost: + d.polygon(slant(pts, y + h), fill=INK if lit else GHOST) + + +def number(d, text, x, y, w, h, t, gap, ghost=True): + """Draw digits and colons; returns x after the last glyph.""" + for ch in text: + if ch == ":": + s = t * 1.1 + cx = x + s + for cy in (y + h * 0.32, y + h * 0.68): + pts = [(cx - s / 2, cy - s / 2), (cx + s / 2, cy - s / 2), + (cx + s / 2, cy + s / 2), (cx - s / 2, cy + s / 2)] + d.polygon(slant(pts, y + h), fill=INK) + x += s * 2 + gap + elif ch == ".": + s = t * 1.0 + pts = [(x, y + h - s), (x + s, y + h - s), (x + s, y + h), (x, y + h)] + d.polygon(slant(pts, y + h), fill=INK) + x += s + gap + elif ch == "-": + c = y + h / 2 + d.polygon(slant(hexseg(True, x + t, x + w - t, c, t), y + h), fill=INK) + x += w + gap + else: + digit(d, x, y, w, h, t, ch, ghost) + x += w + gap + return x + + +def font(size): + for p in ("/opt/lcd/res/fonts/roboto/Roboto-Bold.ttf", + "/System/Library/Fonts/Supplemental/Arial Bold.ttf", + "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"): + if os.path.exists(p): + return ImageFont.truetype(p, size) + return ImageFont.load_default() + + +def sun_cloud(d, x, y, s): + """Partly-cloudy icon in a 'pixel LCD' feel, s = size.""" + cx, cy, r = x + s * 0.36, y + s * 0.36, s * 0.2 + d.ellipse((cx - r, cy - r, cx + r, cy + r), fill=INK) + for dx, dy in ((0, -1), (0, 1), (-1, 0), (1, 0), (-.7, -.7), (.7, -.7), (-.7, .7)): + d.line((cx + dx * r * 1.35, cy + dy * r * 1.35, cx + dx * r * 1.8, cy + dy * r * 1.8), + fill=INK, width=max(2, int(s / 16))) + # cloud with a light outline separating it from the sun + by = y + s * 0.82 + for pad, col in ((3, BG), (0, INK)): + d.ellipse((x + s * 0.30 - pad, by - s * 0.34 - pad, x + s * 0.68 + pad, by + pad), fill=col) + d.ellipse((x + s * 0.52 - pad, by - s * 0.26 - pad, x + s * 0.95 + pad, by + pad), fill=col) + d.rounded_rectangle((x + s * 0.18 - pad, by - s * 0.20 - pad, x + s * 0.95 + pad, by + pad), + radius=int(s * 0.1), fill=col) + + +def render(now): + img = Image.new("RGB", (W, H), BG) + d = ImageDraw.Draw(img) + f_small, f_tiny = font(15), font(12) + + # inner LCD window frame + d.rectangle((6, 6, W - 7, H - 7), outline=INK, width=2) + + # top: weekday row, current day inverted + days = ["PO", "ÚT", "ST", "ČT", "PÁ", "SO", "NE"] + cell = (W - 24) // 7 + for i, name in enumerate(days): + x0 = 12 + i * cell + if i == now.weekday(): + d.rectangle((x0, 14, x0 + cell - 6, 38), fill=INK) + col = BG + else: + col = INK + tw = d.textlength(name, font=f_small) + d.text((x0 + (cell - 6 - tw) / 2, 17), name, font=f_small, fill=col) + d.line((12, 46, W - 13, 46), fill=INK, width=2) + + # row A: time (left), seconds + date (right) + x = number(d, now.strftime("%H:%M"), 24, 54, 54, 96, 12, 9) + number(d, now.strftime("%S"), 378, 58, 24, 42, 6, 6) + number(d, now.strftime("%-d.%-m."), 372, 112, 14, 34, 4, 4, ghost=False) + + d.line((12, 160, W - 13, 160), fill=INK, width=2) + + # row B left: current weather + rain readout + d.text((22, 166), "ZLÍN NYNÍ", font=f_tiny, fill=INK) + sun_cloud(d, 20, 182, 56) + number(d, "14", 90, 184, 26, 46, 6, 7, ghost=False) + d.ellipse((160, 184, 170, 194), outline=INK, width=3) + d.text((22, 244), "MAX 16° MIN 7°", font=f_small, fill=INK) + d.text((22, 264), "DEŠŤ", font=f_tiny, fill=INK) + x = number(d, str(max(RAIN)), 22, 279, 18, 28, 4, 6, ghost=False) + d.text((x + 4, 288), "%", font=f_small, fill=INK) + + # divider + row B right: 12 h rain probability bar graph (LCD-style segments) + d.line((206, 168, 206, H - 14), fill=INK, width=2) + d.text((220, 166), "DEŠŤ % / HOD", font=f_tiny, fill=INK) + mm = f"{sum(MM):.1f} mm" + d.text((W - 18 - d.textlength(mm, font=f_small), 164), mm, font=f_small, fill=INK) + bar_w, pitch, seg_h, seg_gap, n_seg = 14, 21, 5, 1, 16 + gy1 = 282 + for i, pct in enumerate(RAIN): + bx = 222 + i * pitch + lit = round(pct / 100 * n_seg) + for k in range(n_seg): + y1 = gy1 - k * (seg_h + seg_gap) + d.rectangle((bx, y1 - seg_h, bx + bar_w, y1), + fill=INK if k < lit else GHOST) + hour = (now.hour + i) % 24 + if i % 3 == 0: + lab = f"{hour:02d}" + d.text((bx + bar_w / 2 - d.textlength(lab, font=f_tiny) / 2, 290), + lab, font=f_tiny, fill=INK) + return img + + +if __name__ == "__main__": + # fixed time for a stable preview; spike uses a Thursday afternoon + now = datetime(2026, 10, 22, 14, 32, 8) if "--fixed" in sys.argv else datetime.now() + img = render(now) + out = os.environ.get("OUT") + if out: + img.save(out) + print("saved", out) + if os.environ.get("PUSH"): + sys.path.insert(0, "/opt/lcd") + from library.lcd.lcd_comm import Orientation + from library.lcd.lcd_comm_rev_a import LcdCommRevA + lcd = LcdCommRevA(com_port=os.environ["PORT"]) + lcd.InitializeComm() + lcd.SetOrientation(Orientation.LANDSCAPE) + lcd.SetBrightness(50) + lcd.DisplayPILImage(img, x=0, y=0) + print("pushed") diff --git a/docs/reference/weather-mockup.png b/docs/reference/weather-mockup.png new file mode 100644 index 0000000..7ad6b3d Binary files /dev/null and b/docs/reference/weather-mockup.png differ diff --git a/docs/superpowers/specs/2026-10-22-second-screen-design.md b/docs/superpowers/specs/2026-10-22-second-screen-design.md new file mode 100644 index 0000000..764fd9d --- /dev/null +++ b/docs/superpowers/specs/2026-10-22-second-screen-design.md @@ -0,0 +1,173 @@ +# Second screen: Casio-style weather clock and server stats + +Date: 2026-10-22. Project folder name `second-screen` is the designer's call. + +## Intent and why + +A second 3.5" Turing Smart Screen is plugged into the Coolify home server, next +to the one that shows the bus departure board (project `bus-department-schedule`). +The owner wants it to be something nice to glance at and something to play with: + +1. A **Casio digital-watch style** view combining time, date, current weather and + today's forecast, with rain as the most important forecast item. +2. A **server stats** view (CPU, memory, disk, running containers and processes). +3. A way to **switch between views, and to add new views later**, by changing a + variable in the repo, committing, and redeploying. This is the owner's chosen + switching method and the reason for the design: views are cheap, throwaway-friendly + plug-ins and the screen shows exactly one at a time. + +## Goals + +- One Docker container drives the second screen and shows exactly one view, chosen by + the `VIEW` setting (`weather` or `server` to start). +- Adding a view means adding one module and one registry entry; no changes to the + serial/drawing plumbing. +- The weather view looks like the approved mockup (`docs/reference/weather-mockup.png`, + produced by the throwaway script `docs/reference/casio_spike.py`, which is a + reference for the segment-drawing and layout, not code to ship as is). +- Deployed through Coolify from a public Gitea repo, exactly like the bus board. +- Develop and preview without the screen: a script renders each view to a PNG using + fake data, like the bus board's `preview_board.py`. + +## Non-goals + +- No touch or button input (the screen has none). No switching at runtime, no web UI, + no HTTP endpoint, no rotating through views automatically. +- One view per container, one container per screen. Not driving the bus-board screen. +- No alerting, history, graphs over time for server stats, or authentication. +- Not a general dashboard framework. Keep the view interface as small as it needs to be. + +## Anti-goals (a failure even if it technically works) + +- A screen that shows frozen or stale data as if it were fresh (old weather without + any sign it is old; a clock that stopped). +- A crash loop that keeps grabbing the serial port and blocks the bus board's container + or the owner's debugging. +- Weather or server stats code that can bring the clock down: the time must keep running + when the weather service is unreachable. + +## Constraints + +- Hardware: Turing Smart Screen Rev A (sub-revision TURING_3_5), 320x480 panel. + **Orientation for this screen is `LANDSCAPE`** (480x320 image). The bus-board screen + uses `REVERSE_LANDSCAPE`; this one is mounted the opposite way, verified on 2026-10-22. +- Screen library: mathoudebine/turing-smart-screen-python, pinned by commit in the + Dockerfile, same commit as the bus board (`2b33ab4f00a096916dd6a1174441a53a7ec33b03`). + Needs `library/` and `res/` (fonts) from it. Python 3.12-slim, Pillow, numpy, pyserial. +- Device: `/dev/serial/by-id/usb-Turing_UsbMonitor_USB35INCHIPSV2-if00` (currently + `ttyACM1`). The bus board uses `/dev/serial/by-id/usb-2017-2-25_UsbMonitor_USB35INCHIPSV2-if00`. + Always use by-id paths, never `ttyACM*`. +- Server: reach with `ssh coolify` (user `rickzkm`, in the `docker` group, no passwordless sudo). + Deploy via Coolify: public Gitea repo (`https://gitea.madeinzlin.cz/rickzkm/.git`, + branch `main`; the repo must stay public because Gitea SSH is disabled), build pack + Docker Compose, compose location `/docker-compose.yml`, press Deploy after `git push` + (no webhook). Only one container can hold a serial port. +- Time zone `Europe/Prague`. Czech day names: PO ÚT ST ČT PÁ SO NE. 24 hour clock. + Date shown as `22.10.` (day.month.). +- Weather source: Open-Meteo (free, no API key), location **Zlín** (about 49.2265 N, + 17.6627 E; builder confirms coordinates). +- Currently on the server a manual container `apod-test` (NASA picture app, stopped) and + directory `~/apod-test` exist. They are leftovers of the first attempt and should be + removed once this is deployed. + +## Switching views (decided by the owner) + +`VIEW` is set in `docker-compose.yml` (for example `VIEW: weather`). To change view: +edit the value, commit, push, press Deploy in Coolify. Other settings (orientation, +brightness, device path) are also environment variables with defaults in the compose +file, in the style of the bus board. An unknown `VIEW` value must be a loud, visible +failure (log and an on-screen message naming the valid views), not a silent default. +Adding a new view later = new module + registry entry + README line. + +## Weather view (approved mockup) + +Layout, 480x320, pale LCD green-grey background with dark ink, drawn as slanted +7-segment digits with faint "ghost" unlit segments, as in the mockup: + +- **Top row:** weekday strip, today inverted. +- **Time row:** large `HH:MM` on the left; on the right a small seconds readout and + the date (`22.10.`). +- **Bottom left:** "ZLÍN NYNÍ", a weather icon, current temperature in segment digits + with a degree sign, today's `MAX`/`MIN`, and the highest rain probability in the + window as a segment readout with `%`. +- **Bottom right:** a Casio-style segmented **bar graph of rain probability for the next + 12 hours**, one bar per hour, hour labels every 3 hours, and the total expected + precipitation in mm for those hours in the corner. + +Decisions and calls: + +- The graph window is **the next 12 hours from now** (the designer's call; the owner said + the mockup was perfect but never chose between this and fixed calendar hours of today). +- Bars show probability, not amount; the mm total is the amount. +- Weather data refreshed every 15 minutes (designer's call). Needed fields: current + temperature and weather code, today's max and min, hourly precipitation probability + and precipitation amount. +- Weather icon set: sun, partly cloudy, cloudy, rain, snow, storm, fog, drawn in the + mockup's chunky style; mapping from WMO weather codes is left to the builder. +- The time must be correct to the minute; seconds should tick live if the screen can take + partial updates fast enough (builder to measure; if not, drop seconds and say so). +- When weather fetch fails: keep showing the last good data and mark it visibly as old + after a threshold (builder picks, suggest 1 hour); with no data ever, show dashes in the + weather areas. The clock and date are unaffected. + +## Server stats view + +Same Casio LCD style, same palette. Content in priority order: + +1. CPU usage, memory usage, disk usage of the main volume, as segmented bar graphs with + a number. +2. Load average, CPU temperature (if the host exposes one), uptime. +3. Docker containers: name and status (up, healthy, unhealthy, restarting, exited). + Container names on this server carry Coolify-generated random suffixes + (for example `n8n-ebe62bdjbp9f755kwh59lv8d`, `screen-pe28mpghgqnxaz12vyfyijrg-151725872213`); + show a readable short name. +4. Top host processes by CPU (name and percent). + +The owner said "running processes and so on" and the designer interpreted that as both the +containers and the busiest host processes, containers being the primary meaning +(designer's guess). Refresh about every 5 seconds. How many rows fit and the exact layout +are left to the builder, subject to legibility from across a desk. + +How data is read (designer's recommendation, builder may refine): from inside the +container, read the host's `/proc` and `/sys` mounted read-only, and talk to the Docker +Engine API over the mounted socket `/var/run/docker.sock` (plain HTTP over a unix socket, +no extra Python Docker library needed). Note for the README: the Docker socket gives the +container full control of Docker on the server even when mounted read-only. The owner +explicitly approved mounting the socket on 2026-10-22. +Reading host processes may need `pid: host`; builder decides the narrowest setup that works. + +## Fixed by the process, left to the builder + +- Module structure and view interface, drawing helpers (the segment drawing, gap, slant + and thickness values from `casio_spike.py` are a starting point), tests, preview script + with fake data, graceful shutdown (release the serial port on SIGTERM, restart policy + `unless-stopped`), logging, README in the style of the bus board's. +- Throttling/diffing of screen pushes so the serial link is not saturated. +- Whether views share one render loop or each own a small tick schedule. + +## Out of scope but noted + +- Brightness schedule at night, an automatic return to the bus board, more views + (NASA picture, etc.): later, via the same view mechanism. + +## Calls made after the builder check (designer's calls, owner to review) + +- **Bad `VIEW` or other startup failure:** open the port, draw the error message, log once, + and **stay running idle** holding the port. No exit, so no restart loop. +- **Device missing at startup** (cable out, by-id path changed): do not exit. Log once, + retry opening the port every 30 s, draw as soon as it appears. +- **Seconds are optional.** If partial updates are too slow, drop them and leave the date + alone in that space (the date may then be drawn larger). +- **Stale marker applies to both views**, not only weather. For server stats, a failed + read keeps the last numbers and marks them as old after a few missed refreshes. +- **Weather layout authority:** `docs/reference/weather-mockup.png` and `casio_spike.py` + (both in this repo) are final for the weather view. The server view has no mockup: the + builder designs it in the same style and the owner reviews the preview PNG before deploy. +- **Disk bar:** the host's root filesystem, via a read-only mount. Bars are plain level + readouts, no warning thresholds. +- **`pid: host`** (for host process names): the owner approved the Docker socket but did not + answer the question about `pid: host`. The designer's call is to allow it, since socket + access already gives the container full control of Docker. Owner can veto; the fallback is + dropping the top-processes section. +- **Gitea repo creation and removal of the `apod-test` leftovers** are not yet answered by the + owner: do not create the remote repo, push, or delete anything on the server without asking.