diff --git a/consumer/speed_controller.go b/consumer/speed_controller.go index ed3469a..6325092 100644 --- a/consumer/speed_controller.go +++ b/consumer/speed_controller.go @@ -53,21 +53,21 @@ func (c *fanControl) StartControl() { for { select { case <-ticker: - go c.applyFanspeed(pastFanSpeedList, newFanSpeedList) - pastFanSpeedList, newFanSpeedList = newFanSpeedList, make([]int, c.processorCount) - copy(newFanSpeedList, pastFanSpeedList) + if !compareFanSpeed(pastFanSpeedList, newFanSpeedList) { + copy(pastFanSpeedList, newFanSpeedList) + newFanSpeedList = make([]int, c.processorCount) + go c.applyFanspeed(pastFanSpeedList) + } case changedSpeed := <-c.fanSpeedConsumer: - newFanSpeedList[changedSpeed.Id] = changedSpeed.FanSpeed + if changedSpeed.Changed { + newFanSpeedList[changedSpeed.Id] = changedSpeed.FanSpeed + } case <-c.handler.Done(): return } } } -func (c *fanControl) applyFanspeed(pastFanSpeedList, newFanSpeedList []int) { - if !compareFanSpeed(pastFanSpeedList, newFanSpeedList) { - return - } - +func (c *fanControl) applyFanspeed(newFanSpeedList []int) { args := make([]string, 0) args = append(args, "raw", "0x3a", "0x01", ) for _, item := range newFanSpeedList { diff --git a/processor/processor.go b/processor/processor.go index c505aa1..3c82e5e 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -33,12 +33,14 @@ type processor struct { type TempetureInfo struct { Id int Tempeture float64 + Changed bool At time.Time } type FanspeedInfo struct { Id int FanSpeed int + Changed bool At time.Time } @@ -147,6 +149,7 @@ func (p *processor) StartMonitoring() { case p.tempetureChanged <- TempetureInfo{ Id: p.id, Tempeture: highestTemp, + Changed: highestTemp != p.tempeture, At: now, }: default: @@ -164,6 +167,7 @@ func (p *processor) StartMonitoring() { case p.fanSpeedChanged <- FanspeedInfo{ Id: p.id, FanSpeed: fanspeed, + Changed: fanspeed != p.fanSpeed, At: now, }: default: