屏幕控制完成
This commit is contained in:
@@ -11,6 +11,9 @@ import (
|
|||||||
func OnlyVideo(c *leaf.Context) {
|
func OnlyVideo(c *leaf.Context) {
|
||||||
payload := leaf.Value[*schema.PlayModal](c, middleware.PayloadJSONKey)
|
payload := leaf.Value[*schema.PlayModal](c, middleware.PayloadJSONKey)
|
||||||
|
|
||||||
|
utils.BlankOpen()
|
||||||
|
defer utils.BlankClose()
|
||||||
|
|
||||||
if url, ok := payload.Game["video"]; ok {
|
if url, ok := payload.Game["video"]; ok {
|
||||||
_ = video.Play(c, utils.LinkVideo(url.(string)))
|
_ = video.Play(c, utils.LinkVideo(url.(string)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,6 +201,9 @@ func videoAction(c *leaf.Context, item schema.WaitItemModel, root schema.TimeMod
|
|||||||
case <-c.Done():
|
case <-c.Done():
|
||||||
case <-timerAction(item.Start):
|
case <-timerAction(item.Start):
|
||||||
{
|
{
|
||||||
|
utils.BlankOpen()
|
||||||
|
defer utils.BlankClose()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
err := video.Play(c, utils.LinkVideo(item.Data))
|
err := video.Play(c, utils.LinkVideo(item.Data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"game-driver/internal/schema"
|
"game-driver/internal/schema"
|
||||||
"game-driver/leaf"
|
"game-driver/leaf"
|
||||||
"game-driver/pkg/tts"
|
"game-driver/pkg/tts"
|
||||||
|
"game-driver/pkg/utils"
|
||||||
"github.com/eclipse/paho.golang/autopaho"
|
"github.com/eclipse/paho.golang/autopaho"
|
||||||
"github.com/eclipse/paho.golang/paho"
|
"github.com/eclipse/paho.golang/paho"
|
||||||
"log"
|
"log"
|
||||||
@@ -37,18 +38,18 @@ func buildMqtt(c config.MqttConfig, r *leaf.Engine, subTopics ...string) autopah
|
|||||||
KeepAlive: 20,
|
KeepAlive: 20,
|
||||||
CleanStartOnInitialConnection: false,
|
CleanStartOnInitialConnection: false,
|
||||||
SessionExpiryInterval: 60,
|
SessionExpiryInterval: 60,
|
||||||
OnConnectionUp: func(cm *autopaho.ConnectionManager, connAck *paho.Connack) {
|
OnConnectionUp: func(cm *autopaho.ConnectionManager, _ *paho.Connack) {
|
||||||
log.Println("mqtt connection up")
|
log.Println("MQTT 连接成功")
|
||||||
if _, err := cm.Subscribe(context.Background(), &paho.Subscribe{
|
if _, err := cm.Subscribe(context.Background(), &paho.Subscribe{
|
||||||
Subscriptions: subscriptions,
|
Subscriptions: subscriptions,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Printf("failed to subscribe (%s). This is likely to mean no messages will be received.", err)
|
log.Printf("failed to subscribe (%s). This is likely to mean no messages will be received.", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println("mqtt subscription made")
|
log.Println("订阅完成")
|
||||||
},
|
},
|
||||||
OnConnectError: func(err error) {
|
OnConnectError: func(err error) {
|
||||||
log.Printf("error whilst attempting connection: %s\n", err)
|
log.Printf("MQTT 连接异常: %s\n", err)
|
||||||
},
|
},
|
||||||
ClientConfig: paho.ClientConfig{
|
ClientConfig: paho.ClientConfig{
|
||||||
ClientID: "TestSubscriber",
|
ClientID: "TestSubscriber",
|
||||||
@@ -139,6 +140,8 @@ func Run() {
|
|||||||
|
|
||||||
// 启动完成发送一次设备状态
|
// 启动完成发送一次设备状态
|
||||||
device.PublishStatus()
|
device.PublishStatus()
|
||||||
|
// 启动完成关闭屏幕
|
||||||
|
utils.BlankClose()
|
||||||
|
|
||||||
sig := make(chan os.Signal, 1)
|
sig := make(chan os.Signal, 1)
|
||||||
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|||||||
13
pkg/utils/blank.go
Normal file
13
pkg/utils/blank.go
Normal 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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user