diff options
| author | Amir Saeid <amir@glgdgt.com> | 2020-03-28 19:21:01 +0000 |
|---|---|---|
| committer | Amir Saeid <amir@glgdgt.com> | 2020-03-28 19:21:01 +0000 |
| commit | b3f82b55fb2ac1c11eebd0b8ea99a3dbac56df4a (patch) | |
| tree | b70b1051845ccb4abf133d3303518a2fa903291c | |
| parent | 0f08beddff5740cd419b4ac96ba2141b7b0d9cd0 (diff) | |
Fix the way transition progress is calculated
| -rw-r--r-- | src/bin/main.rs | 10 | ||||
| -rw-r--r-- | 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> = 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)); } @@ -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; } |
