mirror of
https://github.com/Luzifer/streamdeck.git
synced 2024-12-30 06:31:23 +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
|
package main
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
DefaultBrightness int `yaml:"default_brightness"`
|
DefaultBrightness int `yaml:"default_brightness"`
|
||||||
DefaultPage string `yaml:"default_page"`
|
DefaultPage string `yaml:"default_page"`
|
||||||
|
DisplayOffTime time.Duration `yaml:"display_off_time"`
|
||||||
Pages map[string]page `yaml:"pages"`
|
Pages map[string]page `yaml:"pages"`
|
||||||
RenderFont string `yaml:"render_font"`
|
RenderFont string `yaml:"render_font"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Luzifer/rconfig/v2"
|
"github.com/Luzifer/rconfig/v2"
|
||||||
"github.com/Luzifer/streamdeck"
|
"github.com/Luzifer/streamdeck"
|
||||||
|
@ -69,6 +70,8 @@ func loadConfig() error {
|
||||||
return errors.Wrap(err, "Unable to parse config")
|
return errors.Wrap(err, "Unable to parse config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applySystemPages(&tempConf)
|
||||||
|
|
||||||
userConfig = tempConf
|
userConfig = tempConf
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -77,11 +80,6 @@ func loadConfig() error {
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Load config
|
|
||||||
if err = loadConfig(); err != nil {
|
|
||||||
log.WithError(err).Fatal("Unable to load config")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initalize control devices
|
// Initalize control devices
|
||||||
kbd, err = uinput.CreateKeyboard()
|
kbd, err = uinput.CreateKeyboard()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -111,6 +109,11 @@ func main() {
|
||||||
"serial": serial,
|
"serial": serial,
|
||||||
}).Info("Found StreamDeck")
|
}).Info("Found StreamDeck")
|
||||||
|
|
||||||
|
// Load config
|
||||||
|
if err = loadConfig(); err != nil {
|
||||||
|
log.WithError(err).Fatal("Unable to load config")
|
||||||
|
}
|
||||||
|
|
||||||
// Initial setup
|
// Initial setup
|
||||||
|
|
||||||
sigs := make(chan os.Signal)
|
sigs := make(chan os.Signal)
|
||||||
|
@ -127,9 +130,18 @@ func main() {
|
||||||
log.WithError(err).Error("Unable to load default page")
|
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 {
|
for {
|
||||||
select {
|
select {
|
||||||
case evt := <-sd.Subscribe():
|
case evt := <-sd.Subscribe():
|
||||||
|
if userConfig.DisplayOffTime > 0 {
|
||||||
|
offTimer.Reset(userConfig.DisplayOffTime)
|
||||||
|
}
|
||||||
|
|
||||||
if evt.Key >= len(activePage.Keys) {
|
if evt.Key >= len(activePage.Keys) {
|
||||||
continue
|
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:
|
case <-sigs:
|
||||||
return
|
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
|
// IconSize returns the required icon size for the StreamDeck
|
||||||
func (c Client) IconSize() int { return c.cfg.IconSize() }
|
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)
|
// SetBrightness sets the brightness of the keys (0-100)
|
||||||
func (c Client) SetBrightness(pct int) error { return c.cfg.SetBrightness(pct) }
|
func (c Client) SetBrightness(pct int) error { return c.cfg.SetBrightness(pct) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue