From 30d86863a4311d486585a364e25923550b4ccbee Mon Sep 17 00:00:00 2001 From: Ian McIntyre Date: Sun, 14 Sep 2025 20:39:38 -0400 Subject: First commit --- examples/power.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/power.rs (limited to 'examples/power.rs') diff --git a/examples/power.rs b/examples/power.rs new file mode 100644 index 0000000..120f424 --- /dev/null +++ b/examples/power.rs @@ -0,0 +1,25 @@ +//! Change the supply's output state. + +use std::env; + +use bkp_168xb::{Output, PowerSupply}; + +static USAGE: &'static str = "Usage: power on [PORT] | power off [PORT]"; + +fn main() { + let mut args = env::args().skip(1); + let output = args + .next() + .and_then(|arg| match arg.to_lowercase().as_str() { + "off" => Some(Output::Off), + "on" => Some(Output::On), + _ => None, + }) + .expect(USAGE); + let port = args.next().expect(USAGE); + + let mut ps = PowerSupply::open(port).unwrap(); + let (volt, curr) = ps.get_max_voltage_current().unwrap(); + println!("{volt} {curr}"); + ps.set_output(output).unwrap() +} -- cgit v1.2.3