ran rustfmt

This commit is contained in:
Nicholas Orlowsky 2025-03-18 21:42:10 -04:00
parent e0b5bab35a
commit fde9f2f408
8 changed files with 30 additions and 47 deletions

View file

@ -4,11 +4,8 @@ use std::time;
fn main() -> Result<(), obd2::Error> {
env_logger::init();
let mut device: obd2::Obd2<obd2::device::Elm327<obd2::device::FTDIDevice>> = obd2::Obd2::new(
obd2::device::Elm327::new(
obd2::device::FTDIDevice::new()?
)?
)?;
let mut device: obd2::Obd2<obd2::device::Elm327<obd2::device::FTDIDevice>> =
obd2::Obd2::new(obd2::device::Elm327::new(obd2::device::FTDIDevice::new()?)?)?;
println!("VIN: {:?}", device.get_vin());
for s in device.get_service_1_pid_support_1()?.iter() {

View file

@ -1,10 +1,7 @@
use log::{debug, info, trace};
use std::{
collections::VecDeque,
thread, time,
};
use std::{collections::VecDeque, thread, time};
use super::{Error, Obd2BaseDevice, Obd2Reader, Result, serial_comm::SerialComm};
use super::{serial_comm::SerialComm, Error, Obd2BaseDevice, Obd2Reader, Result};
/// An ELM327 OBD-II adapter
///
@ -111,9 +108,7 @@ impl<T: SerialComm> Elm327<T> {
let response = self.get_response()?;
debug!(
"reset_ic: got response {:?}",
response
.as_ref()
.map(|l| std::str::from_utf8(l.as_slice()))
response.as_ref().map(|l| std::str::from_utf8(l.as_slice()))
);
Ok(())
}
@ -121,16 +116,10 @@ impl<T: SerialComm> Elm327<T> {
fn reset_protocol(&mut self) -> Result<()> {
info!("Performing protocol reset");
let elm_response = self.serial_cmd("ATSP0")?;
debug!(
"reset_protocol: got response {:?}",
elm_response
);
debug!("reset_protocol: got response {:?}", elm_response);
let obd_response = self.cmd(&[0x01, 0x00])?;
debug!(
"reset_protocol: got OBD response {:?}",
obd_response
);
debug!("reset_protocol: got OBD response {:?}", obd_response);
self.flush_buffers()?;
Ok(())

View file

@ -4,7 +4,7 @@ mod elm327;
pub use elm327::Elm327;
mod serial_comm;
pub use serial_comm::{SerialPort, FTDIDevice};
pub use serial_comm::{FTDIDevice, SerialPort};
type Result<T> = std::result::Result<T, Error>;

View file

@ -1,6 +1,6 @@
use std::time::Duration;
use super::Result;
use std::io::{Read, Write};
use std::time::Duration;
const DEFAULT_BAUD_RATE: u32 = 38_400;
@ -18,7 +18,7 @@ pub trait SerialComm {
/// /dev/tty* or similar on unix-like systems
/// COM devices on Windows systems
pub struct SerialPort {
device: Box<dyn serialport::SerialPort>
device: Box<dyn serialport::SerialPort>,
}
impl SerialPort {
@ -57,7 +57,7 @@ impl SerialComm for SerialPort {
/// Communicate with a USB to Serial FTDI device
/// with the FTDI library
pub struct FTDIDevice {
device: ftdi::Device
device: ftdi::Device,
}
impl FTDIDevice {
@ -92,4 +92,3 @@ impl SerialComm for FTDIDevice {
Ok(self.device.usb_purge_buffers()?)
}
}

View file

@ -42,9 +42,7 @@ impl<T: Obd2BaseDevice> Obd2Device for Obd2<T> {
impl<T: Obd2BaseDevice> Obd2<T> {
/// Creates a new instance of an Obd device
pub fn new(dev: T) -> Result<Self> {
let device = Obd2 {
device: dev
};
let device = Obd2 { device: dev };
Ok(device)
}