diff --git a/README.md b/README.md index 80b3f8b..94e44fe 100644 --- a/README.md +++ b/README.md @@ -119,31 +119,40 @@ fn main() { } }; - if let Ok(device) = cr_client.find_device() { - println!( - "Vendor ID: {:?} Product ID {:?}", - device.vendor_id, device.product_id - ); + let device = match cr_client.find_device() { + Ok(d) => d, + Err(e) => { + eprintln!("Device not found: {}", e.to_string()); + return; + } + }; - let config = Config::new_from(device).set_command(Command::Configuration2); + println!( + "Vendor ID: {:?} Product ID {:?}", + device.vendor_id, device.product_id + ); - let mut rng = thread_rng(); + let config = Config::new_from(device) + .set_command(Command::Configuration2); - // Secret must have 20 bytes - // Used rand here, but you can set your own secret: let secret: &[u8; 20] = b"my_awesome_secret_20"; - let secret: Vec = rng.sample_iter(&Alphanumeric).take(20).collect(); - let hmac_key: HmacKey = HmacKey::from_slice(&secret); + let mut rng = thread_rng(); - let mut device_config = DeviceModeConfig::default(); - device_config.challenge_response_hmac(&hmac_key, false, false); + // Secret must have 20 bytes + // Used rand here, but you can set your own secret: + // let secret: &[u8; 20] = b"my_awesome_secret_20"; + let secret: Vec = + rng.sample_iter(&Alphanumeric).take(20).collect(); + let hmac_key: HmacKey = HmacKey::from_slice(&secret); - if let Err(err) = cr_client.write_config(config, &mut device_config) { - println!("{:?}", err); - } else { - println!("Device configured"); - } + let mut device_config = DeviceModeConfig::default(); + device_config.challenge_response_hmac(&hmac_key, false, false); + + if let Err(err) = + cr_client.write_config(config, &mut device_config) + { + println!("{:?}", err); } else { - println!("Device not found"); + println!("Device configured"); } } ```