From fa3950cd856fcacc98ac4f8f15817ec3140d4117 Mon Sep 17 00:00:00 2001 From: Sangbum Kim Date: Wed, 13 Sep 2017 00:53:45 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=98=EB=AA=BB=EB=90=9C=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=952?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consumer/speed_controller.go | 18 +++++++++--------- processor/processor.go | 4 ++++ 2 files changed, 13 insertions(+), 9 deletions(-) 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: