Skip to content

Commit

Permalink
Refactor moisture level determination logic and add unit display for …
Browse files Browse the repository at this point in the history
…raw soil moisture sensor
  • Loading branch information
psytraxx committed Feb 3, 2025
1 parent 4fa247e commit 9b319bb
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ impl From<u16> for MoistureLevel {

let value = (MOISTURE_MAX - clamped) as f32 / (MOISTURE_MAX - MOISTURE_MIN) as f32;

if value > MOISTURE_WET_THRESHOLD {
Self::Wet
} else if value < MOISTURE_DRY_THRESHOLD {
Self::Dry
} else {
Self::Moist
match value {
p if p > MOISTURE_WET_THRESHOLD => Self::Wet,
p if p < MOISTURE_DRY_THRESHOLD => Self::Dry,
_ => Self::Moist,
}
}
}
Expand Down Expand Up @@ -109,6 +107,7 @@ impl Sensor {
Sensor::AirTemperature(_) => Some("°C"),
Sensor::AirHumidity(_) => Some("%"),
Sensor::BatteryVoltage(_) => Some("mV"),
Sensor::SoilMoistureRaw(_) => Some("mV"),
_ => None,
}
}
Expand Down

0 comments on commit 9b319bb

Please sign in to comment.