diff --git a/cmd/fan/fan.go b/cmd/fan/fan.go index 3138712..aa1f842 100644 --- a/cmd/fan/fan.go +++ b/cmd/fan/fan.go @@ -55,45 +55,40 @@ func main() { log.Fatalf("Error parsing interval duration : %s", err) } ticker := time.NewTicker(pollInterval) - go func() { - for { - select { - case <-ticker.C: - cpuTemp := utils.GetCPUTemp() - gpuTemp := utils.GetGPUTemp() + for range ticker.C { + cpuTemp := utils.GetCPUTemp() + gpuTemp := utils.GetGPUTemp() - if cpuTemp >= SPEED_FULL_TEMP || gpuTemp >= SPEED_FULL_TEMP { - fan.SetSpeed(100) - continue - } - if cpuTemp >= SPEED_SEVENTY_FIVE_PERCENT_TEMP || gpuTemp >= SPEED_SEVENTY_FIVE_PERCENT_TEMP { - fan.SetSpeed(75) - continue - } - if cpuTemp >= SPEED_FIFTY_PERCENT_TEMP || gpuTemp >= SPEED_FIFTY_PERCENT_TEMP { - fan.SetSpeed(50) - continue - } - if cpuTemp >= SPEED_TWENTY_FIVE_PERCENT_TEMP || gpuTemp >= SPEED_TWENTY_FIVE_PERCENT_TEMP { - fan.SetSpeed(25) - continue - } - if cpuTemp <= SPEED_OFF_TEMP || gpuTemp <= SPEED_OFF_TEMP { - fan.SetSpeed(0) - continue - } - // We should never get here but... - fan.SetSpeed(100) - } + log.Printf("CPU Temp : %.2f", cpuTemp) + log.Printf("GPU Temp : %.2f", gpuTemp) + + if cpuTemp >= SPEED_FULL_TEMP || gpuTemp >= SPEED_FULL_TEMP { + fan.SetSpeed(100) + log.Print("Setting fan speed to 100%") + continue } - }() - - // Infinate loop of sleeps to let ticker do it's job working with fan speed - sleepInterval, err := time.ParseDuration("5m") - if err != nil { - log.Fatalf("Error parsing sleep interval : %s", err) - } - for { - time.Sleep(sleepInterval) + if cpuTemp >= SPEED_SEVENTY_FIVE_PERCENT_TEMP || gpuTemp >= SPEED_SEVENTY_FIVE_PERCENT_TEMP { + fan.SetSpeed(75) + log.Print("Setting fan speed to 75%") + continue + } + if cpuTemp >= SPEED_FIFTY_PERCENT_TEMP || gpuTemp >= SPEED_FIFTY_PERCENT_TEMP { + fan.SetSpeed(50) + log.Print("Setting fan speed to 50%") + continue + } + if cpuTemp >= SPEED_TWENTY_FIVE_PERCENT_TEMP || gpuTemp >= SPEED_TWENTY_FIVE_PERCENT_TEMP { + fan.SetSpeed(25) + log.Print("Setting fan speed to 25%") + continue + } + if cpuTemp <= SPEED_OFF_TEMP || gpuTemp <= SPEED_OFF_TEMP { + fan.SetSpeed(0) + log.Print("Setting fan speed to 0%") + continue + } + // We should never get here but... + log.Print("Shouldn't see this but here we are") + fan.SetSpeed(100) } }