From 8c7f1c6ffc16759f504663bf947411702965c139 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Fri, 19 Aug 2022 00:18:09 +0200 Subject: [PATCH] add pattern effects. --- cmd/bustest/main.go | 34 ++++++++++++++++++++++++++++++---- effects/pattern.go | 24 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 effects/pattern.go diff --git a/cmd/bustest/main.go b/cmd/bustest/main.go index c4d3759..9934e7b 100644 --- a/cmd/bustest/main.go +++ b/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,10 +92,20 @@ func main() { bus.RunCommand(commands.Assign{ Match: "**:Hexagon *", - Effect: effects.Manual{ - Power: gentools.Ptr(true), - Color: gentools.Ptr(color.MustParse("rgb:#ffcc11")), - Intensity: gentools.Ptr(1.0), + Effect: effects.Pattern{ + States: []device.State{ + { + Power: gentools.Ptr(true), + 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, }, }) @@ -92,4 +116,6 @@ func main() { log.Println("- ID:", dev.ID) log.Println(" Aliases:", dev.Aliases) } + + time.Sleep(time.Second * 15) } diff --git a/effects/pattern.go b/effects/pattern.go new file mode 100644 index 0000000..b82ac6f --- /dev/null +++ b/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) +}