index_html.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. #pragma once
  2. #include <pgmspace.h>
  3. static const char INDEX_HTML[] PROGMEM = R"HTML(
  4. <!doctype html>
  5. <html lang="en-AU">
  6. <head>
  7. <meta charset="utf-8">
  8. <meta name="viewport" content="width=device-width, initial-scale=1">
  9. <link rel="icon" type="image/x-icon" href="/favicon.ico">
  10. <link rel="stylesheet" href="yeti-bootstrap.min.css">
  11. <link rel="stylesheet" href="font-awesome.min.css">
  12. <script src="jquery-3.7.1.slim.min.js" crossorigin="anonymous"></script>
  13. <title>Modulos DSP - Device Management</title>
  14. <style>
  15. @font-face {
  16. font-family: 'nasalization';
  17. src: url('/nasalization-rg.woff2') format('woff2');
  18. }
  19. .nasalization { font-family: 'nasalization'; }
  20. .reg-row td { font-family: monospace; font-size: 0.85rem; padding: 2px 8px; }
  21. .reg-row td:first-child { color: #6c757d; width: 120px; }
  22. </style>
  23. </head>
  24. <body class="bg-light" style="padding-top: 5rem;">
  25. <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
  26. <div class="container">
  27. <a class="navbar-brand nasalization text-uppercase" href="#">
  28. <img src="/logo-horizontal.webp" height="30" class="d-inline-block align-top" loading="lazy">
  29. </a>
  30. <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
  31. aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
  32. <span class="navbar-toggler-icon"></span>
  33. </button>
  34. <div class="collapse navbar-collapse" id="navbarNav">
  35. <span class="col align-self-end text-end text-white">
  36. <span>{{IP}}</span>
  37. <i class="text-success fas fa-wifi"></i>
  38. </span>
  39. </div>
  40. </div>
  41. </nav>
  42. <div class="container pb-5">
  43. <div class="row">
  44. <div class="col-sm">
  45. <h2 class="text-center pt-2 font-weight-bold">Device Management</h2>
  46. </div>
  47. </div>
  48. <div class="row g-3">
  49. <!-- ── Left column ─────────────────────────────────────── -->
  50. <div class="col-lg-6">
  51. <!-- DSP live status card -->
  52. <div class="card mb-3">
  53. <div class="card-header d-flex justify-content-between align-items-center py-2">
  54. <span class="small fw-semibold"><i class="fa fa-tachometer"></i> DSP Status</span>
  55. <span id="dspBadge" class="badge bg-secondary">Polling&hellip;</span>
  56. </div>
  57. <div class="card-body py-2 px-3">
  58. <table class="w-100">
  59. <tr class="reg-row"><td>Core Register</td><td id="sCoreReg">&mdash;</td></tr>
  60. <tr class="reg-row"><td>Running</td> <td id="sRunning">&mdash;</td></tr>
  61. <tr class="reg-row"><td>GPIO</td> <td id="sGpio">&mdash;</td></tr>
  62. <tr class="reg-row"><td>ADC 0&ndash;3</td><td id="sAdc">&mdash;</td></tr>
  63. </table>
  64. <p class="text-muted mb-0 mt-1" style="font-size:0.72rem">
  65. Updated <span id="sUpdated">&mdash;</span> &bull; auto-refreshes every 2 s
  66. </p>
  67. </div>
  68. </div>
  69. <!-- DSP Control -->
  70. <div class="card mb-3">
  71. <div class="card-header py-2">
  72. <span class="small fw-semibold"><i class="fa fa-refresh"></i> DSP Control</span>
  73. </div>
  74. <div class="card-body py-2 px-3">
  75. <button id="resetBtn" class="btn btn-outline-secondary w-100" onclick="dspReset()">
  76. <i class="fa fa-power-off"></i>&nbsp; Soft Reset DSP
  77. </button>
  78. <div class="form-text">
  79. Restarts DSP program execution. RAM is preserved &mdash; does not reload from EEPROM.
  80. </div>
  81. <div id="resetResult" style="display:none;" class="alert alert-sm mt-2" role="alert"></div>
  82. </div>
  83. </div>
  84. <!-- GPIO Control -->
  85. <div class="card mb-3">
  86. <div class="card-header py-2">
  87. <span class="small fw-semibold"><i class="fa fa-toggle-on"></i> GPIO Control</span>
  88. </div>
  89. <div class="card-body py-2 px-3">
  90. <div class="d-flex gap-2 mb-1">
  91. <button id="gp0" class="btn btn-outline-secondary btn-sm" onclick="toggleGpioPin(0)">GP0</button>
  92. <button id="gp1" class="btn btn-outline-secondary btn-sm" onclick="toggleGpioPin(1)">GP1</button>
  93. <button id="gp2" class="btn btn-outline-secondary btn-sm" onclick="toggleGpioPin(2)">GP2</button>
  94. <button id="gp3" class="btn btn-outline-secondary btn-sm" onclick="toggleGpioPin(3)">GP3</button>
  95. </div>
  96. <div class="form-text">
  97. Writes to GPIO All Register (0x0808). Only output-configured pins respond (set via MpCfg).
  98. </div>
  99. <div id="gpioResult" style="display:none;" class="alert alert-sm mt-1" role="alert"></div>
  100. </div>
  101. </div>
  102. <!-- Parameter Tuner link -->
  103. <div class="card mb-3">
  104. <div class="card-header py-2">
  105. <span class="small fw-semibold"><i class="fa fa-sliders"></i> Parameter Tuner</span>
  106. </div>
  107. <div class="card-body py-2 px-3">
  108. <a href="/params" class="btn btn-outline-primary w-100">
  109. <i class="fa fa-edit"></i>&nbsp; Open Parameter Tuner
  110. </a>
  111. <div class="form-text">
  112. Read and write DSP parameter RAM (0x0000&ndash;0x03FF) in real time using safeload.
  113. </div>
  114. </div>
  115. </div>
  116. <!-- WiFi Settings -->
  117. <div class="card mb-3">
  118. <div class="card-header py-2">
  119. <span class="small fw-semibold"><i class="fa fa-wifi"></i> WiFi Settings</span>
  120. </div>
  121. <div class="card-body py-2 px-3">
  122. <button class="btn btn-outline-danger w-100" onclick="wifiReset()">
  123. <i class="fa fa-trash-o"></i>&nbsp; Reset WiFi Credentials
  124. </button>
  125. <div class="form-text">
  126. Clears stored credentials and reboots into setup mode.
  127. Connect to <strong>ModulosDSP-Setup</strong> then open <strong>192.168.4.1</strong> to reconfigure.
  128. </div>
  129. <div id="wifiResetResult" style="display:none;" class="alert alert-sm mt-1" role="alert"></div>
  130. </div>
  131. </div>
  132. <!-- Firmware Update link -->
  133. <div class="card mb-3">
  134. <div class="card-header py-2">
  135. <span class="small fw-semibold"><i class="fa fa-microchip"></i> Firmware Update</span>
  136. </div>
  137. <div class="card-body py-2 px-3">
  138. <a href="/ota" class="btn btn-outline-warning w-100">
  139. <i class="fa fa-upload"></i>&nbsp; Flash ESP32 Firmware (OTA)
  140. </a>
  141. <div class="form-text">Update the ESP32 firmware via over-the-air upload.</div>
  142. </div>
  143. </div>
  144. </div>
  145. <!-- ── Right column ────────────────────────────────────── -->
  146. <div class="col-lg-6">
  147. <!-- Capture to EEPROM -->
  148. <div class="card mb-3">
  149. <div class="card-header py-2 d-flex justify-content-between align-items-center">
  150. <span class="small fw-semibold"><i class="fa fa-database"></i> Capture to EEPROM</span>
  151. <span id="capBadge" class="badge bg-secondary">Checking&hellip;</span>
  152. </div>
  153. <div class="card-body py-2 px-3">
  154. <p class="text-muted small mb-2">
  155. Connect SigmaStudio via TCP and run <em>Link &rarr; Compile &rarr; Download</em>.
  156. When capture is ready, click <strong>Save to EEPROM</strong> to write the selfboot image.
  157. The DSP will load this program autonomously on next power-up.
  158. </p>
  159. <button id="saveEepromBtn" class="btn w-100 mb-2"
  160. style="background-color:#114378;border-color:#114378;color:#e8b434;"
  161. onclick="saveEeprom()" disabled>
  162. <i class="fa fa-save"></i>&nbsp; Save to EEPROM
  163. </button>
  164. <div id="saveResult" style="display:none;" class="alert alert-sm mt-1" role="alert"></div>
  165. </div>
  166. </div>
  167. <!-- EEPROM Upload -->
  168. <div class="card">
  169. <div class="card-header py-2">
  170. <span class="small fw-semibold"><i class="fa fa-database"></i> EEPROM Upload (24C256)</span>
  171. </div>
  172. <div class="card-body">
  173. <p class="text-muted small mb-3">I&sup2;C 0x50 &bull; 32&thinsp;768 bytes &bull; 64-byte pages</p>
  174. <div class="mb-3">
  175. <label class="form-label fw-semibold">DSP firmware binary</label>
  176. <input class="form-control" type="file" id="binFile" accept=".bin,.hex">
  177. <div class="form-text">
  178. SigmaStudio: <em>Action &rarr; Export System Files</em> &rarr; upload the <strong>.hex</strong> file.<br>
  179. Raw binary <strong>.bin</strong> files are also accepted.
  180. </div>
  181. </div>
  182. <div class="mb-3 form-check">
  183. <input class="form-check-input" type="checkbox" id="verifyChk" checked>
  184. <label class="form-check-label" for="verifyChk">Verify after write (CRC32 readback)</label>
  185. </div>
  186. <button style="background-color:#114378;border-color:#114378;color:#e8b434;"
  187. type="button" class="btn w-100" id="uploadBtn" onclick="startUpload()">
  188. <i class="fa fa-upload"></i>&nbsp; Upload and Program
  189. </button>
  190. <!-- Progress -->
  191. <div id="uploadProgress" style="display:none;" class="mt-3">
  192. <div class="progress mb-2" style="height:6px;">
  193. <div class="progress-bar progress-bar-striped progress-bar-animated"
  194. style="width:100%;background-color:#114378;"></div>
  195. </div>
  196. <p class="text-center text-muted small mb-0">
  197. <i class="fa fa-circle-o-notch fa-spin"></i>&nbsp; Writing to EEPROM&hellip;
  198. </p>
  199. </div>
  200. <!-- Result -->
  201. <div id="uploadResult" style="display:none;" class="mt-3"></div>
  202. </div>
  203. </div>
  204. </div>
  205. </div>
  206. </div>
  207. <footer class="fixed-bottom mt-auto py-3 border-top bg-dark">
  208. <div class="container">
  209. <p class="text-white text-center mb-0">
  210. Copyright &copy; <span id="year"></span> &ndash; Modulos Audio &ndash; DSP Controller &ndash; All Rights Reserved
  211. </p>
  212. <script>document.getElementById('year').innerHTML = new Date().getFullYear();</script>
  213. </div>
  214. </footer>
  215. <script src="/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
  216. <script>
  217. function pollStatus() {
  218. var xhr = new XMLHttpRequest();
  219. xhr.open('GET', '/dsp_status', true);
  220. xhr.timeout = 1800;
  221. xhr.onload = function() {
  222. var badge = document.getElementById('dspBadge');
  223. if (xhr.status !== 200) {
  224. badge.className = 'badge bg-danger'; badge.textContent = 'I2C Error';
  225. return;
  226. }
  227. try {
  228. var d = JSON.parse(xhr.responseText);
  229. if (d.running) {
  230. badge.className = 'badge bg-success'; badge.textContent = 'Running';
  231. } else {
  232. badge.className = 'badge bg-danger'; badge.textContent = 'Stopped';
  233. }
  234. document.getElementById('sCoreReg').textContent = d.coreReg;
  235. document.getElementById('sRunning').textContent = d.running ? 'Yes' : 'No';
  236. document.getElementById('sGpio').textContent = d.gpio;
  237. document.getElementById('sAdc').textContent = d.adc.join(' ');
  238. document.getElementById('sUpdated').textContent = new Date().toLocaleTimeString();
  239. } catch(e) {
  240. badge.className = 'badge bg-warning'; badge.textContent = 'Parse error';
  241. }
  242. };
  243. xhr.ontimeout = xhr.onerror = function() {
  244. var badge = document.getElementById('dspBadge');
  245. badge.className = 'badge bg-secondary'; badge.textContent = 'Offline';
  246. };
  247. xhr.send();
  248. }
  249. pollStatus();
  250. setInterval(pollStatus, 2000);
  251. function dspReset() {
  252. var btn = document.getElementById('resetBtn');
  253. var box = document.getElementById('resetResult');
  254. btn.disabled = true;
  255. box.style.display = 'none';
  256. var xhr = new XMLHttpRequest();
  257. xhr.open('POST', '/dsp_reset', true);
  258. xhr.onload = function() {
  259. box.style.display = 'block';
  260. if (xhr.status === 200) {
  261. box.className = 'alert alert-success alert-sm';
  262. box.innerHTML = '<i class="fa fa-check"></i> ' + xhr.responseText;
  263. } else {
  264. box.className = 'alert alert-danger alert-sm';
  265. box.innerHTML = '<i class="fa fa-times"></i> Reset failed.';
  266. }
  267. btn.disabled = false;
  268. };
  269. xhr.onerror = function() {
  270. box.style.display = 'block';
  271. box.className = 'alert alert-danger alert-sm';
  272. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  273. btn.disabled = false;
  274. };
  275. xhr.send();
  276. }
  277. var gpioVal = null;
  278. function updateGpioBtns(val) {
  279. for (var i = 0; i < 4; i++) {
  280. var btn = document.getElementById('gp' + i);
  281. if (val & (1 << i)) {
  282. btn.className = 'btn btn-success btn-sm';
  283. } else {
  284. btn.className = 'btn btn-outline-secondary btn-sm';
  285. }
  286. }
  287. }
  288. function fetchGpio() {
  289. var xhr = new XMLHttpRequest();
  290. xhr.open('GET', '/gpio', true);
  291. xhr.timeout = 1800;
  292. xhr.onload = function() {
  293. if (xhr.status === 200) {
  294. try {
  295. var d = JSON.parse(xhr.responseText);
  296. gpioVal = d.gpio;
  297. updateGpioBtns(gpioVal);
  298. } catch(e) {}
  299. }
  300. };
  301. xhr.send();
  302. }
  303. function toggleGpioPin(pin) {
  304. if (gpioVal === null) return;
  305. gpioVal ^= (1 << pin);
  306. updateGpioBtns(gpioVal);
  307. var box = document.getElementById('gpioResult');
  308. var xhr = new XMLHttpRequest();
  309. xhr.open('POST', '/gpio', true);
  310. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  311. xhr.onload = function() {
  312. box.style.display = 'block';
  313. if (xhr.status === 200) {
  314. box.className = 'alert alert-success alert-sm';
  315. box.innerHTML = '<i class="fa fa-check"></i> GP' + pin + ' toggled (0x' +
  316. (gpioVal & 0xFF).toString(16).padStart(2,'0').toUpperCase() + ')';
  317. } else {
  318. box.className = 'alert alert-danger alert-sm';
  319. box.innerHTML = '<i class="fa fa-times"></i> GPIO write failed.';
  320. }
  321. };
  322. xhr.onerror = function() {
  323. box.style.display = 'block';
  324. box.className = 'alert alert-danger alert-sm';
  325. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  326. };
  327. xhr.send('value=' + gpioVal);
  328. }
  329. fetchGpio();
  330. setInterval(fetchGpio, 5000);
  331. function parseSigmaHex(text) {
  332. var matches = text.match(/0x[0-9A-Fa-f]{2}/g);
  333. if (!matches || matches.length === 0) return null;
  334. var bytes = new Uint8Array(matches.length);
  335. for (var i = 0; i < matches.length; i++) bytes[i] = parseInt(matches[i], 16);
  336. return bytes;
  337. }
  338. function startUpload() {
  339. var fileInput = document.getElementById('binFile');
  340. if (!fileInput.files || !fileInput.files.length) {
  341. alert('Please select a .hex or .bin file first.');
  342. return;
  343. }
  344. var file = fileInput.files[0];
  345. var ext = file.name.split('.').pop().toLowerCase();
  346. if (ext === 'hex') {
  347. var reader = new FileReader();
  348. reader.onload = function(e) {
  349. var bytes = parseSigmaHex(e.target.result);
  350. if (!bytes) { alert('Could not parse .hex file — unexpected format.'); return; }
  351. doUpload(new Blob([bytes], {type: 'application/octet-stream'}), file.name);
  352. };
  353. reader.readAsText(file);
  354. } else {
  355. doUpload(file, file.name);
  356. }
  357. }
  358. function doUpload(blob, name) {
  359. var formData = new FormData();
  360. if (document.getElementById('verifyChk').checked) formData.append('verify', '1');
  361. formData.append('bin', blob, name);
  362. document.getElementById('uploadBtn').disabled = true;
  363. document.getElementById('uploadProgress').style.display = 'block';
  364. document.getElementById('uploadResult').style.display = 'none';
  365. var xhr = new XMLHttpRequest();
  366. xhr.open('POST', '/upload', true);
  367. xhr.onload = function() {
  368. document.getElementById('uploadProgress').style.display = 'none';
  369. document.getElementById('uploadBtn').disabled = false;
  370. var div = document.getElementById('uploadResult');
  371. div.style.display = 'block';
  372. if (xhr.status === 200) {
  373. try {
  374. var d = JSON.parse(xhr.responseText);
  375. div.innerHTML =
  376. '<div class="alert alert-success mb-0">' +
  377. '<strong><i class="fa fa-check-circle"></i> Programmed OK</strong><br>' +
  378. '<span class="small">Bytes written: <code>' + d.bytes + '</code></span><br>' +
  379. '<span class="small">CRC32: <code>' + d.crc.toUpperCase() + '</code></span>' +
  380. (d.verified ? '<br><span class="small"><i class="fa fa-check"></i> Verified against EEPROM readback</span>' : '') +
  381. '</div>';
  382. } catch(e) {
  383. div.innerHTML = '<div class="alert alert-success mb-0"><i class="fa fa-check-circle"></i> Upload complete.</div>';
  384. }
  385. } else {
  386. var reason = '';
  387. try { var d = JSON.parse(xhr.responseText); if (d.error) reason = d.error; } catch(e) {}
  388. div.innerHTML =
  389. '<div class="alert alert-danger mb-0">' +
  390. '<strong><i class="fa fa-times-circle"></i> Upload failed</strong>' +
  391. (reason ? '<br><span class="small"><code>' + reason + '</code></span>' : '') +
  392. '</div>';
  393. }
  394. };
  395. xhr.onerror = function() {
  396. document.getElementById('uploadProgress').style.display = 'none';
  397. document.getElementById('uploadBtn').disabled = false;
  398. var div = document.getElementById('uploadResult');
  399. div.style.display = 'block';
  400. div.innerHTML = '<div class="alert alert-danger mb-0"><i class="fa fa-times-circle"></i> Connection lost during upload.</div>';
  401. };
  402. xhr.send(formData);
  403. }
  404. function pollCapture() {
  405. var xhr = new XMLHttpRequest();
  406. xhr.open('GET', '/capture_status', true);
  407. xhr.timeout = 1800;
  408. xhr.onload = function() {
  409. if (xhr.status !== 200) return;
  410. try {
  411. var d = JSON.parse(xhr.responseText);
  412. var badge = document.getElementById('capBadge');
  413. var btn = document.getElementById('saveEepromBtn');
  414. if (d.ready) {
  415. badge.className = 'badge bg-success';
  416. badge.textContent = Math.round(d.bytes / 1024 * 10) / 10 + ' kB ready';
  417. btn.disabled = false;
  418. } else {
  419. badge.className = 'badge bg-secondary';
  420. badge.textContent = 'No capture';
  421. btn.disabled = true;
  422. }
  423. } catch(e) {}
  424. };
  425. xhr.send();
  426. }
  427. function saveEeprom() {
  428. var btn = document.getElementById('saveEepromBtn');
  429. var box = document.getElementById('saveResult');
  430. btn.disabled = true;
  431. box.style.display = 'none';
  432. var xhr = new XMLHttpRequest();
  433. xhr.open('POST', '/save_eeprom', true);
  434. xhr.timeout = 30000;
  435. xhr.onload = function() {
  436. box.style.display = 'block';
  437. if (xhr.status === 200) {
  438. try {
  439. var d = JSON.parse(xhr.responseText);
  440. box.className = 'alert alert-success alert-sm';
  441. box.innerHTML = '<i class="fa fa-check"></i> Saved ' + d.bytes + ' bytes to EEPROM.';
  442. } catch(e) {
  443. box.className = 'alert alert-success alert-sm';
  444. box.innerHTML = '<i class="fa fa-check"></i> Saved to EEPROM.';
  445. }
  446. } else {
  447. var reason = '';
  448. try { var d = JSON.parse(xhr.responseText); if (d.error) reason = d.error; } catch(e) {}
  449. box.className = 'alert alert-danger alert-sm';
  450. box.innerHTML = '<i class="fa fa-times"></i> ' + (reason || 'Save failed.');
  451. }
  452. btn.disabled = false;
  453. };
  454. xhr.ontimeout = xhr.onerror = function() {
  455. box.style.display = 'block';
  456. box.className = 'alert alert-danger alert-sm';
  457. box.innerHTML = '<i class="fa fa-times"></i> Request timed out.';
  458. btn.disabled = false;
  459. };
  460. xhr.send();
  461. }
  462. pollCapture();
  463. setInterval(pollCapture, 3000);
  464. function wifiReset() {
  465. if (!confirm('Clear WiFi credentials and reboot into setup mode?')) return;
  466. var box = document.getElementById('wifiResetResult');
  467. var xhr = new XMLHttpRequest();
  468. xhr.open('POST', '/wifi_reset', true);
  469. xhr.onload = function() {
  470. box.style.display = 'block';
  471. box.className = 'alert alert-warning alert-sm';
  472. box.innerHTML = '<i class="fa fa-info-circle"></i> ' + xhr.responseText;
  473. };
  474. xhr.onerror = function() {
  475. box.style.display = 'block';
  476. box.className = 'alert alert-danger alert-sm';
  477. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  478. };
  479. xhr.send();
  480. }
  481. </script>
  482. </body>
  483. </html>
  484. )HTML";