Files
MimiCon/main/web_assets.h
T
dark98 69ebdb4331 Initial commit: MimiCon v1.0.0 - Universal Gamepad Mimic & Console Bridge
- Dual-Core Architecture: Dedicated 1000Hz USB gaming pipeline on Core 1 and BLE/Wi-Fi/Web telemetry on Core 0.
- Multi-Input BLE Host: Parsers for Xbox Wireless, Google Stadia, 8BitDo (Ultimate/Pro2/SN30), and Generic HOGP gamepads.
- Multi-Console USB Emulation: Nintendo Switch, PC DirectInput, PS3, PS4, Xbox 360 (libxsm3 cryptographic challenge-response), Original Xbox, and Couch Mouse/Keyboard.
- Onboard Web Portal & Captive Portal: Real-time SVG gamepad visualizer, stick deadzone calibration, button combo remapping, and Wi-Fi manager.
- Low-Latency Radio Management: Interactive SoftAP toggle to drop to 0-latency gaming mode.
- Dual OTA Firmware Flashing: Browser-based wireless firmware updater and automated Python OTA script.
- Strict Build Quality: Clean build under -Wall -Wextra with zero warnings or errors.
- Versioning & Licensing: Semantic Versioning v1.0.0 and GNU GPLv3 with Commercial Restrictions.
2026-10-17 20:21:09 +01:00

1631 lines
75 KiB
C

#pragma once
static const char INDEX_HTML[] =
"<!DOCTYPE html>\n"
"<html lang=\"en\">\n"
"<head>\n"
"<meta charset=\"UTF-8\">\n"
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\">\n"
"<title>MimiCon - Universal Gamepad Bridge</title>\n"
"<style>\n"
":root {\n"
" --bg-dark: #0a0e17;\n"
" --card-bg: rgba(18, 24, 38, 0.85);\n"
" --card-border: rgba(255, 255, 255, 0.08);\n"
" --card-hover: rgba(255, 255, 255, 0.12);\n"
" --accent-cyan: #00f2fe;\n"
" --accent-blue: #3b82f6;\n"
" --accent-red: #ff3366;\n"
" --accent-green: #00f076;\n"
" --accent-purple: #a855f7;\n"
" --text-main: #f3f4f6;\n"
" --text-dim: #9ca3af;\n"
" --active-glow: 0 0 16px rgba(0, 242, 254, 0.45);\n"
"}\n"
"* { box-sizing: border-box; margin: 0; padding: 0; }\n"
"body {\n"
" font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;\n"
" background: radial-gradient(circle at top center, #131c31 0%, #0a0e17 100%);\n"
" color: var(--text-main);\n"
" min-height: 100vh;\n"
" padding: 16px;\n"
" line-height: 1.5;\n"
"}\n"
".container {\n"
" max-width: 680px;\n"
" margin: 0 auto;\n"
" display: flex;\n"
" flex-direction: column;\n"
" gap: 16px;\n"
"}\n"
"header {\n"
" display: flex;\n"
" justify-content: space-between;\n"
" align-items: center;\n"
" padding: 12px 18px;\n"
" background: var(--card-bg);\n"
" border: 1px solid var(--card-border);\n"
" border-radius: 16px;\n"
" backdrop-filter: blur(12px);\n"
"}\n"
".brand { display: flex; align-items: center; gap: 10px; }\n"
".brand-icon {\n"
" width: 32px; height: 32px;\n"
" background: linear-gradient(135deg, var(--accent-purple), var(--accent-cyan));\n"
" border-radius: 8px;\n"
" display: flex; align-items: center; justify-content: center;\n"
" font-size: 18px;\n"
"}\n"
"h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em; }\n"
".subtitle { font-size: 0.75rem; color: var(--text-dim); }\n"
".badge {\n"
" font-size: 0.7rem;\n"
" font-weight: 600;\n"
" padding: 4px 10px;\n"
" border-radius: 20px;\n"
" background: rgba(168, 85, 247, 0.15);\n"
" border: 1px solid var(--accent-purple);\n"
" color: var(--accent-purple);\n"
" display: inline-flex;\n"
" align-items: center;\n"
" gap: 6px;\n"
" cursor: pointer;\n"
" user-select: none;\n"
" transition: all 0.2s ease;\n"
"}\n"
".badge:hover {\n"
" transform: scale(1.05);\n"
" filter: brightness(1.2);\n"
"}\n"
".badge.off {\n"
" background: rgba(255, 255, 255, 0.05);\n"
" border-color: rgba(255, 255, 255, 0.2);\n"
" color: var(--text-dim);\n"
"}\n"
".badge.off .pulse-dot {\n"
" background: var(--text-dim);\n"
" box-shadow: none;\n"
" animation: none;\n"
"}\n"
".pulse-dot {\n"
" width: 6px; height: 6px;\n"
" background: var(--accent-purple);\n"
" border-radius: 50%;\n"
" box-shadow: 0 0 8px var(--accent-purple);\n"
" animation: pulse 1.5s infinite;\n"
"}\n"
"@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(0.85); } }\n"
"\n"
".card {\n"
" background: var(--card-bg);\n"
" border: 1px solid var(--card-border);\n"
" border-radius: 16px;\n"
" padding: 16px;\n"
" backdrop-filter: blur(12px);\n"
"}\n"
".card-header {\n"
" display: flex;\n"
" justify-content: space-between;\n"
" align-items: center;\n"
" margin-bottom: 12px;\n"
"}\n"
".card-title {\n"
" font-size: 0.9rem;\n"
" text-transform: uppercase;\n"
" letter-spacing: 0.05em;\n"
" font-weight: 700;\n"
" color: var(--text-dim);\n"
"}\n"
"\n"
".banner-exit {\n"
" display: flex;\n"
" align-items: center;\n"
" justify-content: space-between;\n"
" padding: 14px 18px;\n"
" background: linear-gradient(135deg, rgba(0, 240, 118, 0.12), rgba(0, 242, 254, 0.08));\n"
" border: 1px solid rgba(0, 240, 118, 0.35);\n"
" border-radius: 16px;\n"
"}\n"
".btn-play {\n"
" background: linear-gradient(135deg, #00f076, #00d26a);\n"
" color: #042010;\n"
" font-weight: 700;\n"
" border: none;\n"
" padding: 10px 18px;\n"
" border-radius: 10px;\n"
" font-size: 0.9rem;\n"
" cursor: pointer;\n"
" box-shadow: 0 0 16px rgba(0, 240, 118, 0.4);\n"
" transition: transform 0.15s, box-shadow 0.15s;\n"
"}\n"
".btn-play:active { transform: scale(0.96); }\n"
"\n"
".modes-grid {\n"
" display: grid;\n"
" grid-template-columns: 1fr 1fr;\n"
" gap: 10px;\n"
"}\n"
".mode-btn {\n"
" background: rgba(255, 255, 255, 0.03);\n"
" border: 1px solid var(--card-border);\n"
" border-radius: 12px;\n"
" padding: 14px;\n"
" display: flex;\n"
" flex-direction: column;\n"
" gap: 6px;\n"
" cursor: pointer;\n"
" text-align: left;\n"
" transition: all 0.2s;\n"
"}\n"
".mode-btn:hover { background: var(--card-hover); border-color: rgba(255, 255, 255, 0.2); }\n"
".mode-btn.active {\n"
" background: rgba(0, 242, 254, 0.08);\n"
" border-color: var(--accent-cyan);\n"
" box-shadow: 0 0 12px rgba(0, 242, 254, 0.25);\n"
"}\n"
".mode-btn.active.mode-ps3 {\n"
" background: rgba(255, 51, 102, 0.08);\n"
" border-color: var(--accent-red);\n"
" box-shadow: 0 0 12px rgba(255, 51, 102, 0.25);\n"
"}\n"
".mode-btn.active.mode-pc {\n"
" background: rgba(59, 130, 246, 0.08);\n"
" border-color: var(--accent-blue);\n"
" box-shadow: 0 0 12px rgba(59, 130, 246, 0.25);\n"
"}\n"
".mode-btn.active.mode-x360 {\n"
" background: rgba(0, 240, 118, 0.08);\n"
" border-color: var(--accent-green);\n"
" box-shadow: 0 0 12px rgba(0, 240, 118, 0.25);\n"
"}\n"
".mode-btn.active.mode-ogx {\n"
" background: rgba(245, 158, 11, 0.08);\n"
" border-color: #f59e0b;\n"
" box-shadow: 0 0 12px rgba(245, 158, 11, 0.25);\n"
"}\n"
".mode-btn.active.mode-ps4 {\n"
" background: rgba(0, 102, 255, 0.08);\n"
" border-color: #3b82f6;\n"
" box-shadow: 0 0 12px rgba(0, 102, 255, 0.25);\n"
"}\n"
".mode-btn.active.mode-mouse {\n"
" background: rgba(20, 184, 166, 0.08);\n"
" border-color: #14b8a6;\n"
" box-shadow: 0 0 12px rgba(20, 184, 166, 0.35);\n"
"}\n"
".mode-name { font-weight: 700; font-size: 0.95rem; color: #fff; }\n"
".mode-desc { font-size: 0.72rem; color: var(--text-dim); }\n"
"\n"
"/* Gamepad Visualizer */\n"
".visualizer-wrap {\n"
" display: flex;\n"
" flex-direction: column;\n"
" align-items: center;\n"
" gap: 12px;\n"
"}\n"
".gamepad-svg {\n"
" width: 100%;\n"
" max-width: 440px;\n"
" filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.5));\n"
"}\n"
".trigger-bars {\n"
" display: flex;\n"
" width: 100%;\n"
" gap: 12px;\n"
"}\n"
".bar-box {\n"
" flex: 1;\n"
" background: rgba(255, 255, 255, 0.05);\n"
" border-radius: 8px;\n"
" padding: 8px 12px;\n"
" border: 1px solid var(--card-border);\n"
"}\n"
".bar-label {\n"
" display: flex;\n"
" justify-content: space-between;\n"
" font-size: 0.75rem;\n"
" font-weight: 600;\n"
" margin-bottom: 6px;\n"
"}\n"
".bar-track {\n"
" height: 8px;\n"
" background: rgba(0, 0, 0, 0.4);\n"
" border-radius: 4px;\n"
" overflow: hidden;\n"
"}\n"
".bar-fill {\n"
" height: 100%;\n"
" width: 0%;\n"
" background: linear-gradient(90deg, var(--accent-cyan), var(--accent-green));\n"
" border-radius: 4px;\n"
" transition: width 0.05s linear;\n"
"}\n"
"\n"
"/* Sticks coordinates table */\n"
".sticks-readout {\n"
" display: flex;\n"
" width: 100%;\n"
" justify-content: space-around;\n"
" font-family: monospace;\n"
" font-size: 0.78rem;\n"
" color: var(--text-dim);\n"
"}\n"
"\n"
"/* BLE section */\n"
".ble-info-row {\n"
" display: flex;\n"
" align-items: center;\n"
" justify-content: space-between;\n"
" margin-bottom: 12px;\n"
"}\n"
".btn-group {\n"
" display: flex;\n"
" gap: 8px;\n"
"}\n"
".btn-secondary {\n"
" background: rgba(255, 255, 255, 0.06);\n"
" border: 1px solid var(--card-border);\n"
" color: var(--text-main);\n"
" padding: 8px 14px;\n"
" border-radius: 8px;\n"
" font-size: 0.8rem;\n"
" font-weight: 600;\n"
" cursor: pointer;\n"
" transition: background 0.15s;\n"
"}\n"
".btn-secondary:hover { background: rgba(255, 255, 255, 0.12); }\n"
".btn-danger {\n"
" border-color: rgba(255, 51, 102, 0.4);\n"
" color: var(--accent-red);\n"
"}\n"
".btn-danger:hover { background: rgba(255, 51, 102, 0.15); }\n"
"\n"
"/* Slider */\n"
".slider-row {\n"
" display: flex;\n"
" align-items: center;\n"
" gap: 12px;\n"
"}\n"
"input[type=range] {\n"
" flex: 1;\n"
" accent-color: var(--accent-cyan);\n"
"}\n"
"\n"
"/* Virtual Touch Gamepad & Fullscreen Styling */\n"
"#virtual-pad {\n"
" touch-action: none;\n"
" -webkit-user-select: none;\n"
" user-select: none;\n"
"}\n"
"#virtual-pad:fullscreen,\n"
"#virtual-pad:-webkit-full-screen,\n"
"#virtual-pad.vpad-fullscreen {\n"
" position: fixed !important;\n"
" inset: 0 !important;\n"
" width: 100vw !important;\n"
" height: 100vh !important;\n"
" max-width: 100vw !important;\n"
" max-height: 100vh !important;\n"
" margin: 0 !important;\n"
" border-radius: 0 !important;\n"
" border: none !important;\n"
" z-index: 999999 !important;\n"
" background: radial-gradient(circle at 50% 35%, #101c33 0%, #050a14 100%) !important;\n"
" padding: 16px 28px env(safe-area-inset-bottom, 16px) 28px !important;\n"
" box-sizing: border-box !important;\n"
" display: flex !important;\n"
" flex-direction: column !important;\n"
" justify-content: space-between !important;\n"
" overflow: hidden !important;\n"
"}\n"
".vpad-fs-only { display: none !important; }\n"
"#virtual-pad:fullscreen .vpad-fs-only,\n"
"#virtual-pad:-webkit-full-screen .vpad-fs-only,\n"
"#virtual-pad.vpad-fullscreen .vpad-fs-only {\n"
" display: flex !important;\n"
"}\n"
".vpad-fs-header {\n"
" display: flex;\n"
" justify-content: space-between;\n"
" align-items: center;\n"
" width: 100%;\n"
" margin-bottom: 12px;\n"
"}\n"
".vpad-btn {\n"
" background: rgba(255, 255, 255, 0.08);\n"
" border: 1px solid var(--card-border);\n"
" color: var(--text-main);\n"
" border-radius: 12px;\n"
" font-weight: 700;\n"
" cursor: pointer;\n"
" touch-action: none;\n"
" -webkit-user-select: none;\n"
" user-select: none;\n"
" display: inline-flex;\n"
" align-items: center;\n"
" justify-content: center;\n"
" transition: transform 0.05s, background 0.1s, box-shadow 0.1s;\n"
"}\n"
".vpad-btn:active {\n"
" transform: scale(0.92);\n"
" background: rgba(255, 255, 255, 0.22);\n"
" box-shadow: 0 0 14px rgba(0, 242, 254, 0.4);\n"
"}\n"
".vpad-stick-base {\n"
" width: 100px;\n"
" height: 100px;\n"
" border-radius: 50%;\n"
" background: radial-gradient(circle, rgba(255,255,255,0.06) 0%, rgba(0,0,0,0.5) 100%);\n"
" border: 2px solid rgba(255, 255, 255, 0.15);\n"
" position: relative;\n"
" touch-action: none;\n"
" display: flex;\n"
" align-items: center;\n"
" justify-content: center;\n"
" box-shadow: inset 0 0 16px rgba(0,0,0,0.6);\n"
"}\n"
".vpad-stick-nub {\n"
" width: 40px;\n"
" height: 40px;\n"
" border-radius: 50%;\n"
" background: linear-gradient(135deg, rgba(255,255,255,0.25), rgba(255,255,255,0.08));\n"
" border: 2px solid rgba(255, 255, 255, 0.35);\n"
" position: absolute;\n"
" pointer-events: none;\n"
" box-shadow: 0 4px 10px rgba(0,0,0,0.5);\n"
" transform: translate(0px, 0px);\n"
"}\n"
"</style>\n"
"</head>\n"
"<body>\n"
"<div class=\"container\">\n"
" <header>\n"
" <div class=\"brand\">\n"
" <div class=\"brand-icon\">🎮</div>\n"
" <div>\n"
" <h1>MimiCon <span id=\"header-ver\" style=\"font-size:0.75rem;font-weight:600;padding:2px 7px;border-radius:6px;background:rgba(0,242,254,0.15);color:var(--accent-cyan);margin-left:6px;vertical-align:middle;\">v1.0.0</span></h1>\n"
" <div class=\"subtitle\">Universal Gamepad Mimic & Console Bridge</div>\n"
" </div>\n"
" </div>\n"
" <div class=\"badge\" id=\"btn-toggle-ap\" onclick=\"toggleAp()\" title=\"Click to toggle MimiCon-Setup Wi-Fi Hotspot on/off\">\n"
" <span class=\"pulse-dot\"></span>\n"
" <span id=\"cfg-status\">CONFIG AP ACTIVE</span>\n"
" </div>\n"
" </header>\n"
"\n"
" <!-- Exit Config Bar -->\n"
" <div class=\"banner-exit\">\n"
" <div>\n"
" <div style=\"font-weight:700;font-size:0.95rem;\">Web Server Active</div>\n"
" <div style=\"font-size:0.75rem;color:var(--text-dim);\" id=\"timeout-text\">Wi-Fi is on (no auto-timeout). Click to turn off for 0-latency gaming.</div>\n"
" </div>\n"
" <button class=\"btn-play\" id=\"btn-exit\" onclick=\"exitConfig()\">Turn Off Wi-Fi ⚡</button>\n"
" </div>\n"
"\n"
" <!-- Target Console Profile -->\n"
" <div class=\"card\">\n"
" <div class=\"card-header\">\n"
" <div class=\"card-title\">Target Console Mode</div>\n"
" <div style=\"font-size:0.75rem;color:var(--accent-cyan);\" id=\"active-mode-label\">Nintendo Switch</div>\n"
" </div>\n"
" <div class=\"modes-grid\">\n"
" <button class=\"mode-btn active\" id=\"mode-0\" onclick=\"setMode(0)\">\n"
" <div class=\"mode-name\">🔴 Nintendo Switch</div>\n"
" <div class=\"mode-desc\">HORI Pokken Pad emulation (VID 0x0F0D)</div>\n"
" </button>\n"
" <button class=\"mode-btn mode-pc\" id=\"mode-1\" onclick=\"setMode(1)\">\n"
" <div class=\"mode-name\">💻 PC DirectInput</div>\n"
" <div class=\"mode-desc\">Standard 18-button, 6-axis generic gamepad</div>\n"
" </button>\n"
" <button class=\"mode-btn mode-ps3\" id=\"mode-2\" onclick=\"setMode(2)\">\n"
" <div class=\"mode-name\">🎮 PlayStation 3</div>\n"
" <div class=\"mode-desc\">Sony DualShock 3 emulation (VID 0x054C)</div>\n"
" </button>\n"
" <button class=\"mode-btn mode-x360\" id=\"mode-3\" onclick=\"setMode(3)\">\n"
" <div class=\"mode-name\">🟢 Xbox 360</div>\n"
" <div class=\"mode-desc\">XInput with native XSM3 auth handshake</div>\n"
" </button>\n"
" <button class=\"mode-btn mode-ogx\" id=\"mode-4\" onclick=\"setMode(4)\">\n"
" <div class=\"mode-name\">🟠 Original Xbox</div>\n"
" <div class=\"mode-desc\">Native XID Controller S (VID 0x045E PID 0x0289)</div>\n"
" </button>\n"
" <button class=\"mode-btn mode-ps4\" id=\"mode-5\" onclick=\"setMode(5)\">\n"
" <div class=\"mode-name\">🔵 PlayStation 4</div>\n"
" <div class=\"mode-desc\">Sony DualShock 4 (VID 0x054C PID 0x05C4) + Lightbar Sync</div>\n"
" </button>\n"
" <button class=\"mode-btn mode-mouse\" id=\"mode-6\" onclick=\"setMode(6)\">\n"
" <div class=\"mode-name\">🖲️ Couch Mouse & Keys</div>\n"
" <div class=\"mode-desc\">Left stick mouse cursor, triggers click, media keys</div>\n"
" </button>\n"
" </div>\n"
" </div>\n"
"\n"
" <!-- Button Combo Configuration -->\n"
" <div class=\"card\">\n"
" <div class=\"card-header\">\n"
" <div class=\"card-title\">Button Combos (Hold 3s to Switch)</div>\n"
" <div style=\"font-size:0.75rem;\" id=\"combo-save-status\"></div>\n"
" </div>\n"
" <div style=\"font-size:0.75rem;color:var(--text-dim);margin-bottom:12px;\">\n"
" Hold <b>START + [Face Button]</b> for 3s on your controller to switch console profiles instantly:\n"
" </div>\n"
" <div style=\"display:grid;grid-template-columns:1fr 1fr;gap:10px;\">\n"
" <div style=\"background:rgba(255,255,255,0.03);border:1px solid var(--card-border);border-radius:10px;padding:10px;\">\n"
" <div style=\"font-size:0.8rem;font-weight:700;margin-bottom:6px;display:flex;align-items:center;gap:6px;\">\n"
" <span style=\"color:#22c55e;\">●</span> START + A <span style=\"font-size:0.7rem;color:var(--text-dim);\">(Cross ✕)</span>\n"
" </div>\n"
" <select id=\"combo-select-a\" onchange=\"saveCombos()\" style=\"width:100%;background:rgba(255,255,255,0.06);border:1px solid var(--card-border);color:var(--text-main);padding:6px 8px;border-radius:6px;font-size:0.8rem;outline:none;\">\n"
" <option value=\"0\">Nintendo Switch</option>\n"
" <option value=\"1\">PC DirectInput</option>\n"
" <option value=\"2\">PlayStation 3</option>\n"
" <option value=\"3\">Xbox 360</option>\n"
" <option value=\"4\">Original Xbox</option>\n"
" <option value=\"5\">PlayStation 4</option>\n"
" <option value=\"6\">Couch Mouse & Keys</option>\n"
" <option value=\"-1\">Disabled</option>\n"
" </select>\n"
" </div>\n"
" <div style=\"background:rgba(255,255,255,0.03);border:1px solid var(--card-border);border-radius:10px;padding:10px;\">\n"
" <div style=\"font-size:0.8rem;font-weight:700;margin-bottom:6px;display:flex;align-items:center;gap:6px;\">\n"
" <span style=\"color:#ef4444;\">●</span> START + B <span style=\"font-size:0.7rem;color:var(--text-dim);\">(Circle ○)</span>\n"
" </div>\n"
" <select id=\"combo-select-b\" onchange=\"saveCombos()\" style=\"width:100%;background:rgba(255,255,255,0.06);border:1px solid var(--card-border);color:var(--text-main);padding:6px 8px;border-radius:6px;font-size:0.8rem;outline:none;\">\n"
" <option value=\"0\">Nintendo Switch</option>\n"
" <option value=\"1\">PC DirectInput</option>\n"
" <option value=\"2\">PlayStation 3</option>\n"
" <option value=\"3\">Xbox 360</option>\n"
" <option value=\"4\">Original Xbox</option>\n"
" <option value=\"5\">PlayStation 4</option>\n"
" <option value=\"6\">Couch Mouse & Keys</option>\n"
" <option value=\"-1\">Disabled</option>\n"
" </select>\n"
" </div>\n"
" <div style=\"background:rgba(255,255,255,0.03);border:1px solid var(--card-border);border-radius:10px;padding:10px;\">\n"
" <div style=\"font-size:0.8rem;font-weight:700;margin-bottom:6px;display:flex;align-items:center;gap:6px;\">\n"
" <span style=\"color:#3b82f6;\">●</span> START + X <span style=\"font-size:0.7rem;color:var(--text-dim);\">(Square □)</span>\n"
" </div>\n"
" <select id=\"combo-select-x\" onchange=\"saveCombos()\" style=\"width:100%;background:rgba(255,255,255,0.06);border:1px solid var(--card-border);color:var(--text-main);padding:6px 8px;border-radius:6px;font-size:0.8rem;outline:none;\">\n"
" <option value=\"0\">Nintendo Switch</option>\n"
" <option value=\"1\">PC DirectInput</option>\n"
" <option value=\"2\">PlayStation 3</option>\n"
" <option value=\"3\">Xbox 360</option>\n"
" <option value=\"4\">Original Xbox</option>\n"
" <option value=\"5\">PlayStation 4</option>\n"
" <option value=\"6\">Couch Mouse & Keys</option>\n"
" <option value=\"-1\">Disabled</option>\n"
" </select>\n"
" </div>\n"
" <div style=\"background:rgba(255,255,255,0.03);border:1px solid var(--card-border);border-radius:10px;padding:10px;\">\n"
" <div style=\"font-size:0.8rem;font-weight:700;margin-bottom:6px;display:flex;align-items:center;gap:6px;\">\n"
" <span style=\"color:#eab308;\">●</span> START + Y <span style=\"font-size:0.7rem;color:var(--text-dim);\">(Triangle △)</span>\n"
" </div>\n"
" <select id=\"combo-select-y\" onchange=\"saveCombos()\" style=\"width:100%;background:rgba(255,255,255,0.06);border:1px solid var(--card-border);color:var(--text-main);padding:6px 8px;border-radius:6px;font-size:0.8rem;outline:none;\">\n"
" <option value=\"0\">Nintendo Switch</option>\n"
" <option value=\"1\">PC DirectInput</option>\n"
" <option value=\"2\">PlayStation 3</option>\n"
" <option value=\"3\">Xbox 360</option>\n"
" <option value=\"4\">Original Xbox</option>\n"
" <option value=\"5\">PlayStation 4</option>\n"
" <option value=\"6\">Couch Mouse & Keys</option>\n"
" <option value=\"-1\">Disabled</option>\n"
" </select>\n"
" </div>\n"
" </div>\n"
" </div>\n"
"\n"
" <!-- Live Input Visualizer -->\n"
" <div class=\"card\">\n"
" <div class=\"card-header\">\n"
" <div class=\"card-title\">Live Controller Visualizer</div>\n"
" <div style=\"font-size:0.75rem;color:var(--accent-green);\" id=\"ble-status-label\">Scanning for Gamepad...</div>\n"
" </div>\n"
" <div class=\"visualizer-wrap\">\n"
" <svg class=\"gamepad-svg\" viewBox=\"0 0 420 220\">\n"
" <!-- Controller Body Silhouette -->\n"
" <path d=\"M80,50 Q130,30 210,30 Q290,30 340,50 Q390,75 385,150 Q380,200 330,195 Q290,190 260,150 Q230,140 210,140 Q190,140 160,150 Q130,190 90,195 Q40,200 35,150 Q30,75 80,50 Z\" fill=\"#161e2e\" stroke=\"rgba(255,255,255,0.1)\" stroke-width=\"2\"/>\n"
" \n"
" <!-- D-Pad -->\n"
" <g id=\"dpad\" fill=\"#222a3d\">\n"
" <rect id=\"btn-dup\" x=\"112\" y=\"82\" width=\"16\" height=\"18\" rx=\"2\"/>\n"
" <rect id=\"btn-ddown\" x=\"112\" y=\"116\" width=\"16\" height=\"18\" rx=\"2\"/>\n"
" <rect id=\"btn-dleft\" x=\"94\" y=\"100\" width=\"18\" height=\"16\" rx=\"2\"/>\n"
" <rect id=\"btn-dright\" x=\"128\" y=\"100\" width=\"18\" height=\"16\" rx=\"2\"/>\n"
" <rect x=\"112\" y=\"100\" width=\"16\" height=\"16\" fill=\"#1c2434\"/>\n"
" </g>\n"
"\n"
" <!-- Left Stick (Xbox style: upper left) -->\n"
" <circle cx=\"120\" cy=\"65\" r=\"22\" fill=\"#0f1420\" stroke=\"rgba(255,255,255,0.15)\" stroke-width=\"2\"/>\n"
" <circle id=\"stick-left\" cx=\"120\" cy=\"65\" r=\"14\" fill=\"#2a354c\" stroke=\"#3b82f6\" stroke-width=\"1.5\"/>\n"
"\n"
" <!-- Right Stick (Xbox style: lower right) -->\n"
" <circle cx=\"260\" cy=\"115\" r=\"22\" fill=\"#0f1420\" stroke=\"rgba(255,255,255,0.15)\" stroke-width=\"2\"/>\n"
" <circle id=\"stick-right\" cx=\"260\" cy=\"115\" r=\"14\" fill=\"#2a354c\" stroke=\"#3b82f6\" stroke-width=\"1.5\"/>\n"
"\n"
" <!-- Face Buttons (A, B, X, Y) -->\n"
" <circle id=\"btn-y\" cx=\"300\" cy=\"60\" r=\"10\" fill=\"#222a3d\" stroke=\"#eab308\" stroke-width=\"1\"/>\n"
" <text x=\"300\" y=\"64\" font-size=\"10\" font-weight=\"bold\" fill=\"#eab308\" text-anchor=\"middle\">Y</text>\n"
"\n"
" <circle id=\"btn-x\" cx=\"280\" cy=\"78\" r=\"10\" fill=\"#222a3d\" stroke=\"#3b82f6\" stroke-width=\"1\"/>\n"
" <text x=\"280\" y=\"82\" font-size=\"10\" font-weight=\"bold\" fill=\"#3b82f6\" text-anchor=\"middle\">X</text>\n"
"\n"
" <circle id=\"btn-b\" cx=\"320\" cy=\"78\" r=\"10\" fill=\"#222a3d\" stroke=\"#ef4444\" stroke-width=\"1\"/>\n"
" <text x=\"320\" y=\"82\" font-size=\"10\" font-weight=\"bold\" fill=\"#ef4444\" text-anchor=\"middle\">B</text>\n"
"\n"
" <circle id=\"btn-a\" cx=\"300\" cy=\"96\" r=\"10\" fill=\"#222a3d\" stroke=\"#22c55e\" stroke-width=\"1\"/>\n"
" <text x=\"300\" y=\"100\" font-size=\"10\" font-weight=\"bold\" fill=\"#22c55e\" text-anchor=\"middle\">A</text>\n"
"\n"
" <!-- Bumpers -->\n"
" <rect id=\"btn-lb\" x=\"80\" y=\"32\" width=\"55\" height=\"12\" rx=\"4\" fill=\"#222a3d\" stroke=\"rgba(255,255,255,0.15)\"/>\n"
" <text x=\"107\" y=\"41\" font-size=\"8\" font-weight=\"bold\" fill=\"#9ca3af\" text-anchor=\"middle\">LB</text>\n"
" <rect id=\"btn-rb\" x=\"285\" y=\"32\" width=\"55\" height=\"12\" rx=\"4\" fill=\"#222a3d\" stroke=\"rgba(255,255,255,0.15)\"/>\n"
" <text x=\"312\" y=\"41\" font-size=\"8\" font-weight=\"bold\" fill=\"#9ca3af\" text-anchor=\"middle\">RB</text>\n"
"\n"
" <!-- Select / Start / Home -->\n"
" <rect id=\"btn-select\" x=\"175\" y=\"75\" width=\"14\" height=\"8\" rx=\"2\" fill=\"#222a3d\"/>\n"
" <circle id=\"btn-home\" cx=\"210\" cy=\"65\" r=\"11\" fill=\"#1e293b\" stroke=\"#a855f7\" stroke-width=\"1\"/>\n"
" <rect id=\"btn-start\" x=\"231\" y=\"75\" width=\"14\" height=\"8\" rx=\"2\" fill=\"#222a3d\"/>\n"
" </svg>\n"
"\n"
" <div class=\"trigger-bars\">\n"
" <div class=\"bar-box\">\n"
" <div class=\"bar-label\"><span>Left Trigger (LT)</span><span id=\"lt-val\">0%</span></div>\n"
" <div class=\"bar-track\"><div class=\"bar-fill\" id=\"lt-bar\"></div></div>\n"
" </div>\n"
" <div class=\"bar-box\">\n"
" <div class=\"bar-label\"><span>Right Trigger (RT)</span><span id=\"rt-val\">0%</span></div>\n"
" <div class=\"bar-track\"><div class=\"bar-fill\" id=\"rt-bar\"></div></div>\n"
" </div>\n"
" </div>\n"
"\n"
" <div class=\"sticks-readout\">\n"
" <div>Left Stick: <span id=\"ls-coords\">X: 0, Y: 0</span></div>\n"
" <div>Right Stick: <span id=\"rs-coords\">X: 0, Y: 0</span></div>\n"
" </div>\n"
" </div>\n"
" </div>\n"
"\n"
" <!-- Stick Deadzones & Remapping -->\n"
" <div class=\"card\">\n"
" <div class=\"card-header\">\n"
" <div class=\"card-title\">Stick Deadzones & Remapping</div>\n"
" <div style=\"font-size:0.75rem;\" id=\"calib-status\"></div>\n"
" </div>\n"
" <div style=\"display:flex;flex-direction:column;gap:14px;\">\n"
" <div>\n"
" <div style=\"display:flex;justify-content:space-between;font-size:0.8rem;font-weight:600;margin-bottom:6px;\">\n"
" <span>🕹️ Left Stick Radial Deadzone</span>\n"
" <span id=\"ldz-val\" style=\"color:var(--accent-cyan);\">5%</span>\n"
" </div>\n"
" <input type=\"range\" id=\"ldz-slider\" min=\"0\" max=\"40\" value=\"5\" oninput=\"onCalibChange()\" style=\"width:100%;\">\n"
" </div>\n"
" <div>\n"
" <div style=\"display:flex;justify-content:space-between;font-size:0.8rem;font-weight:600;margin-bottom:6px;\">\n"
" <span>🕹️ Right Stick Radial Deadzone</span>\n"
" <span id=\"rdz-val\" style=\"color:var(--accent-cyan);\">5%</span>\n"
" </div>\n"
" <input type=\"range\" id=\"rdz-slider\" min=\"0\" max=\"40\" value=\"5\" oninput=\"onCalibChange()\" style=\"width:100%;\">\n"
" </div>\n"
" <div>\n"
" <div style=\"display:flex;justify-content:space-between;font-size:0.8rem;font-weight:600;margin-bottom:6px;\">\n"
" <span>🎯 Analog Triggers Minimum Cutoff</span>\n"
" <span id=\"tdz-val\" style=\"color:var(--accent-cyan);\">0</span>\n"
" </div>\n"
" <input type=\"range\" id=\"tdz-slider\" min=\"0\" max=\"50\" value=\"0\" oninput=\"onCalibChange()\" style=\"width:100%;\">\n"
" </div>\n"
" <div style=\"display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-top:4px;\">\n"
" <label style=\"display:flex;align-items:center;gap:8px;font-size:0.78rem;cursor:pointer;background:rgba(255,255,255,0.03);padding:8px 10px;border-radius:8px;border:1px solid var(--card-border);\">\n"
" <input type=\"checkbox\" id=\"chk-swap-ab\" onchange=\"onCalibChange()\">\n"
" <span>Swap A & B (Nintendo)</span>\n"
" </label>\n"
" <label style=\"display:flex;align-items:center;gap:8px;font-size:0.78rem;cursor:pointer;background:rgba(255,255,255,0.03);padding:8px 10px;border-radius:8px;border:1px solid var(--card-border);\">\n"
" <input type=\"checkbox\" id=\"chk-swap-xy\" onchange=\"onCalibChange()\">\n"
" <span>Swap X & Y (Nintendo)</span>\n"
" </label>\n"
" <label style=\"display:flex;align-items:center;gap:8px;font-size:0.78rem;cursor:pointer;background:rgba(255,255,255,0.03);padding:8px 10px;border-radius:8px;border:1px solid var(--card-border);\">\n"
" <input type=\"checkbox\" id=\"chk-swap-bt\" onchange=\"onCalibChange()\">\n"
" <span>Swap Bumpers & Triggers</span>\n"
" </label>\n"
" <label style=\"display:flex;align-items:center;gap:8px;font-size:0.78rem;cursor:pointer;background:rgba(255,255,255,0.03);padding:8px 10px;border-radius:8px;border:1px solid var(--card-border);\">\n"
" <input type=\"checkbox\" id=\"chk-invert-ly\" onchange=\"onCalibChange()\">\n"
" <span>Invert Left Stick Y</span>\n"
" </label>\n"
" <label style=\"display:flex;align-items:center;gap:8px;font-size:0.78rem;cursor:pointer;background:rgba(255,255,255,0.03);padding:8px 10px;border-radius:8px;border:1px solid var(--card-border);\">\n"
" <input type=\"checkbox\" id=\"chk-invert-ry\" onchange=\"onCalibChange()\">\n"
" <span>Invert Right Stick Y</span>\n"
" </label>\n"
" </div>\n"
" <div style=\"display:flex;justify-content:flex-end;gap:8px;margin-top:4px;\">\n"
" <button class=\"btn-secondary\" onclick=\"resetCalib()\" style=\"font-size:0.75rem;\">Reset Defaults</button>\n"
" </div>\n"
" </div>\n"
" </div>\n"
"\n"
" <!-- Virtual Touch Gamepad (Phone Remote) -->\n"
" <div class=\"card\">\n"
" <div class=\"card-header\">\n"
" <div class=\"card-title\">📱 Phone / Web Virtual Controller</div>\n"
" <div style=\"display:flex;gap:8px;\">\n"
" <button class=\"btn-secondary\" onclick=\"toggleFullscreenPad()\" id=\"btn-fs-vpad\" style=\"font-size:0.75rem;background:linear-gradient(135deg,var(--accent-purple),var(--accent-cyan));color:#041426;font-weight:700;border:none;\">⛶ Fullscreen Remote</button>\n"
" <button class=\"btn-secondary\" onclick=\"toggleVirtualPad()\" id=\"btn-toggle-vpad\" style=\"font-size:0.75rem;\">Show Touch Gamepad 🎮</button>\n"
" </div>\n"
" </div>\n"
" <div style=\"font-size:0.75rem;color:var(--text-dim);margin-bottom:10px;\">\n"
" Control games directly from your smartphone touchscreen over Wi-Fi with dual analog thumbsticks:\n"
" </div>\n"
" <div id=\"virtual-pad\" style=\"display:none;background:rgba(0,0,0,0.35);border:1px solid var(--card-border);border-radius:14px;padding:16px;\">\n"
" <div class=\"vpad-fs-header\">\n"
" <div style=\"display:flex;gap:8px;\">\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(6,1)\" onpointerup=\"vBtn(6,0)\" onpointercancel=\"vBtn(6,0)\" style=\"padding:10px 16px;font-size:0.85rem;\">L2 (ZL)</button>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(4,1)\" onpointerup=\"vBtn(4,0)\" onpointercancel=\"vBtn(4,0)\" style=\"padding:10px 16px;font-size:0.85rem;\">L1 (L)</button>\n"
" </div>\n"
" <div style=\"display:flex;gap:8px;align-items:center;\">\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(8,1)\" onpointerup=\"vBtn(8,0)\" onpointercancel=\"vBtn(8,0)\" style=\"font-size:0.72rem;padding:7px 12px;\">SELECT</button>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(10,1)\" onpointerup=\"vBtn(10,0)\" onpointercancel=\"vBtn(10,0)\" style=\"font-size:0.72rem;padding:7px 12px;color:var(--accent-cyan);\">HOME</button>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(9,1)\" onpointerup=\"vBtn(9,0)\" onpointercancel=\"vBtn(9,0)\" style=\"font-size:0.72rem;padding:7px 12px;\">START</button>\n"
" <button class=\"vpad-btn vpad-fs-only\" onclick=\"toggleFullscreenPad()\" id=\"btn-fs-exit\" style=\"font-size:0.72rem;padding:7px 12px;background:rgba(255,51,102,0.25);border-color:var(--accent-red);color:#ff99bb;\">✕ Exit</button>\n"
" </div>\n"
" <div style=\"display:flex;gap:8px;\">\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(5,1)\" onpointerup=\"vBtn(5,0)\" onpointercancel=\"vBtn(5,0)\" style=\"padding:10px 16px;font-size:0.85rem;\">R1 (R)</button>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(7,1)\" onpointerup=\"vBtn(7,0)\" onpointercancel=\"vBtn(7,0)\" style=\"padding:10px 16px;font-size:0.85rem;\">R2 (ZR)</button>\n"
" </div>\n"
" </div>\n"
" <div style=\"display:flex;justify-content:space-between;align-items:center;width:100%;margin-top:10px;gap:12px;flex-wrap:wrap;\">\n"
" <div style=\"display:flex;gap:14px;align-items:center;\">\n"
" <div style=\"display:grid;grid-template-columns:repeat(3,44px);grid-template-rows:repeat(3,44px);gap:4px;\">\n"
" <div></div>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(13,1)\" onpointerup=\"vBtn(13,0)\" onpointercancel=\"vBtn(13,0)\" style=\"font-size:1.1rem;color:var(--accent-cyan);\">▲</button>\n"
" <div></div>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(15,1)\" onpointerup=\"vBtn(15,0)\" onpointercancel=\"vBtn(15,0)\" style=\"font-size:1.1rem;color:var(--accent-cyan);\">◀</button>\n"
" <div style=\"background:rgba(255,255,255,0.02);border-radius:6px;\"></div>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(16,1)\" onpointerup=\"vBtn(16,0)\" onpointercancel=\"vBtn(16,0)\" style=\"font-size:1.1rem;color:var(--accent-cyan);\">▶</button>\n"
" <div></div>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(14,1)\" onpointerup=\"vBtn(14,0)\" onpointercancel=\"vBtn(14,0)\" style=\"font-size:1.1rem;color:var(--accent-cyan);\">▼</button>\n"
" <div></div>\n"
" </div>\n"
" <div style=\"display:flex;flex-direction:column;align-items:center;gap:4px;\">\n"
" <div id=\"vpad-stick-l\" class=\"vpad-stick-base\">\n"
" <div id=\"vpad-nub-l\" class=\"vpad-stick-nub\"></div>\n"
" </div>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(11,1)\" onpointerup=\"vBtn(11,0)\" onpointercancel=\"vBtn(11,0)\" style=\"font-size:0.65rem;padding:3px 8px;\">L3</button>\n"
" </div>\n"
" </div>\n"
" <div style=\"display:flex;gap:14px;align-items:center;\">\n"
" <div style=\"display:flex;flex-direction:column;align-items:center;gap:4px;\">\n"
" <div id=\"vpad-stick-r\" class=\"vpad-stick-base\">\n"
" <div id=\"vpad-nub-r\" class=\"vpad-stick-nub\"></div>\n"
" </div>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(12,1)\" onpointerup=\"vBtn(12,0)\" onpointercancel=\"vBtn(12,0)\" style=\"font-size:0.65rem;padding:3px 8px;\">R3</button>\n"
" </div>\n"
" <div style=\"display:grid;grid-template-columns:repeat(3,44px);grid-template-rows:repeat(3,44px);gap:4px;\">\n"
" <div></div>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(3,1)\" onpointerup=\"vBtn(3,0)\" onpointercancel=\"vBtn(3,0)\" style=\"font-size:1.1rem;color:#eab308;font-weight:700;\">Y</button>\n"
" <div></div>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(2,1)\" onpointerup=\"vBtn(2,0)\" onpointercancel=\"vBtn(2,0)\" style=\"font-size:1.1rem;color:#3b82f6;font-weight:700;\">X</button>\n"
" <div style=\"background:rgba(255,255,255,0.02);border-radius:6px;\"></div>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(1,1)\" onpointerup=\"vBtn(1,0)\" onpointercancel=\"vBtn(1,0)\" style=\"font-size:1.1rem;color:#ef4444;font-weight:700;\">B</button>\n"
" <div></div>\n"
" <button class=\"vpad-btn\" onpointerdown=\"vBtn(0,1)\" onpointerup=\"vBtn(0,0)\" onpointercancel=\"vBtn(0,0)\" style=\"font-size:1.1rem;color:#22c55e;font-weight:700;\">A</button>\n"
" <div></div>\n"
" </div>\n"
" </div>\n"
" </div>\n"
" </div>\n"
" </div>\n"
"\n"
" <!-- BLE Connection & Pairing Manager -->\n"
" <div class=\"card\">\n"
" <div class=\"card-header\">\n"
" <div class=\"card-title\">Bluetooth Controller</div>\n"
" <div id=\"ble-battery-badge\" style=\"font-size:0.8rem;font-weight:700;\"></div>\n"
" </div>\n"
" <div class=\"ble-info-row\">\n"
" <div style=\"flex:1;\">\n"
" <div style=\"display:flex;align-items:center;gap:8px;\">\n"
" <div style=\"font-weight:700;\" id=\"ble-dev-name\">Scanning...</div>\n"
" <span id=\"ble-battery-pill\" style=\"display:none;font-size:0.7rem;font-weight:700;padding:2px 8px;border-radius:12px;\">100%</span>\n"
" </div>\n"
" <div style=\"font-size:0.75rem;color:var(--text-dim);\" id=\"ble-dev-status\">Auto-pairing with nearby gamepads</div>\n"
" <div id=\"ble-battery-bar-container\" style=\"display:none;margin-top:6px;width:140px;height:5px;background:rgba(0,0,0,0.4);border-radius:3px;overflow:hidden;\">\n"
" <div id=\"ble-battery-fill\" style=\"width:0%;height:100%;transition:width 0.3s ease;\"></div>\n"
" </div>\n"
" </div>\n"
" <div class=\"btn-group\">\n"
" <button class=\"btn-secondary\" onclick=\"testRumble()\" title=\"Trigger test vibration on connected controller\">Test Rumble 📳</button>\n"
" <button class=\"btn-secondary\" onclick=\"bleDisconnect()\">Disconnect</button>\n"
" <button class=\"btn-secondary btn-danger\" onclick=\"bleClearBonds()\">Forget All</button>\n"
" </div>\n"
" </div>\n"
" <div style=\"border-top:1px solid var(--card-border);padding-top:10px;margin-top:12px;\">\n"
" <div style=\"display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;\">\n"
" <div style=\"font-size:0.75rem;font-weight:700;color:var(--text-dim);\">Stored Paired Controllers (<span id=\"paired-count\">0</span>)</div>\n"
" <div style=\"font-size:0.7rem;color:var(--text-dim);\">NVS Multi-Bond Memory</div>\n"
" </div>\n"
" <div id=\"paired-list\" style=\"display:flex;flex-direction:column;gap:6px;\">\n"
" <div style=\"font-size:0.75rem;color:var(--text-dim);font-style:italic;\">Loading paired controllers...</div>\n"
" </div>\n"
" </div>\n"
" </div>\n"
"\n"
" <!-- Wi-Fi Station & mDNS Network Settings -->\n"
" <div class=\"card\">\n"
" <div class=\"card-header\">\n"
" <div class=\"card-title\">Wi-Fi Station & mDNS</div>\n"
" <div style=\"font-size:0.75rem;\" id=\"wifi-sta-status\"><span style=\"color:var(--text-dim);\">Checking status...</span></div>\n"
" </div>\n"
" <div id=\"mdns-banner\" style=\"background:linear-gradient(135deg, rgba(0, 242, 254, 0.1), rgba(59, 130, 246, 0.08));border:1px solid rgba(0, 242, 254, 0.3);border-radius:12px;padding:12px 14px;margin-bottom:12px;display:flex;align-items:center;justify-content:space-between;\">\n"
" <div>\n"
" <div style=\"font-size:0.85rem;font-weight:700;color:var(--accent-cyan);display:flex;align-items:center;gap:6px;\">\n"
" <span>🌐</span> mDNS Hostname: <a id=\"mdns-link\" href=\"http://mimicon.local/\" target=\"_blank\" style=\"color:#fff;text-decoration:underline;\">http://mimicon.local/</a>\n"
" </div>\n"
" <div style=\"font-size:0.72rem;color:var(--text-dim);margin-top:2px;\">Connect to home Wi-Fi to access this portal from any phone, PC, or tablet on your network!</div>\n"
" </div>\n"
" </div>\n"
" <div style=\"display:flex;flex-direction:column;gap:10px;\">\n"
" <div style=\"display:flex;gap:8px;\">\n"
" <select id=\"wifi-scan-select\" onchange=\"onScanSelect(this.value)\" style=\"flex:1;background:rgba(255,255,255,0.05);border:1px solid var(--card-border);color:var(--text-main);padding:8px 12px;border-radius:8px;font-size:0.85rem;outline:none;\">\n"
" <option value=\"\">-- Discovered Networks --</option>\n"
" </select>\n"
" <button class=\"btn-secondary\" id=\"btn-scan\" onclick=\"scanWifi()\">🔄 Scan</button>\n"
" </div>\n"
" <div style=\"display:flex;gap:8px;\">\n"
" <input type=\"text\" id=\"wifi-ssid-input\" placeholder=\"Network SSID\" style=\"flex:1;background:rgba(255,255,255,0.05);border:1px solid var(--card-border);color:var(--text-main);padding:8px 12px;border-radius:8px;font-size:0.85rem;outline:none;\">\n"
" <input type=\"password\" id=\"wifi-pass-input\" placeholder=\"Password (if secured)\" style=\"flex:1;background:rgba(255,255,255,0.05);border:1px solid var(--card-border);color:var(--text-main);padding:8px 12px;border-radius:8px;font-size:0.85rem;outline:none;\">\n"
" </div>\n"
" <div style=\"display:flex;justify-content:space-between;align-items:center;margin-top:2px;\">\n"
" <div id=\"wifi-msg\" style=\"font-size:0.75rem;color:var(--text-dim);\"></div>\n"
" <div class=\"btn-group\">\n"
" <button class=\"btn-secondary btn-danger\" id=\"btn-forget\" onclick=\"forgetWifi()\" style=\"display:none;\">Forget</button>\n"
" <button class=\"btn-secondary\" id=\"btn-connect\" onclick=\"connectWifi()\" style=\"background:linear-gradient(135deg,var(--accent-blue),var(--accent-cyan));color:#041426;font-weight:700;border:none;\">Connect</button>\n"
" </div>\n"
" </div>\n"
" </div>\n"
" </div>\n"
"\n"
" <!-- Hardware LED Settings -->\n"
" <div class=\"card\">\n"
" <div class=\"card-header\">\n"
" <div class=\"card-title\">Onboard WS2812 RGB LED (GPIO21)</div>\n"
" <div style=\"font-size:0.75rem;\" id=\"led-val-label\">100%</div>\n"
" </div>\n"
" <div class=\"slider-row\">\n"
" <span style=\"font-size:0.8rem;\">🌑 Off</span>\n"
" <input type=\"range\" id=\"led-slider\" min=\"0\" max=\"100\" value=\"100\" oninput=\"onLedChange(this.value)\">\n"
" <span style=\"font-size:0.8rem;\">💡 100%</span>\n"
" </div>\n"
" </div>\n"
"\n"
" <!-- Firmware & OTA Updates -->\n"
" <div class=\"card\">\n"
" <div class=\"card-header\">\n"
" <div class=\"card-title\">Firmware & Over-The-Air (OTA) Update</div>\n"
" <div style=\"font-size:0.75rem;color:var(--accent-purple);font-weight:600;\" id=\"firmware-badge\">Dual OTA Scheme</div>\n"
" </div>\n"
" <div style=\"display:grid;grid-template-columns:1fr 1fr;gap:10px;background:rgba(255,255,255,0.03);border:1px solid var(--card-border);padding:12px 14px;border-radius:12px;margin-bottom:12px;font-size:0.75rem;\">\n"
" <div>\n"
" <div style=\"color:var(--text-dim);\">Running Firmware:</div>\n"
" <div style=\"font-weight:700;color:var(--accent-cyan);font-size:0.85rem;\" id=\"firmware-ver\">Loading...</div>\n"
" </div>\n"
" <div>\n"
" <div style=\"color:var(--text-dim);\">Build Timestamp:</div>\n"
" <div style=\"font-weight:600;color:var(--text-main);\" id=\"firmware-built\">...</div>\n"
" </div>\n"
" <div>\n"
" <div style=\"color:var(--text-dim);\">Active Slot:</div>\n"
" <div style=\"font-weight:600;color:var(--accent-green);\" id=\"firmware-part\">...</div>\n"
" </div>\n"
" <div>\n"
" <div style=\"color:var(--text-dim);\">Next Boot Slot:</div>\n"
" <div style=\"font-weight:600;color:#eab308;\" id=\"firmware-next\">...</div>\n"
" </div>\n"
" </div>\n"
" <div style=\"display:flex;flex-direction:column;gap:10px;\">\n"
" <div style=\"display:flex;align-items:center;gap:10px;\">\n"
" <label id=\"ota-file-btn\" style=\"background:rgba(255,255,255,0.08);border:1px solid var(--card-border);color:var(--text-main);padding:8px 14px;border-radius:8px;font-size:0.8rem;font-weight:600;cursor:pointer;white-space:nowrap;display:inline-flex;align-items:center;gap:6px;transition:0.2s;\">\n"
" <span>📁</span> Choose .bin File\n"
" <input type=\"file\" id=\"ota-file\" accept=\".bin\" onchange=\"onOtaFileSelect()\" style=\"display:none;\">\n"
" </label>\n"
" <div id=\"ota-file-label\" style=\"font-size:0.75rem;color:var(--text-dim);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;\">No .bin file selected</div>\n"
" <button id=\"btn-ota-upload\" class=\"btn-secondary\" onclick=\"uploadFirmware()\" disabled style=\"opacity:0.5;cursor:not-allowed;background:linear-gradient(135deg,var(--accent-purple),var(--accent-cyan));color:#041426;font-weight:700;border:none;white-space:nowrap;padding:8px 16px;\">⚡ Flash Firmware</button>\n"
" </div>\n"
" <div style=\"background:rgba(0,0,0,0.3);border:1px solid var(--card-border);border-radius:8px;height:14px;overflow:hidden;position:relative;\">\n"
" <div id=\"ota-bar\" style=\"width:0%;height:100%;background:linear-gradient(90deg,var(--accent-purple),var(--accent-cyan));transition:width 0.2s ease;\"></div>\n"
" </div>\n"
" <div style=\"display:flex;justify-content:space-between;align-items:center;font-size:0.75rem;\">\n"
" <div id=\"ota-msg\" style=\"color:var(--text-dim);\">Select a compiled .bin file (e.g. build/mimicon.bin) to flash wirelessly.</div>\n"
" <div id=\"ota-pct\" style=\"font-weight:700;color:var(--accent-cyan);\">0%</div>\n"
" </div>\n"
" </div>\n"
" </div>\n"
"</div>\n"
"\n"
"<script>\n"
"let currentMode = 0;\n"
"let remainingSeconds = 180;\n"
"\n"
"function updateModeUI(mode) {\n"
" currentMode = mode;\n"
" const names = ['Nintendo Switch (Cyan)', 'PC DirectInput (Blue)', 'PlayStation 3 (Red)', 'Xbox 360 (Green)', 'Original Xbox (Orange)', 'PlayStation 4 (Indigo)', 'Couch Mouse & Keys (Teal)'];\n"
" document.getElementById('active-mode-label').textContent = names[mode] || 'Unknown';\n"
" for (let i = 0; i < 7; i++) {\n"
" const el = document.getElementById('mode-' + i);\n"
" if (el) {\n"
" if (i === mode) el.classList.add('active');\n"
" else el.classList.remove('active');\n"
" }\n"
" }\n"
"}\n"
"\n"
"function setMode(mode) {\n"
" updateModeUI(mode);\n"
" fetch('/api/mode', {\n"
" method: 'POST',\n"
" headers: {'Content-Type': 'application/json'},\n"
" body: JSON.stringify({ mode: mode })\n"
" }).catch(e => console.log(e));\n"
"}\n"
"\n"
"function exitConfig() {\n"
" if (confirm('Start Gaming now? This will shut down Wi-Fi AP to give BLE 100% radio bandwidth with 0 latency.')) {\n"
" fetch('/api/exit', { method: 'POST' }).catch(() => {});\n"
" document.body.innerHTML = '<div style=\"display:flex;flex-direction:column;align-items:center;justify-content:center;height:90vh;color:#00f076;text-align:center;\"><h1>🎮 Gaming Mode Active!</h1><p style=\"color:#9ca3af;margin-top:10px;\">Wi-Fi is now powered down for minimum latency. Have fun playing!</p><p style=\"color:#9ca3af;font-size:0.8rem;margin-top:20px;\">To re-enter Config Mode later, hold the physical BOOT button on the ESP32 for 2 seconds.</p></div>';\n"
" }\n"
"}\n"
"\n"
"let isApToggling = false;\n"
"async function toggleAp() {\n"
" if (isApToggling) return;\n"
" const statusEl = document.getElementById('cfg-status');\n"
" const origText = statusEl.textContent;\n"
" const isCurrentlyActive = !document.getElementById('btn-toggle-ap').classList.contains('off');\n"
" if (isCurrentlyActive && !document.getElementById('wifi-sta-status').textContent.includes('Connected')) {\n"
" if (!confirm('Warning: You are connected directly through the MimiCon-Setup hotspot. Turning off the AP will disconnect you from this portal. Proceed?')) {\n"
" return;\n"
" }\n"
" }\n"
" isApToggling = true;\n"
" statusEl.textContent = 'SWITCHING...';\n"
" try {\n"
" const res = await fetch('/api/ap/toggle', { method: 'POST' });\n"
" if (res.ok) {\n"
" const data = await res.json();\n"
" updateApBadge(data.ap_active);\n"
" if (data.stopped) {\n"
" document.body.innerHTML = '<div style=\"display:flex;flex-direction:column;align-items:center;justify-content:center;height:90vh;color:#00f076;text-align:center;\"><h1>🎮 Gaming Mode Active!</h1><p style=\"color:#9ca3af;margin-top:10px;\">Wi-Fi is now powered down for minimum latency. Have fun playing!</p><p style=\"color:#9ca3af;font-size:0.8rem;margin-top:20px;\">To re-enter Config Mode later, hold the physical BOOT button on the ESP32 for 2 seconds.</p></div>';\n"
" }\n"
" } else {\n"
" statusEl.textContent = origText;\n"
" }\n"
" } catch(e) {\n"
" statusEl.textContent = origText;\n"
" } finally {\n"
" isApToggling = false;\n"
" }\n"
"}\n"
"\n"
"function updateApBadge(active) {\n"
" const badge = document.getElementById('btn-toggle-ap');\n"
" const statusEl = document.getElementById('cfg-status');\n"
" if (!badge || !statusEl) return;\n"
" if (active) {\n"
" badge.classList.remove('off');\n"
" statusEl.textContent = 'CONFIG AP ACTIVE';\n"
" badge.title = 'MimiCon-Setup Wi-Fi Hotspot is broadcasting. Click to turn off.';\n"
" } else {\n"
" badge.classList.add('off');\n"
" statusEl.textContent = 'CONFIG AP OFF';\n"
" badge.title = 'MimiCon-Setup Wi-Fi Hotspot is OFF. Click to turn on.';\n"
" }\n"
"}\n"
"\n"
"function testRumble() {\n"
" fetch('/api/ble/rumble', { method: 'POST' }).catch(e => console.log(e));\n"
"}\n"
"\n"
"function bleDisconnect() {\n"
" fetch('/api/ble/disconnect', { method: 'POST' }).catch(e => console.log(e));\n"
"}\n"
"\n"
"function bleClearBonds() {\n"
" if (confirm('Forget all bonded Bluetooth controllers and restart scanning?')) {\n"
" fetch('/api/ble/clear_bonds', { method: 'POST' }).then(() => refreshPeers()).catch(e => console.log(e));\n"
" }\n"
"}\n"
"\n"
"async function refreshPeers() {\n"
" try {\n"
" const res = await fetch('/api/ble/peers');\n"
" if (!res.ok) return;\n"
" const peers = await res.json();\n"
" const countEl = document.getElementById('paired-count');\n"
" if (countEl) countEl.textContent = peers.length;\n"
" const list = document.getElementById('paired-list');\n"
" if (!list) return;\n"
" if (peers.length === 0) {\n"
" list.innerHTML = '<div style=\"font-size:0.75rem;color:var(--text-dim);font-style:italic;padding:4px 0;\">No paired controllers stored in NVS</div>';\n"
" return;\n"
" }\n"
" let html = '';\n"
" peers.forEach(p => {\n"
" const typeIcons = ['🕹️', '🟢', '🎮'];\n"
" const icon = typeIcons[p.type] || '🕹️';\n"
" const statusBadge = p.connected \n"
" ? '<span style=\"color:#22c55e;font-size:0.7rem;font-weight:700;\">● Active Connected</span>' \n"
" : '<span style=\"color:var(--text-dim);font-size:0.7rem;\">● Stored / Paired</span>';\n"
" const batt = (p.connected && p.battery >= 0) ? `<span style=\"font-size:0.7rem;color:var(--accent-cyan);margin-left:6px;\">🔋 ${p.battery}%</span>` : '';\n"
" html += `<div style=\"display:flex;align-items:center;justify-content:space-between;background:rgba(255,255,255,0.03);border:1px solid var(--card-border);border-radius:8px;padding:6px 10px;\">` +\n"
" `<div><div style=\"font-size:0.8rem;font-weight:700;display:flex;align-items:center;gap:6px;\"><span>${icon}</span> <span>${p.name}</span>${batt}</div>` +\n"
" `<div style=\"font-size:0.7rem;color:var(--text-dim);margin-top:2px;display:flex;align-items:center;gap:8px;\"><code>${p.mac}</code><span>•</span>${statusBadge}</div></div>` +\n"
" `<button class=\"btn-secondary btn-danger\" onclick=\"unpairPeer('${p.mac}')\" style=\"font-size:0.7rem;padding:4px 8px;\">Forget</button></div>`;\n"
" });\n"
" list.innerHTML = html;\n"
" } catch (e) {}\n"
"}\n"
"\n"
"async function unpairPeer(mac) {\n"
" if (confirm(`Forget paired gamepad ${mac}?`)) {\n"
" await fetch('/api/ble/unpair', {\n"
" method: 'POST',\n"
" headers: {'Content-Type': 'application/json'},\n"
" body: JSON.stringify({ mac: mac })\n"
" });\n"
" refreshPeers();\n"
" }\n"
"}\n"
"\n"
"function onScanSelect(val) {\n"
" if (val) {\n"
" document.getElementById('wifi-ssid-input').value = val;\n"
" document.getElementById('wifi-pass-input').focus();\n"
" }\n"
"}\n"
"\n"
"async function scanWifi() {\n"
" const btn = document.getElementById('btn-scan');\n"
" const sel = document.getElementById('wifi-scan-select');\n"
" const msg = document.getElementById('wifi-msg');\n"
" btn.disabled = true;\n"
" btn.textContent = 'Scanning...';\n"
" msg.textContent = 'Scanning 2.4GHz channels...';\n"
" try {\n"
" const res = await fetch('/api/wifi/scan');\n"
" if (res.ok) {\n"
" const aps = await res.json();\n"
" sel.innerHTML = '<option value=\"\">-- Discovered Networks (' + aps.length + ' found) --</option>';\n"
" aps.forEach(ap => {\n"
" const opt = document.createElement('option');\n"
" opt.value = ap.ssid;\n"
" opt.textContent = ap.ssid + ' (' + ap.rssi + ' dBm' + (ap.auth === 0 ? ', Open' : '') + ')';\n"
" sel.appendChild(opt);\n"
" });\n"
" msg.textContent = 'Found ' + aps.length + ' network(s). Select one above.';\n"
" } else {\n"
" msg.textContent = 'Scan failed.';\n"
" }\n"
" } catch(e) {\n"
" msg.textContent = 'Scan request error.';\n"
" }\n"
" btn.disabled = false;\n"
" btn.textContent = '🔄 Scan';\n"
"}\n"
"\n"
"async function connectWifi() {\n"
" const ssid = document.getElementById('wifi-ssid-input').value.trim();\n"
" const pass = document.getElementById('wifi-pass-input').value;\n"
" const msg = document.getElementById('wifi-msg');\n"
" if (!ssid) {\n"
" msg.textContent = 'Please enter an SSID.';\n"
" return;\n"
" }\n"
" msg.textContent = 'Connecting to ' + ssid + '...';\n"
" try {\n"
" const res = await fetch('/api/wifi/connect', {\n"
" method: 'POST',\n"
" headers: {'Content-Type': 'application/json'},\n"
" body: JSON.stringify({ ssid: ssid, password: pass })\n"
" });\n"
" if (res.ok) {\n"
" msg.textContent = 'Connection initiated! Awaiting IP...';\n"
" } else {\n"
" msg.textContent = 'Failed to submit credentials.';\n"
" }\n"
" } catch(e) {\n"
" msg.textContent = 'Network error while connecting.';\n"
" }\n"
"}\n"
"\n"
"async function forgetWifi() {\n"
" if (confirm('Forget saved Wi-Fi network and disconnect Station?')) {\n"
" const msg = document.getElementById('wifi-msg');\n"
" try {\n"
" await fetch('/api/wifi/forget', { method: 'POST' });\n"
" document.getElementById('wifi-ssid-input').value = '';\n"
" document.getElementById('wifi-pass-input').value = '';\n"
" msg.textContent = 'Network credentials cleared.';\n"
" } catch(e) {}\n"
" }\n"
"}\n"
"\n"
"let combosLoaded = false;\n"
"let comboSaveTimer = null;\n"
"function saveCombos() {\n"
" const ca = parseInt(document.getElementById('combo-select-a').value);\n"
" const cb = parseInt(document.getElementById('combo-select-b').value);\n"
" const cx = parseInt(document.getElementById('combo-select-x').value);\n"
" const cy = parseInt(document.getElementById('combo-select-y').value);\n"
" const statusEl = document.getElementById('combo-save-status');\n"
" statusEl.textContent = 'Saving...';\n"
" statusEl.style.color = '#eab308';\n"
" fetch('/api/combos', {\n"
" method: 'POST',\n"
" headers: {'Content-Type': 'application/json'},\n"
" body: JSON.stringify({ combo_a: ca, combo_b: cb, combo_x: cx, combo_y: cy })\n"
" }).then(res => {\n"
" if (res.ok) {\n"
" statusEl.textContent = 'Saved ✓';\n"
" statusEl.style.color = 'var(--accent-green)';\n"
" clearTimeout(comboSaveTimer);\n"
" comboSaveTimer = setTimeout(() => { statusEl.textContent = ''; }, 2000);\n"
" }\n"
" }).catch(() => {\n"
" statusEl.textContent = 'Error';\n"
" statusEl.style.color = 'var(--accent-red)';\n"
" });\n"
"}\n"
"\n"
"let ledTimeout = null;\n"
"function onLedChange(val) {\n"
" document.getElementById('led-val-label').textContent = val + '%';\n"
" clearTimeout(ledTimeout);\n"
" ledTimeout = setTimeout(() => {\n"
" fetch('/api/led', {\n"
" method: 'POST',\n"
" headers: {'Content-Type': 'application/json'},\n"
" body: JSON.stringify({ brightness: parseInt(val) })\n"
" }).catch(e => console.log(e));\n"
" }, 100);\n"
"}\n"
"\n"
"let peerPollCounter = 0;\n"
"/* Polling Status */\n"
"async function pollStatus() {\n"
" if (peerPollCounter++ % 3 === 0) refreshPeers();\n"
" try {\n"
" const res = await fetch('/api/status');\n"
" if (res.ok) {\n"
" const data = await res.json();\n"
" updateModeUI(data.mode);\n"
" if (data.ap_active !== undefined) updateApBadge(data.ap_active);\n"
" if (data.combos && !combosLoaded) {\n"
" document.getElementById('combo-select-a').value = data.combos.a;\n"
" document.getElementById('combo-select-b').value = data.combos.b;\n"
" document.getElementById('combo-select-x').value = data.combos.x;\n"
" document.getElementById('combo-select-y').value = data.combos.y;\n"
" combosLoaded = true;\n"
" }\n"
" if (data.ble_connected) {\n"
" document.getElementById('ble-dev-name').textContent = data.ble_device || 'Connected Gamepad';\n"
" document.getElementById('ble-dev-status').textContent = 'Active BLE Connection';\n"
" document.getElementById('ble-status-label').textContent = 'Controller: ' + (data.ble_device || 'Connected');\n"
" document.getElementById('ble-status-label').style.color = 'var(--accent-green)';\n"
" if (data.battery !== undefined && data.battery >= 0) {\n"
" const b = data.battery;\n"
" let icon = '🔋';\n"
" let col = '#22c55e';\n"
" let warn = '';\n"
" if (b <= 15) {\n"
" icon = '🪫';\n"
" col = '#ef4444';\n"
" warn = ' (Low)';\n"
" } else if (b <= 30) {\n"
" icon = '🪫';\n"
" col = '#eab308';\n"
" }\n"
" const pill = document.getElementById('ble-battery-pill');\n"
" pill.style.display = 'inline-block';\n"
" pill.style.color = col;\n"
" pill.style.borderColor = col;\n"
" pill.style.background = col + '22';\n"
" pill.textContent = icon + ' ' + b + '%' + warn;\n"
" document.getElementById('ble-battery-bar-container').style.display = 'block';\n"
" const fill = document.getElementById('ble-battery-fill');\n"
" fill.style.width = b + '%';\n"
" fill.style.background = col;\n"
" document.getElementById('ble-battery-badge').innerHTML = '<span style=\"color:' + col + ';\">' + icon + ' ' + b + '%</span>';\n"
" } else {\n"
" document.getElementById('ble-battery-pill').style.display = 'none';\n"
" document.getElementById('ble-battery-bar-container').style.display = 'none';\n"
" document.getElementById('ble-battery-badge').innerHTML = '<span style=\"color:var(--text-dim);font-size:0.75rem;\">🔋 Battery N/A</span>';\n"
" }\n"
" } else {\n"
" document.getElementById('ble-dev-name').textContent = 'No Gamepad Connected';\n"
" document.getElementById('ble-dev-status').textContent = 'Scanning for BLE controller...';\n"
" document.getElementById('ble-status-label').textContent = 'Scanning for controller...';\n"
" document.getElementById('ble-status-label').style.color = '#eab308';\n"
" document.getElementById('ble-battery-pill').style.display = 'none';\n"
" document.getElementById('ble-battery-bar-container').style.display = 'none';\n"
" document.getElementById('ble-battery-badge').innerHTML = '';\n"
" }\n"
" if (data.led_brightness !== undefined) {\n"
" document.getElementById('led-slider').value = data.led_brightness;\n"
" document.getElementById('led-val-label').textContent = data.led_brightness + '%';\n"
" }\n"
" if (data.sta_connected) {\n"
" document.getElementById('wifi-sta-status').innerHTML = '<span style=\"color:var(--accent-green);font-weight:700;\">● Connected</span>: ' + data.sta_ssid + ' (' + data.sta_ip + ')';\n"
" document.getElementById('btn-forget').style.display = 'inline-block';\n"
" if (!document.getElementById('wifi-ssid-input').value) {\n"
" document.getElementById('wifi-ssid-input').value = data.sta_ssid;\n"
" }\n"
" } else if (data.sta_ssid) {\n"
" document.getElementById('wifi-sta-status').innerHTML = '<span style=\"color:#eab308;font-weight:700;\">◌ Connecting...</span> (' + data.sta_ssid + ')';\n"
" document.getElementById('btn-forget').style.display = 'inline-block';\n"
" } else {\n"
" document.getElementById('wifi-sta-status').innerHTML = '<span style=\"color:var(--text-dim);\">○ Disconnected</span> (AP fallback active)';\n"
" document.getElementById('btn-forget').style.display = 'none';\n"
" }\n"
" if (data.app_version) {\n"
" document.getElementById('firmware-ver').textContent = 'v' + data.app_version;\n"
" const hVer = document.getElementById('header-ver');\n"
" if (hVer) hVer.textContent = 'v' + data.app_version;\n"
" }\n"
" if (data.compile_time) {\n"
" document.getElementById('firmware-built').textContent = data.compile_time;\n"
" }\n"
" if (data.running_part) {\n"
" document.getElementById('firmware-part').textContent = data.running_part;\n"
" }\n"
" if (data.next_part) {\n"
" document.getElementById('firmware-next').textContent = data.next_part;\n"
" }\n"
" }\n"
" } catch(e) {}\n"
" setTimeout(pollStatus, 1500);\n"
"}\n"
"\n"
"/* Polling Live Controller State */\n"
"function setBtn(id, active, color) {\n"
" const el = document.getElementById(id);\n"
" if (!el) return;\n"
" if (active) {\n"
" el.setAttribute('fill', color || '#00f2fe');\n"
" el.style.filter = 'drop-shadow(0 0 6px ' + (color || '#00f2fe') + ')';\n"
" } else {\n"
" el.setAttribute('fill', '#222a3d');\n"
" el.style.filter = 'none';\n"
" }\n"
"}\n"
"\n"
"let wsState = null;\n"
"let wsActive = false;\n"
"\n"
"function renderState(s) {\n"
" setBtn('btn-a', s.a, '#22c55e');\n"
" setBtn('btn-b', s.b, '#ef4444');\n"
" setBtn('btn-x', s.x, '#3b82f6');\n"
" setBtn('btn-y', s.y, '#eab308');\n"
" setBtn('btn-dup', s.dup, '#00f2fe');\n"
" setBtn('btn-ddown', s.ddown, '#00f2fe');\n"
" setBtn('btn-dleft', s.dleft, '#00f2fe');\n"
" setBtn('btn-dright', s.dright, '#00f2fe');\n"
" setBtn('btn-lb', s.lb, '#00f2fe');\n"
" setBtn('btn-rb', s.rb, '#00f2fe');\n"
" setBtn('btn-select', s.select, '#a855f7');\n"
" setBtn('btn-start', s.start, '#a855f7');\n"
" setBtn('btn-home', s.home, '#a855f7');\n"
"\n"
" // Triggers (0-255)\n"
" const ltPct = Math.round(((s.lt || 0) / 255) * 100);\n"
" const rtPct = Math.round(((s.rt || 0) / 255) * 100);\n"
" document.getElementById('lt-bar').style.width = ltPct + '%';\n"
" document.getElementById('lt-val').textContent = ltPct + '%';\n"
" document.getElementById('rt-bar').style.width = rtPct + '%';\n"
" document.getElementById('rt-val').textContent = rtPct + '%';\n"
"\n"
" // Left Stick (Center cx=120, cy=65, radius=10 max deflection)\n"
" const ls = document.getElementById('stick-left');\n"
" const lxNorm = ((s.lx || 0) / 32768) * 10;\n"
" const lyNorm = ((s.ly || 0) / 32768) * 10;\n"
" ls.setAttribute('cx', 120 + lxNorm);\n"
" ls.setAttribute('cy', 65 - lyNorm);\n"
" if (s.l3) {\n"
" ls.setAttribute('fill', '#00f2fe');\n"
" ls.setAttribute('stroke', '#ffffff');\n"
" ls.setAttribute('stroke-width', '2.5');\n"
" ls.style.filter = 'drop-shadow(0 0 8px #00f2fe)';\n"
" } else {\n"
" ls.setAttribute('fill', '#2a354c');\n"
" ls.setAttribute('stroke', '#3b82f6');\n"
" ls.setAttribute('stroke-width', '1.5');\n"
" ls.style.filter = 'none';\n"
" }\n"
" document.getElementById('ls-coords').textContent = 'X: ' + (s.lx || 0) + ', Y: ' + (s.ly || 0) + (s.l3 ? ' [L3]' : '');\n"
"\n"
" // Right Stick (Center cx=260, cy=115)\n"
" const rs = document.getElementById('stick-right');\n"
" const rxNorm = ((s.rx || 0) / 32768) * 10;\n"
" const ryNorm = ((s.ry || 0) / 32768) * 10;\n"
" rs.setAttribute('cx', 260 + rxNorm);\n"
" rs.setAttribute('cy', 115 - ryNorm);\n"
" if (s.r3) {\n"
" rs.setAttribute('fill', '#00f2fe');\n"
" rs.setAttribute('stroke', '#ffffff');\n"
" rs.setAttribute('stroke-width', '2.5');\n"
" rs.style.filter = 'drop-shadow(0 0 8px #00f2fe)';\n"
" } else {\n"
" rs.setAttribute('fill', '#2a354c');\n"
" rs.setAttribute('stroke', '#3b82f6');\n"
" rs.setAttribute('stroke-width', '1.5');\n"
" rs.style.filter = 'none';\n"
" }\n"
" document.getElementById('rs-coords').textContent = 'X: ' + (s.rx || 0) + ', Y: ' + (s.ry || 0) + (s.r3 ? ' [R3]' : '');\n"
"}\n"
"\n"
"function requestWsState() {\n"
" if (document.fullscreenElement || document.webkitFullscreenElement) return;\n"
" if (wsState && wsState.readyState === WebSocket.OPEN) {\n"
" wsState.send('1');\n"
" }\n"
"}\n"
"\n"
"function initWsState() {\n"
" try {\n"
" const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';\n"
" wsState = new WebSocket(proto + '//' + location.host + '/ws/state');\n"
" wsState.onopen = () => {\n"
" wsActive = true;\n"
" };\n"
" wsState.onmessage = (e) => {\n"
" try {\n"
" const s = JSON.parse(e.data);\n"
" renderState(s);\n"
" } catch(err) {}\n"
" };\n"
" wsState.onerror = () => { wsActive = false; };\n"
" wsState.onclose = () => {\n"
" wsActive = false;\n"
" setTimeout(initWsState, 2000);\n"
" };\n"
" } catch(e) {\n"
" wsActive = false;\n"
" }\n"
"}\n"
"\n"
"async function pollState() {\n"
" if (wsActive) {\n"
" setTimeout(pollState, 1000);\n"
" return;\n"
" }\n"
" if (document.fullscreenElement || document.webkitFullscreenElement) {\n"
" setTimeout(pollState, 500);\n"
" return;\n"
" }\n"
" try {\n"
" const res = await fetch('/api/state');\n"
" if (res.ok) {\n"
" const s = await res.json();\n"
" renderState(s);\n"
" }\n"
" } catch(e) {}\n"
" setTimeout(pollState, 50);\n"
"}\n"
"\n"
"let calibTimer = null;\n"
"function loadCalib() {\n"
" fetch('/api/calibration')\n"
" .then(r => r.json())\n"
" .then(c => {\n"
" document.getElementById('ldz-slider').value = c.left_deadzone;\n"
" document.getElementById('ldz-val').textContent = c.left_deadzone + '%';\n"
" document.getElementById('rdz-slider').value = c.right_deadzone;\n"
" document.getElementById('rdz-val').textContent = c.right_deadzone + '%';\n"
" document.getElementById('tdz-slider').value = c.trigger_deadzone;\n"
" document.getElementById('tdz-val').textContent = c.trigger_deadzone;\n"
" document.getElementById('chk-swap-ab').checked = c.swap_ab;\n"
" document.getElementById('chk-swap-xy').checked = c.swap_xy;\n"
" document.getElementById('chk-swap-bt').checked = c.swap_bumpers_triggers;\n"
" document.getElementById('chk-invert-ly').checked = c.invert_ly;\n"
" document.getElementById('chk-invert-ry').checked = c.invert_ry;\n"
" }).catch(e => console.log(e));\n"
"}\n"
"\n"
"function onCalibChange() {\n"
" const ldz = parseInt(document.getElementById('ldz-slider').value);\n"
" const rdz = parseInt(document.getElementById('rdz-slider').value);\n"
" const tdz = parseInt(document.getElementById('tdz-slider').value);\n"
" document.getElementById('ldz-val').textContent = ldz + '%';\n"
" document.getElementById('rdz-val').textContent = rdz + '%';\n"
" document.getElementById('tdz-val').textContent = tdz;\n"
" clearTimeout(calibTimer);\n"
" calibTimer = setTimeout(() => { saveCalib(); }, 250);\n"
"}\n"
"\n"
"function saveCalib() {\n"
" const payload = {\n"
" left_deadzone: parseInt(document.getElementById('ldz-slider').value),\n"
" right_deadzone: parseInt(document.getElementById('rdz-slider').value),\n"
" trigger_deadzone: parseInt(document.getElementById('tdz-slider').value),\n"
" swap_ab: document.getElementById('chk-swap-ab').checked,\n"
" swap_xy: document.getElementById('chk-swap-xy').checked,\n"
" swap_bumpers_triggers: document.getElementById('chk-swap-bt').checked,\n"
" invert_ly: document.getElementById('chk-invert-ly').checked,\n"
" invert_ry: document.getElementById('chk-invert-ry').checked\n"
" };\n"
" const st = document.getElementById('calib-status');\n"
" st.innerHTML = '<span style=\"color:var(--text-dim);\">Saving...</span>';\n"
" fetch('/api/calibration', {\n"
" method: 'POST',\n"
" headers: { 'Content-Type': 'application/json' },\n"
" body: JSON.stringify(payload)\n"
" }).then(r => r.json())\n"
" .then(() => {\n"
" st.innerHTML = '<span style=\"color:var(--accent-green);font-weight:700;\">✓ Saved</span>';\n"
" setTimeout(() => { st.innerHTML = ''; }, 1500);\n"
" }).catch(() => {\n"
" st.innerHTML = '<span style=\"color:var(--accent-red);\">Error</span>';\n"
" });\n"
"}\n"
"\n"
"function resetCalib() {\n"
" fetch('/api/calibration/reset', { method: 'POST' })\n"
" .then(() => loadCalib())\n"
" .catch(e => console.log(e));\n"
"}\n"
"\n"
"function onOtaFileSelect() {\n"
" const fi = document.getElementById('ota-file');\n"
" const btn = document.getElementById('btn-ota-upload');\n"
" const lbl = document.getElementById('ota-file-label');\n"
" if (fi.files && fi.files.length > 0) {\n"
" const f = fi.files[0];\n"
" const kb = (f.size / 1024).toFixed(1);\n"
" lbl.textContent = f.name + ' (' + kb + ' KB)';\n"
" btn.disabled = false;\n"
" btn.style.opacity = '1';\n"
" btn.style.cursor = 'pointer';\n"
" } else {\n"
" lbl.textContent = 'No .bin file selected';\n"
" btn.disabled = true;\n"
" btn.style.opacity = '0.5';\n"
" btn.style.cursor = 'not-allowed';\n"
" }\n"
"}\n"
"\n"
"function uploadFirmware() {\n"
" const fi = document.getElementById('ota-file');\n"
" if (!fi.files || fi.files.length === 0) return;\n"
" const file = fi.files[0];\n"
" if (!confirm('Flash firmware ' + file.name + ' (' + (file.size / 1024).toFixed(1) + ' KB) wirelessly? The ESP32-S3 will reboot into the updated firmware.')) {\n"
" return;\n"
" }\n"
" const pBar = document.getElementById('ota-bar');\n"
" const pPct = document.getElementById('ota-pct');\n"
" const pMsg = document.getElementById('ota-msg');\n"
" const btn = document.getElementById('btn-ota-upload');\n"
" const fiBtn = document.getElementById('ota-file-btn');\n"
" btn.disabled = true;\n"
" btn.style.opacity = '0.5';\n"
" btn.style.cursor = 'not-allowed';\n"
" if (fiBtn) fiBtn.style.pointerEvents = 'none';\n"
" pBar.style.width = '0%';\n"
" pPct.textContent = '0%';\n"
" pMsg.innerHTML = '<span style=\"color:var(--accent-cyan);font-weight:700;\">Uploading firmware image...</span>';\n"
" const xhr = new XMLHttpRequest();\n"
" xhr.open('POST', '/api/ota/upload', true);\n"
" xhr.setRequestHeader('Content-Type', 'application/octet-stream');\n"
" xhr.upload.onprogress = function(e) {\n"
" if (e.lengthComputable) {\n"
" const pct = Math.round((e.loaded / e.total) * 100);\n"
" pBar.style.width = pct + '%';\n"
" pPct.textContent = pct + '%';\n"
" if (pct >= 100) {\n"
" pMsg.innerHTML = '<span style=\"color:#eab308;font-weight:700;\">Verifying image & committing to Flash ROM... Please wait!</span>';\n"
" }\n"
" }\n"
" };\n"
" xhr.onload = function() {\n"
" if (xhr.status === 200) {\n"
" pBar.style.width = '100%';\n"
" pPct.textContent = '100%';\n"
" pMsg.innerHTML = '<span style=\"color:var(--accent-green);font-weight:700;\">✓ Update Successful! Rebooting in <span id=\"ota-count\">5</span>s...</span>';\n"
" let count = 5;\n"
" const t = setInterval(() => {\n"
" count--;\n"
" const cntEl = document.getElementById('ota-count');\n"
" if (cntEl) cntEl.textContent = count;\n"
" if (count <= 0) {\n"
" clearInterval(t);\n"
" pMsg.innerHTML = '<span style=\"color:var(--accent-cyan);font-weight:700;\">Reconnecting to portal...</span>';\n"
" setTimeout(() => { location.reload(); }, 2000);\n"
" }\n"
" }, 1000);\n"
" } else {\n"
" btn.disabled = false;\n"
" btn.style.opacity = '1';\n"
" btn.style.cursor = 'pointer';\n"
" if (fiBtn) fiBtn.style.pointerEvents = 'auto';\n"
" let errText = xhr.responseText;\n"
" try {\n"
" const j = JSON.parse(xhr.responseText);\n"
" if (j.message) errText = j.message;\n"
" } catch(e) {}\n"
" pMsg.innerHTML = '<span style=\"color:var(--accent-red);font-weight:700;\">❌ Flash Failed: ' + errText + '</span>';\n"
" }\n"
" };\n"
" xhr.onerror = function() {\n"
" btn.disabled = false;\n"
" btn.style.opacity = '1';\n"
" btn.style.cursor = 'pointer';\n"
" if (fiBtn) fiBtn.style.pointerEvents = 'auto';\n"
" pMsg.innerHTML = '<span style=\"color:var(--accent-red);font-weight:700;\">❌ Network communication failure</span>';\n"
" };\n"
" xhr.send(file);\n"
"}\n"
"\n"
"let vButtons = 0;\n"
"let vLx = 0, vLy = 0, vRx = 0, vRy = 0;\n"
"let vInputPending = false;\n"
"let vLastHttpSend = 0;\n"
"\n"
"function sendVirtualInputImmediate() {\n"
" vInputPending = false;\n"
" const payload = JSON.stringify({\n"
" b: vButtons,\n"
" lx: vLx,\n"
" ly: vLy,\n"
" rx: vRx,\n"
" ry: vRy,\n"
" lt: (vButtons & (1 << 6)) ? 255 : 0,\n"
" rt: (vButtons & (1 << 7)) ? 255 : 0\n"
" });\n"
" if (wsState && wsState.readyState === WebSocket.OPEN) {\n"
" wsState.send(payload);\n"
" } else {\n"
" const now = Date.now();\n"
" if (now - vLastHttpSend >= 50) {\n"
" vLastHttpSend = now;\n"
" fetch('/api/remote/input', {\n"
" method: 'POST',\n"
" headers: {'Content-Type': 'application/json'},\n"
" body: payload\n"
" }).catch(() => {});\n"
" }\n"
" }\n"
"}\n"
"\n"
"function queueVirtualInput() {\n"
" if (vInputPending) return;\n"
" vInputPending = true;\n"
" requestAnimationFrame(sendVirtualInputImmediate);\n"
"}\n"
"\n"
"function vBtn(bit, isDown) {\n"
" if (isDown) {\n"
" vButtons |= (1 << bit);\n"
" if (navigator.vibrate) navigator.vibrate(10);\n"
" } else {\n"
" vButtons &= ~(1 << bit);\n"
" }\n"
" sendVirtualInputImmediate();\n"
"}\n"
"\n"
"function toggleVirtualPad() {\n"
" const pad = document.getElementById('virtual-pad');\n"
" const btn = document.getElementById('btn-toggle-vpad');\n"
" if (pad.style.display === 'none') {\n"
" pad.style.display = 'block';\n"
" btn.textContent = 'Hide Touch Gamepad ✕';\n"
" } else {\n"
" pad.style.display = 'none';\n"
" btn.textContent = 'Show Touch Gamepad 🎮';\n"
" }\n"
"}\n"
"\n"
"function toggleFullscreenPad() {\n"
" const pad = document.getElementById('virtual-pad');\n"
" const isFs = !!(document.fullscreenElement || document.webkitFullscreenElement);\n"
" if (!isFs) {\n"
" if (pad.style.display === 'none') {\n"
" toggleVirtualPad();\n"
" }\n"
" pad.classList.add('vpad-fullscreen');\n"
" const req = pad.requestFullscreen || pad.webkitRequestFullscreen || pad.mozRequestFullScreen || pad.msRequestFullscreen;\n"
" if (req) {\n"
" req.call(pad).catch(() => {});\n"
" }\n"
" if (screen.orientation && screen.orientation.lock) {\n"
" screen.orientation.lock('landscape').catch(() => {});\n"
" }\n"
" } else {\n"
" const exit = document.exitFullscreen || document.webkitExitFullscreen || document.mozCancelFullScreen || document.msExitFullscreen;\n"
" if (exit) {\n"
" exit.call(document).catch(() => {});\n"
" }\n"
" pad.classList.remove('vpad-fullscreen');\n"
" if (screen.orientation && screen.orientation.unlock) {\n"
" screen.orientation.unlock();\n"
" }\n"
" }\n"
"}\n"
"\n"
"function onFullscreenChange() {\n"
" const isFs = !!(document.fullscreenElement || document.webkitFullscreenElement);\n"
" const pad = document.getElementById('virtual-pad');\n"
" const btnFs = document.getElementById('btn-fs-vpad');\n"
" if (isFs) {\n"
" pad.classList.add('vpad-fullscreen');\n"
" if (btnFs) btnFs.innerHTML = '⛶ Exit Fullscreen';\n"
" } else {\n"
" pad.classList.remove('vpad-fullscreen');\n"
" if (btnFs) btnFs.innerHTML = '⛶ Fullscreen Remote';\n"
" }\n"
"}\n"
"document.addEventListener('fullscreenchange', onFullscreenChange);\n"
"document.addEventListener('webkitfullscreenchange', onFullscreenChange);\n"
"\n"
"function setupVirtualStick(baseId, nubId, onMove) {\n"
" const base = document.getElementById(baseId);\n"
" const nub = document.getElementById(nubId);\n"
" if (!base || !nub) return;\n"
" let activeId = null;\n"
"\n"
" function updateTouch(clientX, clientY) {\n"
" const rect = base.getBoundingClientRect();\n"
" const cx = rect.left + rect.width / 2;\n"
" const cy = rect.top + rect.height / 2;\n"
" const maxR = (rect.width / 2) - 8;\n"
"\n"
" let dx = clientX - cx;\n"
" let dy = clientY - cy;\n"
" const dist = Math.sqrt(dx * dx + dy * dy);\n"
" if (dist > maxR) {\n"
" dx = (dx / dist) * maxR;\n"
" dy = (dy / dist) * maxR;\n"
" }\n"
" nub.style.transform = `translate(${dx}px, ${dy}px)`;\n"
" const normX = Math.round((dx / maxR) * 32767);\n"
" const normY = Math.round((-dy / maxR) * 32767);\n"
" onMove(normX, normY);\n"
" }\n"
"\n"
" function endTouch() {\n"
" activeId = null;\n"
" nub.style.transform = 'translate(0px, 0px)';\n"
" onMove(0, 0);\n"
" sendVirtualInputImmediate();\n"
" }\n"
"\n"
" base.addEventListener('pointerdown', (e) => {\n"
" e.preventDefault();\n"
" activeId = e.pointerId;\n"
" base.setPointerCapture(e.pointerId);\n"
" updateTouch(e.clientX, e.clientY);\n"
" });\n"
" base.addEventListener('pointermove', (e) => {\n"
" if (e.pointerId === activeId) {\n"
" e.preventDefault();\n"
" updateTouch(e.clientX, e.clientY);\n"
" }\n"
" });\n"
" base.addEventListener('pointerup', (e) => {\n"
" if (e.pointerId === activeId) {\n"
" e.preventDefault();\n"
" endTouch();\n"
" }\n"
" });\n"
" base.addEventListener('pointercancel', (e) => {\n"
" if (e.pointerId === activeId) {\n"
" endTouch();\n"
" }\n"
" });\n"
"}\n"
"\n"
"pollStatus();\n"
"initWsState();\n"
"pollState();\n"
"loadCalib();\n"
"setInterval(requestWsState, 40);\n"
"setupVirtualStick('vpad-stick-l', 'vpad-nub-l', (x, y) => { vLx = x; vLy = y; queueVirtualInput(); });\n"
"setupVirtualStick('vpad-stick-r', 'vpad-nub-r', (x, y) => { vRx = x; vRy = y; queueVirtualInput(); });\n"
"</script>\n"
"</body>\n"
"</html>\n";