Improve error handling, ensure robust defaults, and eliminate unsafe unwraps/expectations across modules.
This commit is contained in:
@@ -33,7 +33,8 @@ impl<'a> TankSensor<'a> {
|
||||
one_wire_pin.apply_output_config(&OutputConfig::default().with_pull(Pull::None));
|
||||
|
||||
let mut adc1_config = AdcConfig::new();
|
||||
let tank_pin = adc1_config.enable_pin_with_cal::<_, AdcCalLine<_>>(gpio5, Attenuation::_11dB);
|
||||
let tank_pin =
|
||||
adc1_config.enable_pin_with_cal::<_, AdcCalLine<_>>(gpio5, Attenuation::_11dB);
|
||||
let tank_channel = Adc::new(adc1, adc1_config);
|
||||
|
||||
let one_wire_bus = OneWire::new(one_wire_pin, false);
|
||||
@@ -141,12 +142,17 @@ impl<'a> TankSensor<'a> {
|
||||
let value = self.tank_channel.read_oneshot(&mut self.tank_pin);
|
||||
//force yield
|
||||
Timer::after_millis(10).await;
|
||||
*sample = value.unwrap();
|
||||
match value {
|
||||
Ok(v) => *sample = v,
|
||||
Err(e) => {
|
||||
bail!("ADC Hardware error: {:?}", e);
|
||||
}
|
||||
};
|
||||
}
|
||||
self.tank_power.set_low();
|
||||
|
||||
store.sort();
|
||||
let median_mv = store[TANK_MULTI_SAMPLE / 2] as f32;
|
||||
Ok(median_mv/1000.0)
|
||||
Ok(median_mv / 1000.0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user