-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
35 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,43 @@ | ||
mod config; | ||
|
||
use crate::config::Config; | ||
use clap::{App, Arg}; | ||
use failure; | ||
use idasen::Idasen; | ||
use std::thread; | ||
use std::time::Duration; | ||
use std::{process, thread}; | ||
|
||
pub fn main() -> Result<(), failure::Error> { | ||
let mut config = Config::new()?; | ||
config.save(); | ||
println!("{:?}", config); | ||
let desk = Idasen::new()?; | ||
let matches = App::new("Desk") | ||
.version("0.1.0") | ||
.about("Control the IDASEN desk position via bluetooth.") | ||
.subcommand(App::new("up").about("Move desk up")) | ||
.subcommand(App::new("down").about("Move desk down")) | ||
.subcommand(App::new("save-up").about("Save current position as up")) | ||
.subcommand(App::new("save-down").about("Save current position as down")) | ||
.subcommand(App::new("info").about("Display desk information")) | ||
.get_matches(); | ||
|
||
println!("Desk addr: {}", desk.mac_addr); | ||
println!("Position: {}", desk.position()?); | ||
if let Some(subcommand) = matches.subcommand() { | ||
let config = Config::new().expect("Failed to load configuration."); | ||
let subcommand = subcommand.0; | ||
if subcommand == "up" && config.data.position_up.is_none() { | ||
eprintln!( | ||
"Position `up` is not defined. \ | ||
Please set desk manually to desired position and run `save-up` command." | ||
); | ||
process::exit(1); | ||
} else if subcommand == "down" && config.data.position_down.is_none() { | ||
eprintln!( | ||
"Position `down` is not defined. \ | ||
Please set desk manually to desired position and run `save-down` command." | ||
); | ||
process::exit(1); | ||
} | ||
} else { | ||
eprintln!("Please select subcommand. Use `help` to see available subcommands."); | ||
process::exit(1); | ||
} | ||
|
||
Ok(()) | ||
} |