mirror of
https://github.com/Luzifer/streamdeck.git
synced 2024-12-20 17:51:21 +00:00
Add conditional loop on exec display
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
131d09b78c
commit
ac853e585b
2 changed files with 16 additions and 1 deletions
|
@ -111,6 +111,14 @@ func (d displayElementExec) Display(idx int, attributes map[string]interface{})
|
||||||
return errors.Wrap(sd.FillImage(idx, img), "Unable to set image")
|
return errors.Wrap(sd.FillImage(idx, img), "Unable to set image")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d displayElementExec) NeedsLoop(attributes map[string]interface{}) bool {
|
||||||
|
if v, ok := attributes["interval"].(int); ok {
|
||||||
|
return v > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (d *displayElementExec) StartLoopDisplay(idx int, attributes map[string]interface{}) error {
|
func (d *displayElementExec) StartLoopDisplay(idx int, attributes map[string]interface{}) error {
|
||||||
d.running = true
|
d.running = true
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type action interface {
|
type action interface {
|
||||||
|
@ -16,6 +17,7 @@ type displayElement interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type refreshingDisplayElement interface {
|
type refreshingDisplayElement interface {
|
||||||
|
NeedsLoop(attributes map[string]interface{}) bool
|
||||||
StartLoopDisplay(idx int, attributes map[string]interface{}) error
|
StartLoopDisplay(idx int, attributes map[string]interface{}) error
|
||||||
StopLoopDisplay() error
|
StopLoopDisplay() error
|
||||||
}
|
}
|
||||||
|
@ -65,7 +67,12 @@ func callDisplayElement(idx int, kd keyDefinition) error {
|
||||||
inst = reflect.New(t).Interface()
|
inst = reflect.New(t).Interface()
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.Implements(reflect.TypeOf((*refreshingDisplayElement)(nil)).Elem()) {
|
if t.Implements(reflect.TypeOf((*refreshingDisplayElement)(nil)).Elem()) &&
|
||||||
|
inst.(refreshingDisplayElement).NeedsLoop(kd.Display.Attributes) {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"key": idx,
|
||||||
|
"display_type": kd.Display.Type,
|
||||||
|
}).Debug("Starting loop")
|
||||||
activeLoops = append(activeLoops, inst.(refreshingDisplayElement))
|
activeLoops = append(activeLoops, inst.(refreshingDisplayElement))
|
||||||
return inst.(refreshingDisplayElement).StartLoopDisplay(idx, kd.Display.Attributes)
|
return inst.(refreshingDisplayElement).StartLoopDisplay(idx, kd.Display.Attributes)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue