How the emulators work
Each emulator is the device's firmware itself, compiled with Emscripten to WebAssembly and put inside a drawing of the device. The interface — what each press does, every pixel on the glass, the menus and the settings — is the same C that runs on the device. Under it sits a model of the hardware: the chips the firmware talks to, and the iron or the plate it heats, so nothing gets hot. Each emulator is one HTML file that also opens from a disk.
The two are built differently. The station's emulator models the microcontroller's registers, so the firmware runs down to its interrupt handler. The plate's models the firmware's drivers one level up, because its main loop never returns.
TS1C station
make emulator in openware-ts1c builds
web/emulator/index.html from the station's interface code — ui_station.c,
home_station.c, settings_station.c, oled.c and the fonts, logo, QR code and version
— over a model in tools/emulator/proto.c.
What runs for real
ui_station_init()at start,ui_station_poll()every millisecond of model time, and the encoder's timer interrupt handler on the phases of PA5/PA6 for as long as the firmware keeps that timer and its interrupt on; one click is 4 ms of phases.- Buttons A and B are levels on PA0 and PA1, so the debounce, the long press, the steps while held and waking from sleep are the firmware's own.
- The Bluetooth stack's clock is the model's time in its 625 µs ticks.
Registers
The firmware writes the CH579's registers by address. The build rewrites WCH's register header so that every 0x4000xxxx address becomes an offset into a 64 KB buffer; addressed as they are, the page would need a gigabyte of memory. A small override header, included into every file, turns the SPI0 data and flag registers into calls to a model of the SSD1306: it takes D/C and CS from port B and keeps the display on/off state, the contrast, the column and page window and the pixels. The few addresses the firmware defines itself — the interrupt enable registers, the Miniware loader's version, the settings record, the version string pointer — get buffers of their own.
The model around the station
- The settings page lives in RAM, so every load of the page is a new station with no iron of its own.
- Pairing is modelled by its outcome: an iron put in the dock is checked, and 8 s later, if it is linked, it is the station's own. The dock's power and its cut for the check, other irons and the 45 s search are not modelled; the dock sensor is whatever the page says.
- USB PD is the author's charger: a 12 V 3 A contract and a 2800 mA dock budget.
- The buzzer beeps through WebAudio, 100 ms at 4 kHz per beep, once the browser allows sound after the first input. The firmware's log is printed under the picture.
The iron
A model of the iron takes the place of the Bluetooth code. The station links to it 1.5 s after the iron is on and allowed, writes the dock word and the settings to its own iron first, and reads the telemetry every 420 ms. The link ends when the station drops it or the iron turns off, and then the iron forgets the dock word and stops heating.
- The tip: 1.7 J/K, losing 0.018 W/K to a 25 °C room — cooling at 2.5–2.9 °C/s around 280 °C, as in a bench log of the real iron. The regulator gives the losses at the setpoint plus 2 W per degree below it.
- Out of the dock it heats from the supercapacitor up to V²/R at a 12.2 V node, 35.5 W, and no more than 9.96 A out of the supercapacitor. Docked at 12 V with a budget, charging comes first, the way the firmware sizes it, and the heater gets the rest: 19.2 W of a 2800 mA budget.
- The supercapacitor: 750 F between 2.6 and 4.1 V, starting at 3.7 V, with a 90 % converter each way; below 2.6 V the heat goes off. The iron holds its power the way its firmware does: in the dock or linked, else it turns off after 7 s.
- The handle button held for over 0.5 s out of the dock is the boost; the LED follows the iron's firmware.
- Not in the model: the steps of the heater current limiter, the 2.5 s before the dock powers its contacts, the first 2 s at 5 V, the low-charge rule, the rest started from a phone.
The page
The station is drawn in SVG and CSS from a photo. The screen is a 128 × 64 canvas at exactly 4×, with yellow rows 0–15, cyan rows 16–63 and the dark band between them, dark when the firmware turns the panel off and dimmer at a low contrast. The encoder turns with the mouse wheel, by dragging around it, with − and + or the arrow keys; A and B take a click, a touch or the keys A and B. The iron, drawn from the author's photo, is lifted and docked with a click, and its button stays pressed for as long as the finger is on it.
MHP50 plate
make emulator in openware-mhp50 builds
docs/emulator/index.html from the plate's own interface: main.c (what each press does and every
word on the glass), screen.c and lcd.c (the drawing), the fonts, chart.c,
profile.c and settings.c, over a stub plate in tools/proto/proto.c.
Running a loop that never returns
Everything the interface is made of is static inside main.c, so the emulator includes that file as
text instead of linking it. Its main() is renamed and runs once: its own setup runs, and the first pass of
its endless loop leaves through a longjmp in a stub. From then on the page calls one pass of that loop at a
time, the only piece of main.c the emulator repeats: a browser cannot return from a for (;;),
and WebAssembly has no coroutine to leave one in.
The model
- The panel: a stub reads the ST7735 command stream the drawing code writes — column and row windows, memory writes and the pixels — into an RGB565 frame buffer the page blits. The same stub draws the screen pictures on the project pages.
- The buttons: the firmware's button driver masks interrupts with instructions WebAssembly does not have, so its state machine is repeated in the model with its timings: a read every 15 ms, a press counted on two reads, a hold reported at 700 ms. The page only says which button is down.
- The plate: a BS50 head, the DC jack at 26 V, no USB PD, a tilt sensor that answers and no protection that trips. The temperature comes from an inertial model that answers the heater and the fan: it climbs at most 1.5 °C/s, slower the hotter it is, and loses heat to the room faster with the fan on. The regulator is a stub here, so the model chases its target directly: the screens show the lag of a plate, not the firmware's PID.
- The disk: the profiles of the repository are embedded in the page and parsed by the firmware's real profile parser, plus one file that does not parse. There is no computer, no USB volume and no run log.
The page draws the plate's body, the glass, the light strip and the two buttons at its sides.