This commit is contained in:
atse 2024-08-06 12:26:55 +08:00
parent a947e25e8f
commit ce86dc27fd
9 changed files with 16 additions and 16 deletions

View File

@ -199,7 +199,7 @@ impl<SPI: Transfer<u8, Error = E>, NSS: OutputPin, E: fmt::Debug> Adc<SPI, NSS>
ChecksumMode::Crc => ChecksumMode::Crc,
});
checksum.feed(&[address]);
checksum.feed(&reg_data);
checksum.feed(reg_data);
let checksum_out = checksum.result();
let mut data = reg_data.clone();

View File

@ -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::<volt>(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::<volt>(100.0);

View File

@ -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

View File

@ -208,7 +208,7 @@ fn unsigned(input: &[u8]) -> IResult<&[u8], Result<u32, Error>> {
fn float(input: &[u8]) -> IResult<&[u8], Result<f64, Error>> {
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<Command, Error>> {
impl Command {
pub fn parse(input: &[u8]) -> Result<Self, Error> {
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()),
}

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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 {

View File

@ -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;