aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--colortemp.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/colortemp.go b/colortemp.go
index 051ca54..a708a0b 100644
--- a/colortemp.go
+++ b/colortemp.go
@@ -1,16 +1,36 @@
package main
import (
+ "log"
"math"
"time"
hue "github.com/benburwell/gohue"
+ "github.com/cpucycle/astrotime"
)
type ColorTemperature uint
-func getDesiredColorTemperature(at time.Time) ColorTemperature {
- return 1800
+const LATITUDE = 42.348333
+const LONGITUDE = 71.1675
+
+// Get the correct color temperature for a given time. If the time is between
+// sunrise and sunset, a high CT is selected. Otherise, during night, a low
+// color temperature is used.
+//
+// TODO: This is a naive approach and should be revisited
+func getDesiredColorTemperature(t time.Time) ColorTemperature {
+ log.Printf("Calculating sunrise/sunset for: %s\n", t.Format(time.RFC3339))
+ sunrise := astrotime.CalcSunrise(t, LATITUDE, LONGITUDE)
+ sunset := astrotime.CalcSunset(t, LATITUDE, LONGITUDE)
+ log.Printf("Sunrise: %s, Sunset: %s\n", sunrise.Format(time.RFC3339), sunset.Format(time.RFC3339))
+ if t.After(sunrise) && t.Before(sunset) {
+ log.Println("Daytime, setting high CT")
+ return 6500
+ } else {
+ log.Println("Nighttime, setting low CT")
+ return 1800
+ }
}
// Translate a desired color temperature in Kelvins to a value comprehensible