1
0
Fork 0

잘못된 코드 수정2

This commit is contained in:
Sangbum Kim 2017-09-13 00:53:45 +09:00
parent bca37ebec0
commit fa3950cd85
2 changed files with 13 additions and 9 deletions

View File

@ -53,21 +53,21 @@ func (c *fanControl) StartControl() {
for { for {
select { select {
case <-ticker: case <-ticker:
go c.applyFanspeed(pastFanSpeedList, newFanSpeedList) if !compareFanSpeed(pastFanSpeedList, newFanSpeedList) {
pastFanSpeedList, newFanSpeedList = newFanSpeedList, make([]int, c.processorCount) copy(pastFanSpeedList, newFanSpeedList)
copy(newFanSpeedList, pastFanSpeedList) newFanSpeedList = make([]int, c.processorCount)
go c.applyFanspeed(pastFanSpeedList)
}
case changedSpeed := <-c.fanSpeedConsumer: case changedSpeed := <-c.fanSpeedConsumer:
newFanSpeedList[changedSpeed.Id] = changedSpeed.FanSpeed if changedSpeed.Changed {
newFanSpeedList[changedSpeed.Id] = changedSpeed.FanSpeed
}
case <-c.handler.Done(): case <-c.handler.Done():
return return
} }
} }
} }
func (c *fanControl) applyFanspeed(pastFanSpeedList, newFanSpeedList []int) { func (c *fanControl) applyFanspeed(newFanSpeedList []int) {
if !compareFanSpeed(pastFanSpeedList, newFanSpeedList) {
return
}
args := make([]string, 0) args := make([]string, 0)
args = append(args, "raw", "0x3a", "0x01", ) args = append(args, "raw", "0x3a", "0x01", )
for _, item := range newFanSpeedList { for _, item := range newFanSpeedList {

View File

@ -33,12 +33,14 @@ type processor struct {
type TempetureInfo struct { type TempetureInfo struct {
Id int Id int
Tempeture float64 Tempeture float64
Changed bool
At time.Time At time.Time
} }
type FanspeedInfo struct { type FanspeedInfo struct {
Id int Id int
FanSpeed int FanSpeed int
Changed bool
At time.Time At time.Time
} }
@ -147,6 +149,7 @@ func (p *processor) StartMonitoring() {
case p.tempetureChanged <- TempetureInfo{ case p.tempetureChanged <- TempetureInfo{
Id: p.id, Id: p.id,
Tempeture: highestTemp, Tempeture: highestTemp,
Changed: highestTemp != p.tempeture,
At: now, At: now,
}: }:
default: default:
@ -164,6 +167,7 @@ func (p *processor) StartMonitoring() {
case p.fanSpeedChanged <- FanspeedInfo{ case p.fanSpeedChanged <- FanspeedInfo{
Id: p.id, Id: p.id,
FanSpeed: fanspeed, FanSpeed: fanspeed,
Changed: fanspeed != p.fanSpeed,
At: now, At: now,
}: }:
default: default: