diff options
| author | Ian McIntyre <me@mciantyre.dev> | 2025-09-14 20:39:38 -0400 |
|---|---|---|
| committer | Ian McIntyre <me@mciantyre.dev> | 2025-09-14 20:39:38 -0400 |
| commit | 30d86863a4311d486585a364e25923550b4ccbee (patch) | |
| tree | 18b64ebd7856531161b605ac7d205e023fb6fc49 /examples | |
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/power.rs | 25 |
1 files changed, 25 insertions, 0 deletions
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() +} |
