# AmoledOS

A smartwatch firmware for the **Waveshare ESP32-S3-Touch-AMOLED-1.8** — a
368x448 AMOLED you can hold in your hand. Twenty-two watchfaces — fifteen of
them modules installed from the card or the Store, most of them moved by the
accelerometer — twenty built-in apps, fifty-five more loaded from the microSD
as shared objects — one of them a Lua interpreter, so a text file on the card
is an app too, and one a street map with offline zones — a web portal with a
Store that installs them, updates the watch installs by itself, iPhone
notifications over BLE, a link between two watches over ESP-NOW with fourteen
apps on it, and a desktop simulator that runs the same UI code so you can
build the whole thing without the board.

<p align="center">
  <img src="docs/img/board-watchface.png" width="220" alt="Nixie watchface, photographed from the board">
  <img src="docs/img/board-aod.png" width="220" alt="The same face in always-on mode">
  <img src="docs/img/launcher-list.png" width="220" alt="The app launcher">
</p>

<p align="center"><em>The first two are captures from the real panel over HTTP.
Everything else below comes from the simulator, which draws the same
pixels.</em></p>

<p align="center">
  <img src="docs/img/photo-claudito.jpg" width="220" alt="Claudito running on the board, in a printed case">
  <img src="docs/img/photo-arkanos.jpg" width="220" alt="Arkanos running on the board">
  <img src="docs/img/photo-case.jpg" width="220" alt="The analog watchface, in the TPU case">
</p>

<p align="center"><em>And the thing itself. The grey case is printed in TPU —
the STLs are on
<a href="https://www.printables.com/model/1837479-waveshare-esp32-s3-touch-amoled-18-tpu-case">Printables</a>,
in a plain and a keychain version.</em></p>

---

## What it does

**Watch.** Seven watchfaces in the firmware, each with a dimmed always-on
variant. On AMOLED a black pixel is switched off, so a nearly black face costs
almost nothing to leave lit.

| | | | | | | |
|---|---|---|---|---|---|---|
| <img src="docs/img/face-digital.png" width="110"> | <img src="docs/img/face-analog.png" width="110"> | <img src="docs/img/face-nixie.png" width="110"> | <img src="docs/img/face-flip.png" width="110"> | <img src="docs/img/face-rings.png" width="110"> | <img src="docs/img/face-binary.png" width="110"> | <img src="docs/img/face-minimal.png" width="110"> |
| digital | analog | nixie | flip | rings | binary | minimal |

**Watchfaces from the card** (v0.15.0, [docs/FACES.md](docs/FACES.md)). A
face can be a module of its own, delivered on the card and installed into the
flash at boot, so the face you chose is there with or without a card. The
release brings five, and they move: the battery as water that stays level
when you tilt the watch and sloshes when you move it, a kaleidoscope that
turns with the wrist and changes colour under your finger, four things of
your house from Home Assistant with a tap to switch a light, an hourglass of
sand that piles on the digits, and a solar system with stars in parallax.
When nothing is drawn over them, the animated ones push their frames straight
to the panel: 29 fps for the water and the sand, 24 for the orbits, 19 for
the kaleidoscope, which changes every pixel.

| | | | | | |
|---|---|---|---|---|---|
| <img src="docs/img/face-agua.png" width="110"> | <img src="docs/img/face-kaleido.png" width="110"> | <img src="docs/img/face-casa.png" width="110"> | <img src="docs/img/face-arena.png" width="110"> | <img src="docs/img/face-orbitas.png" width="110"> | <img src="docs/img/face-picker.png" width="110"> |
| water | kaleidoscope | home | sand | orbits | the picker |

Four more came in v0.16.0: the time written out in words, in Spanish, English or
German; a pet you can stroke, in six animals and nine colours, that sleeps at
night and eats while the watch charges; an aquarium whose fish come for the
food you drop with a tap; and a landscape whose sky is the hour's and whose
weather is the forecast's, with tomorrow's a tap away.

| | | | |
|---|---|---|---|
| <img src="docs/img/face-palabras.png" width="110"> | <img src="docs/img/face-mascota.png" width="110"> | <img src="docs/img/face-acuario.png" width="110"> | <img src="docs/img/face-paisaje.png" width="110"> |
| words | pet | aquarium | landscape |

<p align="center">
  <img src="docs/img/face-mascota-animales.png" width="760" alt="The six pets: cat, dog, rabbit, bear, frog and penguin"><br>
  <em>The pet is one of six animals, in nine colours: a tap on the time changes it.</em>
</p>

<p align="center">
  <img src="docs/img/face-paisaje-climas.png" width="760" alt="The landscape: clear, dusk, rain, storm, snow and night"><br>
  <em>The landscape under a clear noon, a dusk, rain, a storm, snow and a clear night.</em><br><br>
  <img src="docs/img/face-paisaje-lugares.png" width="760" alt="The landscape's city and beach, three weathers each"><br>
  <em>The same weather seen from a city or from a beach, chosen on the watch or from the portal.</em>
</p>

**Six more came in v0.19.0.** Today's Moon as your hemisphere sees it, with
the rising and setting of the Sun and the Moon worked out on the watch,
offline, and the month's lunar calendar a tap away; the Gecko game's gecko
living on the glass, walking round the time, clinging to the low edge when you
tilt the watch, catching with its tongue the fly a tap lets go and sleeping
curled up at night; a photo from the card, cut to the screen on the portal,
with the time over it; and three that put the time over the old screens: code
rain whose characters light up as they cross the digits, the demoscene's fire
leaning when you tilt the watch, and a plasma whose rings follow the tilt.
Measured on the board: the fire at 24 fps, the plasma and the gecko at 19, the
rain at the 15 steps a second it is paced to.

| | | | | | |
|---|---|---|---|---|---|
| <img src="docs/img/face-luna.png" width="110"> | <img src="docs/img/face-gecko.png" width="110"> | <img src="docs/img/face-foto.png" width="110"> | <img src="docs/img/face-lluvia.png" width="110"> | <img src="docs/img/face-fuego.png" width="110"> | <img src="docs/img/face-plasma.png" width="110"> |
| [moon](faces/face_luna/README.md) | [gecko](faces/face_gecko/README.md) | [photo](faces/face_foto/README.md) | [rain](faces/face_lluvia/README.md) | [fire](faces/face_fuego/README.md) | [plasma](faces/face_plasma/README.md) |

<p align="center">
  <img src="docs/img/face-luna-hemisferios.png" width="330" alt="The Moon face: the same Moon seen from the north and from the south, and dimmed">
  <img src="docs/img/face-gecko-noche.png" width="110" alt="The Gecko face at night: the gecko asleep, curled up">
  <img src="docs/img/face-gecko-tenue.png" width="110" alt="The Gecko face dimmed: the gecko's silhouette">
</p>

The picker opens with a long press or a double tap on any face; its arrows
or a swipe sideways go through the faces, with the real face behind it. A
face from the card is removed from the portal's settings. Writing one of your
own starts from a template: [docs/FACE-GUIDE.md](docs/FACE-GUIDE.md).

**Launcher.** Three styles — a vertical list with the watchOS scale-and-fade
effect, a grid, and a honeycomb.

| List | Grid | Honeycomb |
|---|---|---|
| <img src="docs/img/launcher-list.png" width="220"> | <img src="docs/img/launcher-grid.png" width="220"> | <img src="docs/img/launcher-honeycomb.png" width="220"> |

**Phone notifications.** With a paired iPhone the watch shows its
notifications, sets its own clock from it, reads its battery and controls its
music — all over BLE, on one connection, with no app on the phone side. A
notification takes the whole screen; messages from one conversation are grouped
(WhatsApp sends one per message) and calls carry working answer and reject
buttons.

| What comes from the phone | How |
| --- | --- |
| notifications | ANCS |
| the time, without WiFi | Current Time Service |
| its battery | Battery Service |
| music and its controls | AMS |

It is iPhone only: ANCS is published by iOS and Android has no standard
equivalent. Android phones are planned, starting with music controls over
BLE HID: see [docs/ROADMAP.md](docs/ROADMAP.md).

**Battery.** The cell is a 302530 of 200 mAh, and the AXP2101 is programmed
rather than left at its factory values: "battery care" (a switch) charges it at
100 mA to 4.1 V with a proper termination current, and without it at 200 mA
instead of the chip's 300. The percentage is the firmware's own, not the PMU's
gauge: the voltage at rest, the sag learned with the screen lit, the charge
counted in while charging and the capacity measured on charges that start low.
It is a percentage of the cell full at 4.2 V, so with battery care a finished
charge reads about 87 %, as a phone with a charge limit does. The watch powers
itself off cleanly instead of running the cell down to the PMU's 2.6 V cut, and
the power key works: a click is the screen switch. With the screen off or
dimmed the CPU drops to 80 MHz, WiFi goes to its deepest modem sleep and, on
battery, the chip light-sleeps between wake-ups: 93.5 % of the time with the
screen off, measured. The touch controller sleeps too and still wakes the
screen. Away from its network the WiFi backs off and then waits for the screen
instead of scanning without end. At night, in the do-not-disturb hours, the
watch can go into deep sleep (a switch, off by default), woken by a touch, the
end of the hours or an alarm. Seven of the PMU's regulators feed nothing on
this board and are off. Settings' Battery page shows the charge,
the charger's stage, the last 24 hours as a graph (kept on the card, so a
restart does not wipe it), drain in %/h with hours left, time on battery and
charge cycles; Diagnostics adds the board and PMU temperatures and why the PMU
last powered off. `/api/status` serves the same to a home-automation poller. The whole
investigation, what the datasheet and the schematic say and what the board
said back, is in [docs/POWER.md](docs/POWER.md).

**Network onboarding.** With no stored credentials there is no way to enter
credentials, so the watch brings up its own access point and serves the form
itself. The screen shows the password in a large font and a QR code that
Android and iOS read from the camera out of the box.

**Three languages**, switchable on the device, with the packs on the microSD.
Spanish is the source language; English and German ship inside the binary.
There is also a pseudolocalisation pack for stress-testing layouts.

| Español | English | Deutsch |
|---|---|---|
| <img src="docs/img/settings-es.png" width="220"> | <img src="docs/img/settings-en.png" width="220"> | <img src="docs/img/settings-de.png" width="220"> |

**A web portal**, embedded in the binary, for uploading apps, photos, music and
recordings to the card from any browser — and for configuring the things that
are miserable to type on a 368 px screen: WiFi, the Home Assistant address and
token, the weather location, which exchange rates to watch, which sensors to
plot, the cameras, the radio stations on the Radio app's nine keys (searched in
radio-browser.info from the page itself), the map's zones and the areas
downloaded for use without a connection, and the whole remote-control profile. It also carries every switch of the
Settings app, a live view of the screen with the controls to drive it from the
browser, and the log tailed over wifi. Two of its pages are editors rather than
forms: `/pixel` for the drawings and `/lua` for the scripts, both writing the
same files the apps read. Its pages, the firmware's and the ones each app and
watchface brings, are in a side menu with a search and pinned pages (a drawer
on a phone), and it says so when the watch stops answering. See
[docs/PORTAL.md](docs/PORTAL.md).

<p align="center">
  <img src="docs/img/portal-inicio.png" width="720" alt="The portal's home page: the side menu and what the watch is showing"><br>
  <em>The portal's Home, from the development server: the menu, the watch's screen with its controls, and the state.</em>
</p>

**Updates and a store, from the watch.** Settings → Update finds the latest
release on GitHub and installs it from the watch itself, on trial, with the
previous version a hold away ([docs/UPDATE.md](docs/UPDATE.md)). The portal's
**Store** lists the release's apps and watchfaces with their icons and
pictures, and the watch downloads, checks and installs the ones you pick: no
`apps.zip` to copy ([docs/STORE.md](docs/STORE.md)).

**The menu, in your order.** The portal's `/menu` page arranges the launcher:
drag the apps into the order you want and into folders, and give each folder a
name and an icon. Folders are hexagons with a gradient and a glyph, so they
never look like an app, and they open in the launcher's own style. There is
room for 256 apps, and the launcher shows its first screen in under 200 ms
even then. See [docs/MENU.md](docs/MENU.md).

**Settings, one page per category.** The first page is six quick tiles
(Wi-Fi, Bluetooth, flashlight, always-on, power saver, do not disturb), the
brightness, and the categories with their current value; each category opens
as a page of its own. The screen timeouts are settings now, and the menu and
About pages carry a QR to the portal.

**Control centre.** A swipe down on the watchface pulls down the six quick
tiles, the brightness and the volume, the player while something plays (the
watch's own music, or the phone's), and a way into Settings; a swipe up puts it away. It opens in under 60 ms.

<img src="docs/img/control-centre.png" width="220">

**Battery and Diagnostics, in Settings.** The Battery app is gone: its
figures live in Settings' Battery page, with the charge as a bar and the last
24 hours as a graph, discharging in teal and charging in green, one sample
every five minutes kept on the card. Diagnostics has bars for internal RAM,
PSRAM and the memory apps' code runs from, the load of each core, and the
chip's, the PMU's and the board's temperatures, with the last hour of both as
graphs. The HAL samples once a second on its own; measuring the per-core load
cost nothing measurable (a JPEG decode benchmark stayed at 111 ms).

| Battery | Diagnostics |
|---|---|
| <img src="docs/img/settings-battery.png" width="220"> | <img src="docs/img/settings-diagnostics.png" width="220"> |

| Display | Menu |
|---|---|
| <img src="docs/img/settings-display.png" width="220"> | <img src="docs/img/settings-menu.png" width="220"> |

| Menu with folders | A folder | The honeycomb |
|---|---|---|
| <img src="docs/img/menu-list.png" width="220"> | <img src="docs/img/menu-folder.png" width="220"> | <img src="docs/img/menu-honeycomb.png" width="220"> |

| Notification | Setup AP |
|---|---|
| <img src="docs/img/notification.png" width="220"> | <img src="docs/img/setup-ap.png" width="220"> |

## The apps

Sixty of them, plus one for every Lua script on the card, in three
families that differ in where the code lives — not in what they are allowed
to do.

### Built into the firmware

Twenty ship inside the binary. They are the ones the watch cannot be without
— if the microSD is out, these still work. (Diagnóstico, in the table, was the
twenty-first and is now a page of Settings.)

| | | |
|---|---|---|
| <img src="docs/img/int-activity.png" width="200"><br>**Actividad** — steps against a goal, the week as bars, and the raw QMI8658 reading. The detector is tuned on recorded, counted walks (wrist and pocket): [docs/STEPS.md](docs/STEPS.md). | <img src="docs/img/int-stopwatch.png" width="200"><br>**Cronómetro** — laps, and it keeps counting with the screen off. | <img src="docs/img/int-timer.png" width="200"><br>**Temporizador** — countdown with presets, and it rings through the speaker. |
| <img src="docs/img/int-pomodoro.png" width="200"><br>**Pomodoro** — work and break cycles, with the day's tally kept across restarts. | <img src="docs/img/int-worldclock.png" width="200"><br>**Reloj mundial** — several cities at once, each with its own offset. | <img src="docs/img/int-alarm.png" width="200"><br>**Alarmas** — up to six, each on its own days of the week, checked by a service that runs whatever app is open; also editable from the portal. |
| <img src="docs/img/int-calendar.png" width="200"><br>**Calendario** — the month, drawn with the week starting on Monday. | <img src="docs/img/int-notifs.png" width="200"><br>**Notificaciones** — the iPhone's, over ANCS: history, per-category filter and actions. | <img src="docs/img/int-btremote.png" width="200"><br>**Control BT** — the phone's music over AMS: title, artist, album and transport. |
| <img src="docs/img/int-music.png" width="200"><br>**Música** — MP3 and WAV from the card, folder by folder, and it keeps playing with the app closed ([docs/MUSIC.md](docs/MUSIC.md)). | <img src="docs/img/int-photos.png" width="200"><br>**Fotos** — JPEG, PNG and BMP from the card, decoded and scaled to the screen. | <img src="docs/img/int-flashlight.png" width="200"><br>**Linterna** — the panel at full white, which on an AMOLED is the only way to make light. |
| <img src="docs/img/int-level.png" width="200"><br>**Nivel** — a spirit level off the accelerometer, with the bubble and the angle in degrees. | <img src="docs/img/int-calc.png" width="200"><br>**Calculadora** — four operations, sized for a thumb rather than for density. | <img src="docs/img/int-convert.png" width="200"><br>**Conversor** — units across several families, with the keypad shared with the calculator. |
| <img src="docs/img/settings-diagnostics.png" width="200"><br>**Diagnóstico** — memory, the load of each core and three temperatures, with graphs; a page of Settings, next to Battery, which used to be an app of its own. | <img src="docs/img/app-life.png" width="200"><br>**Vida** — Conway's Game of Life and Langton's ant on a 92x92 grid. | <img src="docs/img/settings-en.png" width="200"><br>**Ajustes** — six quick tiles and the brightness up top, then a page per category: display and its timeouts, sound, notifications and do-not-disturb, menu style, time, language, battery, touch, about. |
| <img src="docs/img/usb-pcremote-keys.png" width="200"><br>**Control PC** — the watch as a keyboard with media keys, a mouse, a gamepad and a MIDI port for the computer on the USB cable, one screen per role. | <img src="docs/img/usb-pato-list.png" width="200"><br>**Pato goma** — runs keyboard-and-mouse scripts on the computer, DuckyScript-style, picked and confirmed on the watch and edited from the portal's `/pato` page. | <img src="docs/img/int-link.png" width="200"><br>**Enlace** — the other watches around, and the one this is paired with. Pairing is bumping the two watches together. See [Two watches](#two-watches). |

### Loaded from the microSD

Forty more live in [`apps/`](apps/) and are loaded from `/sdcard/apps` as
`.so` files at startup. The same source builds into the simulator, so they are
designed on a laptop and copied to the card without changing a line — and a new
one needs no firmware rebuild. That includes its **launcher icon**: an app
describes it as a few dozen bytes of shapes and hands them over at load, or an
`.aic` file dropped on the card does; the firmware's own icons are the same
tables. Until v0.3.7 an icon was a switch case in the firmware, and every new
app meant a reflash for that alone. See [docs/ICONS.md](docs/ICONS.md).

#### Golf, the first app built from 3D assets

<p align="center">
  <img src="docs/img/app-golf-swing.png" width="200" alt="Golf: the top of the backswing, with the power bar">
  <img src="docs/img/app-golf-aim.png" width="200" alt="Golf: aiming on the map of a lake hole">
  <img src="docs/img/app-golf-coast3d.png" width="200" alt="Golf: the coastal course in 3D, the sea to the horizon">
</p>

The golfer is a model built and animated in **Blender** from a script, with
no `.blend` file: a swing, a wait, a cheer, a sulk and a turntable, 750
renders packed with LZ4 into a 1.1 MB `golf.pak` that sits on the
card next to the `.so`. Every frame is rendered twice, once for the light on
neutral grey and once for which region each pixel belongs to (skin, shirt,
stripes, trousers, check, shoes, hat...), and the watch multiplies the two
with the palette of what you are wearing. So the shop sells a red striped
polo, a tartan and a cowboy hat without a single extra render:

<p align="center">
  <img src="docs/img/golf-pipeline.png" width="690" alt="The lighting pass, the region ids, and three outfits coloured from them on the watch">
</p>

Around it the watch draws everything itself: a voxel-space 3D view of each
hole from behind the ball, from the same camera Blender rendered the golfer
with, so he stands on the ground; and a map from above, drawn from vector
shapes at any zoom, with hill shading and the ball's line. Three courses of
eight holes — woods, a windy links by the sea, a park full of water — a
tournament against three computer golfers, and the other watch over the
link. The renders run in a worker task and take 0.9 s for the map and
1.6 s for the 3D view, and the 3D is drawn ahead while you aim. Every
allocation goes to PSRAM: 11 KB of internal RAM while playing. More in
[apps/golf/README.md](apps/golf/README.md).

<p align="center">
  <img src="docs/img/app-golf-green.png" width="200" alt="Golf: a putt with the slope chevrons and the break preview">
  <img src="docs/img/app-golf-shop.png" width="200" alt="Golf: the shop, the golfer on a turntable">
  <img src="docs/img/app-golf-card.png" width="200" alt="Golf: a birdie, and the golfer cheers">
</p>

#### Turbo, an arcade racer

<p align="center">
  <img src="docs/img/app-turbo-city.png" width="160" alt="Turbo: the red wedge on a city highway with towers and traffic">
  <img src="docs/img/app-turbo-night.png" width="160" alt="Turbo: a snowy mountain pass at night, the headlights on the road">
  <img src="docs/img/app-turbo-halloween.png" width="160" alt="Turbo: Hollow Road at night, an orange moon behind a castle, twisted trees and a ghost car">
  <img src="docs/img/app-turbo-tunnel.png" width="160" alt="Turbo: Tunnel Ridge, the car about to enter a road tunnel lit inside">
  <img src="docs/img/app-turbo-space.png" width="160" alt="Turbo: the road floating in space, neon edges and a ringed planet">
</p>

The second game built from Blender renders, and the first that moves the
whole screen every frame. The road is drawn by the watch in **pseudo-3D**,
row by row, with bends, hills and fog; the cars and everything beside the
road are sprites: nine vehicles modelled from a script and rendered as a
lighting pass plus region ids, so the traffic comes in any colour and the
garage sells twelve paints from the same pixels, and 48 props and a 360°
backdrop for each of seven stages, from a city highway with overpasses to a
road floating in space. v0.4.12 added two: Hollow Road for Halloween, with a
hearse and ghost cars you drive through, and Tunnel Ridge, with road
tunnels. Tilt the watch to steer, the pedals are on the
screen, and checkpoints refill the clock.

A full frame through LVGL is 95 ms, so the race skips LVGL: a worker on the
other core renders into PSRAM buffers, in bands of internal RAM, and an LVGL
timer pushes each frame straight to the panel. 25 to 31 fps on the board,
measured over whole races; the story of how it got there from 12 is in
[apps/turbo/README.md](apps/turbo/README.md). Two paired watches race the
same stage at once, each seeing the other as a ghost.

<p align="center">
  <img src="docs/img/turbo-pipeline.png" width="690" alt="The lighting pass, the region ids, and three paints coloured from them on the watch">
</p>

#### Monster Hop, a hop-by-hop monster maze

<p align="center">
  <img src="docs/img/app-monsterhop-sewers.png" width="160" alt="Monster Hop: Tommy in the sewers of Zombie Town, next to a crate, with a zombie and steam vents">
  <img src="docs/img/app-monsterhop-moat.png" width="160" alt="Monster Hop: the castle moat, rafts sliding across violet water and a vampire on the bank">
  <img src="docs/img/app-monsterhop-river.png" width="160" alt="Monster Hop: the forest river with logs and lily pads, lanterns on the bank">
  <img src="docs/img/app-monsterhop-brute.png" width="160" alt="Monster Hop: City Hall, the Brute boss next to Tommy on the plaza">
  <img src="docs/img/app-monsterhop-wardrobe.png" width="160" alt="Monster Hop: the wardrobe, Tommy in a crown and a cape with a black kitten">
</p>
<p align="center">
  <img src="docs/img/app-monsterhop-trex.png" width="160" alt="Monster Hop: the T-Rex Run, the T-Rex right behind Tommy on the red dirt">
  <img src="docs/img/app-monsterhop-lava.png" width="160" alt="Monster Hop: the Lava River, a crack erupting in flames next to the stepping stones">
  <img src="docs/img/app-monsterhop-pier.png" width="160" alt="Monster Hop: High Tide, waves sweeping the quay and a crab">
  <img src="docs/img/app-monsterhop-map.png" width="160" alt="Monster Hop: the map, a hub with the house at the bottom and six zones">
</p>

The third game from Blender renders, and the first built as a world of
blocks. Tommy, eleven and in a cap, hops cell by cell through twenty-four
levels of Zombie Town, Vampire Castle, Mummy Desert, Werewolf Forest, the
Lost Valley and Abyss Bay, collecting five keys in each while zombies lunge,
vampires turn into bats, mummies push boulders, werewolves charge, raptors
pounce and the tide comes in, with a boss in every zone's last level (the
T-Rex chases you; the Kraken slams its tentacles).
BOOT is the action: a lever, a chest, a crate to push into the water, or a
super hop. Every block, prop, monster and each of Tommy's caps, capes and
pets is a sprite with a depth pass: the watch builds each level from them
into a background cache that knows the depth of every pixel, and the
sprites are tested against it pixel by pixel, so Tommy walks behind a wall
and shows through it as a silhouette. Tommy's house is the hub: wardrobe,
shop, a sticker album with one sticker hidden per level, trophies. 25 fps on
the board. Two paired watches race for the same keys. The same game runs
on macOS and Windows in HD, with two players on a split screen:
[charliejgallo/MonsterHop](https://github.com/charliejgallo/MonsterHop).
More in [apps/monsterhop/README.md](apps/monsterhop/README.md).

<p align="center">
  <img src="docs/img/photo-monsterhop-race.jpg" width="330" alt="Two watches in a Monster Hop race on Main Street, the same cars in the same places on both">
  <img src="docs/img/photo-monsterhop-house.jpg" width="330" alt="Tommy's house on two watches, one in English and one in Spanish">
</p>
<p align="center"><em>A key race on two boards: the same cars in the same
places, each watch with its own camera. And Tommy's house on both, one in
English, the other in Spanish.</em></p>

#### Mila, a Sokoban with a black kitten

<p align="center">
  <img src="docs/img/app-mila-casita.png" width="160" alt="Mila at home in her casita, in a party hat and a scarf, with her bed, a scratching post, a fish bowl and a cardboard box">
  <img src="docs/img/app-mila-overview.png" width="160" alt="The whole kitchen level before starting: cookie tins, fish placemats and puddles on mint tiles, with its par">
  <img src="docs/img/app-mila-play.png" width="160" alt="Mila in the garden next to flower pots, a soil circle and a white gate">
  <img src="docs/img/app-mila-map.png" width="160" alt="The world map: the kitchen with its level stones and stars, Mila standing on the current one">
  <img src="docs/img/app-mila-shop.png" width="160" alt="The shop on a light background: Mila turning, in a pink bow, with eight colours to pick">
</p>

The fourth game from Blender renders, and the first puzzle. Mila, a small
black kitten with amber eyes, pushes things back to their place around the
house: yarn balls into baskets, cookie tins onto placemats (on a wet floor
they slide on), flower pots past gates that open while a plate holds
something, cardboard boxes through an attic where only she fits through the
cat flaps, and crates across the rooftops at night, into holes they fill,
with balls that roll until they hit something. Forty levels, each solved by
a solver that runs the game's own rules, which also gives its par. A level
opens on the whole room, then the camera flies down onto Mila and follows
her; a finger held on her shows the whole room again. Her casita is the hub:
she wanders, sleeps, grooms and plays with the toys you buy, chases the
mouse you drag, and leaves a small present once a day. The worlds are data
in the pack, so a new one needs no code. 25-26 fps on the board. More in
[apps/mila/README.md](apps/mila/README.md).

<p align="center">
  <img src="docs/img/app-mila-visit.png" width="200" alt="A visit: the friend's Mila, in her own outfit, playing with Mila on the rug">
  <img src="docs/img/app-mila-peek.png" width="200" alt="The whole rooftop level while a finger holds Mila, with the holes and the crates where they are now">
  <img src="docs/img/app-mila-loader.png" width="200" alt="The loading screen: the Mila logo, a gold-to-pink bar and a tip">
</p>

#### Gecko, an endless runner

<p align="center">
  <img src="docs/img/app-gecko-jungle.png" width="160" alt="Gecko: the gecko running on a mossy causeway high over the jungle canopy, giant trees beside it">
  <img src="docs/img/app-gecko-temple.png" width="160" alt="Gecko: a grey causeway over a misty abyss, broken pillars rising from below">
  <img src="docs/img/app-gecko-desert.png" width="160" alt="Gecko: the gecko ducking under a wooden beam on a sandstone causeway, between hoodoos">
</p>

A temple runner on the wrist, and the work in progress of the November
batch: a gecko sprints down a causeway high over the jungle, a lost temple
and the desert, seen from just behind. Three lanes, swipes to change lane,
jump and slide, and corners taken with a twist of the wrist (or a swipe on
the corner); the speed keeps rising and the distance is the score. The
causeway is a real floor plan drawn the way Mode 7 draws a plane, so the
corners are right angles you see coming and the camera swings round them.
The gecko and the three worlds (textures, the horizon all round, obstacles
and scenery) are modelled and rendered in Blender by script; the gecko
comes in four skins from one render. More in [apps/gecko/README.md](apps/gecko/README.md).

#### Doom

<p align="center">
  <img src="docs/img/app-doom-demo.png" width="200" alt="Doom's attract demo on the watch, the marine firing, with the pad below the picture">
  <img src="docs/img/app-doom-e1m1.png" width="200" alt="E1M1, Hangar, at the start of the level, with MENU, MAP and GUN, a stick, USE and FIRE">
  <img src="docs/img/app-doom-map.png" width="200" alt="The automap of E1M1">
</p>

Can it run Doom? It can: Chocolate Doom through doomgeneric, as a 428 KB
`.so` from the card, with no line of the firmware changed for it. E1M1 runs at
35 fps on the board, Doom's own tic rate. The engine runs on the second core
and hands its frames over in three slots; LVGL's task pushes the newest
straight to the panel, and draws a pad below it: an analogue stick (a mouse to
Doom), FIRE, USE, the menu, the map and the next weapon, with the side button
firing while the thumb walks. `exit()` is a `longjmp` back to the worker, so
quitting from Doom's menu returns to the watch and gives every byte back.
Sound effects and the OPL2 music, synthesised on the watch for 3-13 % of a
core, depending on the track. Bring your own WAD: it was tested with the shareware `DOOM1.WAD` 1.9
(episode 1, freely distributable but id Software's, so it is not in the
repository), and the full games' WADs are searched first and should work,
untested. The engine is GPL v2. More in
[apps/doom/README.md](apps/doom/README.md).

#### Visor 3D, and two fingers everywhere

<p align="center">
  <img src="docs/img/app-visor3d-mila.png" width="200" alt="Mila, the mascot, as a 3D model on a light background">
  <img src="docs/img/app-visor3d-tommy.png" width="200" alt="Tommy from Monster Hop in the viewer">
  <img src="docs/img/app-visor3d-muscle.png" width="200" alt="Turbo's muscle car in the viewer">
</p>

The v2's touch chip reports a second finger in registers no driver reads,
while its finger count never says more than one. Since v0.6.0 the firmware
reads them, on the chip's interrupt, about 73 times a second, and apps get
tap, double tap, long press, drag with fling and pinch
([docs/GESTURES.md](docs/GESTURES.md) has the registers, the chip's faults
and the filters). **Visor 3D** is the app built for it: STL and M3D models
from the card, turned with one finger and zoomed with two, drawn by a
software rasteriser on the second core, about 18 fps at 16 000 triangles
while moving. The portal's `/3d` page converts STL, OBJ and GLB with their
colours, and the samples are the games' own characters: Mila, Tommy, the
zombie and Turbo's muscle car. Photos, Pixel Art, Buscaminas, Laberinto,
Golf's aiming map and Mila zoom with a pinch too; Control PC's mouse face is
a touchpad, Doom walks and shoots with two fingers, and Lua scripts get a
`gesture()` callback. More in [apps/visor3d/README.md](apps/visor3d/README.md).

#### New in v0.19.0

Fourteen apps of the tanda of November 2026, each designed in the simulator
and played on the watch before it came in, and all of them in the portal's
Store. Gecko, the fifteenth, has its own section above. Parejas, Tablero and
Hockey also play across two watches.

| | | |
|---|---|---|
| <img src="docs/img/app-fusion.png" width="200"><br>**Fusión** — numbered tiles that slide with a swipe and fuse two equal ones into one of double the value, on boards of 3×3 to 5×5: a goal per level, two minutes against the clock, or stones that cut the lines. A port of P4OS's game, redrawn for this screen. | <img src="docs/img/app-fusion-neon.png" width="200"><br>The Neon theme on a 5×5 with stones. Every tile is drawn by code at the board's cell size, its number cut from the firmware's font and resampled, so each size gets crisp digits; from 1024 the 5×5 says 1K. | <img src="docs/img/app-fusion-menu.png" width="200"><br>One canvas, painted by hand: the board stands still in a background buffer and only the rectangles the tiles cross are repainted, about a tenth of the screen while they move. Eleven achievements, a record per size and mode, and the game in course kept on the card. |
| <img src="docs/img/app-ruedas.png" width="200"><br>**Ruedas** — a puzzle of wheels carrying beads that touch and cross. A bead changes wheel only through a crossing; every colour goes to its own wheel and a pearl to every crossing. 24 levels in seven layouts, from two wheels to five, plus the wooden figure-of-eight. | <img src="docs/img/app-ruedas-ocho.png" width="200"><br>Drag a wheel and the beads follow the finger; a tap turns it one slot. A move is one turn by any amount, the same metric a two-sided breadth-first search uses to find each level's least number of moves: three stars at the least. | <img src="docs/img/app-ruedas-cruz.png" width="200"><br>Every track is the points at a distance from a segment: a circle, or a racetrack whose straight another one shares. The crossings are not written down; they are the slots two tracks happen to share. The board is one canvas painted per level and the beads are objects, so a turn repaints only where they move. More in [apps/ruedas/README.md](apps/ruedas/README.md). |
| <img src="docs/img/app-vitral.png" width="200"><br>**Vitral** — pieces of coloured glass fall into a window of lead: pieces of three and five squares, never four, in a well twelve wide. A full row breaks; a row of one colour is a *vitral*, scores triple and takes the row below with it. Marathon, three minutes against the clock, and thirty puzzle windows. Ported from P4OS. | <img src="docs/img/app-vitral-light.png" width="200"><br>Every pixel of glass, lead and stone is drawn by code, so the port draws it again at this screen's size instead of scaling it. The settled glass lives in the background buffer and only the 8x8 tiles that change are repainted. | <img src="docs/img/app-vitral-puzzle.png" width="200"><br>One finger: drag to move and lower, flick down to drop, up to hold, tap to turn; or move by tilting the watch. The puzzles are generated and each checked to have a solution, with undo, a hint and stars by time. More in [apps/vitral/README.md](apps/vitral/README.md). |
| <img src="docs/img/app-parejas-game.png" width="200"><br>**Parejas** — the memory game: turn two cards over and find the pairs. Against the clock, counting tries, against the machine (four levels of memory) or against the paired watch over the link, taking turns on the same table, lockstep like Truco. 48 pictures in three themes painted by code, and the flip done by hand in perspective. | | <img src="docs/img/app-parejas-bot.png" width="200"><br>Against the machine: four levels of memory, from forgetful to one that never misses. | <img src="docs/img/app-parejas-link.png" width="200"><br>Two watches on the same table, taking turns over the link. |
| <img src="docs/img/app-cauce.png" width="200"><br>**Cauce** — a sliding puzzle of wooden pieces, each carrying a stretch of groove: straight, bend or crossing. Slide them into the gap until the groove runs unbroken from the red entry to the blue exit, and the steel ball rolls down it. Entry, exit, stone and metal pieces are screwed down. 24 levels, 4x4 and then 5x5. | <img src="docs/img/app-cauce-roll.png" width="200"><br>Drag a piece next to the gap, or tap it; a tap on a piece further along the same row or column slides the whole line. Each level's least number of moves comes from a breadth-first search, and its solution is written next to it: three stars at the least. | <img src="docs/img/app-cauce-drag.png" width="200"><br>The box is one canvas painted once and every piece a small canvas of its own, wood grain, groove and screws drawn in code, so a slide moves one object. More in [apps/cauce/README.md](apps/cauce/README.md). |
| <img src="docs/img/app-sudoku.png" width="200"><br>**Sudoku** — 9×9 in five levels measured by the techniques they need, 6×6, Diagonal, Killer and a daily challenge that is the same board on every watch. A port of P4OS's game, its board made again at 37 px a cell inside the band the finger reaches. | <img src="docs/img/app-sudoku-notes.png" width="200"><br>A cell chosen follows the finger until it lifts; the number pad, keys of 63×52 px, comes up over the other half of the board. Notes are drawn at 11 px from masks of their own, and the pad lights the chosen cell's notes at the size of a key. | <img src="docs/img/app-sudoku-hint.png" width="200"><br>A hint names the technique, says it in a sentence and draws it: the cells, the candidates it rules out, the links of a chain. A worker keeps a board of every level ready, so a Master game starts at once. |
| <img src="docs/img/app-solitario.png" width="200"><br>**Solitario** — four solitaires that fit the watch with cards you can read: TriPeaks, Golf, FreeCell and Pyramid, ported from P4OS with their rules, solver, solved deals, undo, score and statistics (Klondike and Spider stay out: seven or ten columns do not fit 368 px). Tap a card to send it to its best place, or drag it: it rises and grows, and where it may land is ringed in gold. | <img src="docs/img/app-solitario-freecell.png" width="200"><br>Every new hand can be guaranteed solvable: the solver looks for one while the cards gather, and deals from 120 solved deals per game when the watch runs out of time. A hint (light blue) is the same search from the position on the table. Fifty-two cards are one canvas: still cards are stamped on the table, and only a card that moves is an object, from a pool of 24. | <img src="docs/img/app-solitario-rebote.png" width="200"><br>The ending is the old desktop bounce, the cards stamped on the felt as they go so the trail stays. The cards are drawn in code at each game's size, Blackjack's suits and stroke font with the rank and the suit side by side on the strip a fanned column shows. More in [apps/solitario/README.md](apps/solitario/README.md). |
| <img src="docs/img/app-tablero-reversi.png" width="200"><br>**Tablero** — three board games drawn flat: four in a row, reversi and draughts (ours: the flying king, taking compulsory and the most). Against the watch, five levels of negamax with alpha-beta on a worker so the screen never waits, or against the paired watch over the link, a move each in lockstep. The rules and engines come from P4OS's 3D *mesa*; the pieces with their shine, the falling disc behind the frame, the turning discs and the captures are painted by code. | | <img src="docs/img/app-tablero-cuatro.png" width="200"><br>Four in a row: the disc falls behind the frame. | <img src="docs/img/app-tablero-damas.png" width="200"><br>Draughts, with the flying king and taking compulsory. |
| <img src="docs/img/app-hockey.png" width="200"><br>**Hockey** — table air hockey to 7 goals: against the watch at four levels, or across two watches with each screen one half of the table. The physics and the computer's hand come from P4OS's 3D hockey. | <img src="docs/img/app-hockey-goal.png" width="200"><br>A neon table painted once; the puck with its trail, the mallets, the sparks and the goal light are composed on top and only what moved is repainted, about a tenth of the screen a frame. LVGL runs at 15 ms while a match is on. | <img src="docs/img/app-hockey-link.png" width="200"><br>Across two watches the lower MAC simulates and sends 30 states a second; the other runs the same physics so the puck keeps flying between states, and plays its own hits. Each screen only shows its own half. |
| <img src="docs/img/app-asteroides.png" width="200"><br>**Asteroides** — rocks in space in neon, the port of P4OS's Deriva: a ship that turns, thrusts with inertia and fires on its own, five kinds of rock, four enemies, three bosses, powers, and a twelve-sector campaign with a workshop. One finger is a stick wherever it lands (or the tilt turns the ship); a double tap jumps. Only the tiles that changed reach the panel, straight from a worker: 60 fps in the simulator. | | <img src="docs/img/app-asteroides-boss.png" width="200"><br>One of the three bosses. | <img src="docs/img/app-asteroides-shop.png" width="200"><br>The workshop, between sectors. |
| <img src="docs/img/app-flipper.png" width="200"><br>**Flipper** — a 2D pinball, upright like the screen: a table a screen and a half tall that the camera follows, neon on black. A touch on either half is that flipper (two fingers, both), the plunger is a drag down the lane, and shoving the watch nudges the table, with its TILT. | <img src="docs/img/app-flipper-arriba.png" width="200"><br>Bumpers, a ramp over the top to the left inlane, drop targets, lit lanes, a multiplier, the extra ball and a three-ball multiball with a jackpot. The ball is stepped every millisecond and the flipper hands it its own speed, so where it sits on the flipper is where it goes. | <img src="docs/img/app-flipper-multibola.png" width="200"><br>The frame goes straight to the panel, as in Turbo: the table is painted once and each frame is its rows under the camera plus what moves. |
| <img src="docs/img/app-mate.png" width="200"><br>**Mate en dos** — chess puzzles from the Lichess database (CC0): mate in one, two and three in rising difficulty, tactics picked by your score, and a puzzle of the day with its streak. The watch plays the move that sets the puzzle and answers yours with the defence; any move that mates wins. | <img src="docs/img/app-mate-pista.png" width="200"><br>Touch a piece and its square, with the legal moves marked. A hint lights the piece to move, a second one its square; a wrong move shows in red and is taken back; the pause plays the solution out. Castling, en passant and promotion (with the piece to choose) are in the rules, checked on the standard perft positions. | <img src="docs/img/app-mate-fin.png" width="200"><br>The pieces are drawn by code from distance fields when the app opens; the board is one canvas where only the squares that change are repainted. 4,766 puzzles in a 267 KB pack on the card, read one at a time. More in [apps/mate/README.md](apps/mate/README.md). |
| <img src="docs/img/app-metronomo.png" width="200"><br>**Metrónomo** — a metronome from 30 to 250 BPM, set with a thumbwheel or by tapping it in, nine time signatures with the first beat accented, subdivisions, a woodblock, a click or a beep, and a pendulum that swings with what is heard. The beat is counted in samples of the streaming speaker, not by a timer: no drift, no jitter, measured. | <img src="docs/img/app-metronomo-12-8.png" width="200"><br>12/8 with secondary accents where each group starts, and the eighths between the beats. | <img src="docs/img/app-metronomo-tap.png" width="200"><br>Tap tempo: the average of the last five taps, and the next beat moved onto the next tap. |
| <img src="docs/img/app-respirar.png" width="200"><br>**Respirar** — guided breathing: a flower on black that opens as you breathe in, stays open while you hold and closes as you breathe out, with the word and the count. 4-7-8, box, coherence or your own pattern, for one, three or five minutes, with a soft bell at every change if you want it. | <img src="docs/img/app-respirar-menu.png" width="200"><br>The streak of days is kept in the preferences: a day counts with a minute of breathing. The screen stays on only while a session runs. | <img src="docs/img/app-respirar-fin.png" width="200"><br>Every pixel's colour depends only on where it is, so a frame redraws just the thin ring between the old edge and the new one, about 8 % of the screen, and only once the edge has moved a pixel: near 30 fps in the middle of a breath, nothing in the holds. More in [apps/respirar/README.md](apps/respirar/README.md). |

#### The others

| | | |
|---|---|---|
| <img src="docs/img/app-chatarra-map.png" width="200"><br>**Chatarra** — a turn-based robot RPG. Eight zones, 61 rooms, 64 parts drawn from descriptors rather than sprites. A team of three, a phone booth to fight another watch, a fair at the docks, weather and a day that turns to night. | <img src="docs/img/app-chatarra-battle.png" width="200"><br>Its combat: six elemental types, an effectiveness table, the rival's parts as far as your register knows them, and a robot you built from parts torn off others. | <img src="docs/img/app-cjump.png" width="200"><br>**Claude Jump** — a vertical platformer with five zones, coins and sixteen costumes. |
| <img src="docs/img/app-topos.png" width="200"><br>**Topos** — whack-a-mole in three modes. A mole in a hard hat takes two taps, a golden one is worth a lot, and a bomb must not be touched. | <img src="docs/img/app-topos-frenzy.png" width="200"><br>Frenzy: several at once and combos up to ×5. The lawn never moves, so only what comes out of the holes is redrawn — about a tenth of the screen per frame. | <img src="docs/img/app-topos-survival.png" width="200"><br>Survival: three hearts and a level every eight moles. Every state has its own sprite — peeking, glancing about, taunting, dizzy, the hat flying off. |
| <img src="docs/img/app-video-list.png" width="200"><br>**Video** — plays MJPEG AVIs from the card at the screen's size, with sound, at 15 fps. `tools/video_convert.sh` makes the pair of files from anything ffmpeg reads. | <img src="docs/img/app-video.png" width="200"><br>The sound is the clock: the frames follow the player's position and a late one is skipped, never the other way round. Reading and decoding run in a background task on the second core, the first app to have one, and the frame goes straight to the panel past LVGL's render. The numbers are in [docs/VIDEO.md](docs/VIDEO.md). | <img src="docs/img/app-pong.png" width="200"><br>**Pong** — across two watches: the ball leaves the top of one screen and comes down the other's. The host simulates at 30 Hz over the link's fast channel; 30 states a second each way, measured, with an iPhone connected. |
| <img src="docs/img/app-radar.png" width="200"><br>**Radar** — where the other watch is. Pings ten times a second carry the signal strength each side sees, and a path-loss model calibrated at one metre puts the partner on the rings; underneath, FTM time of flight (IEEE 802.11mc): one watch answers from its softAP, the other measures 16 frames every 1.5 s and both show the distance in centimetres. | <img src="docs/img/app-walkie.png" width="200"><br>**Walkie** — push to talk between two watches. Hold the button and 29 ms frames of IMA ADPCM go out on the fast channel, 34 a second; let go and the speaker takes the codec back and plays what arrives through the HAL's streaming speaker. Half duplex because the ES8311 is one codec for both directions. | <img src="docs/img/app-neon-combat.png" width="200"><br>**Neon Snakes** — neon snakes eating neon fruit on a screen that is black everywhere else, no score. Normal is the classic; Battle pulls the camera back to four snakes, you against three bots or against the paired watch and two bots. Every sprite is drawn by code from distance fields, and only the cells that changed are repainted: 28 fps on the board. |
| <img src="docs/img/app-burbujas.png" width="200"><br>**Burbujas** — a bubble shooter in three modes: endless, generated levels where the ceiling comes down, and two minutes against the clock. | <img src="docs/img/app-burbujas-guide.png" width="200"><br>You aim by dragging: the dotted line is the shot itself, run ahead of time through the same stepping function, so it cannot promise a bounce the bubble will not make. The dashed circle is where it would stick. | <img src="docs/img/app-burbujas-timed.png" width="200"><br>Time attack: two minutes, and the rows arrive by the clock rather than by your misses. The still board is the background rather than a sprite per bubble, so sixty bubbles hanging there cost nothing per frame: 9-18 % of the field is redrawn, and the watch holds 29 fps. |
| <img src="docs/img/app-blackjack-play.png" width="200"><br>**Blackjack** — against the house on a green table: six decks, the dealer stands on 17, blackjack pays 3 to 2, with insurance, doubling and a split. The **Hint** switch rings in gold the play basic strategy would make — here, standing on two queens. | <img src="docs/img/app-blackjack-split.png" width="200"><br>A split, each hand settled on its own. Every card is its own ARGB8888 canvas drawn once and then moved as an object, so only the area it crosses is repainted; the hole card turns over by squeezing its horizontal scale. The rules engine plays a million hands on the Mac and checks every payout: 0.46 % house edge with basic strategy, the textbook figure. | <img src="docs/img/app-blackjack-bj.png" width="200"><br>The art is plain C with no bitmaps: the suits are implicit curves (the heart is the classic sextic), the indices a stroke font, and the jack, queen and king pixel art mirrored top to bottom like a real deck. The curved words on the felt are real fonts, so they are translated. |
| <img src="docs/img/app-gemas.png" width="200"><br>**Gemas** — match-three. The jewels are traced in code as convex polygons with facets, not stored as bitmaps. | <img src="docs/img/app-2043.png" width="200"><br>**2043** — a vertical shooter, an homage to Capcom's 1943, with a different boss per planet. | <img src="docs/img/app-arkanos.png" width="200"><br>**Arkanos** — brick breaking, twelve walls, and the app that introduced dirty-rectangle drawing. |
| <img src="docs/img/app-claudito.png" width="200"><br>**Claudito** — a virtual pet, entirely hand-drawn pixel art on a 92x112 grid. | <img src="docs/img/app-truco.png" width="200"><br>**Truco** — Argentine truco against the machine, with cards drawn in code and a matchstick scoreboard. Since v0.4.1 also against the other watch over the link: the same engine runs on both, and only the moves travel. | <img src="docs/img/app-atasco.png" width="200"><br>**Atasco** — a sliding block puzzle. 25 levels, each with a BFS-verified minimum move count. |
| <img src="docs/img/app-clima.png" width="200"><br>**Clima** — weather from Open-Meteo over HTTPS, with the icons drawn from shape descriptions at any size. | <img src="docs/img/app-remoto.png" width="200"><br>**Remoto** — a programmable Home Assistant remote: button pages, accelerometer gestures and a dial you turn with your wrist. | <img src="docs/img/app-sensores.png" width="200"><br>**Sensores** — up to four Home Assistant sensors with three hours of chart, sampled by the watch itself. |
| <img src="docs/img/app-tuner.png" width="200"><br>**Afinador** — a chromatic tuner (NSDF pitch detection) and a sound level meter with A weighting. | <img src="docs/img/app-recorder.png" width="200"><br>**Grabadora** — voice memos to WAV on the card, with a live waveform. | <img src="docs/img/app-mines.png" width="200"><br>**Buscaminas** — minesweeper on a single canvas, because 250 LVGL objects do not fit in internal RAM. |
| <img src="docs/img/app-maze.png" width="200"><br>**Laberinto** — a ball rolling through a generated maze, driven by tilting the board. | <img src="docs/img/app-cotiz.png" width="200"><br>**Cotizaciones** — exchange rates, configured from the portal. | <img src="docs/img/app-scanner.png" width="200"><br>**Escáner** — a WiFi and LAN survey: networks around you, hosts and open ports, written to the card as NDJSON. |
| <img src="docs/img/app-flappy.png" width="200"><br>**Flappy** — one button, one bird, the usual pipes. | <img src="docs/img/app-simon.png" width="200"><br>**Simon** — the colour-and-sound memory game, each pad with its own tone. | <img src="docs/img/app-dice.png" width="200"><br>**Dados** — dice of any number of sides, rolled by shaking the watch. |
| <img src="docs/img/app-pixel.png" width="200"><br>**Pixel Art** — 8x8 and 16x16 drawings with a 32-colour palette, frames that become a looping GIF, exported to the card as PNG and GIF. <img src="docs/img/pixel-kitten.gif" width="96"><br>The kitten is one of the samples it seeds on first run, and this GIF is the watch's own export. Since v0.4.2 a drawing can be sent to the other watch over the link. | <img src="docs/img/app-pixel-gallery.png" width="200"><br>Its gallery of eight canvases. The same files open in the portal's `/pixel` page, where they are drawn with a mouse and saved back; the watch reloads them on its own. | <img src="docs/img/app-hello.png" width="200"><br>**hello_app** — the 30-line template. It is what you copy to start one of your own; see [docs/APP-API.md](docs/APP-API.md). |
| <img src="docs/img/app-camaras-list.png" width="200"><br>**Cámaras** — IP cameras live, straight from the camera: RTSP with H.264 Baseline decoded on the watch, or MJPEG. Cameras are added from the portal's `/camaras` page; the password never goes back to the browser. | <img src="docs/img/app-camaras.png" width="200"><br>640x360 plays at 20 fps and 640x480 at 12; 1280x720 at about 4, and H.265 or Main profile are refused with a message that says why. The decoder runs on one core while the other converts and pushes the previous picture. Every feed measured in [docs/CAMERAS.md](docs/CAMERAS.md). | <img src="docs/img/app-camaras-fill.png" width="200"><br>Tap the picture for the whole screen. The feed in these pictures is the U.S. National Park Service's North Entrance webcam at Yellowstone (public domain, [nps.gov](https://www.nps.gov/yell/learn/photosmultimedia/webcams.htm)), played in the simulator. |

#### Radio

| | | |
|---|---|---|
| <img src="docs/img/app-radio.png" width="200"><br>**Radio** — internet stations on a front panel from the sixties: nine keys, a lit dial with the station, the song and its cover, and a needle over the scale. It plays through the firmware's player, so it goes on with the app closed and the control centre drives it. | <img src="docs/img/app-radio-info.png" width="200"><br>Tap the dial for everything the stream says of itself. The cover is looked up on iTunes by the song's title, and only taken when the artist matches; the title changes when its song is heard, not when it is downloaded ten seconds before. | <img src="docs/img/app-radio-idle.png" width="200"><br>The keys are filled in the portal's `/radio` page, from a list kept on the card and a search in radio-browser.info; the logos are drawn in the browser. MP3 and AAC (HE-AAC too) over http or https, and HLS; [docs/RADIO.md](docs/RADIO.md) has the measurements. |

#### Mapas

| | | |
|---|---|---|
| <img src="docs/img/app-mapas.png" width="200"><br>**Mapas** — OpenStreetMap on the watch, as vector tiles from OpenFreeMap (no key, no quota) drawn by the watch in a dark style for the AMOLED. Drag, flick, pinch, double tap, or + and −. | <img src="docs/img/app-mapas-calles.png" width="200"><br>Street names follow the streets. The map is rendered by a background task into a buffer bigger than the screen, so a pan never waits for it: 28-31 fps panning, 29 pinching, on the board. | <img src="docs/img/app-mapas-alfiler.png" width="200"><br>Zones and whole areas for use without a connection are saved from the portal's `/mapas` page, which downloads and packs the tiles in the browser. |
| <img src="docs/img/app-mapas-teclado.png" width="200"><br>Search with an old phone's keypad: tap a key again within a second for its next letter. | <img src="docs/img/app-mapas-resultados.png" width="200"><br>The names come from the downloaded zones' index, and online from Photon, which knows street numbers too. | Everything measured, and the formats on the card, in [docs/MAPS.md](docs/MAPS.md). |
| <img src="docs/img/app-ble.png" width="200"><br>**BLE** — a Bluetooth LE scanner and analyser: who is around, what each one seems to be (phone, earbuds, tracker, thermometer, mouse...), its company, the signal and its last 30 seconds; every AD structure explained with its bytes, and a GATT explorer for the devices that take a connection. | <img src="docs/img/app-ble-radar.png" width="200"><br>The radar puts everyone at a distance estimated from the signal (the angle means nothing: Bluetooth has no direction); a tap picks one, and the finder beeps faster as you get closer. It scans only while open, at 100 % by default: measured on the watch, listening all the time did not slow the WiFi down. | <img src="docs/img/app-ble-sensors.png" width="200"><br>The readings thermometers broadcast — BTHome, pvvx/ATC, Xiaomi (with its key when it encrypts), Govee, Ruuvi, SwitchBot, Qingping, Inkbird, Eddystone TLM — with their last two hours, and a CSV on the card. The decoders are P4OS's, tested on the Mac under ASan. [apps/ble/README.md](apps/ble/README.md) |

### Written in Lua, on the watch

One of those `.so` files is a **Lua 5.4 interpreter**, and with it a script is
not code you compile but a file you drop on the card. Put `cubo.lua` in
`/sdcard/lua`, open it, and it runs. Get it wrong and you get a message with
a line number on a black screen — never a reboot, which is the whole point.

| | | |
|---|---|---|
| <img src="docs/img/app-lua-cube.png" width="200"><br>**The bench** — a wireframe cube whose two rotations, perspective divide and twelve lines are all done in Lua, per vertex, per frame. Tap for another cube. | <img src="docs/img/app-lua-error.png" width="200"><br>A mistake is a message, with the file, the line and the name of the variable. The watch carries on: every call into Lua goes through `lua_pcall`, and a script that will not come back is cut by an instruction hook before the watchdog notices. | <img src="docs/img/app-lua-hello.png" width="200"><br>The whole of that one: `function draw()`, a circle and two lines of text. All four callbacks — `init`, `tick`, `draw`, `touch` — are optional. |
| <img src="docs/img/app-lua-list.png" width="200"><br>The scripts on the card, listed by the Lua app. | <img src="docs/img/app-lua-launcher.png" width="200"><br>And each one is an entry in the launcher of its own, beside the apps written in C: a script names itself with `-- @name Cubo` and takes an icon from a `.aic` beside it — four lines of shapes assembled with `tools/aic.py asm`, no toolchain involved. The module declares one app per script, which is a thing a `.so` could not do before v0.3.15. | <img src="docs/img/app-lua-balls.png" width="200"><br>**Pelotas** — the other way of drawing: the world is painted once and frozen, the app puts back what the last frame drew, and only the rows that changed go to the panel. 76 of 224, and the frame goes from 40 ms to 21. The grid is the point: erasing by painting over it would leave holes. |

**It is not the interpreter that is slow.** Measured on the board: 200,000
turns of a loop in 105 ms, about 1.9 M a second, with the code running from
PSRAM through the MMU. A frame of the cube is 3 ms of script, 8 of upscaling
and 26 of pushing 368x448 pixels at the panel — so the panel is the ceiling,
and a script has some 30 ms a frame to spend before it becomes the slower
half. That is around 57,000 VM instructions.

And it only pays for what it moves: the app pushes **only the rows the script
touched**, which it works out on its own from the boxes the primitives mark.
The cube clears every frame, so it pushes all 224 rows and costs what it
always did; the bouncing balls, over a background the app puts back for them,
push 76 and take the frame from 40 ms to 21.

And it costs **52 bytes of internal RAM**, the scarce kind, because Lua's heap
is allocated straight out of PSRAM; with the default allocator the same state
took 50 KB of it. The whole story, with the numbers and the two build flags
without which none of this works, is in [docs/LUA.md](docs/LUA.md).

The loop is short on purpose: the portal's `/lua` page is an editor with a
console, and while a script is running the watch watches the file it came from
and reloads it when it changes. You save in the browser and look at the watch.

## Two watches

Two of them talk over **ESP-NOW**, with no router in between: WiFi frames
without an association, a few milliseconds one way. The **Enlace** app shows
the watches around (each beacons its name once a second) and pairs two of
them with a gesture: **bump them together**. Both feel the knock, both say
so on the air, and if the two knocks are within 400 ms and the signal says
"next to me", they are partners: a key derived from both sides' nonces, an
encrypted peer, remembered across restarts. On top of that the firmware
offers apps a fast channel (send and forget, for a game's state) and a
reliable one (in order, acknowledged, resent, for turns and files), and the
simulator has the same link over UDP, so a two-player app is designed on a
laptop with two windows.

<p align="center">
  <img src="docs/img/photo-link-paired.jpg" width="640" alt="Two watches paired, one in Spanish and one in English">
</p>
<p align="center"><em>Paired by a bump: the one on the left is set to Spanish, the
other to English. "Canal cifrado listo" / "encrypted channel ready" is the
proof both hold the same key.</em></p>
<p align="center">
  <img src="docs/img/photo-pong.jpg" width="300" alt="Pong across two watches">
  <img src="docs/img/photo-link-launcher.jpg" width="420" alt="The launchers side by side, with Enlace">
</p>
<p align="center"><em>Pong is played with the two watches top to top: the ball
leaves one screen and comes down the other.</em></p>
<p align="center">
  <img src="docs/img/app-truco-link.png" width="300" alt="Truco against the other watch: the partner called envido">
</p>
<p align="center">
  <img src="docs/img/photo-truco-envido.jpg" width="300" alt="Truco for two: charlie called envido, amoledos has to answer">
  <img src="docs/img/photo-truco-truco.jpg" width="300" alt="Truco for two: amoledos called truco">
</p>
<p align="center"><em>Truco for two (v0.4.1), the watches facing each other
across the table: charlie calls envido and amoledos has to answer; a hand
later amoledos calls truco. Both run the same deterministic engine from
the same seed; the host orders the moves and the guest applies only what
comes back.</em></p>

v0.4.2 adds the two smaller link apps: **Pixel Art** sends a drawing to the
other watch (the `.pix` file, in chunks over the reliable channel, into the
first empty slot on the other side), and **Radar** shows where the other
watch is, by signal strength and by FTM time of flight. v0.4.3 adds the
**Walkie**, push to talk over the fast channel, and with it the streaming
speaker the HAL lacked (`aos_hal_spk_*`). v0.4.8 brings **Neon Snakes**
in lockstep, v0.4.9 **Golf**: only the shots travel, each with the
place the ball stopped, so the two watches can check they agree, and
v0.4.10 **Turbo**: both watches race the same stage at once and see each
other as a ghost car; when both have built the stage they start together,
34 ms apart on two boards. v0.4.13 **Monster Hop** races for keys: both
play the same level with the same clock, the keys, levers, crates and chests
are shared, and a key both grabbed goes to whoever grabbed it first.
v0.5.5 **Mila** does two things: a visit, where the friend's Mila comes in
through the casita's door in her own outfit and plays with yours, and a
race on a level open on both, with the other's progress on a pill.

<p align="center">
  <img src="docs/img/photo-walkie.jpg" width="640" alt="The walkie on two watches, one in Spanish and one in English">
</p>
<p align="center"><em>The walkie after a chat through a closed door, five metres
apart: 24 frames one way, 31 the other, nothing lost. One watch in Spanish,
the other in English.</em></p>

And the sixth app on the link is not a link app at all: **Chatarra**, the robot
RPG, grew a **phone booth** in each of its eight towns. Walk into it and the
watch goes on the air and talks to the one it is paired with — fight, swap a
robot, swap a part — and walk out and the radio comes down. The battle is
lockstep like Truco's: both watches run the same combat over the same seed and
only the two choices of the turn travel, one byte each.

<p align="center">
  <img src="docs/img/photo-chatarra-booth.jpg" width="300" alt="The phone booth on two watches: connected to each other">
  <img src="docs/img/photo-chatarra-link-battle.jpg" width="300" alt="The same battle seen from both watches">
</p>
<p align="center"><em>The booth, and then the same battle from both sides: the
one in English is CRATE LV6 and sees the rival at LV5; the one in Spanish is
CAJA N5 and sees the rival at N6. The guest says ESPERANDO while the host
resolves the turn.</em></p>
<p align="center">
  <img src="docs/img/photo-chatarra-link-end.jpg" width="300" alt="Back in the booth after the fight, one watch at 17/40 and the other at 0/36">
</p>
<p align="center"><em>And back in the booth afterwards: 17/40 against 0/36, and
both say good fight in their own language.</em></p>

The seventh is **Neon Snakes** (v0.4.8): Battle → Multiplayer puts the two
watches in the same arena with two bots. Lockstep again, but with a clock: the
host decides where both snakes turn on every step and sends that decision on
the reliable channel before applying it, eight times a second; the guest
applies exactly what arrives, and checks a hash of the board after each step.
A minute on two boards: 470 steps, none resent, no divergence. It also found
the link's newest trap, which two simulators never showed: a frame on the
reliable channel can overtake one sent earlier on the fast channel, so
nothing that travels fast may be a precondition for something that travels
reliably.

<p align="center">
  <img src="docs/img/photo-neon-link.jpg" width="420" alt="Neon Snakes on two watches: the same arena, each seen from its own side">
</p>
<p align="center"><em>The same Battle on both watches, one turned towards
each player. The ring on the lower screen marks that watch's own snake for a
couple of seconds after it comes back.</em></p>

The plan, and everything measured along the way — 6000 frames with nothing
lost on the air, 3-5 ms round trip, 60 KB/s, what Bluetooth costs, what a
watch that leaves its network to sit on a channel costs, 100 KB over the
reliable channel with a third of the frames dropped on purpose, and the
knock that paired the watches seventeen times — is in
[docs/LINK.md](docs/LINK.md).

## The USB port

The USB-C port is one thing at a time, chosen in Settings or in the portal:
the **console** it boots as (the log and `esptool`), a **keyboard and
network** for the computer, the **card as a disk** of the computer, or a
**host** for a pendrive. In keyboard mode the watch is a keyboard with media
keys, a mouse, a gamepad, a MIDI port and a network card at once, and the
portal answers at `http://192.168.7.1` (and `<name>.local`, `amoledos` unless you name the watch in Settings) over the cable
with no WiFi. Everything measured is in [docs/USB.md](docs/USB.md).

| | | |
| --- | --- | --- |
| <img src="docs/img/usb-pcremote-keys.png" width="200"><br>**Control PC** — music, volume, slides, cmd+tab and the three keys every dialog wants, on the computer the watch is plugged into. | <img src="docs/img/usb-pcremote-mouse.png" width="200"><br>**Mouse** — the gyroscope moves the pointer, tap clicks, hold right-clicks; four speeds and switches for the wrist. | <img src="docs/img/usb-pcremote-pad.png" width="200"><br>**Pad** — a cross, four buttons, shoulders, select and start; the tilt is the left stick after "Centre". |
| <img src="docs/img/usb-pcremote-midi.png" width="200"><br>**MIDI** — an octave of keys into any synthesizer, the octave up and down, and the wrist's roll as pitch bend. | <img src="docs/img/usb-settings.png" width="200"><br>**Settings → USB** — the mode as a dropdown and what the port is doing right now. The portal's `/usb` page has the same, plus a key pad and the diagnostics. | |
| <img src="docs/img/usb-pato-list.png" width="200"><br>**Pato goma** — keyboard-and-mouse scripts the watch plays over USB onto the computer. You write them in the portal's `/pato` page — a step builder or raw DuckyScript-like text — pick one on the watch, and confirm before anything is sent. For education and demonstration only. | <img src="docs/img/usb-pato-confirm.png" width="200"><br>The confirmation, with a preview of the script and its step count. Nothing runs without this tap. | <img src="docs/img/usb-pato-run.png" width="200"><br>Playing out: a progress bar, the current step and a Stop. Each key or typed character is one timer tick, so the screen stays responsive and Stop always answers. |

## First install

Everything below uses the files of the
[latest release](https://github.com/charliejgallo/ESP32S3_AmoledOS/releases/latest):
the firmware and every dynamic app already built. No toolchain needed.

**The cable is needed once.** The first flash goes over USB; from then on
the watch updates its own firmware (Settings → Update) and the portal's
Store installs the apps and watchfaces, both from the latest release, over
wifi. In short:

| | First time | From then on (v0.18.0 and later) |
|---|---|---|
| **Firmware** | `amoledos-full.bin` over USB ([step 1](#1-flash-the-firmware)) | the watch: **Settings → Update** |
| **Apps and watchfaces** | the Store, or `apps.zip` on the card ([step 2](#2-fill-the-card)) | the portal: **Store** |
| **Languages** | in the firmware already; `lang.zip` for the newest | the firmware brings its own; the Store brings each app's |

A watch on v0.17.0 or earlier has no Update page yet: it goes to v0.18.0 once
more through the portal (`amoledos.bin` on the front page, see
[step 4](#4-from-then-on-updates-and-apps-over-wifi)), and updates itself after
that.

> **Tested on v2 boards only.** Every feature and every number in this
> repository comes from the v2 of the board (CO5300 panel, CST820 touch).
> The firmware detects a v1 (SH8601 + FT3168) at run time and should work
> on it, but nobody has tried one yet. If you have a v1 and something does
> not work, please [open an issue](https://github.com/charliejgallo/ESP32S3_AmoledOS/issues)
> with what you see (the portal's `/api/log` helps a lot), and we will fix it
> together. See [HARDWARE.md](docs/HARDWARE.md#one-binary-both-revisions).

**What you need:** the board, a microSD card formatted **FAT32** (see
[the card](#the-microsd-card)), a USB-C cable that carries data, not just
charge, and Chrome or Edge for the browser flasher.

### 1. Flash the firmware

`amoledos-full.bin` is the whole flash in one file, written at address 0x0.
The easiest way is a browser:

1. Open [web.esphome.io](https://web.esphome.io) in Chrome or Edge (it uses
   Web Serial; Safari and Firefox do not have it) and plug the watch in.
2. **Connect**, pick the watch's serial port, then **Install** and choose
   `amoledos-full.bin`. It takes a minute or two; the watch restarts at
   the end. That is how the second watch of this project was flashed.

If the port does not show up, or the flasher cannot talk to the board, put
it in download mode: hold **BOOT** while you plug the cable in, then try
again. [Espressif's esptool-js](https://espressif.github.io/esptool-js/) also
works (write `amoledos-full.bin` at `0x0`), and so does the command line:

```bash
esptool --chip esp32s3 -p <PORT> -b 460800 write_flash 0x0 amoledos-full.bin
```

> `amoledos-full.bin` is a **factory image**: it spans the flash from 0x0, so it
> overwrites the NVS partition and the watch comes up with no wifi credentials,
> no language, no watchface and no app data. That is what you want on a fresh
> board. To update a watch already in use, take
> `amoledos-firmware-files.zip` instead — the same build as four separate files
> that leave NVS alone (their offsets are in `flash_args.txt`). Or, since
> v0.5.0, download a backup from the portal's `/ajustes` page first and restore
> it after: every setting, every app's data and the menu's folders come back.

### 2. Fill the card

**The card only has to be FAT32 and in the watch.** The apps and watchfaces
can come afterwards from the portal's Store, one by one, once the watch is
on wifi ([step 4](#4-from-then-on-updates-and-apps-over-wifi)). To have all
of them from the start, or with no network, copy them with a card reader
before the card goes into the watch:

```bash
unzip apps.zip        -d /Volumes/<sd>/apps/    # the apps, and the games' .pak files
mv /Volumes/<sd>/apps/faces /Volumes/<sd>/faces  # the watchfaces go in /faces (v0.15.0)
unzip lang.zip        -d /Volumes/<sd>/lang/    # English and German, current
unzip lua-scripts.zip -d /Volumes/<sd>/lua/     # example scripts (optional)
```

v0.6.0's release also carries `3d-models.zip`, the Visor 3D's samples, for
`3d/`; in any other version take them from
[`apps/visor3d/models/`](apps/visor3d/models). What else goes on the card,
and where, is in [the next section](#the-microsd-card).

No card reader? Two other ways, once the watch is up and on wifi:
**Settings → USB → Disk (the card)** turns the watch into a USB drive on
your computer, and the portal's **Files** page (its **Card** tab) uploads
into any folder of the card from the browser (up to 8 MB a file). The apps are read at startup, so
**restart the watch after copying apps**.

### 3. First boot

The watch starts in Spanish; the settings are **Ajustes** in the launcher.

1. **Language**: Ajustes → Idioma → English or Deutsch. The packs from
   `lang.zip` are used if they are on the card; the binary carries its own
   copy otherwise.
2. **Calibrate the touch**: Settings → Touch → **Calibrate**, and touch the
   five crosses. Do this on every new watch: each glass stretches its
   coordinates a little differently, and it is the first thing to suspect
   when a button seems to need a second tap. **Try gestures**, on the same
   page, shows both fingers and the gestures as the apps see them.
3. **Wifi**: Settings → Wi-Fi → **Set up network** raises an access point
   and shows a QR code; join it with a phone and pick your network. The
   clock sets itself over NTP, and the web portal answers at the watch's
   address or at `<name>.local`, both shown in Settings → Wi-Fi.

### 4. From then on: updates and apps over wifi

**The firmware: Settings → System → Update** (since v0.18.0). The page looks
at the latest published release when it opens and says whether it is newer
than what runs, with a few lines about it. **Download and install** writes it
into the idle one of the two 5 MB app slots, checking it against the size and
the SHA-256 the release publishes; **hold** the button to restart into it.
Your wifi, language, settings and app data stay. The new version boots on
trial, and goes back to the previous one by itself if it does not come up;
the same page also goes back by hand ("Previous version"). The portal has the
same at `/api/update`. More in [docs/UPDATE.md](docs/UPDATE.md).

<p align="center">
  <img src="docs/img/portal-tienda-ficha.png" width="560" alt="The Store's page for Golf: icon, pictures, the line about it, Remove, and its files each with a tick">
</p>

**Apps and watchfaces: the portal's Store** (`http://<name>.local/tienda`,
under Apps in its side menu, since v0.18.0). Every app and watchface of the
latest release, with its icon, pictures and a line about it, by kind, with a
search. **Install** and **Update** queue it; the watch downloads each of its
files from the release itself, checks it, and puts it in place: the apps on
the card, the watchfaces in the flash, their translations in `lang/`. They
load when the watch starts, and the page offers the restart. **Update all**
takes every update at once, and an app's page has **Remove**; what an app
saved stays either way.

If the card was filled from `apps.zip`, the Store lists those apps as
*copied by hand*: **Check them** hashes them once (about two minutes for a
full card) and from then on it knows them as its own. More in
[docs/STORE.md](docs/STORE.md).

**Coming from v0.17.0 or earlier**, the firmware goes in through the portal
once more: drop `amoledos.bin` on its front page, under *Firmware*. That is
also how a build of your own goes in, with
`./tools/install_fw.sh <name>.local` ([docs/BUILDING.md](docs/BUILDING.md)).

## The microSD card

FAT32 only: the ESP32's FatFs is built without exFAT, and a card over 32 GB
comes formatted exFAT, so reformat it as FAT32 first (any size works once it
is). Long file names are fine. Everything on the card is optional: without
one the watch runs, with the built-in apps and its internal flash. The
settings and the apps' own data (saves, scores, preferences) live in the
internal flash, not on the card; the `/ajustes` backup covers them.

The watch creates the folders it writes to; you only make the ones you copy
into. The portal serves each one by name.

| folder | what goes in it | where from |
|---|---|---|
| `apps/` | the dynamic apps (`.so`), their portal pages (`.html`) and the big games' assets (`golf.pak`, `turbo.pak`, `monsterhop.pak`, `mila.pak`) | the portal's Store, or `apps.zip`; read at startup |
| `faces/` | watchfaces (`face_*.so`) and their pages, copied by hand; installed into the flash at boot, so the card is only how they arrive ([FACES.md](docs/FACES.md)) | `apps.zip`'s `faces/`; the Store puts them straight into the flash |
| `lang/<code>/` | translation packs (`en/`, `de/`), one `.lang` per app plus `_sistema.lang`; a pack on the card wins over the copy in the binary, and what it lacks comes from the binary | `lang.zip`, the Store (each app's), or `tools/install_lang.sh` ([I18N.md](docs/I18N.md)) |
| `lua/` | Lua scripts, each one an app in the launcher | `lua-scripts.zip`, or written in the portal's `/lua` |
| `3d/` | models for Visor 3D: `.stl` and `.m3d` | `apps/visor3d/models/` (v0.6.0: `3d-models.zip`), or the portal's `/3d`, which converts STL, OBJ and GLB |
| `photos/` | JPEG, PNG and BMP for Fotos | your own |
| `music/` | MP3 or 16-bit WAV, in folders if you like, for Música | your own |
| `videos/` | MJPEG AVI at 368x448 with its WAV beside it | `tools/video_convert.sh` ([VIDEO.md](docs/VIDEO.md)) |
| `doom/` | a Doom WAD (`DOOM1.WAD`, the shareware one, was the one tested) | yours: none is included ([why](apps/doom/README.md#the-wad)) |
| `pixel/` | Pixel Art's canvases (`.pix`) and their PNG/GIF exports | the app, or the portal's `/pixel` |
| `pato/` | Pato goma's keyboard scripts (`.pato`) | the portal's `/pato` |
| `icons/` | icon files (`<app.id>.aic`) that replace an app's icon | the portal's `/iconos` ([ICONS.md](docs/ICONS.md)) |
| `recordings/` | what Grabadora records (WAV, 16 kHz mono) | the watch |
| `redes/` | the network scanner's surveys | the watch |
| `radio/` | the Radio app's list of stations (`library.json`) and the logo of each key (`logoN.jpg`) | the portal's `/radio` |
| `maps/` | Mapas: zones (`zones.txt`), offline zones (`.amp` packs and their `.idx` of names) and `cache/`, the tiles seen online | the portal's `/mapas`, `tools/map_pack.py`, and the app ([MAPS.md](docs/MAPS.md)) |
| `menu.txt` | the launcher's order and folders | the portal's `/menu` ([MENU.md](docs/MENU.md)) |
| `.store/` | what the Store installed, file by file (`installed.txt`), and the catalogue it read last | the Store ([STORE.md](docs/STORE.md)) |

## Quick start

```bash
# firmware
source ~/esp/esp-idf/export.sh
idf.py set-target esp32s3
idf.py build && python3 tools/gen_symbols.py && idf.py build
idf.py -p /dev/cu.usbmodem* flash monitor

# simulator — no board needed
brew install sdl2 cmake
cd sim && cmake -B build && cmake --build build -j8 && ./build/amoledos_sim
```

The symbol table needs two passes: dynamic apps resolve LVGL, the HAL and libc
against a table generated from the build's own libraries, so the libraries have
to exist first. See [docs/BUILDING.md](docs/BUILDING.md).

## Starting points: your own apps and watchfaces

Two templates, one for each kind of module, made to be copied: each is
the smallest thing that uses all of its contract, and builds, loads and
runs as it is.

| | An app | A watchface |
| --- | --- | --- |
| | <img src="docs/img/app-hello.png" width="180"> | <img src="docs/img/face-hello.png" width="180"> |
| **The template** | [`apps/hello_app`](apps/hello_app) | [`faces/face_hello`](faces/face_hello) |
| **What it shows** | a screen of its own, its own launcher icon drawn as data, strings marked for translation, and a portal page (`web/hello_app.html`) that reads and writes a file on the card | the time and the date, a ball that rolls to wherever "down" is (`frame()` and the accelerometer), a tap that changes its colour, and a dimmed look |
| **The guide** | [APP-GUIDE.md](docs/APP-GUIDE.md), the long form, and [APP-API.md](docs/APP-API.md), the contract | [FACE-GUIDE.md](docs/FACE-GUIDE.md), from copying it to giving the `.so` to someone |
| **On the watch** | `/sdcard/apps`, in the launcher | installed from the card's `/faces` into the flash, in the picker |

The same four steps for both, on the Mac with the firmware built once
([BUILDING.md](docs/BUILDING.md)):

```bash
cp -r apps/hello_app apps/my_app                 # or faces/face_hello faces/face_mine
                                                 # then rename: the guides say what
cd sim && cmake --build build -j8 && AOS_SIM_VIEW=demo.my_app ./build/amoledos_sim
                                                 # a face: AOS_SIM_FACE=face.mine
./tools/build_apps.sh my_app                     # the .so, its ABI and symbols checked
./tools/install_apps.sh <watch>.local my_app     # onto the watch over wifi, and a restart
```

No compiler at all: a **Lua script** on the card is an app too, written in the
portal's `/lua` page and run as soon as it is saved ([LUA.md](docs/LUA.md)).

## How it is put together

```
main/                 startup on the board
sim/                  startup on the desktop (SDL2)
components/
  aos_hal/            the single contract with the platform
  aos_board/          AXP2101, PCF85063A, QMI8658
  aos_ui/             launcher, watchfaces, navigation, theme, i18n
  aos_apps/           the 20 built-in apps
  aos_dynapp/         .so loader and symbol table
  aos_ble/            NimBLE: ANCS, AMS, pairing
  aos_web/            the web portal, embedded in the binary
apps/                 40 dynamic apps
faces/                watchfaces as modules, installed from the card
tools/                generators, test benches, board utilities
```

The rule that holds it up: **`aos_ui` and `aos_apps` include only LVGL and
`aos_hal.h`**, never an ESP-IDF header. That is why the same interface code
compiles for the board and for the desktop, and why every screen can be
designed, audited and screenshotted without hardware.

Four files are shared verbatim by both platforms because they contain no
platform code at all: the HTTP/TLS client, the notification policy, the
network survey's report format, and the link between two watches (beacons,
pairing, the reliable channel) above a raw layer that is ESP-NOW on the board
and UDP in the simulator.

## Documentation

| | |
| --- | --- |
| [ARCHITECTURE.md](docs/ARCHITECTURE.md) | how the pieces fit, the drawing model, and what the measurements taught |
| [HARDWARE.md](docs/HARDWARE.md) | the board, the pinout, and the quirks the datasheets do not mention |
| [BUILDING.md](docs/BUILDING.md) | firmware, simulator, dynamic apps, and every tool |
| [UPDATE.md](docs/UPDATE.md) | the firmware updating itself from the watch: the manifest a release carries, what keeps it safe, how to try it without publishing |
| [STORE.md](docs/STORE.md) | the portal's Store: what the watch checks before a file takes its place, the catalogue, `gen_store.py`, and what was measured |
| [APP-API.md](docs/APP-API.md) | writing an app, and the things that will bite you |
| [APP-GUIDE.md](docs/APP-GUIDE.md) | the long form: how the apps were actually written - workflow, the four drawing techniques with their costs, data from the internet, configuration from the portal, testing without the board, and every trap that bit |
| [FACES.md](docs/FACES.md) | the watchfaces from the card: the five, choosing and removing them, how the card delivers and the flash keeps, the drawing model, and what was measured |
| [FACE-GUIDE.md](docs/FACE-GUIDE.md) | making a watchface of your own, from the template (`faces/face_hello`) to giving the `.so` to someone |
| [GESTURES.md](docs/GESTURES.md) | the second finger the touch chip reports, and the gesture recogniser built on it |
| [SECURITY.md](docs/SECURITY.md) | the portal's security: other sites refused, trusted networks, the watch approving each browser, the token for scripts |
| [LINK.md](docs/LINK.md) | two watches over ESP-NOW: the plan in phases, the design, what every phase measured, and the apps on it |
| [I18N.md](docs/I18N.md) | how translation works and why the key is the Spanish string |
| [LUA.md](docs/LUA.md) | scripts on the watch: what a script is, everything it can reach, the rules the app enforces and why, and what a frame actually costs |
| [MENU.md](docs/MENU.md) | the launcher's order and folders: `menu.txt`, the hexagon icons, the `/menu` page, and what 256 apps cost the board |
| [ICONS.md](docs/ICONS.md) | icons as data: the AIC format, how a `.so` or a file on the card brings one, how the 36 hand-drawn ones became tables, and what it saved |
| [POWER.md](docs/POWER.md) | the AXP2101, the rails, light sleep, and the measurements behind each switch |
| [PORTAL.md](docs/PORTAL.md) | the web portal: pages, API, what it costs the board, and the dev server |
| [STEPS.md](docs/STEPS.md) | the step counter: why it is software, how it was tuned on counted walks |
| [VIDEO.md](docs/VIDEO.md) | video from the card: the decoder, the background task, the direct blit, and the clock |
| [CAMERAS.md](docs/CAMERAS.md) | live IP cameras: what the H.264 and JPEG decoders do on this board, measured, and how the Cameras app splits the work across the cores |
| [RADIO.md](docs/RADIO.md) | internet radio: what a station URL turns out to be, MP3, AAC and HLS, titles shown when they are heard, what it costs, time to sound and why the WiFi's power save mattered, uploads while a station plays, the covers |
| [MAPS.md](docs/MAPS.md) | the street map: why vector tiles from OpenFreeMap, drawing them on the watch and what each fix saved, one download at a time, the offline packs and the search |
| [MUSIC.md](docs/MUSIC.md) | MP3 and the player: the decoder checked against ffmpeg, the ring, what it costs and what it does to the app in front, gapless, the cover, mixing |
| [RAM-AUDIT.md](docs/RAM-AUDIT.md) | where the internal RAM went and how the apps' code moved to PSRAM |
| [ROADMAP.md](docs/ROADMAP.md) | what is planned and has no date: Android phones, and USB host (a pendrive on the watch), waiting for a way to power it |
| [USB.md](docs/USB.md) | the USB-C port as a device or a host: what the board allows, the catalogue, the test rigs, the measurements and what was found |

## A note on what is written down

Most of the comments in this repository explain *why*, not *what*, and many of
them record something that was measured rather than assumed. A few examples of
what that looks like in practice:

* For months the touch panel seemed to **report nothing below y = 395**,
  although the display draws to 447: printing every touch across four apps
  said so, and every screen was laid out around it. Reading the chip raw
  showed it reaching 447 at the bezel; the dead band was made by our own
  calibration's fit, and went away with it
  ([HARDWARE.md](docs/HARDWARE.md#the-touch-panel-does-not-reach-the-bottom)).
  A measurement can be right and its explanation wrong.
* The v2's touch chip **reports a second finger** in registers no driver
  reads, while its finger count never says more than one. Pinch-to-zoom in
  v0.6.0 comes from there ([GESTURES.md](docs/GESTURES.md)).
* A task that does **floating point is pinned to the core** it first did it
  on, whatever it was created with. The MP3 decoder landed on the same core
  as Visor 3D's renderer while the other one idled; it now moves to the core
  the app is not using ([MUSIC.md](docs/MUSIC.md)).
* Letting LVGL stretch a canvas costs **129 ms per frame**. Every game upscales
  by hand.
* SPIFFS answers every `stat()` by **walking its pages**: asking it about each
  installed watchface cost every boot 0.6 s. One index file read instead made
  it 34 ms ([FACES.md](docs/FACES.md)).
* Rebuilding a twenty-row list costs **111–124 ms** with the LVGL thread
  blocked; filling the same rows in costs 18–31.
* Dynamic apps used to take their code from a **48 KB contiguous reservation**
  claimed at startup, because the general heap fragments. Since the RAM audit
  the loader puts each app's code in PSRAM and maps it onto the instruction
  bus through the MMU; the games run at the same frame rate as from internal
  RAM, and the executable heap idles with 140 KB free instead of 30
  ([docs/RAM-AUDIT.md](docs/RAM-AUDIT.md) has every number).
* An autocorrelation pitch detector returns 146.8 Hz for a 440 Hz tone. The
  tuner uses NSDF and picks the *first* peak over the threshold, not the
  highest.

Where something is a guess, it says so.

## Status

Running on hardware. WiFi, BLE against a real iPhone, audio in and out, the
microSD, the web portal, TLS, over-the-air updates and the USB port in its
device modes (keyboard, mouse, gamepad, MIDI, network, disk) have all been
exercised on the board — most of the measurements quoted throughout the source
were taken there. The link between two watches has been played with on two
boards: Pong, Truco, a drawing sent, the radar, the walkie through a door, a
fight in Chatarra's phone booth and a match of Neon Snakes. Internet radio has
played on both watches, over http and https, MP3, AAC and HLS, with the screen off.
The map has been panned, zoomed and searched on the board, online and from
offline zones of the city of Buenos Aires and its suburbs downloaded through
the portal.
The watchfaces from the card have been installed from it, updated, uploaded
through the portal and removed on the board, and their frame rates measured
there ([FACES.md](docs/FACES.md)).
The firmware has updated itself from GitHub and gone back to the previous
version on the board, and the Store has installed, updated and removed apps
and watchfaces from the published v0.18.0 ([UPDATE.md](docs/UPDATE.md),
[STORE.md](docs/STORE.md)); updating from one published version to the next
from the watch waits for the release after v0.18.0.
USB host mode (a pendrive on the watch) works but is parked: the board cannot
power a peripheral ([USB.md](docs/USB.md)).

Known gaps: on the power side, the percentage still maps the voltage with a
generic LiPo curve, which reads low near empty; the battery history now keeps
the voltage so that this cell's own curve can replace it. Deep sleep at night
has been through wake-ups of minutes on the board but not yet a whole night,
and the charge-cycle counter has not been checked against a real count.
[POWER.md](docs/POWER.md) section 9 has what was measured and how.

## Licence

MIT — see [LICENSE](LICENSE).

`components/elf_loader/` is Espressif's, under Apache-2.0, vendored with a
small local change. `apps/doom/` is Chocolate Doom through doomgeneric, and
like them under the GNU GPL v2; no WAD is included (see
[apps/doom/README.md](apps/doom/README.md#the-wad) for which one was used and
what its licence allows). LVGL and ESP-IDF are pulled in by the component manager
under their own licences.
