Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c459e7a
Launcher: console filter and quick console navigation
finger563 Nov 13, 2026
9c30c3f
Web console: the WebUSB landing page, on GitHub Pages
finger563 Nov 13, 2026
eecdb88
web: history graphs fill their width from the first samples
finger563 Nov 13, 2026
12fdd32
Pin esp_tinyusb to 3.0.0
finger563 Nov 13, 2026
bcda81a
Merge branch 'feat/console-filter' into feat/web-console
finger563 Nov 13, 2026
7838bb6
Revert "Pin esp_tinyusb to 3.0.0"
finger563 Nov 13, 2026
1ccf084
Revert "Pin esp_tinyusb to 3.0.0"
finger563 Nov 13, 2026
8f5cd52
Merge branch 'feat/console-filter' into feat/web-console
finger563 Nov 13, 2026
6681275
Merge remote-tracking branch 'origin/main' into feat/console-filter
finger563 Nov 14, 2026
fbaeb21
Web console: reconnect, disconnect and library-edit fixes from review
finger563 Nov 14, 2026
c303823
Launcher: filtered list stops at its first game; the link closes the …
finger563 Nov 14, 2026
d0c46f7
Merge branch 'feat/console-filter' into feat/web-console
finger563 Nov 14, 2026
3f9a022
Console filter: an empty request only reports it; count the picker in…
finger563 Nov 14, 2026
5e12037
Merge branch 'feat/console-filter' into feat/web-console
finger563 Nov 14, 2026
a132b16
Web console: uploads, settings and requests stay with their connection
finger563 Nov 14, 2026
2968e88
Console filter: not while a launch is pending; a list reload closes t…
finger563 Nov 14, 2026
51d061b
Web console: Add Game stays on its board, keyboard on the Screen tab,…
finger563 Nov 14, 2026
734b32d
Merge branch 'feat/console-filter' into feat/web-console
finger563 Nov 14, 2026
3c8345a
Web console: take the Tab5's remaining web fixes; report lost writes
finger563 Nov 14, 2026
359970f
README: the web console, how it works and what it does, with screenshots
finger563 Nov 14, 2026
8a0cd6c
Console filter: split the assignment out of the condition (cppcheck c…
finger563 Nov 14, 2026
b41a3f7
Merge remote-tracking branch 'origin/feat/console-filter' into feat/w…
finger563 Nov 14, 2026
88c13b9
Merge main (the squash of #134) into feat/web-console
finger563 Nov 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Web console (GitHub Pages)

# The Emulator Console (web/): the page the firmware advertises as its WebUSB
# landing page (esp-cpp.github.io/<repo>/). Needs Settings -> Pages -> Source:
# GitHub Actions.
on:
push:
branches: [main]
paths:
- 'web/**'
- '.github/workflows/pages.yml'
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: pages
cancel-in-progress: true

jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- name: Check the scripts parse
run: for f in web/*.js; do node --check "$f"; done
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v3
with:
path: web
- id: deployment
uses: actions/deploy-pages@v4
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ https://github.com/user-attachments/assets/2d3da6ea-2e80-42c3-bbd6-5a2c59601201
- [Emulators](#emulators)
- [Gallery](#gallery)
- [Quick Start — Play It](#quick-start--play-it)
- [Web Console](#web-console)
- [Build the Hardware](#build-the-hardware)
- [Build the Firmware](#build-the-firmware)
- [ROMs and SD Card Setup](#roms-and-sd-card-setup)
Expand Down Expand Up @@ -71,6 +72,9 @@ interface with boxart, save states, and settings.
Doom (weapon fire, taking damage, pickups, and more).
- 🖼️ **Polished UI** — LVGL menus for ROM select (with boxart) and settings
(sound, brightness, display scaling, haptics), designed in Squareline Studio.
- 🌐 **Web console** — plug into a computer and Chrome or Edge offers a control
panel: watch and play the screen, manage games and boxart, browse the SD
card, change settings, and update the firmware, with nothing to install.
- 🛠️ **Fully open hardware** — 3D-printable GBC-style case and an open PCB
(Fusion/Eagle **and** [atopile](https://atopile.io) + [KiCad](https://kicad.org)),
all included in this repo.
Expand Down Expand Up @@ -178,6 +182,71 @@ published with every release.
Then [set up a micro-SD card](#roms-and-sd-card-setup) with your ROMs and you're
ready to play.

## Web Console

**Plug the emulator into a computer and it hands you a control panel.**
Connect the ESP-BOX-EMU's USB-C port to a computer running Chrome or Edge and
the browser pops up a notification pointing at
**[esp-cpp.github.io/esp-box-emu](https://esp-cpp.github.io/esp-box-emu/)**,
the firmware's WebUSB landing page. Click it, pick the emulator, and you're in:
no drivers, no app, no serial terminal. Watch the game being played,
take a screenshot, add a new game with its boxart, or update the firmware,
all from a browser tab.

<p align="center">
<img src="./images/web-console/dashboard.jpg" alt="Web console dashboard: Sonic The Hedgehog 3 running, with frame rate, memory, firmware and SD card panels" width="49%">
<img src="./images/web-console/screen.jpg" alt="Web console Screen tab: a capture of Sonic 3 next to an on-screen controller and save-state buttons" width="49%">
</p>

What you can do from each tab:

- 📊 **Dashboard**: what's running right now (with its boxart), live frame-rate
and memory graphs, the firmware and partition it booted from, why it last
reset, and a button that hands the SD card to your PC as a USB drive.
- 🖥️ **Screen**: grab the game's (or the launcher's) screen, or turn on
**Live** to keep it updating, and save it as a PNG. Play with the on-screen
controller or your keyboard (arrows, Z / X / A / S, Enter = Start), save and
load states in any slot, or quit the game.
- 📚 **Library**: every game on the card, grouped by console with its boxart
and a game count per console. Search, filter by console (and, if you like,
filter the handheld's launcher the same way), start any game with **Play**,
or **Add a game**: drop in the ROM and a cover and the page uploads both and
adds the line to `metadata.csv` for you. **Remove** takes one out again.
- 📁 **Files**: browse the SD card, download files, upload by drag and drop,
create folders and delete things (handy for copying save states off the card).
- ⚙️ **Settings**: volume, mute, brightness, video scaling, resume last save
and the haptic effect. The handheld's own menu shows each change right away,
and it's saved to the card a moment later.
- 🔧 **System**: chip, flash, PSRAM, heap, ESP-IDF version, OTA state and the
services on the link; restart the emulator (or into download mode for
`idf.py flash`), and **Update firmware**, which restarts into the updater and
opens the espp OTA console to send a new `build/esp-box-emu.bin`.
- 📜 **Console**: the device's log over Web Serial (pick the console's port),
with a line filter, auto-follow, and save to a file.

<p align="center">
<img src="./images/web-console/library.jpg" alt="Web console Library tab filtered to Sega Genesis, showing boxart for 13 games with Play and Remove buttons" width="49%">
<img src="./images/web-console/settings.jpg" alt="Web console Settings tab with volume, mute, brightness, video scaling, resume and haptic controls" width="49%">
</p>
<p align="center">
<img src="./images/web-console/files.jpg" alt="Web console Files tab listing the SD card's folders with Create, Upload and Delete buttons" width="49%">
<img src="./images/web-console/system.jpg" alt="Web console System tab: chip and firmware details, firmware update and restart buttons" width="49%">
</p>

**How it works:** the firmware's composite USB device includes a vendor
(WebUSB) interface that carries the same request/response link as
[`tools/emulink`](./tools/emulink), plus a USB descriptor that names the
landing page, which is how the browser knows where to send you. The page is
plain HTML, CSS and JavaScript modules in [`web/`](./web) (no build step),
published to GitHub Pages from `main`, and it talks to the device directly
from your browser; nothing goes through a server. Only one program can use the
link at a time, so close `emulink` (or the page) before switching between them.

Hacking on the page? Serve it locally with
`python3 -m http.server -d web 8000` and open http://localhost:8000 (WebUSB
needs https or localhost). See [`web/README.md`](./web/README.md) for the
details.

## Build the Hardware

The add-on is designed to match the Game Boy Color form factor and reuse GBC
Expand Down
2 changes: 1 addition & 1 deletion components/box-emu/src/box-emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ bool BoxEmu::initialize_usb_device() {
espp::UsbDevice::VendorFunction vendor;
vendor.interface_name = "ESP-Box-Emu link";
vendor.webusb = true;
vendor.landing_page_url = "esp-cpp.github.io/espp/apps/device_hub.html";
vendor.landing_page_url = "esp-cpp.github.io/esp-box-emu/";
vendor.on_receive = [this](std::span<const uint8_t> data) {
if (vendor_rx_) vendor_rx_(data);
};
Expand Down
9 changes: 9 additions & 0 deletions components/gui/include/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ class Gui {
/// Show only `console`'s games (nullopt: every console's); false if it has none.
bool set_console_filter(std::optional<Console> console);

/// The settings the launcher shows, for the USB link: {settings: {name:
/// value}, limits: {name: [min, max]}} (volume, muted, brightness, video,
/// resume, haptic).
std::string settings_json() const;
/// Change one of them as its control in the launcher does (shown, applied,
/// saved once the changes stop); false for an unknown name or a value out
/// of range.
bool set_setting(const std::string &name, int value);

/// The launcher screen (RGB565, little endian, rows packed), for the USB
/// link's screenshot when no game runs; empty if it cannot be drawn.
struct Snapshot {
Expand Down
42 changes: 42 additions & 0 deletions components/gui/src/gui.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "gui.hpp"

#include <cmath>

extern "C" {
#include "ui.h"
#include "ui_helpers.h"
Expand Down Expand Up @@ -345,6 +347,46 @@ void Gui::roller_key(lv_event_t *e) {
}
}

namespace {
struct SettingLimit {
const char *name;
int min, max;
};
// (brightness from 10: the launcher's own slider stops there too)
constexpr SettingLimit kSettingLimits[] = {{"volume", 0, 100}, {"muted", 0, 1}, {"brightness", 10, 100},
{"video", 0, 2}, {"resume", 0, 1}, {"haptic", 1, 123}};
} // namespace

std::string Gui::settings_json() const {
auto &emu = BoxEmu::get();
const auto s = AppSettings::get().get_settings();
std::string limits;
for (const auto &l : kSettingLimits) {
limits += fmt::format("{}\"{}\":[{},{}]", limits.empty() ? "" : ",", l.name, l.min, l.max);
}
return fmt::format("{{\"settings\":{{\"volume\":{},\"muted\":{},\"brightness\":{},\"video\":{},\"resume\":{},"
"\"haptic\":{}}},\"limits\":{{{}}}}}",
(int)std::lround(emu.volume()), emu.is_muted() ? 1 : 0, (int)std::lround(emu.brightness()),
(int)emu.video_setting(),
s.resume_last_save ? 1 : 0, haptic_waveform_.load(), limits);
}

bool Gui::set_setting(const std::string &name, int value) {
const auto *limit = std::find_if(std::begin(kSettingLimits), std::end(kSettingLimits),
[&](const SettingLimit &l) { return name == l.name; });
if (limit == std::end(kSettingLimits) || value < limit->min || value > limit->max) {
return false;
}
std::lock_guard<std::recursive_mutex> lk(mutex_);
if (name == "volume") set_audio_level(value);
else if (name == "muted") set_mute(value != 0);
else if (name == "brightness") set_brightness(value);
else if (name == "video") set_video_setting(static_cast<VideoSetting>(value));
else if (name == "resume") set_resume_last_save(value != 0);
else if (name == "haptic") set_haptic_waveform(value);
return true;
}

Gui::Snapshot Gui::snapshot() {
std::lock_guard<std::recursive_mutex> lk(mutex_);
Snapshot shot;
Expand Down
Binary file added images/web-console/dashboard.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/web-console/files.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/web-console/library.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/web-console/screen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/web-console/settings.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/web-console/system.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 45 additions & 8 deletions main/remote_control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ class RemoteControl {
public:
static constexpr uint8_t kModule = 0x20;
static constexpr const char *kProtocol = "emu.control";
static constexpr uint16_t kProtocolVersion = 3; // 2: in-memory screenshots, 3: console filter, launcher screenshots
// 2: in-memory screenshots, 3: console filter, launcher screenshots, 4: settings, boxart / console keys in the list
static constexpr uint16_t kProtocolVersion = 4;

enum class Type : uint8_t {
STATUS = 0x01, ///< () -> {state, rom, platform, console, heap, uptime, ...}
LIST_ROMS = 0x02, ///< (offset: text) -> {total, roms: [{name, path, platform, console}]}
LIST_ROMS = 0x02, ///< (offset: text) -> {total, roms: [{name, path, platform, console, key, boxart}]}
LAUNCH = 0x03, ///< (rom path or part of a name / path) -> {rom}
QUIT = 0x04, ///< ()
BUTTONS = 0x05, ///< (u16 buttons, u16 hold ms; 0 = until the next BUTTONS)
Expand All @@ -136,6 +137,10 @@ class RemoteControl {
/// consoles: [keys]}: the launcher's list shows only that console's games.
/// An empty payload only reports them (nothing changes on the device).
CONSOLE_FILTER = 0x0D,
/// (empty, or "name=value" to change one) -> {settings: {name: value},
/// limits: {name: [min, max]}}: the launcher's settings (volume,
/// brightness, ...), applied and saved like the launcher's own controls
SETTINGS = 0x0E,
FILE_LIST = 0x10, ///< (path[\0offset]) -> {entries: [{name, dir, size}], truncated?, next?}
FILE_READ = 0x11, ///< (u32 offset, u16 length, path) -> raw bytes (short at the end)
FILE_WRITE = 0x12, ///< (u32 offset, path_len u16, path, data); offset 0 truncates
Expand Down Expand Up @@ -234,9 +239,11 @@ class RemoteControl {
size_t i = offset;
for (; i < roms.size(); i++) {
const auto &r = roms[i];
auto e = fmt::format("{}{{\"name\":{},\"path\":{},\"platform\":\"{}\",\"console\":{}}}",
i > offset ? "," : "", quote(r.name), quote(r.rom_path), r.platform,
quote(console_info(console_of(r.platform)).name));
const auto &console = console_info(console_of(r.platform));
auto e = fmt::format(
"{}{{\"name\":{},\"path\":{},\"platform\":\"{}\",\"console\":{},\"key\":{},\"boxart\":{}}}",
i > offset ? "," : "", quote(r.name), quote(r.rom_path), r.platform, quote(console.name),
quote(console.key), quote(r.boxart_path));
// (room for the trailer, `],"next":N}`, and reply()'s status byte)
if (j.size() + e.size() + 24 > espp::stream_frame::kMaxPayloadSize) break; // the host asks for the rest
j += e;
Expand Down Expand Up @@ -498,6 +505,29 @@ class RemoteControl {
else json(filter_json());
break;
}
case Type::SETTINGS: {
if (!text.empty()) {
const auto eq = text.find('=');
if (eq == std::string_view::npos) {
fail("payload: name=value");
break;
}
const std::string name(text.substr(0, eq));
const std::string value(text.substr(eq + 1));
char *end = nullptr;
const long v = std::strtol(value.c_str(), &end, 10);
if (value.empty() || *end) {
fail(fmt::format("{}: '{}' is not a number", name, value));
break;
}
if (!gui_.set_setting(name, static_cast<int>(v))) {
fail(fmt::format("unknown setting '{}' (or {} is out of range)", name, v));
break;
}
}
json(gui_.settings_json());
break;
}
case Type::FILE_LIST: {
// path, optionally followed by '\0' and the index to start at (the "next" of a truncated
// reply)
Expand Down Expand Up @@ -592,10 +622,14 @@ class RemoteControl {
write_pos_ = offset + n;
break;
}
case Type::FILE_CLOSE:
// (a buffered write that fails shows up here)
if (!close_file()) fail("closing the file failed (card full?)");
case Type::FILE_CLOSE: {
// (a buffered write that fails shows up here, also one closed earlier
// by a read of the file or the card handover)
const bool closed = close_file();
if (!closed || write_lost_) fail("closing the file failed (card full?)");
write_lost_ = false;
break;
}
case Type::FILE_DELETE: {
const std::string path(text);
close_file(path);
Expand Down Expand Up @@ -816,6 +850,7 @@ class RemoteControl {
}
if (!close_file()) return false; // (the previous file's last data did not land)
if (offset == 0) {
write_lost_ = false; // (a new file: an older one's failure is not its)
std::error_code ec;
std::filesystem::create_directories(std::filesystem::path(path).parent_path(), ec);
write_file_ = fopen(path.c_str(), "wb");
Expand All @@ -838,6 +873,7 @@ class RemoteControl {
const bool ok = fclose(write_file_) == 0;
write_file_ = nullptr;
write_path_.clear();
if (!ok) write_lost_ = true; // (told by the next FILE_CLOSE)
return ok;
}
return true;
Expand Down Expand Up @@ -875,4 +911,5 @@ class RemoteControl {
FILE *write_file_{nullptr};
std::string write_path_;
uint32_t write_pos_{0};
bool write_lost_{false}; ///< an implicit close_file() lost buffered data
};
15 changes: 15 additions & 0 deletions tools/emulink/emulink/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ def cmd_filter(args) -> int:
return 0


def cmd_settings(args) -> int:
with _open(args) as link:
c = Control(link)
r = None
for change in args.change or [None]:
r = c.settings(change)
for name, value in r["settings"].items():
lo, hi = r["limits"].get(name, ("", ""))
print(f"{name:<11} {value:>4} ({lo}..{hi})")
return 0


def cmd_ls(args) -> int:
with _open(args) as link:
for e in Control(link).ls(args.path):
Expand Down Expand Up @@ -497,6 +509,9 @@ def build_parser() -> argparse.ArgumentParser:
s.add_argument("--delete", action="store_true", help="also delete the file")
s.set_defaults(fn=cmd_remove_rom)
sub.add_parser("reload", help="re-read metadata.csv").set_defaults(fn=cmd_reload)
s = sub.add_parser("settings", help="the launcher's settings; name=value changes one (volume=40, muted=1, ...)")
s.add_argument("change", nargs="*", help="name=value")
s.set_defaults(fn=cmd_settings)
s = sub.add_parser("filter", help="show only one console's games in the launcher (a key such as snes, or all)")
s.add_argument("console", nargs="?", help="console key, or all (default: show the current filter)")
s.set_defaults(fn=cmd_filter)
Expand Down
6 changes: 6 additions & 0 deletions tools/emulink/emulink/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
STATUS, LIST_ROMS, LAUNCH, QUIT, BUTTONS, SAVE, LOAD, SCREENSHOT, USB_DRIVE, RELOAD_ROMS, ENTER_UPDATER = range(1, 12)
SCREENSHOT_READ = 0x0C
CONSOLE_FILTER = 0x0D
SETTINGS = 0x0E
FILE_LIST, FILE_READ, FILE_WRITE, FILE_DELETE, MKDIR, FILE_STAT, FILE_CLOSE = range(0x10, 0x17)

#: one FILE_WRITE: the frame payload is at most 4096 bytes, of which 6 + the path are the header
Expand Down Expand Up @@ -209,6 +210,11 @@ def console_filter(self, console: str | None = None) -> dict:
return self._call(CONSOLE_FILTER, b"")
return self._call(CONSOLE_FILTER, (console or "all").encode())

def settings(self, change: str | None = None) -> dict:
"""The launcher's settings ({settings, limits}); `change` ("name=value")
sets one first (protocol 4)."""
return self._call(SETTINGS, (change or "").encode())

def reload_roms(self) -> int:
return self._call(RELOAD_ROMS)["total"]

Expand Down
Loading
Loading