2020-02-28 05:55:07 +03:00
|
|
|
// +build pi0
|
|
|
|
|
2020-03-06 07:56:35 +03:00
|
|
|
/*
|
|
|
|
DESCRIPTION
|
|
|
|
pi0.go defines an initialisation function for use when running on the
|
|
|
|
Raspberry Pi 0.
|
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
Ella Pietraroia <ella@ausocean.org>
|
|
|
|
Scott Barnard <scott@ausocean.org>
|
2020-03-06 08:38:32 +03:00
|
|
|
Saxon Nelson-Milton <saxon@ausocean.org>
|
2020-03-06 07:56:35 +03:00
|
|
|
|
|
|
|
LICENSE
|
|
|
|
Copyright (C) 2020 the Australian Ocean Lab (AusOcean)
|
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
|
|
|
*/
|
|
|
|
|
2020-02-28 05:55:07 +03:00
|
|
|
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-03-06 08:38:32 +03:00
|
|
|
func initCommand(l *logger.Logger) {
|
2020-03-06 08:19:50 +03:00
|
|
|
const (
|
|
|
|
cardPath = "/usr/share/doc/audioInjector/asound.state.RCA.thru.test"
|
|
|
|
retryDur = 5 * time.Second
|
2020-03-06 08:38:32 +03:00
|
|
|
alsactl = "alsactl"
|
2020-03-06 08:19:50 +03:00
|
|
|
)
|
2020-02-28 05:55:07 +03:00
|
|
|
|
2020-03-06 08:19:50 +03:00
|
|
|
// Make sure utility to set up sound card, alsactl, exists.
|
2020-03-06 08:38:32 +03:00
|
|
|
checkPath(alsactl, l)
|
2020-02-28 05:55:07 +03:00
|
|
|
|
2020-03-06 08:19:50 +03:00
|
|
|
// Set up sound card using alsactl.
|
2020-03-06 08:38:32 +03:00
|
|
|
cmdInit := exec.Command(alsactl, "-f", cardPath, "restore")
|
|
|
|
err := cmdInit.Run()
|
2020-03-06 08:19:50 +03:00
|
|
|
for err != nil {
|
2020-03-06 08:38:32 +03:00
|
|
|
l.Log(logger.Warning, "alsactl run failed, retrying...", "error", err)
|
2020-03-06 08:19:50 +03:00
|
|
|
time.Sleep(retryDur)
|
|
|
|
err = cmdInit.Run()
|
2020-02-28 05:55:07 +03:00
|
|
|
}
|
|
|
|
|
2020-03-06 08:19:50 +03:00
|
|
|
// Make sure utility to play audio exists.
|
2020-03-06 08:38:32 +03:00
|
|
|
checkPath(audioCmd, l)
|
2020-02-28 05:55:07 +03:00
|
|
|
}
|