ota_html.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. #pragma once
  2. #include <pgmspace.h>
  3. static const char OTA_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. body { padding-top: 40px; }
  16. .ota-card { max-width: 520px; margin: 0 auto; }
  17. #progressWrap { display: none; margin-top: 1.2rem; }
  18. #resultBox { display: none; margin-top: 1rem; }
  19. #resetResult { display: none; margin-top: 0.6rem; }
  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>
  25. <div class="container ota-card">
  26. <h4 class="mb-1"><i class="fa fa-microchip"></i> Device Management</h4>
  27. <p class="text-muted small mb-2">Device: <strong>{{IP}}</strong></p>
  28. <!-- DSP live status card -->
  29. <div class="card mb-4">
  30. <div class="card-header d-flex justify-content-between align-items-center py-2">
  31. <span class="small fw-semibold"><i class="fa fa-tachometer"></i> DSP Status</span>
  32. <span id="dspBadge" class="badge bg-secondary">Polling&hellip;</span>
  33. </div>
  34. <div class="card-body py-2 px-3">
  35. <table class="w-100">
  36. <tr class="reg-row"><td>Core Register</td><td id="sCoreReg">&mdash;</td></tr>
  37. <tr class="reg-row"><td>Running</td> <td id="sRunning">&mdash;</td></tr>
  38. <tr class="reg-row"><td>GPIO</td> <td id="sGpio">&mdash;</td></tr>
  39. <tr class="reg-row"><td>ADC 0&ndash;3</td><td id="sAdc">&mdash;</td></tr>
  40. </table>
  41. <p class="text-muted mb-0 mt-1" style="font-size:0.72rem">
  42. Updated <span id="sUpdated">&mdash;</span> &bull; auto-refreshes every 2 s
  43. </p>
  44. </div>
  45. </div>
  46. <form id="otaForm" action="/ota_do" method="POST" enctype="multipart/form-data">
  47. <div class="mb-3">
  48. <label class="form-label fw-semibold">Firmware binary (.bin)</label>
  49. <input class="form-control" type="file" id="fwFile" name="firmware" accept=".bin" required>
  50. <div class="form-text">Export from Arduino IDE: <em>Sketch &rarr; Export Compiled Binary</em></div>
  51. </div>
  52. <button type="submit" id="flashBtn" class="btn btn-warning w-100">
  53. <i class="fa fa-upload"></i>&nbsp; Flash Firmware
  54. </button>
  55. </form>
  56. <div id="progressWrap">
  57. <div class="progress" style="height:22px">
  58. <div class="progress-bar progress-bar-striped progress-bar-animated bg-warning"
  59. style="width:100%; font-size:0.8rem; line-height:22px">
  60. Uploading&hellip;
  61. </div>
  62. </div>
  63. <p class="text-center text-muted small mt-2">
  64. <i class="fa fa-spinner fa-spin"></i>
  65. Do not power off the device.
  66. </p>
  67. </div>
  68. <div id="resultBox" class="alert" role="alert"></div>
  69. <hr class="mt-4">
  70. <h6 class="text-muted mb-2"><i class="fa fa-refresh"></i> DSP Control</h6>
  71. <button id="resetBtn" class="btn btn-outline-secondary w-100"
  72. onclick="dspReset()">
  73. <i class="fa fa-power-off"></i>&nbsp; Soft Reset DSP
  74. </button>
  75. <div class="form-text mb-1">
  76. Restarts DSP program execution. RAM is preserved — does not reload from EEPROM.
  77. </div>
  78. <div id="resetResult" class="alert alert-sm" role="alert"></div>
  79. <hr class="mt-3">
  80. <h6 class="text-muted mb-2"><i class="fa fa-toggle-on"></i> GPIO Control</h6>
  81. <div class="d-flex gap-2 mb-1">
  82. <button id="gp0" class="btn btn-outline-secondary btn-sm" onclick="toggleGpioPin(0)">GP0</button>
  83. <button id="gp1" class="btn btn-outline-secondary btn-sm" onclick="toggleGpioPin(1)">GP1</button>
  84. <button id="gp2" class="btn btn-outline-secondary btn-sm" onclick="toggleGpioPin(2)">GP2</button>
  85. <button id="gp3" class="btn btn-outline-secondary btn-sm" onclick="toggleGpioPin(3)">GP3</button>
  86. </div>
  87. <div class="form-text mb-1">
  88. Writes to GPIO All Register (0x0808). Only output-configured pins respond (set via MpCfg).
  89. </div>
  90. <div id="gpioResult" style="display:none; margin-top:0.4rem;" class="alert alert-sm" role="alert"></div>
  91. <hr class="mt-3">
  92. <a href="/" class="text-muted small"><i class="fa fa-arrow-left"></i> Back to EEPROM Uploader</a>
  93. </div>
  94. <script>
  95. function pollStatus() {
  96. var xhr = new XMLHttpRequest();
  97. xhr.open('GET', '/dsp_status', true);
  98. xhr.timeout = 1800;
  99. xhr.onload = function() {
  100. var badge = document.getElementById('dspBadge');
  101. if (xhr.status !== 200) {
  102. badge.className = 'badge bg-danger'; badge.textContent = 'I2C Error';
  103. return;
  104. }
  105. try {
  106. var d = JSON.parse(xhr.responseText);
  107. if (d.running) {
  108. badge.className = 'badge bg-success'; badge.textContent = 'Running';
  109. } else {
  110. badge.className = 'badge bg-danger'; badge.textContent = 'Stopped';
  111. }
  112. document.getElementById('sCoreReg').textContent = d.coreReg;
  113. document.getElementById('sRunning').textContent = d.running ? 'Yes' : 'No';
  114. document.getElementById('sGpio').textContent = d.gpio;
  115. document.getElementById('sAdc').textContent = d.adc.join(' ');
  116. document.getElementById('sUpdated').textContent =
  117. new Date().toLocaleTimeString();
  118. } catch(e) {
  119. badge.className = 'badge bg-warning'; badge.textContent = 'Parse error';
  120. }
  121. };
  122. xhr.ontimeout = xhr.onerror = function() {
  123. var badge = document.getElementById('dspBadge');
  124. badge.className = 'badge bg-secondary'; badge.textContent = 'Offline';
  125. };
  126. xhr.send();
  127. }
  128. pollStatus();
  129. setInterval(pollStatus, 2000);
  130. function dspReset() {
  131. var btn = document.getElementById('resetBtn');
  132. var box = document.getElementById('resetResult');
  133. btn.disabled = true;
  134. box.style.display = 'none';
  135. var xhr = new XMLHttpRequest();
  136. xhr.open('POST', '/dsp_reset', true);
  137. xhr.onload = function() {
  138. box.style.display = 'block';
  139. if (xhr.status === 200) {
  140. box.className = 'alert alert-success alert-sm';
  141. box.innerHTML = '<i class="fa fa-check"></i> ' + xhr.responseText;
  142. } else {
  143. box.className = 'alert alert-danger alert-sm';
  144. box.innerHTML = '<i class="fa fa-times"></i> Reset failed.';
  145. }
  146. btn.disabled = false;
  147. };
  148. xhr.onerror = function() {
  149. box.style.display = 'block';
  150. box.className = 'alert alert-danger alert-sm';
  151. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  152. btn.disabled = false;
  153. };
  154. xhr.send();
  155. }
  156. var gpioVal = null;
  157. function updateGpioBtns(val) {
  158. for (var i = 0; i < 4; i++) {
  159. var btn = document.getElementById('gp' + i);
  160. if (val & (1 << i)) {
  161. btn.className = 'btn btn-success btn-sm';
  162. } else {
  163. btn.className = 'btn btn-outline-secondary btn-sm';
  164. }
  165. }
  166. }
  167. function fetchGpio() {
  168. var xhr = new XMLHttpRequest();
  169. xhr.open('GET', '/gpio', true);
  170. xhr.timeout = 1800;
  171. xhr.onload = function() {
  172. if (xhr.status === 200) {
  173. try {
  174. var d = JSON.parse(xhr.responseText);
  175. gpioVal = d.gpio;
  176. updateGpioBtns(gpioVal);
  177. } catch(e) {}
  178. }
  179. };
  180. xhr.send();
  181. }
  182. function toggleGpioPin(pin) {
  183. if (gpioVal === null) return;
  184. gpioVal ^= (1 << pin);
  185. updateGpioBtns(gpioVal);
  186. var box = document.getElementById('gpioResult');
  187. var xhr = new XMLHttpRequest();
  188. xhr.open('POST', '/gpio', true);
  189. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  190. xhr.onload = function() {
  191. box.style.display = 'block';
  192. if (xhr.status === 200) {
  193. box.className = 'alert alert-success alert-sm';
  194. box.innerHTML = '<i class="fa fa-check"></i> GP' + pin + ' toggled (0x' +
  195. (gpioVal & 0xFF).toString(16).padStart(2,'0').toUpperCase() + ')';
  196. } else {
  197. box.className = 'alert alert-danger alert-sm';
  198. box.innerHTML = '<i class="fa fa-times"></i> GPIO write failed.';
  199. }
  200. };
  201. xhr.onerror = function() {
  202. box.style.display = 'block';
  203. box.className = 'alert alert-danger alert-sm';
  204. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  205. };
  206. xhr.send('value=' + gpioVal);
  207. }
  208. fetchGpio();
  209. setInterval(fetchGpio, 5000);
  210. document.getElementById('otaForm').addEventListener('submit', function(e) {
  211. e.preventDefault();
  212. var file = document.getElementById('fwFile').files[0];
  213. if (!file) return;
  214. document.getElementById('flashBtn').disabled = true;
  215. document.getElementById('progressWrap').style.display = 'block';
  216. document.getElementById('resultBox').style.display = 'none';
  217. var fd = new FormData(this);
  218. var xhr = new XMLHttpRequest();
  219. xhr.open('POST', '/ota_do', true);
  220. xhr.onload = function() {
  221. document.getElementById('progressWrap').style.display = 'none';
  222. var box = document.getElementById('resultBox');
  223. box.style.display = 'block';
  224. if (xhr.status === 200) {
  225. box.className = 'alert alert-success';
  226. box.innerHTML = '<i class="fa fa-check-circle"></i> ' + xhr.responseText +
  227. '<br><small>Reconnecting in 5 seconds&hellip;</small>';
  228. setTimeout(function(){ window.location.href = '/'; }, 5500);
  229. } else {
  230. box.className = 'alert alert-danger';
  231. box.innerHTML = '<i class="fa fa-times-circle"></i> ' + xhr.responseText;
  232. document.getElementById('flashBtn').disabled = false;
  233. }
  234. };
  235. xhr.onerror = function() {
  236. document.getElementById('progressWrap').style.display = 'none';
  237. var box = document.getElementById('resultBox');
  238. box.style.display = 'block';
  239. box.className = 'alert alert-danger';
  240. box.innerHTML = '<i class="fa fa-times-circle"></i> Upload error — check Serial log.';
  241. document.getElementById('flashBtn').disabled = false;
  242. };
  243. xhr.send(fd);
  244. });
  245. </script>
  246. </body>
  247. </html>
  248. )HTML";