diff --git a/fan-controller/src/fan.rs b/fan-controller/src/fan.rs index 6a5d829..d0813c9 100644 --- a/fan-controller/src/fan.rs +++ b/fan-controller/src/fan.rs @@ -26,12 +26,12 @@ pub(crate) fn get_configuration() -> uart::Config { pub(crate) const MAX_SET_POINT: u16 = 64_000; #[derive(Debug)] -pub(crate) struct FanSetting(u16); +pub(crate) struct Setting(u16); #[derive(Debug)] pub(crate) struct SetPointOutOfBoundsError; -impl FanSetting { +impl Setting { const ZERO: Self = Self(0); pub(crate) const fn new(set_point: u16) -> Result { if set_point > MAX_SET_POINT { @@ -88,7 +88,7 @@ impl<'a, UART: uart::Instance, PIN: Pin> Client<'a, UART, PIN> { } } - pub(crate) async fn set_set_point(&mut self, FanSetting(set_point): FanSetting) { + pub(crate) async fn set_set_point(&mut self, Setting(set_point): Setting) { // Send update through UART to MAX845 to modbus fans // Form message to fan 1 let mut message: [u8; 8] = [ diff --git a/fan-controller/src/main.rs b/fan-controller/src/main.rs index 23e074e..90a8d23 100644 --- a/fan-controller/src/main.rs +++ b/fan-controller/src/main.rs @@ -56,7 +56,6 @@ use crate::mqtt::subscribe_acknowledgement::SubscribeAcknowledgement; use crate::mqtt::task::{send, Encode}; use crate::mqtt::QualityOfService; use crate::mqtt::{connect, publish, subscribe}; -use fan::FanSetting; mod async_callback; mod configuration; @@ -368,7 +367,7 @@ async fn mqtt_task( } }; - let Ok(setting) = FanSetting::new(set_point) else { + let Ok(setting) = fan::Setting::new(set_point) else { warn!( "Setting fan speed out of bounds. Not accepting new setting: {}", set_point @@ -893,7 +892,7 @@ async fn input_task(pin_18: PIN_18) { }; // Send signal to change fan speed - let Ok(setting) = FanSetting::new(set_point) else { + let Ok(setting) = fan::Setting::new(set_point) else { warn!("Setting fan speed out of bounds. Not accepting new setting"); continue; }; @@ -958,8 +957,8 @@ mod tests { #[test] fn setting_does_not_exceed_max_set_point() { assert_eq!(fan::MAX_SET_POINT, 64_000); - assert_eq!(FanSetting::new(64_000), Ok(FanSetting(64_000))); - assert_eq!(FanSetting::new(64_000 + 1), Err(SetPointOutOfBoundsError)); - assert_eq!(FanSetting::new(u16::MAX), Err(SetPointOutOfBoundsError)); + assert_eq!(Setting::new(64_000), Ok(Setting(64_000))); + assert_eq!(Setting::new(64_000 + 1), Err(SetPointOutOfBoundsError)); + assert_eq!(Setting::new(u16::MAX), Err(SetPointOutOfBoundsError)); } }