Forráskód Böngészése

Fixing i2cReadBloc

Benjamin Harris 1 hónapja
szülő
commit
c8f7b70d78
3 módosított fájl, 4 hozzáadás és 19 törlés
  1. 4 4
      ModulosDSP_101.ino
  2. 0 12
      ota_html.h
  3. 0 3
      params_html.h

+ 4 - 4
ModulosDSP_101.ino

@@ -189,13 +189,13 @@ static bool eepromWriteBlock(uint16_t memAddr, const uint8_t* data, uint16_t len
 
 static bool i2cReadBlock(uint8_t addr7, uint16_t memAddr, uint8_t* out, uint16_t len)
 {
-  Wire.beginTransmission(addr7);
-  Wire.write((uint8_t)(memAddr >> 8));
-  Wire.write((uint8_t)(memAddr & 0xFF));
-  if (Wire.endTransmission(false) != 0) return false;
   uint16_t got = 0;
   while (got < len) {
     uint8_t ask = (len - got) > 32 ? 32 : (len - got);
+    Wire.beginTransmission(addr7);
+    Wire.write((uint8_t)((memAddr + got) >> 8));
+    Wire.write((uint8_t)((memAddr + got) & 0xFF));
+    if (Wire.endTransmission(false) != 0) return false;
     if (Wire.requestFrom((int)addr7, (int)ask) != ask) return false;
     for (uint8_t i = 0; i < ask; i++) out[got++] = Wire.read();
   }

+ 0 - 12
ota_html.h

@@ -10,7 +10,6 @@ static const char OTA_HTML[] PROGMEM = R"HTML(
   <link rel="icon" type="image/x-icon" href="/favicon.ico">
   <link rel="stylesheet" href="yeti-bootstrap.min.css">
   <link rel="stylesheet" href="font-awesome.min.css">
-
   <title>Modulos DSP - Firmware Update</title>
   <style>
     body { padding-top: 40px; }
@@ -21,10 +20,8 @@ static const char OTA_HTML[] PROGMEM = R"HTML(
 </head>
 <body>
 <div class="container ota-card">
-
   <h4 class="mb-1"><i class="fa fa-upload"></i> Firmware Update</h4>
   <p class="text-muted small mb-3">Device: <strong>{{IP}}</strong></p>
-
   <form id="otaForm" action="/ota_do" method="POST" enctype="multipart/form-data">
     <div class="mb-3">
       <label class="form-label fw-semibold">Firmware binary (.bin)</label>
@@ -35,7 +32,6 @@ static const char OTA_HTML[] PROGMEM = R"HTML(
       <i class="fa fa-upload"></i>&nbsp; Flash Firmware
     </button>
   </form>
-
   <div id="progressWrap">
     <div class="progress" style="height:22px">
       <div class="progress-bar progress-bar-striped progress-bar-animated bg-warning"
@@ -48,27 +44,21 @@ static const char OTA_HTML[] PROGMEM = R"HTML(
       Do not power off the device.
     </p>
   </div>
-
   <div id="resultBox" class="alert" role="alert"></div>
-
   <hr class="mt-4">
   <a href="/" class="text-muted small"><i class="fa fa-arrow-left"></i> Back to Device Management</a>
 </div>
-
 <script>
 document.getElementById('otaForm').addEventListener('submit', function(e) {
   e.preventDefault();
   var file = document.getElementById('fwFile').files[0];
   if (!file) return;
-
   document.getElementById('flashBtn').disabled = true;
   document.getElementById('progressWrap').style.display = 'block';
   document.getElementById('resultBox').style.display = 'none';
-
   var fd = new FormData(this);
   var xhr = new XMLHttpRequest();
   xhr.open('POST', '/ota_do', true);
-
   xhr.onload = function() {
     document.getElementById('progressWrap').style.display = 'none';
     var box = document.getElementById('resultBox');
@@ -84,7 +74,6 @@ document.getElementById('otaForm').addEventListener('submit', function(e) {
       document.getElementById('flashBtn').disabled = false;
     }
   };
-
   xhr.onerror = function() {
     document.getElementById('progressWrap').style.display = 'none';
     var box = document.getElementById('resultBox');
@@ -93,7 +82,6 @@ document.getElementById('otaForm').addEventListener('submit', function(e) {
     box.innerHTML = '<i class="fa fa-times-circle"></i> Upload error — check Serial log.';
     document.getElementById('flashBtn').disabled = false;
   };
-
   xhr.send(fd);
 });
 </script>

+ 0 - 3
params_html.h

@@ -11,7 +11,6 @@ static const char PARAMS_HTML[] PROGMEM = R"HTML(
   <link rel="stylesheet" href="yeti-bootstrap.min.css">
   <link rel="stylesheet" href="font-awesome.min.css">
   <script src="jquery-3.7.1.slim.min.js" crossorigin="anonymous"></script>
-
   <title>Modulos DSP - Parameter Tuner</title>
   <style>
     @font-face {
@@ -24,7 +23,6 @@ static const char PARAMS_HTML[] PROGMEM = R"HTML(
     td.val-cell { line-height: 1.3; font-size: 0.85rem; }
   </style>
 </head>
-
 <body class="bg-light" style="padding-top: 5rem;">
   <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
     <div class="container">
@@ -43,7 +41,6 @@ static const char PARAMS_HTML[] PROGMEM = R"HTML(
       </div>
     </div>
   </nav>
-
   <div class="container pb-5">
     <div class="row mb-2">
       <div class="col">