Browse Source

add pattern effects.

beelzebub
Gisle Aune 2 years ago
parent
commit
8c7f1c6ffc
  1. 30
      cmd/bustest/main.go
  2. 24
      effects/pattern.go

30
cmd/bustest/main.go

@ -62,6 +62,20 @@ func main() {
ColorFlags: device.CFlagRGB,
State: device.State{},
})
bus.RunEvent(events.HardwareState{
ID: "nanoleaf:10.80.1.11:dead",
InternalName: "Hexagon 7",
SupportFlags: device.SFlagPower | device.SFlagColor | device.SFlagIntensity,
ColorFlags: device.CFlagRGB,
State: device.State{},
})
bus.RunEvent(events.HardwareState{
ID: "nanoleaf:10.80.1.11:beef",
InternalName: "Hexagon 8",
SupportFlags: device.SFlagPower | device.SFlagColor | device.SFlagIntensity,
ColorFlags: device.CFlagRGB,
State: device.State{},
})
time.Sleep(time.Millisecond)
@ -78,11 +92,21 @@ func main() {
bus.RunCommand(commands.Assign{
Match: "**:Hexagon *",
Effect: effects.Manual{
Effect: effects.Pattern{
States: []device.State{
{
Power: gentools.Ptr(true),
Color: gentools.Ptr(color.MustParse("rgb:#ffcc11")),
Color: gentools.Ptr(color.MustParse("rgb:#ff0000")),
Intensity: gentools.Ptr(1.0),
},
{
Power: gentools.Ptr(true),
Color: gentools.Ptr(color.MustParse("rgb:#00ff00")),
Intensity: gentools.Ptr(0.7),
},
},
ShiftMS: 1000,
},
})
time.Sleep(time.Millisecond * 100)
@ -92,4 +116,6 @@ func main() {
log.Println("- ID:", dev.ID)
log.Println(" Aliases:", dev.Aliases)
}
time.Sleep(time.Second * 15)
}

24
effects/pattern.go

@ -0,0 +1,24 @@
package effects
import (
"fmt"
"git.aiterp.net/lucifer3/server/device"
"time"
)
type Pattern struct {
States []device.State `json:"states,omitempty"`
ShiftMS int64 `json:"shiftMs,omitempty"`
}
func (p Pattern) State(index, round, _ int) device.State {
return p.States[(index+round)%len(p.States)]
}
func (p Pattern) Frequency() time.Duration {
return time.Duration(p.ShiftMS) * time.Millisecond
}
func (p Pattern) EffectDescription() string {
return fmt.Sprintf("Pattern(len:%d, animation:%dms)", len(p.States), p.ShiftMS)
}
Loading…
Cancel
Save