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, EventRequestFlags, 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 line = chip.get_line(args.line)?;
24 
25     for event in line.events(
26         LineRequestFlags::INPUT,
27         EventRequestFlags::BOTH_EDGES,
28         "gpioevents",
29     )? {
30         println!("{:?}", event?);
31     }
32 
33     Ok(())
34 }
35 
main() -> CliResult36 fn main() -> CliResult {
37     let args = Cli::from_args();
38     do_main(args).or_else(|e| {
39         error!("{:?}", e);
40         Ok(())
41     })
42 }
43