From 27d3a097038727eb3d3b445532667942f5e3204e Mon Sep 17 00:00:00 2001 From: kounocom <71262281+kounocom@users.noreply.github.com> Date: Sun, 19 Jan 2025 08:58:42 +0200 Subject: [PATCH] More cleanup --- lib/i2cscan/i2cscan.cpp | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/i2cscan/i2cscan.cpp b/lib/i2cscan/i2cscan.cpp index 0b67f376..ae6f0326 100644 --- a/lib/i2cscan/i2cscan.cpp +++ b/lib/i2cscan/i2cscan.cpp @@ -65,10 +65,8 @@ namespace I2CSCAN Wire.end(); #endif // Select next port - currentSCL++; if (currentSCL >= validPorts.size()) { currentSCL = 0; - currentSDA++; if (currentSDA >= validPorts.size()) { scanState = ScanState::DONE; return; @@ -97,29 +95,26 @@ namespace I2CSCAN currentAddress++; if (currentAddress >= 127) { currentAddress = 1; - while (true) { - // Select next port - currentSCL++; - if (currentSCL >= validPorts.size()) { - currentSCL = 0; - currentSDA++; - if (currentSDA >= validPorts.size()) { - if (!found) { - Serial.println("[ERR] I2C: No I2C devices found"); - } + // Select next port + currentSCL++; + if (currentSCL >= validPorts.size()) { + currentSCL = 0; + currentSDA++; + if (currentSDA >= validPorts.size()) { + if (!found) { + Serial.println("[ERR] I2C: No I2C devices found"); + } #if ESP32 - Wire.end(); + Wire.end(); #endif - Wire.begin(static_cast(PIN_IMU_SDA), static_cast(PIN_IMU_SCL)); - scanState = ScanState::DONE; - return; - } + Wire.begin(static_cast(PIN_IMU_SDA), static_cast(PIN_IMU_SCL)); + scanState = ScanState::DONE; + return; } - - // Check port - Wire.begin((int)validPorts[currentSDA], (int)validPorts[currentSCL]); - break; } + + // Check port + Wire.begin((int)validPorts[currentSDA], (int)validPorts[currentSCL]); } }