summaryrefslogtreecommitdiff
path: root/examples/power.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/power.rs')
-rw-r--r--examples/power.rs25
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()
+}