index_html.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. <!-- WiFi Settings -->
  103. <div class="card mb-3">
  104. <div class="card-header py-2">
  105. <span class="small fw-semibold"><i class="fa fa-wifi"></i> WiFi Settings</span>
  106. </div>
  107. <div class="card-body py-2 px-3">
  108. <button class="btn btn-outline-danger w-100" onclick="wifiReset()">
  109. <i class="fa fa-trash-o"></i>&nbsp; Reset WiFi Credentials
  110. </button>
  111. <div class="form-text">
  112. Clears stored credentials and reboots into setup mode.
  113. Connect to <strong>ModulosDSP-Setup</strong> then open <strong>192.168.4.1</strong> to reconfigure.
  114. </div>
  115. <div id="wifiResetResult" style="display:none;" class="alert alert-sm mt-1" role="alert"></div>
  116. </div>
  117. </div>
  118. <!-- Firmware Update link -->
  119. <div class="card mb-3">
  120. <div class="card-header py-2">
  121. <span class="small fw-semibold"><i class="fa fa-microchip"></i> Firmware Update</span>
  122. </div>
  123. <div class="card-body py-2 px-3">
  124. <a href="/ota" class="btn btn-outline-warning w-100">
  125. <i class="fa fa-upload"></i>&nbsp; Flash ESP32 Firmware (OTA)
  126. </a>
  127. <div class="form-text">Update the ESP32 firmware via over-the-air upload.</div>
  128. </div>
  129. </div>
  130. </div>
  131. <!-- ── Right column ────────────────────────────────────── -->
  132. <div class="col-lg-6">
  133. <!-- EEPROM Upload -->
  134. <div class="card">
  135. <div class="card-header py-2">
  136. <span class="small fw-semibold"><i class="fa fa-database"></i> EEPROM Upload (24C256)</span>
  137. </div>
  138. <div class="card-body">
  139. <p class="text-muted small mb-3">I&sup2;C 0x50 &bull; 32&thinsp;768 bytes &bull; 64-byte pages</p>
  140. <form method="POST" action="/upload" enctype="multipart/form-data">
  141. <div class="mb-3">
  142. <label class="form-label fw-semibold">DSP firmware binary</label>
  143. <input class="form-control" type="file" name="bin" required>
  144. <div class="form-text">Export from SigmaStudio: <em>Action &rarr; Export System Files</em></div>
  145. </div>
  146. <div class="mb-3 form-check">
  147. <input class="form-check-input" type="checkbox" name="verify" value="1" id="verifyChk" checked>
  148. <label class="form-check-label" for="verifyChk">Verify after write (CRC32)</label>
  149. </div>
  150. <button style="background-color:#114378;border-color:#114378;color:#e8b434;"
  151. type="submit" class="btn w-100">
  152. <i class="fa fa-upload"></i>&nbsp; Upload and Program
  153. </button>
  154. </form>
  155. <p class="mt-3 mb-0">
  156. <a href="/status" class="text-muted small">View upload status</a>
  157. </p>
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. <footer class="fixed-bottom mt-auto py-3 border-top bg-dark">
  164. <div class="container">
  165. <p class="text-white text-center mb-0">
  166. Copyright &copy; <span id="year"></span> &ndash; Modulos Audio &ndash; DSP Controller &ndash; All Rights Reserved
  167. </p>
  168. <script>document.getElementById('year').innerHTML = new Date().getFullYear();</script>
  169. </div>
  170. </footer>
  171. <script src="/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
  172. <script>
  173. function pollStatus() {
  174. var xhr = new XMLHttpRequest();
  175. xhr.open('GET', '/dsp_status', true);
  176. xhr.timeout = 1800;
  177. xhr.onload = function() {
  178. var badge = document.getElementById('dspBadge');
  179. if (xhr.status !== 200) {
  180. badge.className = 'badge bg-danger'; badge.textContent = 'I2C Error';
  181. return;
  182. }
  183. try {
  184. var d = JSON.parse(xhr.responseText);
  185. if (d.running) {
  186. badge.className = 'badge bg-success'; badge.textContent = 'Running';
  187. } else {
  188. badge.className = 'badge bg-danger'; badge.textContent = 'Stopped';
  189. }
  190. document.getElementById('sCoreReg').textContent = d.coreReg;
  191. document.getElementById('sRunning').textContent = d.running ? 'Yes' : 'No';
  192. document.getElementById('sGpio').textContent = d.gpio;
  193. document.getElementById('sAdc').textContent = d.adc.join(' ');
  194. document.getElementById('sUpdated').textContent = new Date().toLocaleTimeString();
  195. } catch(e) {
  196. badge.className = 'badge bg-warning'; badge.textContent = 'Parse error';
  197. }
  198. };
  199. xhr.ontimeout = xhr.onerror = function() {
  200. var badge = document.getElementById('dspBadge');
  201. badge.className = 'badge bg-secondary'; badge.textContent = 'Offline';
  202. };
  203. xhr.send();
  204. }
  205. pollStatus();
  206. setInterval(pollStatus, 2000);
  207. function dspReset() {
  208. var btn = document.getElementById('resetBtn');
  209. var box = document.getElementById('resetResult');
  210. btn.disabled = true;
  211. box.style.display = 'none';
  212. var xhr = new XMLHttpRequest();
  213. xhr.open('POST', '/dsp_reset', true);
  214. xhr.onload = function() {
  215. box.style.display = 'block';
  216. if (xhr.status === 200) {
  217. box.className = 'alert alert-success alert-sm';
  218. box.innerHTML = '<i class="fa fa-check"></i> ' + xhr.responseText;
  219. } else {
  220. box.className = 'alert alert-danger alert-sm';
  221. box.innerHTML = '<i class="fa fa-times"></i> Reset failed.';
  222. }
  223. btn.disabled = false;
  224. };
  225. xhr.onerror = function() {
  226. box.style.display = 'block';
  227. box.className = 'alert alert-danger alert-sm';
  228. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  229. btn.disabled = false;
  230. };
  231. xhr.send();
  232. }
  233. var gpioVal = null;
  234. function updateGpioBtns(val) {
  235. for (var i = 0; i < 4; i++) {
  236. var btn = document.getElementById('gp' + i);
  237. if (val & (1 << i)) {
  238. btn.className = 'btn btn-success btn-sm';
  239. } else {
  240. btn.className = 'btn btn-outline-secondary btn-sm';
  241. }
  242. }
  243. }
  244. function fetchGpio() {
  245. var xhr = new XMLHttpRequest();
  246. xhr.open('GET', '/gpio', true);
  247. xhr.timeout = 1800;
  248. xhr.onload = function() {
  249. if (xhr.status === 200) {
  250. try {
  251. var d = JSON.parse(xhr.responseText);
  252. gpioVal = d.gpio;
  253. updateGpioBtns(gpioVal);
  254. } catch(e) {}
  255. }
  256. };
  257. xhr.send();
  258. }
  259. function toggleGpioPin(pin) {
  260. if (gpioVal === null) return;
  261. gpioVal ^= (1 << pin);
  262. updateGpioBtns(gpioVal);
  263. var box = document.getElementById('gpioResult');
  264. var xhr = new XMLHttpRequest();
  265. xhr.open('POST', '/gpio', true);
  266. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  267. xhr.onload = function() {
  268. box.style.display = 'block';
  269. if (xhr.status === 200) {
  270. box.className = 'alert alert-success alert-sm';
  271. box.innerHTML = '<i class="fa fa-check"></i> GP' + pin + ' toggled (0x' +
  272. (gpioVal & 0xFF).toString(16).padStart(2,'0').toUpperCase() + ')';
  273. } else {
  274. box.className = 'alert alert-danger alert-sm';
  275. box.innerHTML = '<i class="fa fa-times"></i> GPIO write failed.';
  276. }
  277. };
  278. xhr.onerror = function() {
  279. box.style.display = 'block';
  280. box.className = 'alert alert-danger alert-sm';
  281. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  282. };
  283. xhr.send('value=' + gpioVal);
  284. }
  285. fetchGpio();
  286. setInterval(fetchGpio, 5000);
  287. function wifiReset() {
  288. if (!confirm('Clear WiFi credentials and reboot into setup mode?')) return;
  289. var box = document.getElementById('wifiResetResult');
  290. var xhr = new XMLHttpRequest();
  291. xhr.open('POST', '/wifi_reset', true);
  292. xhr.onload = function() {
  293. box.style.display = 'block';
  294. box.className = 'alert alert-warning alert-sm';
  295. box.innerHTML = '<i class="fa fa-info-circle"></i> ' + xhr.responseText;
  296. };
  297. xhr.onerror = function() {
  298. box.style.display = 'block';
  299. box.className = 'alert alert-danger alert-sm';
  300. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  301. };
  302. xhr.send();
  303. }
  304. </script>
  305. </body>
  306. </html>
  307. )HTML";