Przeglądaj źródła

hex file & IST register fix

Benjamin Harris 1 miesiąc temu
rodzic
commit
bc40329bd3
1 zmienionych plików z 31 dodań i 4 usunięć
  1. 31 4
      index_html.h

+ 31 - 4
index_html.h

@@ -168,8 +168,11 @@ static const char INDEX_HTML[] PROGMEM = R"HTML(
             <p class="text-muted small mb-3">I&sup2;C 0x50 &bull; 32&thinsp;768 bytes &bull; 64-byte pages</p>
             <div class="mb-3">
               <label class="form-label fw-semibold">DSP firmware binary</label>
-              <input class="form-control" type="file" id="binFile" accept=".bin">
-              <div class="form-text">Export from SigmaStudio: <em>Action &rarr; Export System Files</em></div>
+              <input class="form-control" type="file" id="binFile" accept=".bin,.hex">
+              <div class="form-text">
+                SigmaStudio: <em>Action &rarr; Export System Files</em> &rarr; upload the <strong>.hex</strong> file.<br>
+                Raw binary <strong>.bin</strong> files are also accepted.
+              </div>
             </div>
             <div class="mb-3 form-check">
               <input class="form-check-input" type="checkbox" id="verifyChk" checked>
@@ -332,16 +335,40 @@ function toggleGpioPin(pin) {
 fetchGpio();
 setInterval(fetchGpio, 5000);
 
+function parseSigmaHex(text) {
+  var matches = text.match(/0x[0-9A-Fa-f]{2}/g);
+  if (!matches || matches.length === 0) return null;
+  var bytes = new Uint8Array(matches.length);
+  for (var i = 0; i < matches.length; i++) bytes[i] = parseInt(matches[i], 16);
+  return bytes;
+}
+
 function startUpload() {
   var fileInput = document.getElementById('binFile');
   if (!fileInput.files || !fileInput.files.length) {
-    alert('Please select a firmware binary (.bin) first.');
+    alert('Please select a .hex or .bin file first.');
     return;
   }
   var file = fileInput.files[0];
+  var ext = file.name.split('.').pop().toLowerCase();
+
+  if (ext === 'hex') {
+    var reader = new FileReader();
+    reader.onload = function(e) {
+      var bytes = parseSigmaHex(e.target.result);
+      if (!bytes) { alert('Could not parse .hex file — unexpected format.'); return; }
+      doUpload(new Blob([bytes], {type: 'application/octet-stream'}), file.name);
+    };
+    reader.readAsText(file);
+  } else {
+    doUpload(file, file.name);
+  }
+}
+
+function doUpload(blob, name) {
   var formData = new FormData();
   if (document.getElementById('verifyChk').checked) formData.append('verify', '1');
-  formData.append('bin', file, file.name);
+  formData.append('bin', blob, name);
 
   document.getElementById('uploadBtn').disabled = true;
   document.getElementById('uploadProgress').style.display = 'block';