11use clap:: { Parser , ValueEnum } ;
2- use std:: collections:: HashMap ;
32use std:: { error:: Error , time:: Duration } ;
43
54use 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