diff options
| author | Ben Burwell <ben@benburwell.com> | 2018-05-24 22:17:58 -0400 | 
|---|---|---|
| committer | Ben Burwell <ben@benburwell.com> | 2018-05-24 22:17:58 -0400 | 
| commit | b279470a75dd6f3e59809650424a8e21d979eefc (patch) | |
| tree | 7107fbe4f865d795ddcec223ec5bc1336d3c9b0f /colortemp.go | |
| parent | 307a3802dc7c9637b9b3a1a95ff47c0686fa1a01 (diff) | |
Select proper color temperature depending on time
Diffstat (limited to 'colortemp.go')
| -rw-r--r-- | colortemp.go | 24 | 
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  | 
