Skip to content

Commit

Permalink
guest_rust: if --list-sensors option is specified, only print the list
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Dec 26, 2023
1 parent b312c28 commit ced9134
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions guest_rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ fn process_frame(frame: &wasi::buffer_pool::buffer_pool::FrameInfo) -> Result<()
fn main2() -> Result<()> {
let args: Vec<String> = env::args().collect();
let mut opts = Options::new();
opts.optflag("", "list-sensors", "list sensor names");
opts.optopt("", "pool", "pool name", "POOL");
opts.optopt("", "sensor", "device name", "DEVICE");
opts.optopt("", "sampling-rate", "samples per sec", "RATE");
Expand All @@ -168,6 +169,11 @@ fn main2() -> Result<()> {
return Err(f.into());
}
};
if matches.opt_present("list-sensors") {
let device_names = wasi::sensor::sensor::Device::list_names()?;
println!("available devices: {:?}", device_names);
return Ok(());
}
let pool_name = matches.opt_str("pool").unwrap_or("my-pool".to_string());
let device_name = matches
.opt_str("sensor")
Expand All @@ -185,9 +191,6 @@ fn main2() -> Result<()> {
&pool_name,
)?;

let device_names = wasi::sensor::sensor::Device::list_names()?;
println!("available devices: {:?}", device_names);

let sensor = wasi::sensor::sensor::Device::open(&device_name)?;
println!("opened sensor {:?}", sensor);

Expand Down

0 comments on commit ced9134

Please sign in to comment.