treatment: add support for digital volume control

This commit is contained in:
Trek H 2021-03-03 21:42:01 +10:30
parent e35b5d72ea
commit 78cc2a6ca8
1 changed files with 21 additions and 0 deletions

View File

@ -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: