Commit: 764d986f782a6956e795917299d6eaebfc05c9ad Parent: 7f6a786786772752a0fd795376dff2ff40a17ae8 Author: Vi Grey Date: 2023-10-16 10:21 UTC Summary: Make compatible with new version of syzygy src/config.go | 1 + src/moon.go | 2 +- src/redshift.go | 36 +++++++++++++++++++++++------------- src/solartime.go | 2 +- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/config.go b/src/config.go index fb85f7a..fc5790f 100644 --- a/src/config.go +++ b/src/config.go @@ -16,6 +16,7 @@ type Config struct { Longitude float32 `json:"longitude"` SolarTime ConfigSolarTime `json:"solar-time"` Email []ConfigEmail `json:"email"` + Monitors []string `json:"monitors"` } type ConfigEmail struct { diff --git a/src/moon.go b/src/moon.go index b43d030..435ec42 100644 --- a/src/moon.go +++ b/src/moon.go @@ -12,7 +12,7 @@ type Syzygy struct { MoonPhase float64 `json:"moonPhase"` SunAngle float64 `json:"sunAngle"` SunEarthPhase float64 `json:"sunEarthPhase"` - EarthGeoditicLocation SyzygyGeoditicLocation `json:"earthGeoditicLocation"` + EarthGeodeticLocation SyzygyGeoditicLocation `json:"earthGeodeticLocation"` SunECEF SyzygyECEF `json:"sunECEF"` EarthECEF SyzygyECEF `json:"earthECEF"` EquationOfTime SyzygyEquationOfTime `json:"equationOfTime"` diff --git a/src/redshift.go b/src/redshift.go index b48cd34..e7403da 100644 --- a/src/redshift.go +++ b/src/redshift.go @@ -1,13 +1,11 @@ package main import ( + "fmt" "math" "os/exec" - "strconv" ) -const () - var ( rsBrightnessDiff float64 = 1 - 0.55 rsGreenDiff float64 = 1 - 0.88 @@ -16,22 +14,34 @@ var ( ) func getRedshiftScalingFactor(s Syzygy) float64 { - sunRad := degreesToRadians(s.SunAngle) - minDist := 7 * math.Pi / 180 - if sunRad >= math.Pi/2 { + sunDist := getSunDist(s) + sunDiscAngle := getSunDiscRadiusAngle(sunDist) + sunAlt := s.SunAngle - 90 + sunDiscAngle + if sunAlt >= 0 { return 0 - } else if sunRad <= math.Pi/2-minDist { + } else if sunAlt < -6 { return -1 } else { - return (math.Cos((math.Pi/2-sunRad)/minDist*math.Pi) - 1) / 2 + return (math.Cos((sunAlt/-6)*math.Pi) - 1) / 2 } } +func getSunDiscRadiusAngle(sunDist float64) float64 { + return math.Atan(sunRadius/sunDist) / (2 * math.Pi) * 360 +} + +func getSunDist(s Syzygy) float64 { + return math.Sqrt(math.Pow((s.SunECEF.X-s.EarthECEF.X), 2) + + math.Pow((s.SunECEF.Y-s.EarthECEF.Y), 2) + + math.Pow((s.SunECEF.Z-s.EarthECEF.Z), 2)) +} + func runRedshift(s Syzygy) { rsScale := getRedshiftScalingFactor(s) - rsGreen := strconv.FormatFloat((1.0 + rsGreenDiff*rsScale), 'f', 5, 64) - rsBlue := strconv.FormatFloat((1.0 + rsBlueDiff*rsScale), 'f', 5, 64) - rsBrightness := strconv.FormatFloat((1.0 + rsBrightnessDiff*rsScale), 'f', 5, 64) - exec.Command("xrandr", "--output", "VGA-1", "--gamma", "1.0:"+rsGreen+":"+rsBlue, "--brightness", rsBrightness).Run() - exec.Command("xrandr", "--output", "DVI-0", "--gamma", "1.0:"+rsGreen+":"+rsBlue, "--brightness", rsBrightness).Run() + rsGreen := 1.0 + rsGreenDiff*rsScale + rsBlue := 1.0 + rsBlueDiff*rsScale + rsBrightness := 1.0 + rsBrightnessDiff*rsScale + for x := range configData.Monitors { + exec.Command("xrandr", "--output", configData.Monitors[x], "--gamma", fmt.Sprintf("1.0:%.5f:%.5f", rsGreen, rsBlue), "--brightness", fmt.Sprintf("%.5f", rsBrightness)).Run() + } } diff --git a/src/solartime.go b/src/solartime.go index f5e4d95..deb42b6 100644 --- a/src/solartime.go +++ b/src/solartime.go @@ -8,7 +8,7 @@ import ( func getSolarTime(sy Syzygy) (s string) { if configData.SolarTime.Enabled { newTime := time.Unix(int64(sy.Time), 0).UTC().Add( - time.Duration((sy.EarthGeoditicLocation.Longitude+ + time.Duration((sy.EarthGeodeticLocation.Longitude+ sy.EquationOfTime.Eccentricity+ sy.EquationOfTime.Obliquity)*240) * time.Second) hour := newTime.Hour()