diff --git a/cmd/treatment/main.go b/cmd/treatment/main.go index b59bbc5c..bac80404 100644 --- a/cmd/treatment/main.go +++ b/cmd/treatment/main.go @@ -46,6 +46,7 @@ import ( "bitbucket.org/ausocean/iot/pi/netlogger" "bitbucket.org/ausocean/iot/pi/netsender" "bitbucket.org/ausocean/utils/logger" + "github.com/kidoman/embd" _ "github.com/kidoman/embd/host/rpi" lumberjack "gopkg.in/natefinch/lumberjack.v2" ) @@ -71,6 +72,9 @@ const ( netSendRetryTime = 5 * time.Second defaultSleepTime = 60 // Seconds pkg = "rv: " + minAmpVolume = 0 + maxAmpVolume = 63 + volAddr = 0x4B ) // Treatment modes. @@ -184,6 +188,23 @@ func run(rv *revid.Revid, ns *netsender.Sender, file *string, l *logger.Logger, } l.Info("revid successfully reconfigured") + l.Debug("checking amplifier volume") + v := vars["AmpVolume"] + if v != "" { + vol, err := strconv.ParseInt(v, 10, 8) + if err != nil { + l.Error(pkg+"failed to parse amplifier volume", "error", err.Error()) + } else if vol < minAmpVolume || vol > maxAmpVolume { + l.Error(fmt.Sprintf("%s invalid amplifier volume, must be between %v and %v", pkg, minAmpVolume, maxAmpVolume), "volume", vol) + } else { + bus := embd.NewI2CBus(1) + err := bus.WriteByte(volAddr, byte(vol)) + if err != nil { + l.Error(pkg+"failed to write amplifier volume", "error", err.Error()) + } + } + } + l.Debug("checking mode") switch ns.Mode() { case modePaused: