C
add installer
YU CHIH CHANGd53fb9f720fd
diff --git a/README.md b/README.mdindex a4e6ccb..c9f2cf2 100644--- a/README.md+++ b/README.md@@ -75,6 +75,10 @@ No development tools are required.👉 **https://caa1211.github.io/esp32-gt7-dashboard/**+The browser installer supports the classic ESP32 target configured by this repository.+Firmware maintainers can find the local build, binary staging, flash-offset, and publishing+procedure in [docs/RELEASING.md](docs/RELEASING.md).+---## Quick Startdiff --git a/README.zh-TW.md b/README.zh-TW.mdindex a2e778b..c29909e 100644--- a/README.zh-TW.md+++ b/README.zh-TW.md@@ -76,6 +76,9 @@👉 **https://caa1211.github.io/esp32-gt7-dashboard/**+網頁安裝程式支援本專案所設定的傳統 ESP32 目標。韌體維護者可參閱+[docs/RELEASING.md](docs/RELEASING.md),了解本機編譯、二進位檔案放置、燒錄位址及發佈流程。+---## 快速開始@@ -219,4 +222,4 @@ https://makerworld.com/zh/models/2171220-slim-minimal-case-for-esp32-cyd-2-4-2-8## 授權-本專案採用 **MIT License**。\ No newline at end of file+本專案採用 **MIT License**。diff --git a/VERSION b/VERSIONnew file mode 100644index 0000000..e8ea05d--- /dev/null+++ b/VERSION@@ -0,0 +1 @@+1.2.4diff --git a/docs/RELEASING.md b/docs/RELEASING.mdnew file mode 100644index 0000000..367361d--- /dev/null+++ b/docs/RELEASING.md@@ -0,0 +1,114 @@+# Publishing firmware for the Web Installer++The GitHub Pages workflow publishes only the contents of `installer/`. It does not install+PlatformIO and does not compile the firmware. Build and test every release locally before+committing its binary images.++`VERSION` is the only manually controlled version source. The publish helper synchronizes+that value into the generated C++ header and ESP Web Tools manifest.++## Flash layout++The project uses the `esp32` PlatformIO environment, the classic+`esp32doit-devkit-v1` board, Arduino framework, and `huge_app.csv` partition table.+PlatformIO's resolved upload metadata defines this flash layout:++| Offset | Installer file | Local source |+| --- | --- | --- |+| `0x1000` | `installer/firmware/bootloader.bin` | `.pio/build/esp32/bootloader.bin` |+| `0x8000` | `installer/firmware/partitions.bin` | `.pio/build/esp32/partitions.bin` |+| `0xE000` | `installer/firmware/boot_app0.bin` | PlatformIO's Arduino ESP32 package, `tools/partitions/boot_app0.bin` |+| `0x10000` | `installer/firmware/firmware.bin` | `.pio/build/esp32/firmware.bin` |++These offsets are not arbitrary: the ESP32 PlatformIO integration places the bootloader at+`0x1000`, the partition table at `0x8000`, the OTA data initializer at `0xE000`, and the+application at `0x10000`. The selected `huge_app.csv` confirms that the OTA data partition+starts at `0xE000` and the first application partition starts at `0x10000`.++Re-check PlatformIO's verbose upload command or resolved project metadata if the board,+framework platform, or partition table changes. Update both this document and+`installer/manifest.json` if the flash map changes.++## Build and test locally++1. Install PlatformIO locally and check out the revision to release.+2. Choose a release version and run the single local publishing command. Supply a numeric+ `major.minor.patch` version:++ ```bash+ node scripts/publish-firmware.mjs 1.2.3+ ```++ The script validates the version, updates `VERSION`, `include/version.h`, and+ `installer/manifest.json`, then runs `pio run -e esp32`. After a successful build it+ validates and copies all four non-empty binaries into `installer/firmware/`, verifies+ every manifest binary, and prints sizes, SHA-256 hashes, and a release summary.++ Running the command without a version preserves the existing behavior by reading the+ current value from `VERSION`:++ ```bash+ node scripts/publish-firmware.mjs+ ```++ To synchronize the version files without building or copying binaries, use:++ ```bash+ node scripts/publish-firmware.mjs 1.2.3 --skip-build+ ```++ Set `PLATFORMIO_CMD` if PlatformIO is not on `PATH`, or `PLATFORMIO_ENV` if a future+ release uses another environment. The helper never commits, tags, pushes, creates a+ GitHub Release, or deploys Pages.++ To build without staging installer files, run PlatformIO directly:++ ```bash+ pio run -e esp32+ ```++3. Upload it to the target hardware and test the dashboard:++ ```bash+ pio run -e esp32 -t upload+ ```++4. Confirm that the display, touch input, Wi-Fi setup, and GT7 telemetry work as expected.++## Stage the installer binaries++Create `installer/firmware/` if necessary, then copy the four real binary files listed in+the flash-layout table into it. The first, second, and fourth files come from+`.pio/build/esp32/`. Locate `boot_app0.bin` in the installed Arduino ESP32 framework package+reported by PlatformIO; on typical systems it is under:++```text+<PlatformIO home>/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin+```++Do not commit `.pio/`. Do not add empty or placeholder binary files. Before committing,+verify that all four installer binaries exist and have non-zero sizes:++```bash+git status --short+git check-ignore -v installer/firmware/firmware.bin+```++The second command should produce no output. Review the files that will be committed, then+commit the four binaries together with any intentional manifest version change.++## Verify the installer++1. Serve `installer/` from a local HTTP server or push the tested binaries and allow the+ GitHub Pages workflow to deploy them. Web Serial requires a secure context; the deployed+ HTTPS Pages site is the most representative test.+2. Open the installer in Chrome, Edge, or another desktop browser with Web Serial support.+3. Connect a test ESP32 using a data-capable USB cable and close any serial monitor.+4. Select **Install firmware**, choose the correct serial port, and complete the flash.+5. Power-cycle the device and repeat the functional checks above.+6. In repository **Settings > Pages**, ensure the source is set to **GitHub Actions**. Confirm+ that the deployment succeeded and that the public installer loads its manifest and all+ four binary URLs without 404 errors.++The Pages workflow is intentionally path-filtered and uploads only `installer/`; source code,+documentation, `.pio/`, and local build tooling are not included in the published artifact.diff --git a/include/version.h b/include/version.hnew file mode 100644index 0000000..458eb85--- /dev/null+++ b/include/version.h@@ -0,0 +1,3 @@+#pragma once++inline constexpr char GT7_DASH_VERSION[] = "1.2.4";diff --git a/installer/firmware/boot_app0.bin b/installer/firmware/boot_app0.binnew file mode 100644index 0000000..13562caBinary files /dev/null and b/installer/firmware/boot_app0.bin differdiff --git a/installer/firmware/bootloader.bin b/installer/firmware/bootloader.binnew file mode 100644index 0000000..d592359Binary files /dev/null and b/installer/firmware/bootloader.bin differdiff --git a/installer/firmware/firmware.bin b/installer/firmware/firmware.binnew file mode 100644index 0000000..6f0be69Binary files /dev/null and b/installer/firmware/firmware.bin differdiff --git a/installer/firmware/partitions.bin b/installer/firmware/partitions.binnew file mode 100644index 0000000..1954582Binary files /dev/null and b/installer/firmware/partitions.bin differdiff --git a/installer/index.html b/installer/index.htmlnew file mode 100644index 0000000..e65470e--- /dev/null+++ b/installer/index.html@@ -0,0 +1,210 @@+<!doctype html>+<html lang="en">+ <head>+ <meta charset="utf-8">+ <meta name="viewport" content="width=device-width, initial-scale=1">+ <meta name="theme-color" content="#07111f">+ <meta name="description" content="Install the ESP32 GT7 Dashboard firmware from a compatible browser.">+ <title>ESP32 GT7 Dashboard Installer</title>+ <script type="module" src="https://unpkg.com/esp-web-tools@10/dist/web/install-button.js?module"></script>+ <style>+ :root {+ color-scheme: dark;+ font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;+ background: #07111f;+ color: #e7eef8;+ }++ * { box-sizing: border-box; }++ body {+ min-height: 100vh;+ margin: 0;+ display: grid;+ place-items: center;+ padding: 24px;+ background:+ radial-gradient(circle at top left, rgba(14, 165, 233, 0.24), transparent 42%),+ radial-gradient(circle at bottom right, rgba(37, 99, 235, 0.20), transparent 38%),+ #07111f;+ }++ main {+ width: min(100%, 680px);+ padding: clamp(28px, 6vw, 52px);+ border: 1px solid rgba(148, 163, 184, 0.22);+ border-radius: 24px;+ background: rgba(15, 23, 42, 0.88);+ box-shadow: 0 28px 80px rgba(0, 0, 0, 0.35);+ backdrop-filter: blur(14px);+ }++ .eyebrow {+ margin: 0 0 10px;+ color: #38bdf8;+ font-size: 0.82rem;+ font-weight: 750;+ letter-spacing: 0.14em;+ text-transform: uppercase;+ }++ .release-version {+ display: inline-flex;+ align-items: center;+ margin-top: 16px;+ padding: 6px 10px;+ border: 1px solid rgba(56, 189, 248, 0.28);+ border-radius: 999px;+ background: rgba(14, 165, 233, 0.1);+ color: #bae6fd;+ font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;+ font-size: 0.85rem;+ }++ h1 {+ margin: 0;+ font-size: clamp(2rem, 7vw, 3.7rem);+ line-height: 1.02;+ letter-spacing: -0.045em;+ }++ .lead {+ margin: 20px 0 0;+ color: #b7c5d8;+ font-size: 1.05rem;+ line-height: 1.7;+ }++ .steps {+ margin: 30px 0;+ padding: 22px 22px 22px 44px;+ border-radius: 16px;+ background: rgba(30, 41, 59, 0.72);+ color: #d8e2ef;+ line-height: 1.75;+ }++ .install {+ display: flex;+ justify-content: center;+ padding: 8px 0 16px;+ }++ .note {+ margin: 12px 0 0;+ color: #8fa3bb;+ font-size: 0.9rem;+ line-height: 1.6;+ text-align: center;+ }++ .quick-start {+ margin-top: 28px;+ padding: 22px;+ border: 1px solid rgba(34, 197, 94, 0.3);+ border-radius: 16px;+ background: rgba(20, 83, 45, 0.2);+ }++ .quick-start h2 {+ margin: 0;+ color: #86efac;+ font-size: 1.15rem;+ }++ .quick-start p {+ margin: 14px 0 8px;+ color: #d8e2ef;+ font-weight: 650;+ }++ .quick-start ol {+ margin: 0;+ padding-left: 24px;+ color: #b7c5d8;+ line-height: 1.75;+ }++ .wifi-name {+ display: inline-block;+ margin-top: 4px;+ padding: 2px 8px;+ border-radius: 6px;+ background: rgba(15, 23, 42, 0.8);+ color: #f8fafc;+ font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;+ font-weight: 700;+ }++ a { color: #7dd3fc; }+ a:hover { color: #bae6fd; }++ footer {+ margin-top: 28px;+ padding-top: 22px;+ border-top: 1px solid rgba(148, 163, 184, 0.18);+ color: #8fa3bb;+ font-size: 0.88rem;+ text-align: center;+ }+ </style>+ </head>+ <body>+ <main>+ <p class="eyebrow">USB Web Installer</p>+ <h1>ESP32 GT7 Dashboard</h1>+ <span class="release-version" id="release-version" aria-live="polite">Version loading…</span>+ <p class="lead">+ Flash the dashboard firmware directly from a compatible desktop browser.+ No PlatformIO installation is required.+ </p>++ <ol class="steps">+ <li>Connect the classic ESP32 board with a data-capable USB cable.</li>+ <li>Close serial monitors and other programs using its serial port.</li>+ <li>Select <strong>Install firmware</strong>, choose the port, and confirm.</li>+ <li>Leave the board connected until the installation finishes.</li>+ </ol>++ <div class="install">+ <esp-web-install-button manifest="manifest.json">+ <button slot="unsupported">Use Chrome, Edge, or another Web Serial browser</button>+ </esp-web-install-button>+ </div>++ <p class="note">+ Installing replaces the firmware currently stored on the device. Web Serial is not+ available in every browser or on every mobile device.+ </p>++ <section class="quick-start" aria-labelledby="quick-start-title">+ <h2 id="quick-start-title">✅ Installation complete</h2>+ <p>Next steps:</p>+ <ol>+ <li>Disconnect USB.</li>+ <li>Reconnect power.</li>+ <li>Connect to Wi-Fi:<br><span class="wifi-name">GT7-DASH-SETUP</span></li>+ </ol>+ </section>++ <footer>+ Firmware source and release instructions are available in the+ <a href="https://github.com/caa1211/esp32-gt7-dashboard">GitHub repository</a>.+ </footer>+ </main>++ <script>+ fetch("manifest.json", { cache: "no-store" })+ .then((response) => {+ if (!response.ok) throw new Error(`HTTP ${response.status}`);+ return response.json();+ })+ .then((manifest) => {+ document.getElementById("release-version").textContent = `Version ${manifest.version}`;+ })+ .catch(() => {+ document.getElementById("release-version").textContent = "Version unavailable";+ });+ </script>+ </body>+</html>diff --git a/installer/manifest.json b/installer/manifest.jsonnew file mode 100644index 0000000..17647d2--- /dev/null+++ b/installer/manifest.json@@ -0,0 +1,28 @@+{+ "name": "ESP32 GT7 Dashboard",+ "version": "1.2.4",+ "new_install_prompt_erase": true,+ "builds": [+ {+ "chipFamily": "ESP32",+ "parts": [+ {+ "path": "firmware/bootloader.bin",+ "offset": 4096+ },+ {+ "path": "firmware/partitions.bin",+ "offset": 32768+ },+ {+ "path": "firmware/boot_app0.bin",+ "offset": 57344+ },+ {+ "path": "firmware/firmware.bin",+ "offset": 65536+ }+ ]+ }+ ]+}diff --git a/package.json b/package.jsonnew file mode 100644index 0000000..b7a3224--- /dev/null+++ b/package.json@@ -0,0 +1,7 @@+++{+ "scripts": {+ "publish:firmware": "node scripts/publish-firmware.mjs"+ }+}\ No newline at end of filediff --git a/scripts/publish-firmware.mjs b/scripts/publish-firmware.mjsnew file mode 100644index 0000000..0bda70f--- /dev/null+++ b/scripts/publish-firmware.mjs@@ -0,0 +1,246 @@+#!/usr/bin/env node++import { createHash } from "node:crypto";+import { copyFile, mkdir, readFile, stat, writeFile } from "node:fs/promises";+import { homedir } from "node:os";+import { basename, dirname, join, relative, resolve } from "node:path";+import { spawnSync } from "node:child_process";+import { fileURLToPath } from "node:url";++const scriptDirectory = dirname(fileURLToPath(import.meta.url));+const projectDirectory = resolve(scriptDirectory, "..");+const environment = process.env.PLATFORMIO_ENV ?? "esp32";+const buildDirectory = join(projectDirectory, ".pio", "build", environment);+const firmwareDirectory = join(projectDirectory, "installer", "firmware");+const versionPath = join(projectDirectory, "VERSION");+const versionHeaderPath = join(projectDirectory, "include", "version.h");+const manifestPath = join(projectDirectory, "installer", "manifest.json");+const versionPattern = /^\d+\.\d+\.\d+$/;++function displayPath(path) {+ return relative(projectDirectory, path).replaceAll("\\", "/");+}++async function fileContents(path) {+ try {+ return await readFile(path, "utf8");+ } catch (error) {+ if (error.code === "ENOENT") {+ return null;+ }+ throw error;+ }+}++async function writeIfChanged(path, contents, modifiedFiles) {+ if ((await fileContents(path)) === contents) {+ return;+ }++ await mkdir(dirname(path), { recursive: true });+ await writeFile(path, contents, "utf8");+ modifiedFiles.push(displayPath(path));+}++function parseArguments() {+ const argumentsList = process.argv.slice(2);+ const skipBuild = argumentsList.includes("--skip-build");+ const positional = argumentsList.filter((argument) => argument !== "--skip-build");++ if (positional.length > 1 || argumentsList.some((argument) => argument.startsWith("--") && argument !== "--skip-build")) {+ throw new Error("Usage: node scripts/publish-firmware.mjs [x.y.z] [--skip-build]");+ }++ return { suppliedVersion: positional[0], skipBuild };+}++async function resolveVersion(suppliedVersion) {+ const version = suppliedVersion ?? (await readFile(versionPath, "utf8")).trim();++ if (!versionPattern.test(version)) {+ throw new Error(`Invalid version "${version}". Expected x.y.z using digits only.`);+ }++ return version;+}++async function synchronizeVersion(version) {+ const modifiedFiles = [];+ const manifest = JSON.parse(await readFile(manifestPath, "utf8"));+ manifest.version = version;++ await writeIfChanged(versionPath, `${version}\n`, modifiedFiles);+ await writeIfChanged(+ versionHeaderPath,+ `#pragma once\n\ninline constexpr char GT7_DASH_VERSION[] = "${version}";\n`,+ modifiedFiles,+ );+ await writeIfChanged(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, modifiedFiles);++ return modifiedFiles;+}++async function verifySynchronizedVersion(expectedVersion) {+ const version = (await readFile(versionPath, "utf8")).trim();+ const header = await readFile(versionHeaderPath, "utf8");+ const headerMatch = header.match(/inline constexpr char GT7_DASH_VERSION\[\] = "(\d+\.\d+\.\d+)";/);+ const manifest = JSON.parse(await readFile(manifestPath, "utf8"));++ if (version !== expectedVersion || headerMatch?.[1] !== version || manifest.version !== version) {+ throw new Error("Version verification failed for VERSION, include/version.h, or installer/manifest.json.");+ }++ return manifest;+}++function platformioCandidates() {+ const candidates = [];++ if (process.env.PLATFORMIO_CMD) {+ candidates.push(process.env.PLATFORMIO_CMD);+ }++ candidates.push("pio", "platformio");++ if (process.platform === "win32") {+ candidates.push(+ join(homedir(), ".platformio", "penv", "Scripts", "pio.exe"),+ join(homedir(), ".platformio", "penv", "Scripts", "platformio.exe"),+ );+ } else {+ candidates.push(+ join(homedir(), ".platformio", "penv", "bin", "pio"),+ join(homedir(), ".platformio", "penv", "bin", "platformio"),+ );+ }++ return [...new Set(candidates)];+}++function runBuild() {+ for (const command of platformioCandidates()) {+ const result = spawnSync(command, ["run", "-e", environment], {+ cwd: projectDirectory,+ encoding: "utf8",+ stdio: "inherit",+ shell: false,+ });++ if (result.error?.code === "ENOENT") {+ continue;+ }++ if (result.error) {+ throw result.error;+ }++ if (result.status !== 0) {+ throw new Error(`PlatformIO exited with status ${result.status}.`);+ }++ return command;+ }++ throw new Error(+ "PlatformIO was not found. Install PlatformIO, add pio to PATH, or set PLATFORMIO_CMD.",+ );+}++function frameworkBootAppPath() {+ const coreDirectory = process.env.PLATFORMIO_CORE_DIR+ ? resolve(process.env.PLATFORMIO_CORE_DIR)+ : join(homedir(), ".platformio");++ return join(+ coreDirectory,+ "packages",+ "framework-arduinoespressif32",+ "tools",+ "partitions",+ "boot_app0.bin",+ );+}++async function verifyNonEmpty(path) {+ const details = await stat(path);++ if (!details.isFile() || details.size === 0) {+ throw new Error(`Expected a non-empty binary file: ${path}`);+ }++ return details.size;+}++async function sha256(path) {+ const contents = await readFile(path);+ return createHash("sha256").update(contents).digest("hex");+}++async function verifyManifestBinaries(manifest) {+ const parts = manifest.builds?.flatMap((build) => build.parts ?? []) ?? [];++ if (parts.length === 0) {+ throw new Error("The installer manifest does not reference any binary files.");+ }++ for (const part of parts) {+ const binaryPath = resolve(dirname(manifestPath), part.path);+ await verifyNonEmpty(binaryPath);+ }+}++function printSummary({ version, skipBuild, copiedFiles, modifiedFiles }) {+ console.log("\nRelease summary");+ console.log(` Version: ${version}`);+ console.log(` PlatformIO environment: ${environment}`);+ console.log(` Build output: ${displayPath(buildDirectory)}`);+ console.log(` Manifest: ${displayPath(manifestPath)}`);+ console.log(` Build: ${skipBuild ? "skipped" : "successful"}`);+ console.log(` Copied binaries: ${copiedFiles.length ? copiedFiles.join(", ") : "none (--skip-build)"}`);+ console.log(` Modified files: ${modifiedFiles.length ? modifiedFiles.join(", ") : "none"}`);+}++async function main() {+ const { suppliedVersion, skipBuild } = parseArguments();+ const version = await resolveVersion(suppliedVersion);+ const modifiedFiles = await synchronizeVersion(version);+ let manifest = await verifySynchronizedVersion(version);++ if (skipBuild) {+ printSummary({ version, skipBuild, copiedFiles: [], modifiedFiles });+ return;+ }++ console.log(`Building PlatformIO environment: ${environment}`);+ const command = runBuild();+ console.log(`Build completed with: ${command}`);++ const binaries = [+ join(buildDirectory, "bootloader.bin"),+ join(buildDirectory, "partitions.bin"),+ frameworkBootAppPath(),+ join(buildDirectory, "firmware.bin"),+ ];++ await mkdir(firmwareDirectory, { recursive: true });++ const copiedFiles = [];+ console.log(`Copying firmware to: ${firmwareDirectory}`);+ for (const source of binaries) {+ await verifyNonEmpty(source);+ const destination = join(firmwareDirectory, basename(source));+ await copyFile(source, destination);+ const size = await verifyNonEmpty(destination);+ copiedFiles.push(displayPath(destination));+ console.log(`${basename(destination)}: ${size} bytes, SHA-256 ${await sha256(destination)}`);+ }++ manifest = await verifySynchronizedVersion(version);+ await verifyManifestBinaries(manifest);+ printSummary({ version, skipBuild, copiedFiles, modifiedFiles });+}++main().catch((error) => {+ console.error(`publish-firmware: ${error.message}`);+ process.exitCode = 1;+});diff --git a/src/SHCustomProtocol.h b/src/SHCustomProtocol.hindex 4897d91..24c9062 100644--- a/src/SHCustomProtocol.h+++ b/src/SHCustomProtocol.h@@ -12,10 +12,10 @@#include <map>#include <BleGamepad.h> // libreria bluetooth#include <GT7DerivedMetrics.h>+#include "version.h"static LGFX tft;-static String GT7_DASH_VERSION = "1.2.2";static const int RESET_WAITING_TIME = 3;static const int SCREEN_WIDTH = 320;static const int SCREEN_HEIGHT = 240;@@ -828,7 +828,7 @@ public:1);tft.drawCentreString(- "v" + GT7_DASH_VERSION + " | by caa1211",+ String("v") + GT7_DASH_VERSION + " | by caa1211",SCREEN_WIDTH / 2,SCREEN_HEIGHT - 12,1);