Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/pr-sim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,14 @@ jobs:
echo
echo "All per-screen before/after files are also in the \`sim-before-after\` artifact of [this run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). These per-run GIFs (\`*_r<run_id>.gif\`, newest 40 kept) are archived on the [pr-sim-assets release](${{ github.server_url }}/${{ github.repository }}/releases/tag/pr-sim-assets). ASCII frames for one screen are in the job log above."
} > /tmp/comment.md
gh pr comment "${{ github.event.pull_request.number }}" --repo "$GITHUB_REPOSITORY" --body-file /tmp/comment.md
# one standing comment per PR: edit the workflow's previous comment
# if it exists, create it only on the first run (re-runs would
# otherwise pile up one comment per run)
COMMENT_ID=$(gh api "repos/$GITHUB_REPOSITORY/issues/${{ github.event.pull_request.number }}/comments?per_page=100" \
--jq '[.[] | select(.user.login == "github-actions[bot]" and (.body | startswith("Sim before/after")))][0].id')
if [ -n "$COMMENT_ID" ]; then
gh api -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$COMMENT_ID" \
-f body=@/tmp/comment.md > /dev/null
else
gh pr comment "${{ github.event.pull_request.number }}" --repo "$GITHUB_REPOSITORY" --body-file /tmp/comment.md
fi
16 changes: 10 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ hi/lo screen.
Variable contract + how to create it: `secrets.example.py` and README
"Board configuration" — fill the template, upload host -> board, delete local.
- Board code must stay MicroPython-compatible: no CPython-only stdlib, match
the existing `%`-formatting style, keep `src/render.py` free of board imports
(it also runs on the host in `sim/`).
the existing `%`-formatting style, keep the `src/` drawing modules
(`render.py`, `weather.py`, `matrix.py`, `scenes.py`) free of board imports
(they also run on the host in `sim/`).
- The SCD41 driver is frozen into Pimoroni's MicroPython firmware
(`breakout_scd41`, `pimoroni_i2c`) — do not vendor a copy; the sim mocks
those two modules (sim/run_main.py).
Expand All @@ -34,7 +35,7 @@ hi/lo screen.
`skills/unicorn/`.
- **Preview display changes in sim/ before deploying** — not as a fallback for
a detached board, but because you can actually see what the matrix will
show, using the exact `src/render.py` code and real bitmap6 font metrics:
show, using the exact `src/` render code and real bitmap6 font metrics:
`python3 sim/sim.py print --screen weather --code 61 --temp 21 --frames 8`
writes plain ASCII frames to stdout for agent analysis;
`python3 sim/sim.py play ...` animates in the terminal. Render the whole
Expand Down Expand Up @@ -72,7 +73,7 @@ Most contributions here come from agents — this file is the contract:
screen inline on the PR (artifact `sim-before-after`; screens pixel-identical
to the base produce no GIFs). For icon changes, also do a HITL pass on the
physical board: `python3 skills/unicorn/display.py --icons` after
`scripts/deploy.sh --no-reset` (so the board runs *your* render.py), then
`scripts/deploy.sh --no-reset` (so the board runs *your* render code), then
`mpremote reset` to return to the clock.
`micropython` is protected by a ruleset: one approving review and all threads
resolved are required; merges are **rebase-only with required linear
Expand All @@ -91,8 +92,11 @@ Most contributions here come from agents — this file is the contract:

## Layout

- `main.py` — board entry point (WiFi/NTP/open-meteo/SCD41 + screen loop), thin
- `src/render.py` — all drawing; pure functions taking a PicoGraphics-like `d`
- `main.py` — board entry point (WiFi/NTP/open-meteo/SCD41 + dashboard loop), thin
- `src/render.py` — core drawing (clock, CO2, hi/lo, boot); pure functions
taking a PicoGraphics-like `d`
- `src/weather.py` — weather icon art; `src/matrix.py` — matrix rain;
`src/scenes.py` — dashboard composition and widgets
- `src/tz.py` — EU DST offset, pure integer math (no tzdata on the board)
- `sim/` — host simulator: `sim.py`, `font6_data.py` (Pimoroni font6),
`run_main.py` (mocked full run of main.py), `before_after.py` (PR GIFs)
Expand Down
134 changes: 54 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,50 @@
# galactic-clock

Pimoroni Galactic Unicorn (53x11 LED matrix) on a Raspberry Pi Pico W running
MicroPython. A weather clock that rotates four screens on the matrix:

- **clock** — local time, RTC synced via NTP (EU DST computed in pure integer
math in `src/tz.py` — MicroPython has no tzdata), blinking colon; shown only
when the RTC is trustworthy (NTP-synced, or already reading >= 2026 after a
soft reset) — otherwise the slot shows `no ntp`
- **weather** — animated 10x11 icon + current temperature from open-meteo (no
API key); icons are hand-drawn pixel art per WMO code with day/night variants
(twinkling sun/moon, drifting fog bands, falling rain/snow, flashing storm bolt)
- **hi/lo** — today's high/low with up/down arrows
- **CO2** — ppm from an optional SCD41 sensor on the STEMMA QT connector,
color-coded green/amber/red by indoor air quality

Buttons: **A** toggles the **matrix rain** mode — one anti-aliased drop per
column (subpixel motion, gradual brightness between rows) with a fading trail.
Five speed/brightness tiers (very dim crawl → full-brightness sprint) are
hashed across the columns, gaps between passes span 4–11 rows, and ~1 pass in
10 rests entirely, so the rain's density and tempo visibly breathe; each drop's
head cycles through a few subtle green variations as it falls and settles on
its hue
for the second half of the pass, and every pass mixes its hue and trail length
from a deterministic LCG (no randomness — sim and board render identically).
One press plays it full-screen for two minutes (a second press stops it early),
then the regular rotation resumes. With a trusted RTC the clock shows through
the rain (`sim/sim.py --screen rainclock`): the clock phases in over ~0.3 s
on entry; when the mode ends it dissolves right away — the dim box lifts,
the field pours across the still-bright digits, and the clock's ink converts
to falling drops pixel by pixel (staggered, organic); at full strength
the field dims to 35 % alpha inside
the clock's text box while bright white digits draw on top, so
the rain visibly
pours across the time; without a trusted RTC the rain runs alone (same rule as
the rotation's clock-hiding). The rain keeps a persistent frame tick
across runs, so it always continues where it left off.
A weather and air-quality clock for the Pico W and its 53x11 LED matrix,
written in MicroPython for the board. The rendering is pure, deterministic
functions, so a host simulator can drive the exact same code the board runs —
reproducing the matrix pixel-for-pixel. The GIF below is bit-identical to the
hardware.

![Display loop demo](docs/demo-rotation.gif)

The regular rotation (clock → animated weather → hi/lo → CO2), rendered by the
host sim from the real `main.py` — regenerate with
Rendered by the host sim from the real `main.py` — regenerate with
`python3 sim/run_main.py --seconds 24 --delay 0.12 --preseed-co2 53 --gif docs/demo-rotation.gif`
(the preseed fills the CO2 history with ~2.6 h of canned readings so the
GIF's strip isn't empty; `micropython-check` verifies the tracked GIF
against this exact command; needs Pillow; these GIFs are tracked, all other
recordings stay uncommitted).
(`--preseed-co2` fills the CO2 history so the GIF's strip isn't empty;
`micropython-check` verifies the tracked GIF against this exact command;
needs Pillow).

![Rain-clock demo](docs/demo-rainclock.gif)
The dashboard: local time always on the left, one widget at a time on the
right, rotating every 8 s with a vertical roll:

The rain-clock mode as one press plays it: the bare field pours, the clock
phases in over ~0.3 s, holds steady with drops crossing the bright digits,
then the exit dissolves the ink into falling drops frame by frame.
`python3 sim/sim.py play --screen rainclock --delay 0.12
--gif docs/demo-rainclock.gif` renders the whole episode (lengths ride the
render constants, so `--frames` doesn't apply); `sim/check_demo_gif.py` (CI)
enforces that both GIFs match the code.
- **clock** — 5x7 digits in fixed slots, so the colon holds one column,
blinking two-dot colon; RTC synced via NTP (EU DST computed in pure integer
math in `src/tz.py` — MicroPython has no tzdata); shown only
when the RTC is trustworthy (NTP-synced, or already reading >= 2026 after a
soft reset) — otherwise the slot shows `no ntp`
- **weather widget** — animated 10x11 icon + current temperature from
open-meteo (no API key); icons are hand-drawn pixel art per WMO code with
day/night variants (twinkling sun/moon, drifting fog bands, falling
rain/snow, flashing storm bolt)
- **hi/lo widget** — today's high/low with up/down arrows
- **CO2 widget** — ppm from an optional SCD41 sensor on the STEMMA QT
connector, color-coded green/amber/red by indoor air quality; readings stay
untrusted for ~3 min after boot (the sensor's startup settling)

Buttons: **A** toggles the **matrix rain** mode — anti-aliased drops with
fading trails; column-by-column speed/brightness tiers and occasional rests
make the density and tempo visibly breathe, and the rendering is
deterministic, so sim and board match frame for frame. One press plays it
full-screen for two minutes (a second press stops it early), then the
dashboard resumes. With a trusted RTC the clock shows through the rain;
without one, the rain runs alone.

![Matrix rain demo](docs/demo-matrix.gif)

The rain-clock episode, rendered by
`python3 sim/sim.py play --screen rainclock --delay 0.12 --gif docs/demo-matrix.gif`
(the episode length rides the render constants, so `--frames` doesn't apply);
`sim/check_demo_gif.py` (CI) enforces that both GIFs match the code.

## Hardware & host setup

Expand Down Expand Up @@ -115,53 +105,32 @@ weather values are CLI args (`--code/--temp/--hi/--lo/--night`).

```
python3 sim/sim.py print --screen weather --code 61 --temp 21 --frames 8
# plain ASCII frames on stdout (for agent analysis)
# plain ASCII frames on stdout
python3 sim/sim.py play --screen weather --code 61 --temp 21 # animate in terminal
python3 sim/sim.py play --screen weather --code 0 --night # moon + stars
python3 sim/sim.py play --screen icons --frames 8 # contact sheet: all icons
python3 sim/sim.py play --screen hilo --hi 25 --lo 18
python3 sim/sim.py play --screen matrix --frames 60 # code rain
```

See it in motion — render any screen, or the whole display loop of the real
See it in motion — render any screen, or the whole dashboard loop of the real
`main.py` (fully mocked: WiFi/NTP/open-meteo/SCD41), to an animated GIF
(needs Pillow; GIFs are gitignored and generated on demand for PRs — the only
tracked one is the README demo above):
(needs Pillow; GIFs are gitignored):

```
python3 sim/run_main.py --seconds 24 --gif /tmp/rotation.gif # clock -> weather -> hi/lo -> CO2
python3 sim/run_main.py --seconds 24 --gif /tmp/rotation.gif # dashboard, widgets rolling
python3 sim/sim.py play --screen matrix --frames 60 --gif /tmp/matrix.gif
python3 sim/sim.py play --screen icons --frames 8 --gif /tmp/icons.gif
python3 sim/sim.py play --screen weather --code 61 --temp 21 --frames 12 --gif /tmp/rain.gif
```

HITL review on the physical board (see all icons before approving a PR):
`python3 skills/unicorn/display.py --icons` cycles every weather icon on the
matrix, 3 s each, WMO code labelled (`n` = night); then `--stop` and
`mpremote reset` return to the clock.

The weather icon (10x11, left of the temperature) is animated per WMO code:
twinkling sun/moon, partly-cloudy sun+moon peeking behind a drifting cloud,
fog bands, falling rain streaks (drizzle/snow fall slower, showers pulse,
heavy variants denser), and a flashing bolt for storms. The icons are
hand-drawn 10x11 pixel art, tuned frame by frame in the sim.

Recordings are generated on demand and never committed (gitignored). For PR
reviews, before/after GIFs of every screen (base ref vs PR head) are rendered
automatically:
For PR reviews, before/after GIFs of every changed screen (base ref vs PR
head) are rendered automatically:

```
python3 sim/before_after.py --ref origin/micropython --out /tmp/pr
# writes /tmp/pr_<screen>_{before,after,compare}.gif per screen
# (weather/icons/clock/hilo/co2) plus pr_rotation_* — a full mocked
# run of the real main.py (sim/run_main.py), robust to screen changes.
# "icons" is a contact sheet of every animated weather icon
# (WMO code x day/night) in one GIF. --ref takes the PR base SHA
# (CI passes github.event.pull_request.base.sha); locally use
# origin/micropython. Screens pixel-identical to the base
# produce no GIFs at all, so the CI upload/PR comment skips
# them — the review only shows what changed. Attach the GIFs
# to the PR; CI does this automatically.
# writes /tmp/pr_<screen>_{before,after,compare}.gif
# screens pixel-identical to the base produce no GIFs
```

## Development
Expand All @@ -185,8 +154,13 @@ python3 sim/before_after.py --ref origin/micropython --out /tmp/pr
## Layout

- `AGENTS.md` — ramp-up essentials: golden rules, workflow, layout
- `main.py` — board entry point: WiFi/NTP/open-meteo/SCD41 + screen loop (thin)
- `src/render.py` — all drawing; pure functions, no board imports (also runs in the sim)
- `main.py` — board entry point: WiFi/NTP/open-meteo/SCD41 + dashboard loop (thin)
- `src/render.py` — core drawing (clock, CO2, hi/lo, boot); pure functions, no
board imports
- `src/weather.py` — animated weather icon art; `src/matrix.py` — matrix rain
and the rain-clock overlay; `src/scenes.py` — dashboard composition and widgets
- `src/co2.py` — SCD41 sampling with warmup gating and the history ring buffer
- `src/ntp.py` — periodic RTC re-sync while the clock runs
- `src/tz.py` — EU DST offset in pure integer math (MicroPython has no tzdata)
- `sim/` — host simulator: `sim.py` (play/print/GIF), `font6_data.py` (real
bitmap6 font metrics), `run_main.py` (mocked full run of `main.py`),
Expand Down
Binary file added docs/demo-matrix.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/demo-rainclock.gif
Binary file not shown.
Binary file modified docs/demo-rotation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading