From ce86dc27fde366f7dca7c18f6aab1921ef923ff8 Mon Sep 17 00:00:00 2001 From: atse Date: Tue, 6 Aug 2024 12:26:55 +0800 Subject: [PATCH] clippy --- src/ad7172/adc.rs | 2 +- src/channels.rs | 10 +++++----- src/command_handler.rs | 2 +- src/command_parser.rs | 4 ++-- src/config.rs | 2 +- src/main.rs | 2 +- src/pid.rs | 2 +- src/pins.rs | 4 ++-- src/session.rs | 4 ++-- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ad7172/adc.rs b/src/ad7172/adc.rs index 6cbf561..a881078 100644 --- a/src/ad7172/adc.rs +++ b/src/ad7172/adc.rs @@ -199,7 +199,7 @@ impl, NSS: OutputPin, E: fmt::Debug> Adc ChecksumMode::Crc => ChecksumMode::Crc, }); checksum.feed(&[address]); - checksum.feed(®_data); + checksum.feed(reg_data); let checksum_out = checksum.result(); let mut data = reg_data.clone(); diff --git a/src/channels.rs b/src/channels.rs index 9f53411..a04d71d 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -158,7 +158,7 @@ impl Channels { pub fn set_i(&mut self, channel: usize, i_set: ElectricCurrent) -> ElectricCurrent { let i_set = i_set.min(MAX_TEC_I).max(-MAX_TEC_I); - let vref_meas = match channel.into() { + let vref_meas = match channel { 0 => self.channel0.vref_meas, 1 => self.channel1.vref_meas, _ => unreachable!(), @@ -193,7 +193,7 @@ impl Channels { } sample / avg_pt as u32 } - Channel0VRef::Disabled(_) => 2048 as u32, + Channel0VRef::Disabled(_) => 2048_u32, }, PinsAdcReadTarget::DacVfb => { for _ in (0..avg_pt).rev() { @@ -238,7 +238,7 @@ impl Channels { } sample / avg_pt as u32 } - Channel1VRef::Disabled(_) => 2048 as u32, + Channel1VRef::Disabled(_) => 2048_u32, }, PinsAdcReadTarget::DacVfb => { for _ in (0..avg_pt).rev() { @@ -310,9 +310,9 @@ impl Channels { let samples = 50; let mut target_voltage = ElectricPotential::new::(0.0); for _ in 0..samples { - target_voltage = target_voltage + self.get_center(channel); + target_voltage += self.get_center(channel); } - target_voltage = target_voltage / samples as f64; + target_voltage /= samples as f64; let mut start_value = 1; let mut best_error = ElectricPotential::new::(100.0); diff --git a/src/command_handler.rs b/src/command_handler.rs index 8ca97e6..f175c7c 100644 --- a/src/command_handler.rs +++ b/src/command_handler.rs @@ -54,7 +54,7 @@ fn send_line(socket: &mut TcpSocket, data: &[u8]) -> bool { data.len(), ); } else { - match socket.send_slice(&data) { + match socket.send_slice(data) { Ok(sent) if sent == data.len() => { let _ = socket.send_slice(b"\n"); // success diff --git a/src/command_parser.rs b/src/command_parser.rs index 8f9fe48..f1216ac 100644 --- a/src/command_parser.rs +++ b/src/command_parser.rs @@ -208,7 +208,7 @@ fn unsigned(input: &[u8]) -> IResult<&[u8], Result> { fn float(input: &[u8]) -> IResult<&[u8], Result> { let (input, sign) = opt(is_a("-"))(input)?; let negative = sign.is_some(); - let (input, digits) = take_while1(|c| is_digit(c) || c == '.' as u8)(input)?; + let (input, digits) = take_while1(|c| is_digit(c) || c == b'.')(input)?; let result = from_utf8(digits) .map_err(|e| e.into()) .and_then(|digits| f64::from_str_radix(digits, 10).map_err(|e| e.into())) @@ -580,7 +580,7 @@ fn command(input: &[u8]) -> IResult<&[u8], Result> { impl Command { pub fn parse(input: &[u8]) -> Result { match command(input) { - Ok((input_remain, result)) if input_remain.len() == 0 => result, + Ok((input_remain, result)) if input_remain.is_empty() => result, Ok((input_remain, _)) => Err(Error::UnexpectedInput(input_remain[0])), Err(e) => Err(e.into()), } diff --git a/src/config.rs b/src/config.rs index 35e32b1..1150d67 100644 --- a/src/config.rs +++ b/src/config.rs @@ -43,7 +43,7 @@ impl ChannelConfig { pid: state.pid.parameters.clone(), pid_target: state.pid.target as f32, pid_engaged: state.pid_engaged, - i_set: i_set, + i_set, sh: state.sh.clone(), pwm, adc_postfilter, diff --git a/src/main.rs b/src/main.rs index b08c2cc..7298c54 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,7 +74,7 @@ fn send_line(socket: &mut TcpSocket, data: &[u8]) -> bool { data.len(), ); } else { - match socket.send_slice(&data) { + match socket.send_slice(data) { Ok(sent) if sent == data.len() => { let _ = socket.send_slice(b"\n"); // success diff --git a/src/pid.rs b/src/pid.rs index 29b697a..e602805 100644 --- a/src/pid.rs +++ b/src/pid.rs @@ -39,7 +39,7 @@ pub struct Controller { impl Controller { pub const fn new(parameters: Parameters) -> Controller { Controller { - parameters: parameters, + parameters, target: 0.0, u1: 0.0, x1: 0.0, diff --git a/src/pins.rs b/src/pins.rs index 08d4030..3e98791 100644 --- a/src/pins.rs +++ b/src/pins.rs @@ -188,7 +188,7 @@ impl Pins { let (dac0_spi, dac0_sync) = Self::setup_dac0(clocks, spi4, gpioe.pe2, gpioe.pe4, gpioe.pe6); let mut shdn0 = gpioe.pe10.into_push_pull_output(); - let _ = shdn0.set_low(); + shdn0.set_low(); let vref0_pin = if hwrev.major > 2 { Channel0VRef::Analog(gpioa.pa0.into_analog()) } else { @@ -209,7 +209,7 @@ impl Pins { let (dac1_spi, dac1_sync) = Self::setup_dac1(clocks, spi5, gpiof.pf7, gpiof.pf6, gpiof.pf9); let mut shdn1 = gpioe.pe15.into_push_pull_output(); - let _ = shdn1.set_low(); + shdn1.set_low(); let vref1_pin = if hwrev.major > 2 { Channel1VRef::Analog(gpioa.pa3.into_analog()) } else { diff --git a/src/session.rs b/src/session.rs index f029fa9..fe4e5ad 100644 --- a/src/session.rs +++ b/src/session.rs @@ -96,7 +96,7 @@ impl Session { self.report_pending.iter().enumerate().fold( None, |result, (channel, report_pending)| { - result.or_else(|| if *report_pending { Some(channel) } else { None }) + result.or(if *report_pending { Some(channel) } else { None }) }, ) } @@ -113,7 +113,7 @@ impl Session { let line = self.reader.feed(*b); match line { Some(line) => { - let command = Command::parse(&line); + let command = Command::parse(line); match command { Ok(Command::Reporting(reporting)) => { self.reporting = reporting;