1
0
Fork 0

Thermostat: Add default to ChannelState

This commit is contained in:
linuswck 2024-01-17 16:00:02 +08:00
parent f49fd08c69
commit d0f226ce03
1 changed files with 15 additions and 2 deletions

View File

@ -34,10 +34,17 @@ pub struct ChannelState {
} }
impl ChannelState { impl ChannelState {
pub fn new(adc_calibration: ad7172::ChannelCalibration) -> Self { fn adc_calibration(mut self, adc_calibration: ad7172::ChannelCalibration) -> Self {
self.adc_calibration = adc_calibration;
self
}
}
impl Default for ChannelState {
fn default() -> Self {
ChannelState { ChannelState {
adc_data: None, adc_data: None,
adc_calibration, adc_calibration: ad7172::ChannelCalibration::default(),
adc_time: Instant::from_secs(0), adc_time: Instant::from_secs(0),
// default: 10 Hz // default: 10 Hz
adc_interval: Duration::from_millis(100), adc_interval: Duration::from_millis(100),
@ -48,6 +55,12 @@ impl ChannelState {
sh: sh::Parameters::default(), sh: sh::Parameters::default(),
} }
} }
}
impl ChannelState {
pub fn new(adc_calibration: ad7172::ChannelCalibration) -> Self {
ChannelState::default().adc_calibration(adc_calibration)
}
pub fn update(&mut self, now: Instant, adc_data: u32) { pub fn update(&mut self, now: Instant, adc_data: u32) {
self.adc_data = if adc_data == ad7172::MAX_VALUE { self.adc_data = if adc_data == ad7172::MAX_VALUE {