mirror of https://bitbucket.org/ausocean/av.git
treatment: included rpi support, renew cmd
This commit is contained in:
parent
bfaa33aa99
commit
5b035a6e77
|
@ -46,6 +46,7 @@ import (
|
||||||
"bitbucket.org/ausocean/iot/pi/netlogger"
|
"bitbucket.org/ausocean/iot/pi/netlogger"
|
||||||
"bitbucket.org/ausocean/iot/pi/netsender"
|
"bitbucket.org/ausocean/iot/pi/netsender"
|
||||||
"bitbucket.org/ausocean/utils/logger"
|
"bitbucket.org/ausocean/utils/logger"
|
||||||
|
_ "github.com/kidoman/embd/host/rpi"
|
||||||
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -109,7 +110,6 @@ func main() {
|
||||||
if *filePtr == "" {
|
if *filePtr == "" {
|
||||||
log.Log(logger.Fatal, "no file path provided, check usage")
|
log.Log(logger.Fatal, "no file path provided, check usage")
|
||||||
}
|
}
|
||||||
cmd := exec.Command(audioCmd, *filePtr)
|
|
||||||
|
|
||||||
// The netsender client will handle communication with netreceiver and GPIO stuff.
|
// The netsender client will handle communication with netreceiver and GPIO stuff.
|
||||||
log.Log(logger.Debug, "initialising netsender client")
|
log.Log(logger.Debug, "initialising netsender client")
|
||||||
|
@ -127,12 +127,12 @@ func main() {
|
||||||
|
|
||||||
// Start the control loop.
|
// Start the control loop.
|
||||||
log.Log(logger.Debug, "starting control loop")
|
log.Log(logger.Debug, "starting control loop")
|
||||||
run(rv, ns, cmd, log, netLog)
|
run(rv, ns, filePtr, log, netLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
// run starts a control loop that runs netsender, sends logs, checks for var changes, and
|
// run starts a control loop that runs netsender, sends logs, checks for var changes, and
|
||||||
// if var changes, changes current mode (paused,audio playback or soundcheck)
|
// if var changes, changes current mode (paused,audio playback or soundcheck)
|
||||||
func run(rv *revid.Revid, ns *netsender.Sender, cmd *exec.Cmd, l *logger.Logger, nl *netlogger.Logger) {
|
func run(rv *revid.Revid, ns *netsender.Sender, file *string, l *logger.Logger, nl *netlogger.Logger) {
|
||||||
var (
|
var (
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
audioQuit chan struct{}
|
audioQuit chan struct{}
|
||||||
|
@ -196,7 +196,7 @@ func run(rv *revid.Revid, ns *netsender.Sender, cmd *exec.Cmd, l *logger.Logger,
|
||||||
audioQuit = make(chan struct{})
|
audioQuit = make(chan struct{})
|
||||||
treating = true
|
treating = true
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go playAudio(cmd, audioQuit, &wg, l)
|
go playAudio(file, audioQuit, &wg, l)
|
||||||
}
|
}
|
||||||
case modeCheck:
|
case modeCheck:
|
||||||
stopAudio(&wg, &treating, audioQuit)
|
stopAudio(&wg, &treating, audioQuit)
|
||||||
|
@ -217,9 +217,10 @@ func run(rv *revid.Revid, ns *netsender.Sender, cmd *exec.Cmd, l *logger.Logger,
|
||||||
// playAudio is intended to be run as a routine. It will repeatedly play an audio file until
|
// playAudio is intended to be run as a routine. It will repeatedly play an audio file until
|
||||||
// a signal is received to return. The entire audio file is played before the termination
|
// a signal is received to return. The entire audio file is played before the termination
|
||||||
// signal chan is checked.
|
// signal chan is checked.
|
||||||
func playAudio(cmd *exec.Cmd, quit chan struct{}, wg *sync.WaitGroup, l *logger.Logger) {
|
func playAudio(file *string, quit chan struct{}, wg *sync.WaitGroup, l *logger.Logger) {
|
||||||
var numPlays int
|
var numPlays int
|
||||||
for {
|
for {
|
||||||
|
cmd := exec.Command(audioCmd, *file)
|
||||||
// We'd like to see what the playback software is outputting, so pipe
|
// We'd like to see what the playback software is outputting, so pipe
|
||||||
// stdout and stderr.
|
// stdout and stderr.
|
||||||
outPipe, err := cmd.StdoutPipe()
|
outPipe, err := cmd.StdoutPipe()
|
||||||
|
@ -285,6 +286,9 @@ func playAudio(cmd *exec.Cmd, quit chan struct{}, wg *sync.WaitGroup, l *logger.
|
||||||
// stopAudio signals to the playAudio routine to terminate and then waits for it to
|
// stopAudio signals to the playAudio routine to terminate and then waits for it to
|
||||||
// do so.
|
// do so.
|
||||||
func stopAudio(wg *sync.WaitGroup, treating *bool, signal chan struct{}) {
|
func stopAudio(wg *sync.WaitGroup, treating *bool, signal chan struct{}) {
|
||||||
|
if !*treating {
|
||||||
|
return
|
||||||
|
}
|
||||||
close(signal)
|
close(signal)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
*treating = false
|
*treating = false
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -10,6 +10,7 @@ require (
|
||||||
github.com/go-audio/wav v0.0.0-20181013172942-de841e69b884
|
github.com/go-audio/wav v0.0.0-20181013172942-de841e69b884
|
||||||
github.com/go-delve/delve v1.5.0
|
github.com/go-delve/delve v1.5.0
|
||||||
github.com/google/go-cmp v0.4.1
|
github.com/google/go-cmp v0.4.1
|
||||||
|
github.com/kidoman/embd v0.0.0-20170508013040-d3d8c0c5c68d
|
||||||
github.com/mewkiz/flac v1.0.5
|
github.com/mewkiz/flac v1.0.5
|
||||||
github.com/pkg/errors v0.8.1
|
github.com/pkg/errors v0.8.1
|
||||||
github.com/yobert/alsa v0.0.0-20180630182551-d38d89fa843e
|
github.com/yobert/alsa v0.0.0-20180630182551-d38d89fa843e
|
||||||
|
|
Loading…
Reference in New Issue