This commit is contained in:
2025-02-27 13:53:15 +08:00
parent 6e4bf4a2c0
commit b36e67f826
6 changed files with 44 additions and 7 deletions

View File

@@ -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:

View File

@@ -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 的发卡器配置

View File

@@ -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,
}
}

View File

@@ -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():

View File

@@ -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"
}
}
```

View File

@@ -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 .