From 798e691c06aba2c9b4d049dde5c183184364be88 Mon Sep 17 00:00:00 2001 From: Russell Stanley Date: Mon, 11 Apr 2022 16:26:22 +0930 Subject: [PATCH] cmd/rv/main.go: add probe update after revid variable update --- cmd/rv/main.go | 17 ++++++++++------- cmd/rv/probe.go | 1 - 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/rv/main.go b/cmd/rv/main.go index c430faed..50869bbe 100644 --- a/cmd/rv/main.go +++ b/cmd/rv/main.go @@ -146,11 +146,6 @@ func main() { p *turbidityProbe ) - p, err := NewTurbidityProbe(*log, 60*time.Second, rv.Config().TransformMatrix) - if err != nil { - log.Log(logger.Fatal, "could not create new turbidity probe", "error", err.Error()) - } - log.Log(logger.Debug, "initialising netsender client") ns, err := netsender.New(log, nil, readPin(p, rv, log), nil, createVarMap()) if err != nil { @@ -163,6 +158,11 @@ func main() { log.Log(logger.Fatal, pkg+"could not initialise revid", "error", err.Error()) } + p, err = NewTurbidityProbe(*log, 60*time.Second, rv.Config().TransformMatrix) + if err != nil { + log.Log(logger.Fatal, "could not create new turbidity probe", "error", err.Error()) + } + err = rv.SetProbe(p) if err != nil { log.Log(logger.Error, pkg+"could not set probe", "error", err.Error()) @@ -175,12 +175,12 @@ func main() { time.Sleep(runPreDelay) log.Log(logger.Debug, "beginning main loop") - run(rv, ns, log, netLog) + run(rv, ns, log, netLog, p) } // run starts the main loop. This will run netsender on every pass of the loop // (sleeping inbetween), check vars, and if changed, update revid as appropriate. -func run(rv *revid.Revid, ns *netsender.Sender, l *logger.Logger, nl *netlogger.Logger) { +func run(rv *revid.Revid, ns *netsender.Sender, l *logger.Logger, nl *netlogger.Logger, p *turbidityProbe) { var vs int for { l.Log(logger.Debug, "running netsender") @@ -225,6 +225,9 @@ func run(rv *revid.Revid, ns *netsender.Sender, l *logger.Logger, nl *netlogger. } l.Log(logger.Info, "revid successfully reconfigured") + // Update transform matrix based on new revid variables. + p.transform = rv.Config().TransformMatrix + l.Log(logger.Debug, "checking mode") switch ns.Mode() { case modePaused: diff --git a/cmd/rv/probe.go b/cmd/rv/probe.go index 5e1ca408..8f697c80 100644 --- a/cmd/rv/probe.go +++ b/cmd/rv/probe.go @@ -127,7 +127,6 @@ func (tp *turbidityProbe) Write(p []byte) (int, error) { select { case <-tp.ticker.C: tp.log.Log(logger.Debug, "beginning turbidity calculation") - tp.log.Log(logger.Debug, "transformation matrix", tp.transform[0]) startTime := time.Now() err := tp.turbidityCalculation() if err != nil {