Skip to content

Commit

Permalink
Fixed so it's possible to select Crazyflies on addresses other than d…
Browse files Browse the repository at this point in the history
…efault
  • Loading branch information
evoggy committed Sep 6, 2024
1 parent bf39bd9 commit 77aa08d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,35 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let link_context = crazyflie_link::LinkContext::new(async_executors::AsyncStd);

let cf_address: [u8; 5] = match u64::from_str_radix(&args.address.replace("0x", ""), 16) {
Ok(a) if a <= 0xFFFFFFFFFF => {
a.to_be_bytes()[3..].try_into().expect("Could not convert u64 to [u8; 5]")
}
Ok(_) => {
return Err("Invalid address, please provide a valid 5 byte hexadecimal address".into());
}
Err(_) => {
return Err("Invalid address, please provide a valid 5 byte hexadecimal address".into());
}
};

match &args.command {
Commands::Scan => {
// Scan for Crazyflies on the default address
let found = link_context.scan([0xE7; 5]).await?;
let found = link_context.scan(cf_address).await?;

for uri in found {
println!("> {}", uri);
}
}
Commands::Select => {
// Scan for Crazyflies on the default address
let found = link_context.scan([0xE7; 5]).await?;
let found = link_context.scan(cf_address).await?;

if found.is_empty() {
println!("No Crazyflies found");
return Ok(());
}

for (idx, uri) in found.clone().into_iter().enumerate() {
println!("[{}] {}", idx, uri);
Expand Down

0 comments on commit 77aa08d

Please sign in to comment.