mirror of https://bitbucket.org/ausocean/av.git
cmd/treatment: main.go updated to exactly what's on macquarie speaker
This commit is contained in:
parent
b55961b089
commit
88ae00ede1
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue