aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmir Saeid <amir@glgdgt.com>2020-06-19 18:55:42 +0100
committerAmir Saeid <amir@glgdgt.com>2020-06-19 18:55:42 +0100
commit053fc952d16f849b30fff5d99dd40338055101e3 (patch)
treec577fe8c430e444e997626b2b8deda32fcedc409
parent6d3f23229a49e1ed0c54657a968e32b85396f254 (diff)
Reduce sleep time
Also only attempt to change temprature if the value has changed
-rw-r--r--src/bin/sctd.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/bin/sctd.rs b/src/bin/sctd.rs
index 8161bee..ca93fa8 100644
--- a/src/bin/sctd.rs
+++ b/src/bin/sctd.rs
@@ -17,7 +17,7 @@ fn main() {
env_logger::init_from_env(env);
let matches = App::new("sctd")
- .version("0.1.2")
+ .version("0.2.0")
.about("set color temperature daemon")
.arg(
Arg::with_name("latitude")
@@ -39,20 +39,29 @@ fn main() {
} else {
let latitude = value_t_or_exit!(matches, "latitude", f64);
let longitude = value_t_or_exit!(matches, "longitude", f64);
+ let mut temp = 0;
loop {
let utc: DateTime<Utc> = Utc::now();
match calc_sunrise_and_set(utc, latitude, longitude) {
Ok(ss) => {
- let temp = sctd::get_temp(utc, &ss, latitude, longitude) as u32;
- info!("setting temprature to {}", temp);
- sctd::set_temp(temp);
+ let new_temp = sctd::get_temp(utc, &ss, latitude, longitude) as u32;
+ if new_temp != temp {
+ temp = new_temp;
+ info!("setting temprature to {}", temp);
+ sctd::set_temp(temp);
+ } else {
+ debug!("skipping temperature change as it hasn't changed ({})", temp);
+ }
}
Err(e) => {
- error!("error calculating sunrise and sunset for {}, {}: {:?}", latitude, longitude, e);
+ error!(
+ "error calculating sunrise and sunset for {}, {}: {:?}",
+ latitude, longitude, e
+ );
}
}
- thread::sleep(Duration::from_secs(300));
+ thread::sleep(Duration::from_secs(5));
}
}
}