Skip to content

Commit 157e347

Browse files
Copilotdorkmo
andcommitted
Improve bounds validation for 4mA-20mA sensors and clarify tooltip text
Co-authored-by: dorkmo <[email protected]>
1 parent 9d97064 commit 157e347

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

TankAlarm-112025-Client-BluesOpta/TankAlarm-112025-Client-BluesOpta.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ static float readTankSensor(uint8_t idx) {
15491549
// Distance at 4mA = 0 (full), Distance at 20mA = sensorMountHeight (empty)
15501550
float distanceFromSensor = linearMap(milliamps, 4.0f, 20.0f, 0.0f, cfg.sensorMountHeight);
15511551
levelInches = cfg.sensorMountHeight - distanceFromSensor;
1552-
// Clamp to valid range
1552+
// Clamp to valid range (0 to maxValue)
15531553
if (levelInches < 0.0f) levelInches = 0.0f;
15541554
if (levelInches > cfg.maxValue) levelInches = cfg.maxValue;
15551555
} else {
@@ -1561,6 +1561,8 @@ static float readTankSensor(uint8_t idx) {
15611561
float rawLevel = linearMap(milliamps, 4.0f, 20.0f, 0.0f, cfg.maxValue);
15621562
// Add mount height offset (sensor is mounted above tank bottom)
15631563
levelInches = rawLevel + cfg.sensorMountHeight;
1564+
// Clamp to valid range (sensorMountHeight to maxValue + sensorMountHeight)
1565+
if (levelInches < cfg.sensorMountHeight) levelInches = cfg.sensorMountHeight;
15641566
}
15651567
return levelInches;
15661568
}

TankAlarm-112025-Server-BluesOpta/TankAlarm-112025-Server-BluesOpta.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ static const char CONFIG_GENERATOR_HTML[] PROGMEM = R"HTML(
11231123
mountHeightLabel.textContent = 'Sensor Mount Height (in)';
11241124
mountHeightTooltip.setAttribute('data-tooltip', 'Height of the pressure sensor above the tank bottom (usually 0-2 inches). This offset is added to the measured level.');
11251125
heightLabel.textContent = 'Max Measured Height (in)';
1126-
heightTooltip.setAttribute('data-tooltip', 'Maximum liquid height the sensor can measure (corresponds to 20mA / max PSI). Does not include the sensor mount height offset.');
1126+
heightTooltip.setAttribute('data-tooltip', 'Maximum liquid height the sensor can measure (corresponds to 20mA / full sensor scale). Does not include the sensor mount height offset.');
11271127
}
11281128
};
11291129

0 commit comments

Comments
 (0)