Skip to content

Commit 50d750b

Browse files
Update scan.rs
1 parent 8293a21 commit 50d750b

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

src/bin/scan.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clap::{Parser, ValueEnum};
2-
use std::collections::HashMap;
32
use std::{error::Error, time::Duration};
43

54
use rustypot::servo::ServoKind;
@@ -29,17 +28,8 @@ fn main() -> Result<(), Box<dyn Error>> {
2928
let baudrate: u32 = args.baudrate;
3029
let protocol: ProtocolVersion = args.protocol;
3130

32-
//print the standard ids for the arm motors
31+
println!("Scanning for Dynamixel motors on {serialport} at {baudrate} baud using {protocol:?}");
3332

34-
//print all the argument values
35-
println!("serialport: {}", serialport);
36-
println!("baudrate: {}", baudrate);
37-
match protocol {
38-
ProtocolVersion::V1 => println!("protocol: V1"),
39-
ProtocolVersion::V2 => println!("protocol: V2"),
40-
}
41-
42-
let mut found = HashMap::new();
4333
println!("Scanning...");
4434
let mut serial_port = serialport::new(serialport, baudrate)
4535
.timeout(Duration::from_millis(10))
@@ -55,22 +45,15 @@ fn main() -> Result<(), Box<dyn Error>> {
5545
Ok(present) => {
5646
if present {
5747
let model = dph.read(serial_port.as_mut(), id, 0, 2).unwrap();
48+
let model = u16::from_le_bytes([model[0], model[1]]);
49+
let model = ServoKind::try_from(model);
5850

59-
found.insert(id, u16::from_le_bytes([model[0], model[1]]));
51+
println!("Found motor with id {id} and model {model:?}");
6052
}
6153
}
6254
Err(e) => eprintln!("Error: {e}"),
6355
};
6456
}
6557

66-
println!("found {} motors", found.len());
67-
for (key, value) in found {
68-
println!(
69-
"id: {} model: {:?}",
70-
key,
71-
ServoKind::try_from(value).unwrap()
72-
);
73-
}
74-
7558
Ok(())
7659
}

0 commit comments

Comments
 (0)