diff --git a/docs/project-state.md b/docs/project-state.md index 3132312..430fd99 100644 --- a/docs/project-state.md +++ b/docs/project-state.md @@ -163,4 +163,4 @@ Examples: 5. Add config backup/restore. 6. Improve BMS out-of-range behavior without changing NimBLE connect timeout. -- Fixed WebUI temperature probe scan by registering `/temps/scan`, `/temps/assign`, and `/temps/clear` firmware routes.\n\n- Added per-temperature-sensor `weather` flag and WebUI outside temperature badge with emoji thresholds: below 50°F ice, 50-74°F happy, 75-84°F sun, and 85°F+ fire.\n\n- Improved WebUI temperature sensor config checkbox layout with compact On/Weather controls.\n\n- Temperature probe assignment now enforces one logical slot per physical DS18B20 address; assigning a probe to a new slot clears the old slot mapping.\n\n- Added per-slot WebUI Clear buttons for temperature probe assignments using the existing `/temps/clear` API.\n\n- Fixed weather temp checkbox persistence by saving the `weather` flag from WebUI temp config and auto-saving checkbox changes.\n\n- Fixed temperature assignment clearing so Clear removes the stored DS18B20 address, disables the slot, clears weather flag, and resets cached temp state.\n\n- Hardened `/temps/clear` so clearing a temp slot removes the persisted DS18B20 address, disables the slot, clears weather flag, resets cached temp state, and supports clearing all slots with an empty POST body.\n\n- Removed legacy physical-scan-order fallback for unassigned DS18B20 slots; enabled slots now require an explicit assigned address before reporting a value.\n \ No newline at end of file +- Fixed WebUI temperature probe scan by registering `/temps/scan`, `/temps/assign`, and `/temps/clear` firmware routes.\n\n- Added per-temperature-sensor `weather` flag and WebUI outside temperature badge with emoji thresholds: below 50°F ice, 50-74°F happy, 75-84°F sun, and 85°F+ fire.\n\n- Improved WebUI temperature sensor config checkbox layout with compact On/Weather controls.\n\n- Temperature probe assignment now enforces one logical slot per physical DS18B20 address; assigning a probe to a new slot clears the old slot mapping.\n\n- Added per-slot WebUI Clear buttons for temperature probe assignments using the existing `/temps/clear` API.\n\n- Fixed weather temp checkbox persistence by saving the `weather` flag from WebUI temp config and auto-saving checkbox changes.\n\n- Fixed temperature assignment clearing so Clear removes the stored DS18B20 address, disables the slot, clears weather flag, and resets cached temp state.\n\n- Hardened `/temps/clear` so clearing a temp slot removes the persisted DS18B20 address, disables the slot, clears weather flag, resets cached temp state, and supports clearing all slots with an empty POST body.\n\n- Removed legacy physical-scan-order fallback for unassigned DS18B20 slots; enabled slots now require an explicit assigned address before reporting a value.\n\n- Filtered DS18B20 scan results so already-assigned probe addresses are hidden until cleared from their configured temp slot.\n \ No newline at end of file diff --git a/firmware/esp32/overland-controller/sensors.cpp b/firmware/esp32/overland-controller/sensors.cpp index 921c0c4..e1e7a71 100644 --- a/firmware/esp32/overland-controller/sensors.cpp +++ b/firmware/esp32/overland-controller/sensors.cpp @@ -52,6 +52,26 @@ bool addressMatches(DeviceAddress address, const String& expected) { return actual == normalizedExpected; } +bool isTempAddressAssigned(const String& address) { + if (address.length() == 0) { + return false; + } + + String normalizedAddress = address; + normalizedAddress.toUpperCase(); + + for (int i = 0; i < MAX_TEMP_SENSORS; i++) { + String assigned = appConfig.tempSensors[i].address; + assigned.toUpperCase(); + + if (assigned == normalizedAddress) { + return true; + } + } + + return false; +} + void clearSensorRuntimeData() { for (int i = 0; i < MAX_TEMP_SENSORS; i++) { sensors.tempsF[i] = -127.0; @@ -72,12 +92,28 @@ int scanTempSensors() { sensorAddressStrings[i] = ""; } + int availableCount = 0; + for (int i = 0; i < sensorCount; i++) { - if (ds18b20.getAddress(sensorAddresses[i], i)) { - sensorAddressStrings[i] = addressToString(sensorAddresses[i]); + DeviceAddress address; + + if (!ds18b20.getAddress(address, i)) { + continue; } + + String addressString = addressToString(address); + + if (isTempAddressAssigned(addressString)) { + continue; + } + + memcpy(sensorAddresses[availableCount], address, 8); + sensorAddressStrings[availableCount] = addressString; + availableCount++; } + sensorCount = availableCount; + return sensorCount; }