From 88ae00ede129b90d2e0702421a0006f8c27d905f Mon Sep 17 00:00:00 2001 From: trekhopton Date: Mon, 29 Apr 2024 14:07:28 +0930 Subject: [PATCH] cmd/treatment: main.go updated to exactly what's on macquarie speaker --- cmd/treatment/main.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/treatment/main.go b/cmd/treatment/main.go index 7baa380f..f05e78d6 100644 --- a/cmd/treatment/main.go +++ b/cmd/treatment/main.go @@ -154,7 +154,7 @@ func main() { log.Debug("got cached config", "config", cfg) // Set the volume from the cached value. - err = setVolume(cfg.Volume, bus) + err = setVolume(cfg.Volume, bus, log) if err != nil { log.Error("failed to set cached volume", "error", err) } else { @@ -181,6 +181,11 @@ func main() { // Start the control loop. log.Debug("starting control loop") + + setChannels(modeStereo, log) + if err != nil { + log.Error("could not set to stereo", err) + } run(rv, ns, &cfg.Path, bus, log, netLog) } @@ -248,7 +253,7 @@ func run(rv *revid.Revid, ns *netsender.Sender, file *string, bus embd.I2CBus, l l.Debug("checking amplifier volume") v := vars["AmpVolume"] if v != "" { - err = setVolume(v, bus) + err = setVolume(v, bus, l) if err != nil { l.Error("unable to set requested volume", "volume", v, "error", err) continue @@ -275,7 +280,7 @@ func setChannels(mode string, l logging.Logger) error { modeMute: "0%,0%", }[mode] if vols == "" { - l.Warning("invalid SpeakeMode", "SpeakerMode", mode) + l.Warning("invalid SpeakerMode", "SpeakerMode", mode) return fmt.Errorf("invalid SpeakerMode: %s", mode) } @@ -327,11 +332,12 @@ func setChannels(mode string, l logging.Logger) error { } // setVolume sends i2c commands to the amplifier in order to set the volume of the amplifier. -func setVolume(hexVol string, bus embd.I2CBus) error { - vol, err := strconv.ParseInt(hexVol, 16, 8) +func setVolume(hexVol string, bus embd.I2CBus, l logging.Logger) error { + vol, err := strconv.Atoi(hexVol) if err != nil { return fmt.Errorf("could not parse hex volume: %w", err) } + l.Debug("volume log: ", "hexStr", hexVol, "intVol", vol, "byteVol", byte(vol)) if vol < minAmpVolume || vol > maxAmpVolume { return fmt.Errorf("volume %d, out of range: [%d, %d]", vol, minAmpVolume, maxAmpVolume) }