From b3f82b55fb2ac1c11eebd0b8ea99a3dbac56df4a Mon Sep 17 00:00:00 2001 From: Amir Saeid Date: Sat, 28 Mar 2020 19:21:01 +0000 Subject: Fix the way transition progress is calculated --- src/bin/main.rs | 10 ++++++++-- src/lib.rs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 0de2709..fc96325 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -36,8 +36,14 @@ fn main() { loop { let utc: DateTime = Utc::now(); match calc_sunrise_and_set(utc, latitude, longitude) { - Ok(ss) => sctd::set_temp(sctd::get_temp(utc, &ss, latitude, longitude) as u32), - Err(e) => println!("Error calculating sunrise and sunset: {:?}", e), + Ok(ss) => { + let temp = sctd::get_temp(utc, &ss, latitude, longitude) as u32; + println!("setting temprature to: {}", temp); + sctd::set_temp(temp); + } + Err(e) => { + println!("Error calculating sunrise and sunset: {:?}", e); + } } thread::sleep(Duration::from_secs(300)); } diff --git a/src/lib.rs b/src/lib.rs index cc4bb92..b6270b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,7 +57,7 @@ fn get_transition_progress_from_elevation(elevation: f64) -> f64 { if elevation < TRANSITION_LOW { return 0.0; } else if elevation < TRANSITION_HIGH { - (-TRANSITION_LOW - elevation) / (-TRANSITION_LOW - TRANSITION_HIGH) + (TRANSITION_LOW - elevation) / (TRANSITION_LOW - TRANSITION_HIGH) } else { return 1.0; } -- cgit v1.2.3