From a1a80276c91d37a8b87b5d97404af6edb556f2e1 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Mon, 30 Dec 2024 15:16:04 +1100 Subject: [PATCH] ccs: clippy --- charge-controller-supervisor/src/controller.rs | 15 +++++++-------- charge-controller-supervisor/src/tristar.rs | 5 +++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/charge-controller-supervisor/src/controller.rs b/charge-controller-supervisor/src/controller.rs index f6148cf..303141b 100644 --- a/charge-controller-supervisor/src/controller.rs +++ b/charge-controller-supervisor/src/controller.rs @@ -98,14 +98,13 @@ impl Controller { &mut self, tx: Vec>, ) { - if self.voltage_rx.is_some() { - panic!( - "trying to set {} as primary when it is also a secondary!", - self.name - ); - } + assert!( + self.voltage_rx.is_none(), + "trying to set {} as primary when it is also a secondary!", + self.name + ); - self.voltage_tx = Some(MultiTx(tx)) + self.voltage_tx = Some(MultiTx(tx)); } pub fn get_rx(&mut self) -> Option<&mut tokio::sync::mpsc::UnboundedReceiver> { @@ -125,7 +124,7 @@ struct MultiTx(Vec>); impl MultiTx { fn send_to_all(&mut self, command: VoltageCommand) { - for sender in self.0.iter_mut() { + for sender in &mut self.0 { if let Err(e) = sender.send(command) { log::error!("failed to send command {command:?}: {e:?}"); } diff --git a/charge-controller-supervisor/src/tristar.rs b/charge-controller-supervisor/src/tristar.rs index d9bb6ff..0aa2140 100644 --- a/charge-controller-supervisor/src/tristar.rs +++ b/charge-controller-supervisor/src/tristar.rs @@ -41,7 +41,8 @@ impl Scaling { f64::from(data) * self.v_scale * self.i_scale * f64::powf(2., -17.) } - fn from_voltage(&self, voltage: f64) -> u16 { + #[expect(clippy::cast_sign_loss)] + fn inverse_voltage(&self, voltage: f64) -> u16 { (voltage / (self.v_scale * f64::powf(2., -15.))) as u16 } } @@ -344,7 +345,7 @@ impl Tristar { let Some(scaling) = &self.scaling else { return Err(eyre::eyre!("no scaling data present")); }; - Ok(scaling.from_voltage(voltage)) + Ok(scaling.inverse_voltage(voltage)) } async fn get_data(&mut self) -> eyre::Result {