Implement hdmi on/off command for boot
This commit is contained in:
parent
9349b91819
commit
97a3474bd2
|
@ -31,6 +31,7 @@ steps:
|
||||||
- go build -o out/inotify cmd/inotify/inotify.go
|
- go build -o out/inotify cmd/inotify/inotify.go
|
||||||
- go build -o out/gui cmd/gui/gui.go
|
- go build -o out/gui cmd/gui/gui.go
|
||||||
- go build -o out/fan cmd/fan/fan.go
|
- go build -o out/fan cmd/fan/fan.go
|
||||||
|
- go build -o out/hdmi cmd/hdmi/hdmi.go
|
||||||
- cp CHANGELOG.md out/
|
- cp CHANGELOG.md out/
|
||||||
- name: gitea-release
|
- name: gitea-release
|
||||||
image: plugins/gitea-release
|
image: plugins/gitea-release
|
||||||
|
|
3
cmd/hdmi/README.md
Normal file
3
cmd/hdmi/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# hdmi
|
||||||
|
|
||||||
|
This is the source for the screen on/off tool. systemd timers are great but if the system auto-reboots overnight for update purposes the screen will remain on post-boot. This tool will ensure the screen turns back off if a PiFrame is rebooted during off hours.
|
91
cmd/hdmi/hdmi.go
Normal file
91
cmd/hdmi/hdmi.go
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"git.kemonine.info/PiFrame/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
CMD_VCGENCMD = "/opt/vc/bin//vcgencmd"
|
||||||
|
CMD_VCGENCMD_DISPLAY_POWER = "display_power"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Load the config file
|
||||||
|
pfConfig, _ := config.LoadConfig()
|
||||||
|
pfConfig.Print()
|
||||||
|
|
||||||
|
// Read config values
|
||||||
|
hdmiOn := pfConfig.String(config.CONFIG_KEY_HDMI_ON)
|
||||||
|
hdmiOff := pfConfig.String(config.CONFIG_KEY_HDMI_OFF)
|
||||||
|
|
||||||
|
// Strip off systemd stuff we don't care about for this purpose
|
||||||
|
hdmiOn = strings.TrimLeft(hdmiOn, "*-*-* ")
|
||||||
|
hdmiOnSplit := strings.Split(hdmiOn, ":")
|
||||||
|
|
||||||
|
// Split the config into hours/minutes/seconds
|
||||||
|
hdmiOff = strings.TrimLeft(hdmiOff, "*-*-* ")
|
||||||
|
hdmiOffSplit := strings.Split(hdmiOff, ":")
|
||||||
|
|
||||||
|
log.Print(hdmiOnSplit)
|
||||||
|
log.Print(hdmiOffSplit)
|
||||||
|
|
||||||
|
// Parse hdmi on hours/minutes/seconds into ints so they can be used to create real date/time
|
||||||
|
hdmiOnHour, err := strconv.Atoi(hdmiOnSplit[0])
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not parse hdmi on hour : %s", err)
|
||||||
|
}
|
||||||
|
hdmiOnMinute, err := strconv.Atoi(hdmiOnSplit[1])
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not parse hdmi on minute : %s", err)
|
||||||
|
}
|
||||||
|
hdmiOnSecond, err := strconv.Atoi(hdmiOnSplit[2])
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not parse htmi on second : %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse hdmi off hours/minutes/seconds into ints so they can be used to create real date/time
|
||||||
|
hdmiOffHour, err := strconv.Atoi(hdmiOffSplit[0])
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not parse hdmi off hour : %s", err)
|
||||||
|
}
|
||||||
|
hdmiOffMinute, err := strconv.Atoi(hdmiOffSplit[1])
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not parse hdmi off minute : %s", err)
|
||||||
|
}
|
||||||
|
hdmiOffSecond, err := strconv.Atoi(hdmiOffSplit[2])
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not parse hdmi off second : %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup date/time vars for comparison
|
||||||
|
currentTime := time.Now()
|
||||||
|
hdmiOnTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), hdmiOnHour, hdmiOnMinute, hdmiOnSecond, 0, currentTime.Location())
|
||||||
|
hdmiOffTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), hdmiOffHour, hdmiOffMinute, hdmiOffSecond, 0, currentTime.Location())
|
||||||
|
|
||||||
|
log.Print(currentTime)
|
||||||
|
log.Print(hdmiOnTime)
|
||||||
|
log.Print(hdmiOffTime)
|
||||||
|
|
||||||
|
// Turn on/off screen depending on current time
|
||||||
|
vcgencmdOnOffFlag := "-1"
|
||||||
|
if currentTime.After(hdmiOnTime) && currentTime.Before(hdmiOffTime) {
|
||||||
|
log.Print("Turning ON screen")
|
||||||
|
vcgencmdOnOffFlag = "1"
|
||||||
|
}
|
||||||
|
if currentTime.After(hdmiOffTime) && currentTime.Before(hdmiOnTime) {
|
||||||
|
log.Print("Turning OFF screen")
|
||||||
|
vcgencmdOnOffFlag = "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
hdmiControl := exec.Command(CMD_VCGENCMD, CMD_VCGENCMD_DISPLAY_POWER, vcgencmdOnOffFlag)
|
||||||
|
err = hdmiControl.Run()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error turning display on/off (%s) : %s", vcgencmdOnOffFlag, err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue