diff --git a/internal/lib/cputemp.go b/internal/lib/cputemp.go index d402fb1..37847a7 100644 --- a/internal/lib/cputemp.go +++ b/internal/lib/cputemp.go @@ -23,6 +23,7 @@ func (c *MyConfig) UpdateCPUTemperature() { temperature = make([]int64, n) tSum int64 tAvg int64 + validCount int ) if Delay == InitialDelay { @@ -62,20 +63,30 @@ func (c *MyConfig) UpdateCPUTemperature() { } temperature[i] = temp + validCount++ } } } } } - if len(temperature) == 1 { - tAvg = temperature[0] + if validCount == 0 { + continue + } + + if validCount == 1 { + for _, t := range temperature { + if t != 0 { + tAvg = t + break + } + } } else { for _, t := range temperature { tSum += t } - tAvg = tSum / int64(len(temperature)) + tAvg = tSum / int64(validCount) } if c.Values.CPUTemperature != tAvg {