diff --git a/consumer/speed_controller.go b/consumer/speed_controller.go index 9544fe1..d02e3db 100644 --- a/consumer/speed_controller.go +++ b/consumer/speed_controller.go @@ -48,10 +48,9 @@ func (c *fanControl) StartControl() { log.Info("Fan control started") ticker := time.Tick(c.sampleDuration) - fanSpeedList := make([]int, c.processorCount) - + pastFanSpeedList := make([]int, c.processorCount) + newFanSpeedList := make([]int, c.processorCount) for { - newFanSpeedList := make([]int, c.processorCount) checker: for { select { @@ -63,11 +62,11 @@ func (c *fanControl) StartControl() { return } } - if (!compareFanSpeed(fanSpeedList, newFanSpeedList)) { - copy(fanSpeedList, newFanSpeedList) + if (!compareFanSpeed(pastFanSpeedList, newFanSpeedList)) { + copy(pastFanSpeedList, newFanSpeedList) args := make([]string, 0) args = append(args, "raw", "0x3a", "0x01", ) - for _, item := range fanSpeedList { + for _, item := range newFanSpeedList { args = append(args, fmt.Sprintf("0x%x", item)) } args = append(args, @@ -89,6 +88,7 @@ func (c *fanControl) StartControl() { } func compareFanSpeed(old, new []int) bool { + new = new[:len(old)] // this line is the key for i, v := range old { if v != new[i] { // here is no bounds checking for b[i] return false