2020-02-28 05:55:07 +03:00
|
|
|
// +build pi0
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
"time"
|
2020-02-28 07:00:55 +03:00
|
|
|
|
|
|
|
"bitbucket.org/ausocean/utils/logger"
|
2020-02-28 05:55:07 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
const audioCmd = "play"
|
|
|
|
|
2020-02-28 07:00:55 +03:00
|
|
|
func initCommand(log *logger.Logger) {
|
2020-02-28 05:55:07 +03:00
|
|
|
const soundcardPath = "/usr/share/doc/audioInjector/asound.state.RCA.thru.test"
|
|
|
|
const sleepDur = 1 * time.Second
|
|
|
|
|
|
|
|
// alsactl is a command that ensures the sound will be played through the correct soundcard.
|
|
|
|
path, err := exec.LookPath("alsactl")
|
|
|
|
if err != nil {
|
2020-02-28 07:00:55 +03:00
|
|
|
log.Log(logger.Fatal, "didn't find 'alsactl' executable")
|
2020-02-28 05:55:07 +03:00
|
|
|
}
|
2020-02-28 07:00:55 +03:00
|
|
|
log.Log(logger.Debug, "'alsactl' executable path", "path", path)
|
2020-02-28 05:55:07 +03:00
|
|
|
|
|
|
|
for {
|
|
|
|
cmdInit := exec.Command("alsactl", "-f", soundcardPath, "restore")
|
|
|
|
err := cmdInit.Run()
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
2020-02-28 07:00:55 +03:00
|
|
|
log.Log(logger.Warning, "cmd.Run() for 'alsactl' failed", "error", err.Error())
|
2020-02-28 05:55:07 +03:00
|
|
|
time.Sleep(sleepDur)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Making sure that play command is on the pi.
|
|
|
|
path, err = exec.LookPath(audioCmd)
|
|
|
|
if err != nil {
|
2020-02-28 07:00:55 +03:00
|
|
|
log.Log(logger.Fatal, "didn't find 'play' executable")
|
2020-02-28 05:55:07 +03:00
|
|
|
}
|
2020-02-28 07:00:55 +03:00
|
|
|
log.Log(logger.Debug, "'play' executable path", "path", path)
|
2020-02-28 05:55:07 +03:00
|
|
|
}
|