屏幕控制完成

This commit is contained in:
2024-11-08 16:15:12 +08:00
parent 660ae1326f
commit 3da1fe761e
4 changed files with 26 additions and 4 deletions

View File

@@ -11,6 +11,9 @@ import (
func OnlyVideo(c *leaf.Context) {
payload := leaf.Value[*schema.PlayModal](c, middleware.PayloadJSONKey)
utils.BlankOpen()
defer utils.BlankClose()
if url, ok := payload.Game["video"]; ok {
_ = video.Play(c, utils.LinkVideo(url.(string)))
}

View File

@@ -201,6 +201,9 @@ func videoAction(c *leaf.Context, item schema.WaitItemModel, root schema.TimeMod
case <-c.Done():
case <-timerAction(item.Start):
{
utils.BlankOpen()
defer utils.BlankClose()
for {
err := video.Play(c, utils.LinkVideo(item.Data))
if err != nil {

View File

@@ -10,6 +10,7 @@ import (
"game-driver/internal/schema"
"game-driver/leaf"
"game-driver/pkg/tts"
"game-driver/pkg/utils"
"github.com/eclipse/paho.golang/autopaho"
"github.com/eclipse/paho.golang/paho"
"log"
@@ -37,18 +38,18 @@ func buildMqtt(c config.MqttConfig, r *leaf.Engine, subTopics ...string) autopah
KeepAlive: 20,
CleanStartOnInitialConnection: false,
SessionExpiryInterval: 60,
OnConnectionUp: func(cm *autopaho.ConnectionManager, connAck *paho.Connack) {
log.Println("mqtt connection up")
OnConnectionUp: func(cm *autopaho.ConnectionManager, _ *paho.Connack) {
log.Println("MQTT 连接成功")
if _, err := cm.Subscribe(context.Background(), &paho.Subscribe{
Subscriptions: subscriptions,
}); err != nil {
log.Printf("failed to subscribe (%s). This is likely to mean no messages will be received.", err)
return
}
log.Println("mqtt subscription made")
log.Println("订阅完成")
},
OnConnectError: func(err error) {
log.Printf("error whilst attempting connection: %s\n", err)
log.Printf("MQTT 连接异常: %s\n", err)
},
ClientConfig: paho.ClientConfig{
ClientID: "TestSubscriber",
@@ -139,6 +140,8 @@ func Run() {
// 启动完成发送一次设备状态
device.PublishStatus()
// 启动完成关闭屏幕
utils.BlankClose()
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)

13
pkg/utils/blank.go Normal file
View File

@@ -0,0 +1,13 @@
package utils
import "os"
// BlankOpen 打开屏幕
func BlankOpen() {
os.WriteFile("/sys/class/graphics/fb0/blank", []byte("0"), 0644)
}
// BlankClose 关闭屏幕
func BlankClose() {
os.WriteFile("/sys/class/graphics/fb0/blank", []byte("1"), 0644)
}