channel_state: recognize unplugged thermistor
This commit is contained in:
parent
f690599f9e
commit
20059aff5c
|
@ -19,6 +19,8 @@ pub const SPI_MODE: spi::Mode = spi::Mode {
|
|||
/// 2 MHz
|
||||
pub const SPI_CLOCK: MegaHertz = MegaHertz(2);
|
||||
|
||||
pub const MAX_VALUE: u32 = 0xFF_FFFF;
|
||||
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[repr(u8)]
|
||||
|
|
|
@ -63,7 +63,13 @@ impl ChannelState {
|
|||
}
|
||||
|
||||
pub fn get_adc(&self) -> Option<ElectricPotential> {
|
||||
Some(self.adc_calibration.convert_data(self.adc_data?))
|
||||
let data = self.adc_data?;
|
||||
if data == ad7172::MAX_VALUE {
|
||||
// this means there is no thermistor plugged into the ADC.
|
||||
None
|
||||
} else {
|
||||
Some(self.adc_calibration.convert_data(data))
|
||||
}
|
||||
}
|
||||
|
||||
/// Get `SENS[01]` input resistance
|
||||
|
|
|
@ -182,10 +182,10 @@ fn main() -> ! {
|
|||
|
||||
let state = channels.channel_state(channel);
|
||||
let _ = writeln!(
|
||||
socket, "channel {}: t={:.0} adc{}={:.3} adc_r={:.3} vref={:.3} dac_feedback={:.3} itec={:.3} tec={:.3} tec_u_meas={:.3} r={:.3}",
|
||||
socket, "channel {}: t={:.0} adc{}={:.3} adc_r={:?} vref={:.3} dac_feedback={:.3} itec={:.3} tec={:.3} tec_u_meas={:.3} r={:.3}",
|
||||
channel, state.adc_time,
|
||||
channel, adc_input.into_format_args(volt, Abbreviation),
|
||||
state.get_sens().unwrap().into_format_args(ohm, Abbreviation),
|
||||
state.get_sens().map(|sens| sens.into_format_args(ohm, Abbreviation)),
|
||||
vref.into_format_args(volt, Abbreviation), dac_feedback.into_format_args(volt, Abbreviation),
|
||||
itec.into_format_args(volt, Abbreviation), tec_i.into_format_args(ampere, Abbreviation),
|
||||
tec_u_meas.into_format_args(volt, Abbreviation),
|
||||
|
|
Loading…
Reference in New Issue