mirror of
https://github.com/Luzifer/streamdeck.git
synced 2024-12-20 17:51:21 +00:00
Add automatic display-off
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
8fafd39221
commit
d6733c7181
4 changed files with 42 additions and 5 deletions
|
@ -1,8 +1,11 @@
|
|||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
type config struct {
|
||||
DefaultBrightness int `yaml:"default_brightness"`
|
||||
DefaultPage string `yaml:"default_page"`
|
||||
DisplayOffTime time.Duration `yaml:"display_off_time"`
|
||||
Pages map[string]page `yaml:"pages"`
|
||||
RenderFont string `yaml:"render_font"`
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"os/signal"
|
||||
"path"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/Luzifer/rconfig/v2"
|
||||
"github.com/Luzifer/streamdeck"
|
||||
|
@ -69,6 +70,8 @@ func loadConfig() error {
|
|||
return errors.Wrap(err, "Unable to parse config")
|
||||
}
|
||||
|
||||
applySystemPages(&tempConf)
|
||||
|
||||
userConfig = tempConf
|
||||
|
||||
return nil
|
||||
|
@ -77,11 +80,6 @@ func loadConfig() error {
|
|||
func main() {
|
||||
var err error
|
||||
|
||||
// Load config
|
||||
if err = loadConfig(); err != nil {
|
||||
log.WithError(err).Fatal("Unable to load config")
|
||||
}
|
||||
|
||||
// Initalize control devices
|
||||
kbd, err = uinput.CreateKeyboard()
|
||||
if err != nil {
|
||||
|
@ -111,6 +109,11 @@ func main() {
|
|||
"serial": serial,
|
||||
}).Info("Found StreamDeck")
|
||||
|
||||
// Load config
|
||||
if err = loadConfig(); err != nil {
|
||||
log.WithError(err).Fatal("Unable to load config")
|
||||
}
|
||||
|
||||
// Initial setup
|
||||
|
||||
sigs := make(chan os.Signal)
|
||||
|
@ -127,9 +130,18 @@ func main() {
|
|||
log.WithError(err).Error("Unable to load default page")
|
||||
}
|
||||
|
||||
var offTimer *time.Timer = &time.Timer{}
|
||||
if userConfig.DisplayOffTime > 0 {
|
||||
offTimer = time.NewTimer(userConfig.DisplayOffTime)
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case evt := <-sd.Subscribe():
|
||||
if userConfig.DisplayOffTime > 0 {
|
||||
offTimer.Reset(userConfig.DisplayOffTime)
|
||||
}
|
||||
|
||||
if evt.Key >= len(activePage.Keys) {
|
||||
continue
|
||||
}
|
||||
|
@ -141,6 +153,11 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
case <-offTimer.C:
|
||||
if err := togglePage("@@blank"); err != nil {
|
||||
log.WithError(err).Error("Unable to toggle to blank page")
|
||||
}
|
||||
|
||||
case <-sigs:
|
||||
return
|
||||
|
||||
|
|
14
cmd/streamdeck/system_pages.go
Normal file
14
cmd/streamdeck/system_pages.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package main
|
||||
|
||||
func applySystemPages(conf *config) {
|
||||
blankKey := keyDefinition{
|
||||
Display: dynamicElement{Type: "color", Attributes: map[string]interface{}{"rgba": []interface{}{0x0, 0x0, 0x0, 0xff}}},
|
||||
Actions: []dynamicElement{{Type: "page", Attributes: map[string]interface{}{"name": conf.DefaultPage}}},
|
||||
}
|
||||
|
||||
blankPage := page{}
|
||||
for len(blankPage.Keys) < sd.NumKeys() {
|
||||
blankPage.Keys = append(blankPage.Keys, blankKey)
|
||||
}
|
||||
conf.Pages["@@blank"] = blankPage
|
||||
}
|
|
@ -87,6 +87,9 @@ func (c Client) ClearAllKeys() error { return c.cfg.ClearAllKeys() }
|
|||
// IconSize returns the required icon size for the StreamDeck
|
||||
func (c Client) IconSize() int { return c.cfg.IconSize() }
|
||||
|
||||
// NumKeys returns the number of keys available on the StreamDeck
|
||||
func (c Client) NumKeys() int { return c.cfg.NumKeys() }
|
||||
|
||||
// SetBrightness sets the brightness of the keys (0-100)
|
||||
func (c Client) SetBrightness(pct int) error { return c.cfg.SetBrightness(pct) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue