Switch to a library and move main to an example

This commit is contained in:
Robert Sammelson 2023-05-14 23:07:54 -04:00
parent 559fbbaa12
commit 2a43bf94bd
No known key found for this signature in database
GPG key ID: 92F1F04EDB06B9E9
9 changed files with 21 additions and 389 deletions

28
examples/basic/main.rs Normal file
View file

@ -0,0 +1,28 @@
use obd2::Obd2Device;
use std::time;
fn main() {
env_logger::init();
let mut device: obd2::Obd2<obd2::device::Elm327> = obd2::Obd2::default();
println!("VIN: {:?}", device.get_vin());
println!("DTC Info: {:#?}", device.get_dtc_info());
let dtcs = device.get_dtcs();
println!("DTCs: {:?}", dtcs);
if let Ok(dtcs) = dtcs {
for (i, response) in dtcs.iter().enumerate() {
println!("DTCs from response {}:", i);
for dtc in response {
println!(" - {}", dtc);
}
}
}
let state = time::Instant::now();
while state.elapsed() < time::Duration::from_secs(5) {
println!("RPM: {:?}", device.get_rpm());
println!("Speed: {:?}", device.get_speed());
}
}