Files
second-screen/README.md
T
rickzkmandClaude Opus 5.5 6c9a1420d2 Week ahead in the weather strip, reverse LCD at night
The weekday strip now shows today and the next six days (icon, max, min),
the current temperature and feels-like sit next to the clock, and the rain
graph spans the full width with the hour under every bar. From sunset to
sunrise the whole frame, seconds patch included, is drawn as a reverse LCD.
The rain label is now spelled DÉŠŤ.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-28 22:40:34 +01:00

101 lines
6.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# second-screen
A second 3.5" Turing Smart Screen (Rev A) on the Coolify home server, next to the bus board
(`bus-department-schedule`). One Docker container shows **one view at a time**: a Casio digital watch (slanted
7-segment digits, pale LCD green) for the weather, and a Cyberpunk 2077 look (yellow/cyan on black, chamfered
shapes, glitch numbers) for the server stats:
| `VIEW` | Shows |
|---|---|
| `weather` | The week ahead in the Czech weekday strip (today first and inverted: icon, max and min for each day), big `HH:MM` with seconds, date, current temperature and feels-like (`POCIT`) for Zlín, and a 12-hour rain probability bar graph with the hour under every bar and the total mm. From sunset to sunrise the whole screen turns into a reverse LCD (light segments on black) |
| `server` | Cyberpunk style: CPU / RAM / disk gauges (red from 80 %), load, CPU temperature, uptime, Docker containers (readable names and status chips) and the busiest processes. Refreshed every second; the container list every 5 s and the process ranking over 3 s windows |
Design: `docs/superpowers/specs/2026-10-22-second-screen-design.md`.
Plan: `docs/superpowers/plans/2026-10-22-second-screen.md`. Previews: `docs/previews/`.
## Switching views
Edit `VIEW:` in `docker-compose.yml`, commit, `git push`, then in Coolify press **Reload Compose** on the app page
(it keeps its own copy of the compose file) and **Deploy**. An unknown or missing
`VIEW` shows an error screen naming the valid views and keeps the container idle (no restart loop).
## Add a view
1. Write a module (any `*.py` in the project root is copied into the image) with a class that follows the `View` protocol in `view.py` (`start`, `stop`, `frame_key`,
`render`, `patch`). Put anything slow (network, system reads) in a `Poller` so drawing never blocks.
2. Add one entry to `REGISTRY` in `registry.py`.
3. Add a line to the table above, a sample to `preview.py`, and tests.
## Develop (no screen needed)
python3 -m venv .venv && .venv/bin/pip install -r requirements-dev.txt
.venv/bin/pytest
.venv/bin/python preview.py # writes docs/previews/weather.png and server.png
## Deployment (Coolify)
- Source: **Public Repository** on Gitea, branch `main`. The repo must stay public: Gitea SSH is disabled,
so Coolify cannot use a deploy key.
- Build pack **Docker Compose**, base directory `/`, **Docker Compose Location `/docker-compose.yml`**.
- No domain and no environment variables: the defaults in `docker-compose.yml` fit this server.
- **Update:** commit, `git push`, press **Reload Compose** if `docker-compose.yml` changed, then **Deploy** (no webhook).
- **Logs:** Coolify → the application → Logs, or `ssh coolify 'docker logs --tail 30 <container>'`.
- Only one container can hold a screen's serial port. Stop manual copies before deploying.
### Security note
The container mounts the Docker socket. Even with `:ro` that gives it full control of Docker on the server
(including Coolify, the bus board and everything else), because the API is not read-only. It also mounts the
host's `/proc` and `/sys` read-only. This was accepted for this LAN-only home server (owner approved the
socket on 2026-10-22). Remove the socket mount and the container list disappears (`NO DOCKER`), everything
else keeps working.
### Running by hand on the server (debugging only)
ls -l /dev/serial/by-id/
docker compose up --build -d
docker compose logs -f second-screen
## If something is wrong
- **Upside-down:** this screen is mounted the opposite way to the bus board. Set `SCREEN_ORIENTATION` to
`REVERSE_LANDSCAPE`.
- **Blank screen:** `docker compose logs second-screen`. If the port cannot be opened the app retries every 30 s
(the screen library's own exit is caught); if the port disappears mid-run the app exits after about a minute of
failed draws and Docker restarts it. With the cable out *before* the container starts, Docker itself refuses to
start it (the compose `devices:` entry). Check the cable and `ls -l /dev/serial/by-id/`. ModemManager can interfere (`systemctl status ModemManager`).
- **`STARÉ` tag:** the data is old (weather older than 1 h, server stats older than 30 s). The clock keeps running.
- **Error screen at startup:** `VIEW` is not one of the valid views.
## Config (env vars)
| Variable | Default | |
|---|---|---|
| `VIEW` | none (must be set) | `weather` or `server` |
| `SCREEN_DEVICE` | `/dev/serial/by-id/usb-Turing_UsbMonitor_USB35INCHIPSV2-if00` | serial device, also passed into the container |
| `SCREEN_ORIENTATION` | `LANDSCAPE` | `REVERSE_LANDSCAPE` flips it |
| `SCREEN_BRIGHTNESS` | `50` | 0–100 |
| `BOARD_TZ` | `Europe/Prague` | time zone of the clock |
| `LCD_LIB_PATH` | `/opt/lcd` | where the pinned screen library lives in the image |
The screen library is pinned to one upstream commit in the `Dockerfile` (`LCD_COMMIT`), the same as the bus board.
## Known limitations
- Weather comes from Open-Meteo for Zlín only (coordinates in `weather_data.py`), refreshed every 15 minutes.
- Night mode uses the forecast's sunrise and sunset for today. If the forecast has no today (fetches failing for
days), the closest day's times are used; with no forecast at all (right after a start) the screen stays in day
mode. Switching day/night redraws the whole screen once (about 2 s).
- The weather graph is the next 12 hours from now, so late in the day it runs into tomorrow.
- Server stats: process CPU is a share of the whole machine and grouped by command name; temperature is the CPU
package sensor if the host has one, else the hottest thermal zone.
- The screen's link moves about 150 KB/s (measured 2026-10-22: a full 480x320 frame takes 1.96 s, a 96x52 box 65 ms),
and time grows with the bytes sent. So after the first frame the runner sends only the rectangles that changed
(`regions.py`), a full frame when more than 60 % of the screen changed or after any failed push, and a full refresh
every 15 minutes. The weather seconds are a small patch once per second.
## Fonts
`assets/fonts/Roboto-Bold.ttf` (Apache 2.0, from the screen library) is used by the weather view;
`Rajdhani-Bold.ttf` / `Rajdhani-SemiBold.ttf` (SIL Open Font License, see `Rajdhani-OFL.txt`) by the server view.