diff options
| author | Amir Saeid <amir@glgdgt.com> | 2020-03-15 20:22:22 +0000 |
|---|---|---|
| committer | Amir Saeid <amir@glgdgt.com> | 2020-03-15 20:22:22 +0000 |
| commit | 742aaa2a08a9e8837edf47bdc107d9d535dbf45a (patch) | |
| tree | ed19be8df0c3a165beffcb98ea7b65fdbcb7f9fd /src | |
| parent | ec54cbd0528a146ac346aec425909f7230bf8270 (diff) | |
Add command line arguments
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/main.rs | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs index 7e69ae1..832320a 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,8 +1,10 @@ extern crate chrono; +extern crate clap; extern crate spa; use chrono::prelude::*; -use spa::{SunriseAndSet, calc_sunrise_and_set}; +use clap::{value_t_or_exit, App, Arg}; +use spa::{calc_sunrise_and_set, SunriseAndSet}; use std::os::raw::{c_ushort, c_void}; use std::ptr; use std::thread; @@ -56,23 +58,41 @@ fn get_temp(utc: DateTime<Utc>, ss: &SunriseAndSet) -> u32 { } else { return low_temp; } - }, + } SunriseAndSet::PolarDay => return high_temp, SunriseAndSet::PolarNight => return low_temp, } } fn main() { - // Dublin - let lat: f64 = 53.3498; - let lon: f64 = 6.2603; + let matches = App::new("sctd") + .about("set color temperature daemon") + .arg( + Arg::with_name("latitude") + .long("latitude") + .takes_value(true), + ) + .arg( + Arg::with_name("longitude") + .long("longitude") + .takes_value(true), + ) + .arg(Arg::with_name("reset").long("reset")) + .get_matches(); + + if matches.is_present("reset") { + set_temp(5500); + } else { + let latitude = value_t_or_exit!(matches, "latitude", f64); + let longitude = value_t_or_exit!(matches, "longitude", f64); - loop { - let utc: DateTime<Utc> = Utc::now(); - match calc_sunrise_and_set(utc, lat, lon) { - Ok(ss) => set_temp(get_temp(utc, &ss)), - Err(e) => println!("Error calculating sunrise and sunset: {:?}", e), + loop { + let utc: DateTime<Utc> = Utc::now(); + match calc_sunrise_and_set(utc, latitude, longitude) { + Ok(ss) => set_temp(get_temp(utc, &ss)), + Err(e) => println!("Error calculating sunrise and sunset: {:?}", e), + } + thread::sleep(Duration::from_secs(300)); } - thread::sleep(Duration::from_secs(300)); } } |
