From e74fe0308e7bb4110b3320fe2c32f1e38ae34254 Mon Sep 17 00:00:00 2001 From: Krzysztof Jamroz Date: Fri, 20 Nov 2026 22:39:42 +0100 Subject: [PATCH 1/4] fix(test): ensure correct servo move tracking in setup wizard tests --- ui/test/wizard.test.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui/test/wizard.test.tsx b/ui/test/wizard.test.tsx index 3772e603..13f7da52 100644 --- a/ui/test/wizard.test.tsx +++ b/ui/test/wizard.test.tsx @@ -491,7 +491,9 @@ describe("setup wizard", () => { { index: 4, angle: 90 }, ]), ); + const movesAtFace = robot.sent("POST", "/setup/servo").length; + await click("Save and continue"); await waitFor(() => expect(stepLabel()).toBe("Step 2 of 5 · Screen")); @@ -503,7 +505,9 @@ describe("setup wizard", () => { const { robot, click } = await reachFace(); await waitFor(() => expect(screen.getByRole("heading", { name: "Face me" })).toBeTruthy()); + const movesAtFace = robot.sent("POST", "/setup/servo").length; + robot.failing.add("/setup/servo"); await click("Save and continue"); From 70f12bcd57f2013d8acb77ff2ba5af5781203aa0 Mon Sep 17 00:00:00 2001 From: Krzysztof Jamroz Date: Fri, 20 Nov 2026 22:50:02 +0100 Subject: [PATCH 2/4] docs(firmware): introduce 'evil' eye style with procedural rendering and comprehensive documentation --- .../changes/evil-eyes-style/.openspec.yaml | 2 + openspec/changes/evil-eyes-style/design.md | 55 ++++++++++++ openspec/changes/evil-eyes-style/proposal.md | 32 +++++++ .../evil-eyes-style/specs/evil-eyes/spec.md | 83 +++++++++++++++++++ openspec/changes/evil-eyes-style/tasks.md | 25 ++++++ 5 files changed, 197 insertions(+) create mode 100644 openspec/changes/evil-eyes-style/.openspec.yaml create mode 100644 openspec/changes/evil-eyes-style/design.md create mode 100644 openspec/changes/evil-eyes-style/proposal.md create mode 100644 openspec/changes/evil-eyes-style/specs/evil-eyes/spec.md create mode 100644 openspec/changes/evil-eyes-style/tasks.md diff --git a/openspec/changes/evil-eyes-style/.openspec.yaml b/openspec/changes/evil-eyes-style/.openspec.yaml new file mode 100644 index 00000000..4ee7b3f0 --- /dev/null +++ b/openspec/changes/evil-eyes-style/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-20 diff --git a/openspec/changes/evil-eyes-style/design.md b/openspec/changes/evil-eyes-style/design.md new file mode 100644 index 00000000..614abffb --- /dev/null +++ b/openspec/changes/evil-eyes-style/design.md @@ -0,0 +1,55 @@ +# Design + +## Context + +See proposal.md — Why. Eye styles plug in via `EyeStyleRenderer` (`styles/*.cpp` → `registry.cpp` + `eye_style_ids.cpp`). Pose/blink live in `display/eyes/core`; `dots` is the closest precedent: `needsPoseUpdate` + `needsBlink`, paint from `renderEye` + `blinkOpenAmount`, dead X via `drawDeadXEyes`. Settings validate uses registered ids only. Config `EYES_STYLES` and `docs/api.md` list the strings. + +Canonical open look (from the reference silhouette): solid white filled shapes on black — pointed high outer tips, lower rounded inners, concave brow notch on top, smooth convex bottom, mirrors, no pupil/outline. Earlier pupil-notch frames are out of v1 scope. + +## Goals / Non-Goals + +**Goals:** + +- Ship `evil` as a sixth registered style with dots-tier motion coupling +- Procedural draw that reads as the reference on 128×32 +- Keep settings / HTTP / UI / docs in sync in one change + +**Non-Goals:** + +- New `POST /anim` names or servo/audio variants +- Kawaii-style mood director or kaomoji expression remap +- Bitmap/RLE asset pack or flash-heavy frame library +- Per-mode geometry redesigns beyond height/position from classic pose + +## Decisions + +### D1. Style id `evil` +Short, matches the persona, fits NVS/JSON string lists. Alternatives `menace` / `scowl` rejected as vaguer. + +### D2. Follow dots architecture +One `drawEvil` in `styles/evil.cpp`, `kEvilEyeStyle` with `needsPoseUpdate`/`needsBlink` true. Scale/place a mirrored polygon (or filled path) from each rendered `Eye`. Height ≤ 0 → skip draw. Dead X hold → `drawDeadXEyes` on boxes centered like dots. Alternatives: static full-screen bitmap (no glance/blink fidelity); kawaii mood stack (overkill for “always evil”). + +### D3. Procedural geometry, not assets +Encode swoosh as polygon / triangle fan / mask scaled to the eye box so blinks shrink cleanly. Pixel-perfect PNG copy deferred unless procedural fails visual check on device. Alternative: host-generated masks like expression RLE — more pipeline, unnecessary for one shape. + +### D4. Docs and gallery in the same change +Update `docs/api.md`, UI ApiReference, Config select, styles README. Add a `web/eyes` card + preview path (cover stays optional/hidden). Keeps “list evil” requirement honest for the public gallery. + +### D5. No settings schema version bump +New enum member only; unknown old firmware ignores / rejects; new firmware accepts. Factory default stays `classic`. + +## Risks / Trade-offs + +- [Swoosh hard to fill with Adafruit primitives] → Start with triangle/polygon fill or row-scan inside the eye AABB; fall back to a small PROGMEM mask if jagged +- [Look too soft when height-scaled during blink] → Prefer vertical squash of the same outline over morphing to classic ovals +- [Preview JS drifts from firmware] → Approximate like other styles; note gallery is not a C++ port +- [Flash/CPU on fill] → Profile against dots; keep fill bounded to eye boxes only + +## Migration Plan + +- Flash firmware that includes `evil`; set via Config or `POST /settings {"eyes_style":"evil"}` +- Rollback: flash prior firmware, or set another style; orphaned `evil` in NVS → validate fails on old builds that only know five ids — user re-selects a known style (same as any unknown style string) + +## Open Questions + +- Exact polygon control points vs on-device tweak after first flash (does not change requirements) diff --git a/openspec/changes/evil-eyes-style/proposal.md b/openspec/changes/evil-eyes-style/proposal.md new file mode 100644 index 00000000..2e689d5b --- /dev/null +++ b/openspec/changes/evil-eyes-style/proposal.md @@ -0,0 +1,32 @@ +# Proposal + +## Why + +Users can pick classic, kaomoji, cover, dots, or kawaii OLED faces, but nothing matches a sharp, always-menacing “evil eyes” look. A sixth `eyes_style` lets the desk robot wear that persona without new animation names or servo/audio changes. + +## What Changes + +- Add `eyes_style` value **`evil`**: solid white scowling silhouettes (pointed high outers, rounded low inners, concave brow notch, convex bottoms; no pupils), mirrored left/right on the 128×32 OLED +- Reuse the classic eye pose pipeline for blinks, glances, height, sleep close/open, and dead X — same motion language as `dots`, different paint +- Always look evil for every `EyeMode` / `POST /anim` (no cute moods, no kaomoji face table) +- Wire the id through settings validate, style registry, Config UI, API docs, and (optionally) the public `/eyes` preview gallery +- Default stays `classic`; existing saved styles unchanged + +## Capabilities + +### New Capabilities + +- `evil-eyes`: OLED face style `evil` — registration, look, and how it tracks classic pose / blink / sleep / dead + +### Modified Capabilities + +- (none) + +## Impact + +- Firmware: `src/display/eyes/styles/` (new renderer + registry / `eye_style_ids`), settings validate already keyed off registered ids +- HTTP/settings: `eyes_style` accepts `evil`; GET/POST unchanged otherwise +- Web UI Config select; `docs/api.md` + `ui` ApiReference param lists +- Marketing gallery `web/eyes/` + preview JS (same pattern as dots/classic) +- Tests: `pio test -e native` eyes-style validate; `pio run` after style code +- No new `/anim` names, packages, NVS key rename, or flash-size asset pack (procedural draw preferred) diff --git a/openspec/changes/evil-eyes-style/specs/evil-eyes/spec.md b/openspec/changes/evil-eyes-style/specs/evil-eyes/spec.md new file mode 100644 index 00000000..468e84aa --- /dev/null +++ b/openspec/changes/evil-eyes-style/specs/evil-eyes/spec.md @@ -0,0 +1,83 @@ +# Spec Delta + +## Purpose + +Adds an OLED face style that always draws sharp, menacing scowling silhouettes while the robot keeps using its existing animations and motion. + +## ADDED Requirements + +### Requirement: Evil is a valid eyes_style value +The device MUST accept `eyes_style` value `evil` on settings read and write paths that already accept other eye styles. An unknown style MUST still be rejected. The default when unset MUST remain `classic`. + +#### Scenario: Save evil style +- **WHEN** a client posts `{"eyes_style":"evil"}` +- **THEN** the value is stored and `GET /settings` reports `eyes_style` as `evil` + +#### Scenario: Reject unknown style +- **WHEN** a client posts an `eyes_style` that is not a registered style id +- **THEN** the request is rejected as invalid and no settings are saved + +#### Scenario: Default unchanged +- **WHEN** settings load on a device that never saved `eyes_style` +- **THEN** the effective style is `classic` + +### Requirement: Evil style applies immediately +Changing `eyes_style` to or from `evil` MUST take effect on the OLED without reboot, same as other eye styles. + +#### Scenario: Switch to evil without reboot +- **WHEN** the device is running another style and a client sets `eyes_style` to `evil` +- **THEN** the next eye redraw uses the evil look + +### Requirement: Evil open eyes are solid white silhouettes +When `eyes_style` is `evil` and an eye is open, each eye MUST be one solid white filled shape on black with no pupil, iris, outline, gradient, or separate brow stroke. + +#### Scenario: No separate pupil or outline +- **WHEN** `eyes_style` is `evil` and an eye is drawn open +- **THEN** that eye is one filled white shape (not a rim around a black pupil) + +### Requirement: Evil open eyes use the scowling silhouette geometry +When `eyes_style` is `evil` and an eye is open, the outer corner MUST end in a sharp tip higher than the rest of that eye, and the inner corner MUST sit lower and stay rounded. The top edge MUST show a concave brow notch; the bottom edge MUST be a smooth convex curve. Left and right MUST be horizontal mirrors. At the default open pose, the gap between the inner corners MUST be roughly half an eye width. + +#### Scenario: Open idle silhouette +- **WHEN** `eyes_style` is `evil` and the eyes are in an open idle pose +- **THEN** the OLED shows two mirrored solid white scowling silhouettes on black, with pointed high outer tips, lower rounded inners, concave tops, and convex bottoms + +### Requirement: Evil look stays across animations +When `eyes_style` is `evil`, every animation mode MUST keep that silhouette language (no cute or smiling face, and no switch to another style’s face set). Pose may move, scale, or blink the same shapes. + +#### Scenario: Every animation stays evil +- **WHEN** `eyes_style` is `evil` and any existing animation runs +- **THEN** the OLED face stays in the evil silhouette language + +### Requirement: Evil eyes track classic pose and blink +Evil eyes MUST follow the same pose and blink pipeline as classic for position, size/height, glances, and lid open amount. Height that renders as closed MUST draw no white eye (full blink or sleep shut). + +#### Scenario: Blink closes the silhouette +- **WHEN** `eyes_style` is `evil` and a blink reaches fully closed +- **THEN** neither eye shows white fill for that frame + +#### Scenario: Glance moves both silhouettes +- **WHEN** `eyes_style` is `evil` and the classic pose glances horizontally +- **THEN** both evil eyes move with that pose + +### Requirement: Evil eyes handle sleep and dead like other pose styles +When `eyes_style` is `evil`, sleep close/open MUST collapse or restore silhouette height with the sleep lid phase. During the dead X hold, the OLED MUST show X marks instead of open silhouettes (same idea as dots/classic). + +#### Scenario: Sleep blanks the display path +- **WHEN** `eyes_style` is `evil` and sleep lids reach shut +- **THEN** the evil style draws no open silhouettes for that closed phase + +#### Scenario: Dead X hold +- **WHEN** `eyes_style` is `evil` and the dead animation is in its X hold +- **THEN** the OLED shows X marks rather than open evil eyes + +### Requirement: Config and docs list evil +The on-device Config eyes-style control MUST offer `evil` beside the existing styles. Public API documentation that lists `eyes_style` values MUST include `evil` and a short description of the look. + +#### Scenario: Config select includes evil +- **WHEN** the user opens Config eyes style +- **THEN** `evil` is available as a choice + +#### Scenario: API docs mention evil +- **WHEN** a reader checks the documented `eyes_style` values +- **THEN** `evil` is listed with the other styles diff --git a/openspec/changes/evil-eyes-style/tasks.md b/openspec/changes/evil-eyes-style/tasks.md new file mode 100644 index 00000000..adcebdb9 --- /dev/null +++ b/openspec/changes/evil-eyes-style/tasks.md @@ -0,0 +1,25 @@ +# Tasks + +## 1. Firmware style + registration + +- [ ] 1.1 Add `src/display/eyes/styles/evil.cpp` implementing `kEvilEyeStyle` (`id` `evil`, pose+blink on) that paints mirrored solid white scowling silhouettes (pointed high outers, rounded low inners, concave brow notch, convex bottoms; no pupils) from classic `renderEye`/`blinkOpenAmount`, skips fill when height is closed, and uses `drawDeadXEyes` on the dead X hold — verify `pio run` links the new object +- [ ] 1.2 Register `kEvilEyeStyle` in `registry.cpp` and add `"evil"` to `eye_style_ids.cpp`; extend `test_eyes_style` in `test/test_settings_validate` to accept `evil` and still reject unknowns — verify `pio test -e native` passes +- [ ] 1.3 Note `evil` in `src/display/eyes/styles/README.md` (table + add-a-style list stays accurate) — verify the row describes the scowling silhouette look + +## 2. Config, API docs, UI + +- [ ] 2.1 Add `evil` to Config `EYES_STYLES` and refresh the hint so it mentions the new style — verify `npm run lint --prefix ui` passes +- [ ] 2.2 Document `evil` in `docs/api.md` (`eyes_style` field, POST allowed values, short “Evil eyes” section parallel to Cover/Dots) and in `ui/src/views/ApiReference.tsx` param text — verify the listed values match exactly across both + +## 3. Public eyes gallery + +- [ ] 3.1 Add an `evil` card on `web/eyes/index.html` and a canvas preview in `web/js/eyes-preview.js` that approximates the scowling silhouette (blink/pose like dots) — verify the page lists six previewable styles including `evil` (cover may remain footnote-only) + +## 4. Integration + +- [ ] 4.1 Run `pio run` after the firmware/docs/UI edits and verify the default env builds clean + +## Workflow follow-up + +- Archive the change after review when implementation is done (`/opsx-archive` or project equivalent) +- On-device visual check of open, blink, glance, sleep, and dead X with `eyes_style=evil` if hardware is available From c4953db69a28d5c9cd6a044394c8df2c4d0dbfaf Mon Sep 17 00:00:00 2001 From: Krzysztof Jamroz Date: Fri, 20 Nov 2026 23:07:50 +0100 Subject: [PATCH 3/4] feat(firmware): update documentation to include 'evil' eye style with detailed description and usage --- docs/api.md | 10 +- openspec/changes/evil-eyes-style/tasks.md | 14 +- src/display/eyes/styles/README.md | 1 + src/display/eyes/styles/evil.cpp | 168 ++++++++++++++++++ src/display/eyes/styles/eye_style_ids.cpp | 1 + src/display/eyes/styles/registry.cpp | 2 + .../test_settings_validate.cpp | 1 + ui/src/config/ConfigForm.tsx | 5 +- ui/src/views/ApiReference.tsx | 4 +- web/eyes/index.html | 14 +- web/js/eyes-preview.js | 57 ++++++ 11 files changed, 261 insertions(+), 16 deletions(-) create mode 100644 src/display/eyes/styles/evil.cpp diff --git a/docs/api.md b/docs/api.md index 2be50ec5..6109e4d0 100644 --- a/docs/api.md +++ b/docs/api.md @@ -208,7 +208,7 @@ curl http://tiny-engineer.local/settings | `lcd1602_line1` / `lcd1602_line2` | Configured boot lines when `lcd1602_boot` is `config` (max **64** bytes each, no C0 control bytes, default empty). Persists when off. Applies **immediately** | | `continuous_timeout` | Minutes a continuous animation (`typing` / `reading` / `thinking` / `talking` / `waiting`) may run before the firmware switches to `attention` then idle (default **5**) | | `loading` | Boot loading screen: `progress` (bar + large IP for 3 s) or `sleep_inertia` (eyes wake; no bar/IP). Default **`progress`**. Applies on **next reboot** | -| `eyes_style` | OLED eyes look: `classic` (procedural rounded eyes), `kaomoji` (animated faces), `cover` (full-half bars for an eye-hole mask), `dots` (12×12 circles), or `kawaii` (round eyes with big moving pupils, a talking mouth, and blush). Default **`classic`**. Applies **immediately**. Classic, cover, and dots sequences are described under [`POST /anim`](#post-anim); kaomoji face mapping is under [Kaomoji eyes](#kaomoji-eyes); cover drawing is under [Cover eyes](#cover-eyes); dots drawing is under [Dots eyes](#dots-eyes); kawaii moods are under [Kawaii eyes](#kawaii-eyes) | +| `eyes_style` | OLED eyes look: `classic` (procedural rounded eyes), `kaomoji` (animated faces), `cover` (full-half bars for an eye-hole mask), `dots` (12×12 circles), `kawaii` (round eyes with big moving pupils, a talking mouth, and blush), or `evil` (solid white scowling silhouettes). Default **`classic`**. Applies **immediately**. Classic, cover, and dots sequences are described under [`POST /anim`](#post-anim); kaomoji face mapping is under [Kaomoji eyes](#kaomoji-eyes); cover drawing is under [Cover eyes](#cover-eyes); dots drawing is under [Dots eyes](#dots-eyes); kawaii moods are under [Kawaii eyes](#kawaii-eyes); evil drawing is under [Evil eyes](#evil-eyes) | | `access_token_set` | `true` when a non-empty access token is stored (secret itself is never returned) | | `link_mode` | `""` unprovisioned, `"wifi"`, or `"usb"` (connection mode; see [`serial.md`](serial.md)) | | `wifi_configured` | `true` when at least one WiFi network is saved | @@ -290,7 +290,7 @@ curl -X POST "http://192.168.4.1/settings" \ | `lcd1602_line1` / `lcd1602_line2` | string | Boot lines for `config` (max **64** bytes, no C0 control bytes) | | `continuous_timeout` | integer | 1–1440 minutes (positive) | | `loading` | string | `progress` or `sleep_inertia` | -| `eyes_style` | string | `classic`, `kaomoji`, `cover`, `dots`, or `kawaii` | +| `eyes_style` | string | `classic`, `kaomoji`, `cover`, `dots`, `kawaii`, or `evil` | | `access_token` | string | 0–64 printable ASCII, no space at either end; empty string clears the token and disables auth. Setting or rotating a non-empty value disconnects WebSocket `/events` subscribers (they must reconnect with the new token); clearing does not | | `link_mode` | string | `wifi` or `usb`; setup Connection step uses `usb` for USB-only; Wi-Fi mode is usually set when saving networks via [`PUT /settings/wifi`](#put-settingswifi) | | `servo_mins` | integer array | Five integers `0`–`180` (`head, neck, left, right, body`); setup AP only; must be sent with `servo_maxs` | @@ -743,7 +743,7 @@ curl -X POST "http://tiny-engineer.local/anim?name=none" { "ok": true, "animation": "typing" } ``` -Eye detail below for `eyes_style=classic` (default). With `eyes_style=cover`, the same sequences drive full-half bars ([Cover eyes](#cover-eyes)). With `eyes_style=dots`, the same sequences drive 12×12 circles ([Dots eyes](#dots-eyes)). With `eyes_style=kawaii`, the same sequences move and blink a kawaii face whose expression follows the animation and whose mouth says the voice clips ([Kawaii eyes](#kawaii-eyes)). With `eyes_style=kaomoji`, faces follow [Kaomoji eyes](#kaomoji-eyes) instead of procedural blinks, glances, flicker, or X eyes. Servo/audio behavior is the same for every style. +Eye detail below for `eyes_style=classic` (default). With `eyes_style=cover`, the same sequences drive full-half bars ([Cover eyes](#cover-eyes)). With `eyes_style=dots`, the same sequences drive 12×12 circles ([Dots eyes](#dots-eyes)). With `eyes_style=kawaii`, the same sequences move and blink a kawaii face whose expression follows the animation and whose mouth says the voice clips ([Kawaii eyes](#kawaii-eyes)). With `eyes_style=evil`, the same sequences drive solid white scowling silhouettes ([Evil eyes](#evil-eyes)). With `eyes_style=kaomoji`, faces follow [Kaomoji eyes](#kaomoji-eyes) instead of procedural blinks, glances, flicker, or X eyes. Servo/audio behavior is the same for every style. Durations and quoted lines below are the stock clips in [`assets/`](../assets/). A filesystem built with `custom_audio_mod` can replace some of those WAVs. Phrase timing then follows that clip's `.cue` file on LittleFS (`/welcome.cue` and the same pattern for `attention`, `error`, `abort`, and `dead`). See [flash.md](flash.md). @@ -790,6 +790,10 @@ When `eyes_style=cover`, each eye is a solid white rectangle filling one half of When `eyes_style=dots`, each eye is a filled circle. At the classic open height the circle’s bounding box is 12×12 px, centered on the classic eye. Diameter scales with rendered height (`12 * height / 14`), so blinks, squints, wide looks, and the `dead` flicker shrink or grow the dots. Height 0 draws nothing (full blink or sleep close). Glance, scan, and look-up/down move the circle with the classic center. The `dead` X hold draws X marks in 12×12 boxes at those centers. Diameter is capped at the 32 px panel height. +#### Evil eyes + +When `eyes_style=evil`, each eye is one solid white filled silhouette on black (no pupil, iris, outline, or separate brow stroke). The outer corner ends in a sharp tip higher than the rest of that eye; the inner corner sits lower and stays rounded. The top edge has a concave brow notch (scowl); the bottom edge is a smooth convex curve. Left and right are horizontal mirrors. At the default open pose the gap between the inner corners is roughly half an eye width. Animations keep the classic pose and blink timing: height tracks the rendered classic eye (closed height draws nothing), glances move both silhouettes with the classic centers, and the look stays menacing for every mode. The `dead` X hold draws X marks in boxes centered on those eyes instead of open silhouettes. + #### Kawaii eyes When `eyes_style=kawaii`, each eye is a round eye about 23 px across with a big dark pupil and white catch-lights in it (one round light and two small dots). A small mouth sits between the eyes, with dithered blush under the outer corners. The classic pose still drives position, height, glances, and blinks, and the pupils look where its glances point: at the task or the human, up while thinking. Two animations lead the eyes themselves: `typing` reads code instead of following the typing jitter, and `ring` keeps the eyes full size instead of the classic small circles. Moods change pupil size (small when surprised or angry, large when sad). A pupil otherwise keeps its size: lids, smiles, and blinks cover it like eyelids, and a white rim always stays around it. A closed eye draws a `‿` lid line (`∩` while smiling). Each animation picks a mood, and the face eases into it. Eye size, happy crescents, and mouth opening use springs with a little overshoot. Shape changes that cannot morph (round eyes to `> <`, `x x`, or hearts) happen behind a quick blink. diff --git a/openspec/changes/evil-eyes-style/tasks.md b/openspec/changes/evil-eyes-style/tasks.md index adcebdb9..e58edafa 100644 --- a/openspec/changes/evil-eyes-style/tasks.md +++ b/openspec/changes/evil-eyes-style/tasks.md @@ -2,22 +2,22 @@ ## 1. Firmware style + registration -- [ ] 1.1 Add `src/display/eyes/styles/evil.cpp` implementing `kEvilEyeStyle` (`id` `evil`, pose+blink on) that paints mirrored solid white scowling silhouettes (pointed high outers, rounded low inners, concave brow notch, convex bottoms; no pupils) from classic `renderEye`/`blinkOpenAmount`, skips fill when height is closed, and uses `drawDeadXEyes` on the dead X hold — verify `pio run` links the new object -- [ ] 1.2 Register `kEvilEyeStyle` in `registry.cpp` and add `"evil"` to `eye_style_ids.cpp`; extend `test_eyes_style` in `test/test_settings_validate` to accept `evil` and still reject unknowns — verify `pio test -e native` passes -- [ ] 1.3 Note `evil` in `src/display/eyes/styles/README.md` (table + add-a-style list stays accurate) — verify the row describes the scowling silhouette look +- [x] 1.1 Add `src/display/eyes/styles/evil.cpp` implementing `kEvilEyeStyle` (`id` `evil`, pose+blink on) that paints mirrored solid white scowling silhouettes (pointed high outers, rounded low inners, concave brow notch, convex bottoms; no pupils) from classic `renderEye`/`blinkOpenAmount`, skips fill when height is closed, and uses `drawDeadXEyes` on the dead X hold — verify `pio run` links the new object +- [x] 1.2 Register `kEvilEyeStyle` in `registry.cpp` and add `"evil"` to `eye_style_ids.cpp`; extend `test_eyes_style` in `test/test_settings_validate` to accept `evil` and still reject unknowns — verify `pio test -e native` passes +- [x] 1.3 Note `evil` in `src/display/eyes/styles/README.md` (table + add-a-style list stays accurate) — verify the row describes the scowling silhouette look ## 2. Config, API docs, UI -- [ ] 2.1 Add `evil` to Config `EYES_STYLES` and refresh the hint so it mentions the new style — verify `npm run lint --prefix ui` passes -- [ ] 2.2 Document `evil` in `docs/api.md` (`eyes_style` field, POST allowed values, short “Evil eyes” section parallel to Cover/Dots) and in `ui/src/views/ApiReference.tsx` param text — verify the listed values match exactly across both +- [x] 2.1 Add `evil` to Config `EYES_STYLES` and refresh the hint so it mentions the new style — verify `npm run lint --prefix ui` passes +- [x] 2.2 Document `evil` in `docs/api.md` (`eyes_style` field, POST allowed values, short “Evil eyes” section parallel to Cover/Dots) and in `ui/src/views/ApiReference.tsx` param text — verify the listed values match exactly across both ## 3. Public eyes gallery -- [ ] 3.1 Add an `evil` card on `web/eyes/index.html` and a canvas preview in `web/js/eyes-preview.js` that approximates the scowling silhouette (blink/pose like dots) — verify the page lists six previewable styles including `evil` (cover may remain footnote-only) +- [x] 3.1 Add an `evil` card on `web/eyes/index.html` and a canvas preview in `web/js/eyes-preview.js` that approximates the scowling silhouette (blink/pose like dots) — verify the page lists six previewable styles including `evil` (cover may remain footnote-only) ## 4. Integration -- [ ] 4.1 Run `pio run` after the firmware/docs/UI edits and verify the default env builds clean +- [x] 4.1 Run `pio run` after the firmware/docs/UI edits and verify the default env builds clean ## Workflow follow-up diff --git a/src/display/eyes/styles/README.md b/src/display/eyes/styles/README.md index 561e5c78..d7400d38 100644 --- a/src/display/eyes/styles/README.md +++ b/src/display/eyes/styles/README.md @@ -9,6 +9,7 @@ Extensible eye renderers selected by Config / `POST /settings` `{"eyes_style":" | `cover` | Full-half bars for mods with a mask with eye holes; height changes via top and/or bottom black margins | | `dots` | 12×12 filled circles; diameter tracks pose height, center tracks pose | | `kawaii` | Round eyes with big moving pupils, a talking mouth, and blush. Each animation has its own mood (with occasional accents while idle, typing, reading, or thinking), the mouth says the stock voice clips in sync, and the bell gets a celebration ([`kawaii/`](kawaii/)) | +| `evil` | Solid white scowling silhouettes (pointed high outers, rounded low inners, concave brow notch, convex bottoms; no pupils). Always menacing; pose and blink track classic | ## Add a style diff --git a/src/display/eyes/styles/evil.cpp b/src/display/eyes/styles/evil.cpp new file mode 100644 index 00000000..82a88895 --- /dev/null +++ b/src/display/eyes/styles/evil.cpp @@ -0,0 +1,168 @@ +#include "display/eyes/styles/eye_style.h" + +#include + +#include "animation/dead.h" +#include "display/eyes/core/blink.h" +#include "display/eyes/core/constants.h" +#include "display/eyes/core/draw.h" +#include "display/eyes/core/util.h" +#include "display/oled.h" +#include "display/oled_internal.h" +#include "pins.h" + +namespace { + +// Open silhouette taller than classic 14px so the scowl reads on 128×32. +// Blink scales this height; width stays near kEvilWidth for the inter-eye gap. +constexpr int16_t kEvilWidth = 42; +constexpr int16_t kEvilOpenHeight = 24; + +float bump01(float t) { + if (t <= 0.0f || t >= 1.0f) { + return 0.0f; + } + return 4.0f * t * (1.0f - t); +} + +// Left-eye unit test: nx=0 outer, nx=1 inner; ny=0 top, ny=1 bottom. +// Top and bottom share a slanted base (outer high → inner low). Depth bump +// opens the eye; a smaller notch digs the brow without collapsing fill. +bool insideEvilUnit(float nx, float ny) { + if (nx < 0.0f || nx > 1.0f || ny < 0.0f || ny > 1.0f) { + return false; + } + + constexpr float kOuterY = 0.06f; + constexpr float kInnerY = 0.50f; + constexpr float kNotch = 0.10f; + constexpr float kDepth = 0.72f; + + const float base = kOuterY + (kInnerY - kOuterY) * nx; + const float lift = bump01(nx); + float top = base + kNotch * lift; + float bottom = base + kDepth * lift; + + if (bottom <= top) { + return false; + } + + // Sharp outer tip only — keep mid-eye thickness. + if (nx < 0.08f) { + const float tip = nx / 0.08f; + const float mid = 0.5f * (top + bottom); + top = mid + (top - mid) * tip; + bottom = mid + (bottom - mid) * tip; + } + + return ny >= top && ny <= bottom; +} + +int16_t evilHeight(int16_t renderedHeight) { + if (renderedHeight <= 0 || eyes::DEFAULT_LEFT.height <= 0) { + return 0; + } + + const int16_t h = (int16_t)( + (int32_t)kEvilOpenHeight * renderedHeight / eyes::DEFAULT_LEFT.height + ); + + if (h > OLED_HEIGHT) { + return OLED_HEIGHT; + } + + return h; +} + +void drawEvilSilhouette(const Eye& rendered, bool mirrorRight) { + if (rendered.height <= 0 || rendered.width <= 0) { + return; + } + + const int16_t h = evilHeight(rendered.height); + if (h <= 0) { + return; + } + + int16_t w = kEvilWidth; + if (rendered.width > 0) { + w = (int16_t)( + (int32_t)kEvilWidth * rendered.width / eyes::DEFAULT_LEFT.width + ); + } + if (w < 4) { + return; + } + if (w > OLED_WIDTH) { + w = OLED_WIDTH; + } + + const int16_t cx = (int16_t)(rendered.x + rendered.width / 2); + const int16_t cy = (int16_t)(rendered.y + rendered.height / 2); + const int16_t x0 = (int16_t)(cx - w / 2); + const int16_t y0 = (int16_t)(cy - h / 2); + + for (int16_t y = 0; y < h; y++) { + const float ny = (h <= 1) ? 0.5f : (float)y / (float)(h - 1); + + for (int16_t x = 0; x < w; x++) { + float nx = (w <= 1) ? 0.5f : (float)x / (float)(w - 1); + if (mirrorRight) { + nx = 1.0f - nx; + } + + if (!insideEvilUnit(nx, ny)) { + continue; + } + + display.drawPixel( + (int16_t)(x0 + x), + (int16_t)(y0 + y), + SSD1306_WHITE + ); + } + } +} + +Eye evilBox(const Eye& eye) { + const int16_t cx = (int16_t)(eye.x + eye.width / 2); + const int16_t cy = (int16_t)(eye.y + eye.height / 2); + + return { + (int16_t)(cx - kEvilWidth / 2), + (int16_t)(cy - kEvilOpenHeight / 2), + kEvilWidth, + kEvilOpenHeight + }; +} + +void drawEvil( + EyeMode mode, + AnimationId /*animation*/, + uint32_t /*modeStartedMs*/, + uint32_t /*now*/, + EyeStyleSleepPhase /*sleepPhase*/ +) { + if (mode == EyeMode::Dead && deadShowingX()) { + drawDeadXEyes(evilBox(leftEye()), evilBox(rightEye())); + return; + } + + if (!oledAvailable) { + return; + } + + display.clearDisplay(); + drawEvilSilhouette(eyes::renderEye(leftEye(), blinkOpenAmount()), false); + drawEvilSilhouette(eyes::renderEye(rightEye(), blinkOpenAmount()), true); + display.display(); +} + +} // namespace + +extern const EyeStyleRenderer kEvilEyeStyle = { + "evil", + true, + true, + drawEvil, +}; diff --git a/src/display/eyes/styles/eye_style_ids.cpp b/src/display/eyes/styles/eye_style_ids.cpp index 0ab545dd..0c14ebce 100644 --- a/src/display/eyes/styles/eye_style_ids.cpp +++ b/src/display/eyes/styles/eye_style_ids.cpp @@ -10,6 +10,7 @@ constexpr const char* kEyeStyleIds[] = { "cover", "dots", "kawaii", + "evil", }; } // namespace diff --git a/src/display/eyes/styles/registry.cpp b/src/display/eyes/styles/registry.cpp index a1937285..3f08ddc6 100644 --- a/src/display/eyes/styles/registry.cpp +++ b/src/display/eyes/styles/registry.cpp @@ -9,6 +9,7 @@ extern const EyeStyleRenderer kKaomojiEyeStyle; extern const EyeStyleRenderer kCoverEyeStyle; extern const EyeStyleRenderer kDotsEyeStyle; extern const EyeStyleRenderer kKawaiiEyeStyle; +extern const EyeStyleRenderer kEvilEyeStyle; namespace { @@ -18,6 +19,7 @@ const EyeStyleRenderer* const kEyeStyles[] = { &kCoverEyeStyle, &kDotsEyeStyle, &kKawaiiEyeStyle, + &kEvilEyeStyle, }; } // namespace diff --git a/test/test_settings_validate/test_settings_validate.cpp b/test/test_settings_validate/test_settings_validate.cpp index 95ee4f4c..9c626733 100644 --- a/test/test_settings_validate/test_settings_validate.cpp +++ b/test/test_settings_validate/test_settings_validate.cpp @@ -111,6 +111,7 @@ void test_eyes_style() { TEST_ASSERT_TRUE(settingsValidateEyesStyle("cover")); TEST_ASSERT_TRUE(settingsValidateEyesStyle("dots")); TEST_ASSERT_TRUE(settingsValidateEyesStyle("kawaii")); + TEST_ASSERT_TRUE(settingsValidateEyesStyle("evil")); TEST_ASSERT_FALSE(settingsValidateEyesStyle("other")); TEST_ASSERT_FALSE(settingsValidateEyesStyle(nullptr)); } diff --git a/ui/src/config/ConfigForm.tsx b/ui/src/config/ConfigForm.tsx index 381e1f34..ad31f93c 100644 --- a/ui/src/config/ConfigForm.tsx +++ b/ui/src/config/ConfigForm.tsx @@ -14,7 +14,7 @@ import { useAccessToken } from "./useAccessToken"; import { useWifiNetworks } from "./useWifiNetworks"; import { WifiNetworksSection } from "./WifiNetworksSection"; -const EYES_STYLES = ["classic", "kaomoji", "cover", "dots", "kawaii"]; +const EYES_STYLES = ["classic", "kaomoji", "cover", "dots", "kawaii", "evil"]; // An emptied number field reads NaN; the stock volume stands in until the user types again. const clampVolume = (value: number) => (Number.isNaN(value) ? 70 : clamp(value, 0, 100)); @@ -197,7 +197,8 @@ export function ConfigForm({ settings }: { settings: Settings }) { Classic is the default procedural eyes. Kaomoji maps each animation to a face from the expression library. Cover fills each half of the screen for a mask with eye holes; animations change height with black margins. Dots draws a 12x12 circle per eye; size and - position follow the same poses as classic. Add new styles in firmware under{" "} + position follow the same poses as classic. Evil draws solid white scowling silhouettes + that stay menacing for every animation. Add new styles in firmware under{" "} display/eyes/styles/.

diff --git a/ui/src/views/ApiReference.tsx b/ui/src/views/ApiReference.tsx index 9184439b..44b8dd3b 100644 --- a/ui/src/views/ApiReference.tsx +++ b/ui/src/views/ApiReference.tsx @@ -200,8 +200,8 @@ export function ApiReference() { string - classic, kaomoji, cover, dots, or{" "} - kawaii (OLED eyes look; immediate) + classic, kaomoji, cover, dots,{" "} + kawaii, or evil (OLED eyes look; immediate) diff --git a/web/eyes/index.html b/web/eyes/index.html index 957fc5b9..55ada950 100644 --- a/web/eyes/index.html +++ b/web/eyes/index.html @@ -4,7 +4,7 @@ Eye styles · Tiny Engineer - + @@ -68,12 +68,22 @@

kawaii

Round eyes, big pupils, blush, and a talking mouth — each animation has its own mood.

+
  • + +
    +

    eyes_style

    +

    evil

    +

    Solid white scowling silhouettes — pointed high outers, rounded low inners, always menacing.

    +
    +
  • Set the style on your robot in the web config at http://tiny-engineer.local. - A fifth style, cover, is for eye-hole mask mods and is not shown here. + A sixth style, cover, is for eye-hole mask mods and is not shown here.

    diff --git a/web/js/eyes-preview.js b/web/js/eyes-preview.js index 430790ea..e8878186 100644 --- a/web/js/eyes-preview.js +++ b/web/js/eyes-preview.js @@ -155,6 +155,61 @@ function drawDots(buf, pose) { drawDot(buf, pose.right); } +const EVIL_W = 42; +const EVIL_OPEN_H = 24; + +function evilBump(t) { + if (t <= 0 || t >= 1) return 0; + return 4 * t * (1 - t); +} + +function insideEvilUnit(nx, ny) { + if (nx < 0 || nx > 1 || ny < 0 || ny > 1) return false; + const outerY = 0.06; + const innerY = 0.5; + const notch = 0.1; + const depth = 0.72; + const base = outerY + (innerY - outerY) * nx; + const lift = evilBump(nx); + let top = base + notch * lift; + let bottom = base + depth * lift; + if (bottom <= top) return false; + if (nx < 0.08) { + const tip = nx / 0.08; + const mid = 0.5 * (top + bottom); + top = mid + (top - mid) * tip; + bottom = mid + (bottom - mid) * tip; + } + return ny >= top && ny <= bottom; +} + +function drawEvilEye(buf, eye, mirrorRight) { + if (eye.h <= 0 || eye.w <= 0) return; + const h = Math.min(H, Math.round((EVIL_OPEN_H * eye.h) / DEFAULT_LEFT.h)); + if (h <= 0) return; + let w = Math.round((EVIL_W * eye.w) / DEFAULT_LEFT.w); + if (w < 4) return; + w = Math.min(W, w); + const cx = eye.x + ((eye.w / 2) | 0); + const cy = eye.y + ((eye.h / 2) | 0); + const x0 = cx - ((w / 2) | 0); + const y0 = cy - ((h / 2) | 0); + for (let y = 0; y < h; y++) { + const ny = h <= 1 ? 0.5 : y / (h - 1); + for (let x = 0; x < w; x++) { + let nx = w <= 1 ? 0.5 : x / (w - 1); + if (mirrorRight) nx = 1 - nx; + if (insideEvilUnit(nx, ny)) put(buf, x0 + x, y0 + y); + } + } +} + +function drawEvil(buf, pose) { + clear(buf); + drawEvilEye(buf, pose.left, false); + drawEvilEye(buf, pose.right, true); +} + function drawKaomoji(buf, nowMs, reduceMotion) { clear(buf); let id = "idle"; @@ -302,6 +357,7 @@ const STYLE_PHASE = { dots: 1700, kawaii: 3100, kaomoji: 900, + evil: 2400, }; function createPreview(canvas, style) { @@ -325,6 +381,7 @@ function createPreview(canvas, style) { else if (style === "dots") drawDots(buf, pose); else if (style === "kaomoji") drawKaomoji(buf, now + phaseMs, reduceMotion); else if (style === "kawaii") drawKawaii(buf, pose, now + phaseMs, reduceMotion); + else if (style === "evil") drawEvil(buf, pose); blit(buf, canvas); if (!reduceMotion && visible) raf = requestAnimationFrame(frame); } From 88b019ce4ddf65e3835117361dd5f984a2256926 Mon Sep 17 00:00:00 2001 From: Krzysztof Jamroz Date: Fri, 20 Nov 2026 23:16:16 +0100 Subject: [PATCH 4/4] fix(firmware): enhance wavStreamUpdate to prevent I2S DMA underruns by processing multiple WAV chunks per tick --- AGENTS.md | 2 + docs/README.md | 2 +- docs/testing.md | 2 + src/audio/wav_stream.cpp | 21 ++++++--- src/display/eyes/styles/README.md | 14 ++++++ src/display/eyes/styles/evil.cpp | 73 ++++++++++++++++++------------- 6 files changed, 75 insertions(+), 39 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index a612268e..2c141658 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -89,6 +89,7 @@ Breaking rules, SemVer mapping, and examples: [CONTRIBUTING.md](CONTRIBUTING.md) - **Mods** — optional add-ons under `mods//`. Models live in `3d_models/{cad,parts}/`. Commit `type(mods)` and name the mod in the summary. `feat(mods)` / `fix(mods)` do not version stock CAD. See [mods/README.md](mods/README.md). - **PCB** — [docs/pcb.md](docs/pcb.md) checklist + KiCad review rules below. Run `python3 scripts/check_pcb.py` (KiCad 10). New board paths need `REUSE.toml`. CERN-OHL-S. - **Motion** — poses −1..1 mapped to saved min/max; see [docs/robot-movement.md](docs/robot-movement.md). Do not widen NVS servo clamps without testing on a real robot. +- **OLED eye styles** — add/register under [`src/display/eyes/styles/`](src/display/eyes/styles/README.md). Keep `draw` cheap so I2S audio does not underrun (slow/gappy speech, clipped welcome); see **Keep audio fed** in that README. - **Secrets** — no `.env`, tokens, or Wi-Fi passwords in logs or screenshots. ## KiCad / PCB review @@ -121,6 +122,7 @@ Contribute/review process: [docs/pcb.md](docs/pcb.md). `expected-nets.yml`: [doc | Drive robot from any IDE | [docs/integration.md](docs/integration.md) | | Settings layers | [docs/settings.md](docs/settings.md) | | Servo axes / ranges | [docs/robot-movement.md](docs/robot-movement.md) | +| OLED eye styles / audio underrun | [src/display/eyes/styles/README.md](src/display/eyes/styles/README.md#keep-audio-fed-i2s-underrun) | | Tests | [docs/testing.md](docs/testing.md) | | PCB / KiCad | [docs/pcb.md](docs/pcb.md) | | Humans contributing | [CONTRIBUTING.md](CONTRIBUTING.md) | diff --git a/docs/README.md b/docs/README.md index cd913db9..c98d8a27 100644 --- a/docs/README.md +++ b/docs/README.md @@ -38,6 +38,6 @@ Pick a path. Depth lives in the linked pages. | **Share a finished build** | [Show and tell](https://github.com/jamro/tiny-engineer/discussions/categories/show-and-tell) — [how to post](../CONTRIBUTING.md#share-your-build) | | **Public landing content** (tinyengineer.dev `/`) | [`web/landing-page.md`](../web/landing-page.md) — messaging brief; visuals in [`web/STYLE.md`](../web/STYLE.md) | -Also: [robot-movement.md](robot-movement.md) (servo axes and safe ranges); optional [macos-lock-unlock.md](macos-lock-unlock.md) (sleep/wake on Mac screen lock). +Also: [robot-movement.md](robot-movement.md) (servo axes and safe ranges); optional [macos-lock-unlock.md](macos-lock-unlock.md) (sleep/wake on Mac screen lock); OLED eye styles / avoid I2S underrun when adding a face: [`src/display/eyes/styles/README.md`](../src/display/eyes/styles/README.md). **Source of truth:** pin constants in firmware (`include/pins.h`); electrical detail in `docs/hardware/`; HTTP shapes in [api.md](api.md). Overall build order: [getting-started.md](getting-started.md). diff --git a/docs/testing.md b/docs/testing.md index 494fdda9..f78d58cd 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -17,6 +17,8 @@ python3 scripts/test_audio_pack.py The optional [expression library](../lib/TinyEngineerExpressions/README.md) has deterministic asset checks and native renderer tests. These checks require Node 18+ and PlatformIO; they do not access hardware. On the robot, enable those faces with Config / `eyes_style=kaomoji` (default remains `classic`). +Adding a procedural `eyes_style` (not only kaomoji assets): keep the OLED `draw` cheap so welcome/attention audio does not underrun — [Keep audio fed](../src/display/eyes/styles/README.md#keep-audio-fed-i2s-underrun). + ```bash node scripts/expressions/generate.js --check node scripts/expressions/test-assets.js diff --git a/src/audio/wav_stream.cpp b/src/audio/wav_stream.cpp index ddc7b5ba..cd7d8c93 100644 --- a/src/audio/wav_stream.cpp +++ b/src/audio/wav_stream.cpp @@ -149,14 +149,21 @@ bool wavStreamUpdate() { const WavClipDef& def = clipDef(g_active); - if (!pumpWavChunk(g_file)) { - if (g_file) { - g_file.close(); + // Top up a few chunks per tick. One OLED redraw (heavy eye styles) can take + // longer than one 512-sample slice (~23 ms at 22050 Hz); without this the + // I2S DMA underruns, speech sounds slow/gappy, and cue timers cut the clip. + constexpr int kChunksPerUpdate = 3; + + for (int i = 0; i < kChunksPerUpdate; i++) { + if (!pumpWavChunk(g_file)) { + if (g_file) { + g_file.close(); + } + g_playing = false; + serialLogPrint(def.label); + serialLogPrintln(" OK"); + return false; } - g_playing = false; - serialLogPrint(def.label); - serialLogPrintln(" OK"); - return false; } return true; diff --git a/src/display/eyes/styles/README.md b/src/display/eyes/styles/README.md index d7400d38..107d5bfe 100644 --- a/src/display/eyes/styles/README.md +++ b/src/display/eyes/styles/README.md @@ -19,3 +19,17 @@ Extensible eye renderers selected by Config / `POST /settings` `{"eyes_style":" 4. Add a Config `