diff --git a/cmd/root.go b/cmd/root.go index 5b28ca5..dd1da4d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -21,7 +21,7 @@ var cfgFile string // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "game-driver", - Version: "0.0.1", + Version: "1.0.0", Short: "A brief description of your application", Long: `A longer description that spans multiple lines and likely contains examples and usage of using your application. For example: diff --git a/config.yml b/config.yml index 8f014ea..ba0c17c 100755 --- a/config.yml +++ b/config.yml @@ -17,9 +17,9 @@ aliyun: accessKeySecret: appKey: timeout: 10 # 单位 s - volume: 200 # 音量 + volume: 100 # 音量,取值范围:0~100 voice: zhifeng_emo # 发音人 - speechRate: 50 # 语速 + speechRate: 50 # 语速,取值范围:-500~500 #game: # addr: /dev/ttyUSB0 # 点位 11 的串口地址 # pushGroups: # 点位 10 的发卡器配置 diff --git a/internal/common/pause.go b/internal/common/pause.go index eb6724e..c157207 100644 --- a/internal/common/pause.go +++ b/internal/common/pause.go @@ -1,20 +1,46 @@ package common +import "sync" + type CtrlWait struct { // 用于暂停的chan P chan struct{} // 用于恢复的chan R chan struct{} + // 状态 + s bool + + m sync.RWMutex } // Pause 暂停 func (c *CtrlWait) Pause() { - c.P <- struct{}{} + c.m.RLock() + defer c.m.RUnlock() + if c.s { + c.P <- struct{}{} + } } // Resume 恢复 func (c *CtrlWait) Resume() { - c.R <- struct{}{} + c.m.RLock() + defer c.m.RUnlock() + if c.s { + c.R <- struct{}{} + } +} + +func (c *CtrlWait) Open() { + c.m.Lock() + defer c.m.Unlock() + c.s = true +} + +func (c *CtrlWait) Close() { + c.m.Lock() + defer c.m.Unlock() + c.s = false } // NewCtrlWait 创建一个控制等待 @@ -22,6 +48,7 @@ func NewCtrlWait() *CtrlWait { return &CtrlWait{ P: make(chan struct{}), R: make(chan struct{}), + s: false, } } diff --git a/internal/middleware/pause.go b/internal/middleware/pause.go index de0f0df..2ff5ef5 100644 --- a/internal/middleware/pause.go +++ b/internal/middleware/pause.go @@ -29,6 +29,9 @@ func Pause(ctrl *common.CtrlWait) leaf.HandlerFunc { defer wait.Done() zap.S().Infoln("待机控制器") + ctrl.Open() + defer ctrl.Close() + for { select { case <-originalCtx.Done(): diff --git a/json.md b/json.md index 05af5e1..0cea813 100644 --- a/json.md +++ b/json.md @@ -8,7 +8,7 @@ url: `server/wushan/2/wait` "cron": "* * * *", "items": [ { - "data": "file:///opt/game/三峡龙脊BGM.mp3" + "data": "file://./三峡龙脊BGM.mp3" } ] } @@ -30,7 +30,7 @@ url: `server/wushan/2/play` ] }, "game": { - "video": "file:///opt/game/镇水塔法阵.mp4" + "video": "file://./镇水塔法阵.mp4" } } ``` diff --git a/todo.md b/todo.md index 809e34f..1ed277f 100644 --- a/todo.md +++ b/todo.md @@ -33,6 +33,13 @@ xset dpms force on ffplay -autoexit -fs -i video.mp4 ``` +### 注册为 service ,并开机启动 +```bash +sudo cp /script/game-driver.service /etc/systemd/system/ +sudo systemctl enable game-driver +sudo systemctl start game-driver +``` + ## 编译 arm64 架构 ```bash CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -o game-driver-arm64 .