diff --git a/consumer/speed_controller.go b/consumer/speed_controller.go index d02e3db..e452591 100644 --- a/consumer/speed_controller.go +++ b/consumer/speed_controller.go @@ -45,6 +45,7 @@ func (c *fanControl) StartControl() { } }() defer close(c.fanSpeedConsumer) + defer log.Info("Fan control stopped") log.Info("Fan control started") ticker := time.Tick(c.sampleDuration) diff --git a/main.go b/main.go index 2879329..43151c3 100644 --- a/main.go +++ b/main.go @@ -13,14 +13,28 @@ import ( "amuz.es/src/infra/cpu_ctrl/processor" "amuz.es/src/infra/cpu_ctrl/util" "amuz.es/src/infra/cpu_ctrl/consumer" + + "gopkg.in/alecthomas/kingpin.v2" ) var ( + app = kingpin.New("cpu_ctrl", "Interactive CPU fan controller").Author("Sangbum Kim") + verbose = app.Flag("verbose", "Enable verbose mode.").Short('v').Bool() + P = app.Flag("proportional-gain", "Set proportional gain value.").Short('p').Default("1.5").Float64() + I = app.Flag("integral-gain", "Set integral gain value.").Short('i').Default("0.3").Float64() + D = app.Flag("derivative-gain", "Set derivative gain value.").Short('d').Default("1.0").Float64() + SetPoint = app.Flag("set-point", "Set pointe tempeture").Short('t').Default("38.0").Float64() + log = logger.NewLogger("cpu_ctrl") ) func init() { - logger.InitLogger(true, "", &logger.Config{FileName: "Stderr"}) + app.Version("0.3") + if _, err := app.Parse(os.Args[1:]); err != nil { + panic(err) + } + logger.InitLogger(*verbose, "", &logger.Config{FileName: "Stderr"}) + setMaxProcs() } @@ -75,7 +89,7 @@ func main() { handler = util.NewHandler() sampleDuration = time.Second ) - log.Info("Cpu fan controller v0.2") + log.Infof("Cpu fan controller") if processorCount == 0 { handler.NotifyError(errors.New("cpu not found!")) @@ -86,7 +100,7 @@ func main() { processors = make([]processor.Processor, 0, processorCount) for i := 0; i < processorCount; i++ { if info, err := processor.NewProcessorInfo(handler, i, sampleDuration, - 1.5, 0.4, 2.0, 38.0, 0x64, 0x4, + *P, *I, *D, *SetPoint, 0x64, 0x4, nil, fanController.Consumer(), ); err != nil { diff --git a/processor/processor.go b/processor/processor.go index 51caadb..b12cca6 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -125,6 +125,7 @@ func (p *processor) StartMonitoring() { tempeturePathGlob := path.Join(p.tempeturePath, "temp?_input") ticker := time.Tick(p.sampleDuration) + defer log.Infof("Processor %d monitor stopped", p.id) log.Infof("Processor %d monitor started with %s", p.id, p.sampleDuration) for { @@ -147,7 +148,7 @@ func (p *processor) StartMonitoring() { } } p.tempeture = highestTemp - log.Infof("processor %d : tempeture changed %f", p.id, highestTemp) + log.Debugf("processor %d : tempeture changed %f", p.id, highestTemp) } fanspeed = p.normalizeFanspeed(p.fanController.Update(highestTemp)) @@ -162,7 +163,7 @@ func (p *processor) StartMonitoring() { } } p.fanSpeed = fanspeed - log.Infof("processor %d : fan changed 0x%x", p.id, fanspeed) + log.Debugf("processor %d : fan changed 0x%x", p.id, fanspeed) } case <-p.handler.Done(): return