forked from M-Labs/thermostat
clippy
This commit is contained in:
parent
b44892a7f5
commit
45412cd504
@ -199,7 +199,7 @@ impl<SPI: Transfer<u8, Error = E>, NSS: OutputPin, E: fmt::Debug> Adc<SPI, NSS>
|
|||||||
ChecksumMode::Crc => ChecksumMode::Crc,
|
ChecksumMode::Crc => ChecksumMode::Crc,
|
||||||
});
|
});
|
||||||
checksum.feed(&[address]);
|
checksum.feed(&[address]);
|
||||||
checksum.feed(®_data);
|
checksum.feed(reg_data);
|
||||||
let checksum_out = checksum.result();
|
let checksum_out = checksum.result();
|
||||||
|
|
||||||
let mut data = reg_data.clone();
|
let mut data = reg_data.clone();
|
||||||
|
@ -113,8 +113,7 @@ impl<'a> Channels<'a> {
|
|||||||
let center_point = self.get_center(channel);
|
let center_point = self.get_center(channel);
|
||||||
let r_sense = ElectricalResistance::new::<ohm>(R_SENSE);
|
let r_sense = ElectricalResistance::new::<ohm>(R_SENSE);
|
||||||
let voltage = self.get_dac(channel);
|
let voltage = self.get_dac(channel);
|
||||||
let i_tec = (voltage - center_point) / (10.0 * r_sense);
|
(voltage - center_point) / (10.0 * r_sense)
|
||||||
i_tec
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// i_set DAC
|
/// i_set DAC
|
||||||
@ -131,7 +130,7 @@ impl<'a> Channels<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_i(&mut self, channel: usize, i_tec: ElectricCurrent) -> ElectricCurrent {
|
pub fn set_i(&mut self, channel: usize, i_tec: ElectricCurrent) -> ElectricCurrent {
|
||||||
let vref_meas = match channel.into() {
|
let vref_meas = match channel {
|
||||||
0 => self.channel0.vref_meas,
|
0 => self.channel0.vref_meas,
|
||||||
1 => self.channel1.vref_meas,
|
1 => self.channel1.vref_meas,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
@ -140,8 +139,7 @@ impl<'a> Channels<'a> {
|
|||||||
let r_sense = ElectricalResistance::new::<ohm>(R_SENSE);
|
let r_sense = ElectricalResistance::new::<ohm>(R_SENSE);
|
||||||
let voltage = i_tec * 10.0 * r_sense + center_point;
|
let voltage = i_tec * 10.0 * r_sense + center_point;
|
||||||
let voltage = self.set_dac(channel, voltage);
|
let voltage = self.set_dac(channel, voltage);
|
||||||
let i_tec = (voltage - center_point) / (10.0 * r_sense);
|
(voltage - center_point) / (10.0 * r_sense)
|
||||||
i_tec
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_dac_feedback(&mut self, channel: usize) -> ElectricPotential {
|
pub fn read_dac_feedback(&mut self, channel: usize) -> ElectricPotential {
|
||||||
@ -268,9 +266,9 @@ impl<'a> Channels<'a> {
|
|||||||
let samples = 50;
|
let samples = 50;
|
||||||
let mut target_voltage = ElectricPotential::new::<volt>(0.0);
|
let mut target_voltage = ElectricPotential::new::<volt>(0.0);
|
||||||
for _ in 0..samples {
|
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 start_value = 1;
|
||||||
let mut best_error = ElectricPotential::new::<volt>(100.0);
|
let mut best_error = ElectricPotential::new::<volt>(100.0);
|
||||||
|
|
||||||
|
@ -35,9 +35,9 @@ pub enum Handler {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
ReportError,
|
Report,
|
||||||
PostFilterRateError,
|
PostFilterRate,
|
||||||
FlashError,
|
Flash,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type JsonBuffer = Vec<u8, U1024>;
|
pub type JsonBuffer = Vec<u8, U1024>;
|
||||||
@ -54,7 +54,7 @@ fn send_line(socket: &mut TcpSocket, data: &[u8]) -> bool {
|
|||||||
data.len(),
|
data.len(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
match socket.send_slice(&data) {
|
match socket.send_slice(data) {
|
||||||
Ok(sent) if sent == data.len() => {
|
Ok(sent) if sent == data.len() => {
|
||||||
let _ = socket.send_slice(b"\n");
|
let _ = socket.send_slice(b"\n");
|
||||||
// success
|
// success
|
||||||
@ -87,7 +87,7 @@ impl Handler {
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("unable to serialize report: {:?}", e);
|
error!("unable to serialize report: {:?}", e);
|
||||||
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
||||||
return Err(Error::ReportError);
|
return Err(Error::Report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Handler::Handled)
|
Ok(Handler::Handled)
|
||||||
@ -101,7 +101,7 @@ impl Handler {
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("unable to serialize pid summary: {:?}", e);
|
error!("unable to serialize pid summary: {:?}", e);
|
||||||
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
||||||
return Err(Error::ReportError);
|
return Err(Error::Report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Handler::Handled)
|
Ok(Handler::Handled)
|
||||||
@ -115,7 +115,7 @@ impl Handler {
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("unable to serialize pwm summary: {:?}", e);
|
error!("unable to serialize pwm summary: {:?}", e);
|
||||||
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
||||||
return Err(Error::ReportError);
|
return Err(Error::Report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Handler::Handled)
|
Ok(Handler::Handled)
|
||||||
@ -132,7 +132,7 @@ impl Handler {
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("unable to serialize steinhart-hart summaries: {:?}", e);
|
error!("unable to serialize steinhart-hart summaries: {:?}", e);
|
||||||
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
||||||
return Err(Error::ReportError);
|
return Err(Error::Report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Handler::Handled)
|
Ok(Handler::Handled)
|
||||||
@ -146,7 +146,7 @@ impl Handler {
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("unable to serialize postfilter summary: {:?}", e);
|
error!("unable to serialize postfilter summary: {:?}", e);
|
||||||
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
||||||
return Err(Error::ReportError);
|
return Err(Error::Report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Handler::Handled)
|
Ok(Handler::Handled)
|
||||||
@ -287,7 +287,7 @@ impl Handler {
|
|||||||
socket,
|
socket,
|
||||||
b"{{\"error\": \"unable to choose postfilter rate\"}}",
|
b"{{\"error\": \"unable to choose postfilter rate\"}}",
|
||||||
);
|
);
|
||||||
return Err(Error::PostFilterRateError);
|
return Err(Error::PostFilterRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Handler::Handled)
|
Ok(Handler::Handled)
|
||||||
@ -313,7 +313,7 @@ impl Handler {
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("unable to load config from flash: {:?}", e);
|
error!("unable to load config from flash: {:?}", e);
|
||||||
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
||||||
return Err(Error::FlashError);
|
return Err(Error::Flash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -338,7 +338,7 @@ impl Handler {
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("unable to save channel {} config to flash: {:?}", c, e);
|
error!("unable to save channel {} config to flash: {:?}", c, e);
|
||||||
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
||||||
return Err(Error::FlashError);
|
return Err(Error::Flash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -409,7 +409,7 @@ impl Handler {
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("unable to serialize fan summary: {:?}", e);
|
error!("unable to serialize fan summary: {:?}", e);
|
||||||
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
||||||
Err(Error::ReportError)
|
Err(Error::Report)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -458,7 +458,7 @@ impl Handler {
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("unable to serialize HWRev summary: {:?}", e);
|
error!("unable to serialize HWRev summary: {:?}", e);
|
||||||
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
||||||
Err(Error::ReportError)
|
Err(Error::Report)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ fn unsigned(input: &[u8]) -> IResult<&[u8], Result<u32, Error>> {
|
|||||||
fn float(input: &[u8]) -> IResult<&[u8], Result<f64, Error>> {
|
fn float(input: &[u8]) -> IResult<&[u8], Result<f64, Error>> {
|
||||||
let (input, sign) = opt(is_a("-"))(input)?;
|
let (input, sign) = opt(is_a("-"))(input)?;
|
||||||
let negative = sign.is_some();
|
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)
|
let result = from_utf8(digits)
|
||||||
.map_err(|e| e.into())
|
.map_err(|e| e.into())
|
||||||
.and_then(|digits| f64::from_str_radix(digits, 10).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 {
|
impl Command {
|
||||||
pub fn parse(input: &[u8]) -> Result<Self, Error> {
|
pub fn parse(input: &[u8]) -> Result<Self, Error> {
|
||||||
match command(input) {
|
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])),
|
Ok((input_remain, _)) => Err(Error::UnexpectedInput(input_remain[0])),
|
||||||
Err(e) => Err(e.into()),
|
Err(e) => Err(e.into()),
|
||||||
}
|
}
|
||||||
|
@ -101,9 +101,7 @@ impl FanCtrl {
|
|||||||
return 0f32;
|
return 0f32;
|
||||||
}
|
}
|
||||||
let fan = self.fan.as_mut().unwrap();
|
let fan = self.fan.as_mut().unwrap();
|
||||||
let fan_pwm = fan_pwm
|
let fan_pwm = fan_pwm.clamp(MIN_USER_FAN_PWM as u32, MAX_USER_FAN_PWM as u32);
|
||||||
.min(MAX_USER_FAN_PWM as u32)
|
|
||||||
.max(MIN_USER_FAN_PWM as u32);
|
|
||||||
let duty = scale_number(
|
let duty = scale_number(
|
||||||
fan_pwm as f32,
|
fan_pwm as f32,
|
||||||
self.hw_settings.min_fan_pwm,
|
self.hw_settings.min_fan_pwm,
|
||||||
|
@ -74,7 +74,7 @@ fn send_line(socket: &mut TcpSocket, data: &[u8]) -> bool {
|
|||||||
data.len(),
|
data.len(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
match socket.send_slice(&data) {
|
match socket.send_slice(data) {
|
||||||
Ok(sent) if sent == data.len() => {
|
Ok(sent) if sent == data.len() => {
|
||||||
let _ = socket.send_slice(b"\n");
|
let _ = socket.send_slice(b"\n");
|
||||||
// success
|
// success
|
||||||
@ -280,10 +280,10 @@ fn main() -> ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply new IPv4 address/gateway
|
// Apply new IPv4 address/gateway
|
||||||
new_ipv4_config.take().map(|config| {
|
if let Some(config) = new_ipv4_config.take() {
|
||||||
server.set_ipv4_config(config.clone());
|
server.set_ipv4_config(config.clone());
|
||||||
ipv4_config = config;
|
ipv4_config = config;
|
||||||
});
|
}
|
||||||
|
|
||||||
// Update watchdog
|
// Update watchdog
|
||||||
wd.feed();
|
wd.feed();
|
||||||
|
@ -39,7 +39,7 @@ pub struct Controller {
|
|||||||
impl Controller {
|
impl Controller {
|
||||||
pub const fn new(parameters: Parameters) -> Controller {
|
pub const fn new(parameters: Parameters) -> Controller {
|
||||||
Controller {
|
Controller {
|
||||||
parameters: parameters,
|
parameters,
|
||||||
target: 0.0,
|
target: 0.0,
|
||||||
u1: 0.0,
|
u1: 0.0,
|
||||||
x1: 0.0,
|
x1: 0.0,
|
||||||
|
@ -170,7 +170,7 @@ impl Pins {
|
|||||||
|
|
||||||
let (dac0_spi, dac0_sync) = Self::setup_dac0(clocks, spi4, gpioe.pe2, gpioe.pe4, gpioe.pe6);
|
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 mut shdn0 = gpioe.pe10.into_push_pull_output();
|
||||||
let _ = shdn0.set_low();
|
shdn0.set_low();
|
||||||
let vref0_pin = gpioa.pa0.into_analog();
|
let vref0_pin = gpioa.pa0.into_analog();
|
||||||
let itec0_pin = gpioa.pa6.into_analog();
|
let itec0_pin = gpioa.pa6.into_analog();
|
||||||
let dac_feedback0_pin = gpioa.pa4.into_analog();
|
let dac_feedback0_pin = gpioa.pa4.into_analog();
|
||||||
@ -187,7 +187,7 @@ impl Pins {
|
|||||||
|
|
||||||
let (dac1_spi, dac1_sync) = Self::setup_dac1(clocks, spi5, gpiof.pf7, gpiof.pf6, gpiof.pf9);
|
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 mut shdn1 = gpioe.pe15.into_push_pull_output();
|
||||||
let _ = shdn1.set_low();
|
shdn1.set_low();
|
||||||
let vref1_pin = gpioa.pa3.into_analog();
|
let vref1_pin = gpioa.pa3.into_analog();
|
||||||
let itec1_pin = gpiob.pb0.into_analog();
|
let itec1_pin = gpiob.pb0.into_analog();
|
||||||
let dac_feedback1_pin = gpioa.pa5.into_analog();
|
let dac_feedback1_pin = gpioa.pa5.into_analog();
|
||||||
|
@ -103,15 +103,10 @@ impl<'a, 'b, S: Default> Server<'a, 'b, S> {
|
|||||||
fn set_ipv4_address(&mut self, ipv4_address: Ipv4Cidr) {
|
fn set_ipv4_address(&mut self, ipv4_address: Ipv4Cidr) {
|
||||||
self.net.update_ip_addrs(|addrs| {
|
self.net.update_ip_addrs(|addrs| {
|
||||||
for addr in addrs.iter_mut() {
|
for addr in addrs.iter_mut() {
|
||||||
match addr {
|
if let IpCidr::Ipv4(_) = addr {
|
||||||
IpCidr::Ipv4(_) => {
|
*addr = IpCidr::Ipv4(ipv4_address);
|
||||||
*addr = IpCidr::Ipv4(ipv4_address);
|
// done
|
||||||
// done
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
// skip
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -96,7 +96,7 @@ impl Session {
|
|||||||
self.report_pending.iter().enumerate().fold(
|
self.report_pending.iter().enumerate().fold(
|
||||||
None,
|
None,
|
||||||
|result, (channel, report_pending)| {
|
|result, (channel, report_pending)| {
|
||||||
result.or_else(|| if *report_pending { Some(channel) } else { None })
|
result.or(if *report_pending { Some(channel) } else { None })
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -111,18 +111,12 @@ impl Session {
|
|||||||
for (i, b) in buf.iter().enumerate() {
|
for (i, b) in buf.iter().enumerate() {
|
||||||
buf_bytes = i + 1;
|
buf_bytes = i + 1;
|
||||||
let line = self.reader.feed(*b);
|
let line = self.reader.feed(*b);
|
||||||
match line {
|
if let Some(line) = line {
|
||||||
Some(line) => {
|
let command = Command::parse(line);
|
||||||
let command = Command::parse(&line);
|
if let Ok(Command::Reporting(reporting)) = command {
|
||||||
match command {
|
self.reporting = reporting;
|
||||||
Ok(Command::Reporting(reporting)) => {
|
|
||||||
self.reporting = reporting;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
return (buf_bytes, command.into());
|
|
||||||
}
|
}
|
||||||
None => {}
|
return (buf_bytes, command.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(buf_bytes, SessionInput::Nothing)
|
(buf_bytes, SessionInput::Nothing)
|
||||||
|
Loading…
Reference in New Issue
Block a user