Skip to content

Commit dca878e

Browse files
committed
core: flesh out core structure
Focused around the read command, flesh out the basic modules that compose the core library. Signed-off-by: Paul Osborne <[email protected]>
1 parent 199820e commit dca878e

File tree

6 files changed

+91
-4
lines changed

6 files changed

+91
-4
lines changed

src/commands/gpio_read.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (C) 2016, Paul Osborne <[email protected]>
2+
3+
use options::{GpioReadOptions};
4+
5+
pub fn main(opts: &GpioReadOptions) {
6+
println!("{:?}", opts);
7+
}

src/commands/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Copyright (C) 2016, Paul Osborne <[email protected]>
2+
3+
pub mod gpio_read;

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Copyright (C) 2016, Paul Osborne <[email protected]>

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (C) 2016, Paul Osborne <[email protected]>
2+
3+
extern crate sysfs_gpio;
4+
5+
pub mod options;
6+
pub mod config;
7+
pub mod commands;

src/main.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
// Copyright (C) 2016, Paul Osborne <[email protected]>
2+
3+
extern crate gpio_utils;
14
extern crate clap;
25

3-
use clap::{Arg, App, SubCommand};
6+
use clap::{Arg, App, SubCommand, AppSettings};
7+
use gpio_utils::options::*;
8+
use gpio_utils::commands::{gpio_read};
49

510
fn main() {
6-
let gpio_cmd_matches = App::new("GPIO Utils")
11+
let matches = App::new("GPIO Utils")
712
.version(env!("CARGO_PKG_VERSION"))
813
.about("Read, Write, and Configure GPIOs")
14+
.setting(AppSettings::SubcommandRequired)
915

1016
// Global options
1117
.arg(Arg::with_name("config")
@@ -78,8 +84,19 @@ fn main() {
7884

7985
.get_matches();
8086

81-
match gpio_cmd_matches.subcommand() {
82-
("read", Some(m)) => {},
87+
// process global options
88+
let gpio_options = GpioOptions {
89+
configs: matches.values_of_lossy("config").unwrap_or(Vec::new()),
90+
};
91+
92+
match matches.subcommand() {
93+
("read", Some(m)) => {
94+
let read_options = GpioReadOptions {
95+
gpio_opts: gpio_options,
96+
pin: String::from(m.value_of("pin").unwrap()),
97+
};
98+
gpio_read::main(&read_options);
99+
},
83100
("poll", Some(m)) => {},
84101
("write", Some(m)) => {},
85102
("export", Some(m)) => {},

src/options.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (C) 2016, Paul Osborne <[email protected]>
2+
3+
#[derive(Debug)]
4+
pub struct GpioOptions {
5+
pub configs: Vec<String>,
6+
}
7+
8+
#[derive(Debug)]
9+
pub struct GpioReadOptions {
10+
pub gpio_opts: GpioOptions,
11+
pub pin: String,
12+
}
13+
14+
#[derive(Debug)]
15+
pub struct GpioWriteOptions {
16+
pub gpio_opts: GpioOptions,
17+
pub pin: String,
18+
}
19+
20+
#[derive(Debug)]
21+
pub struct GpioPollOptions {
22+
pub gpio_opts: GpioOptions,
23+
pub pin: String,
24+
}
25+
26+
#[derive(Debug)]
27+
pub struct GpioExportOptions {
28+
pub gpio_opts: GpioOptions,
29+
pub pin: String,
30+
}
31+
32+
#[derive(Debug)]
33+
pub struct GpioExportAllOptions {
34+
pub gpio_opts: GpioOptions,
35+
}
36+
37+
#[derive(Debug)]
38+
pub struct GpioUnexportOptions {
39+
pub gpio_opts: GpioOptions,
40+
pub pin: String,
41+
}
42+
43+
#[derive(Debug)]
44+
pub struct GpioUnexportAllOptions {
45+
pub gpio_opts: GpioOptions,
46+
}
47+
48+
#[derive(Debug)]
49+
pub struct GpioStatusOptions {
50+
pub gpio_opts: GpioOptions,
51+
pub pin: Option<String>,
52+
}

0 commit comments

Comments
 (0)