1 // Copyright (c) 2018 The rust-gpio-cdev Project Developers.
2 //
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
8
9 use gpio_cdev::{Chip, LineRequestFlags};
10 use quicli::prelude::*;
11 use structopt::StructOpt;
12
13 #[derive(Debug, StructOpt)]
14 struct Cli {
15 /// The gpiochip device (e.g. /dev/gpiochip0)
16 chip: String,
17 /// The offset of the GPIO line for the provided chip
18 line: u32,
19 }
20
do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error>21 fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
22 let mut chip = Chip::new(args.chip)?;
23 let handle = chip
24 .get_line(args.line)?
25 .request(LineRequestFlags::INPUT, 0, "readinput")?;
26 println!("Value: {:?}", handle.get_value()?);
27
28 Ok(())
29 }
30
main() -> CliResult31 fn main() -> CliResult {
32 let args = Cli::from_args();
33 do_main(args).or_else(|e| {
34 error!("{:?}", e);
35 Ok(())
36 })
37 }
38