Browse Source

add pattern effects.

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

34
cmd/bustest/main.go

@ -62,6 +62,20 @@ func main() {
ColorFlags: device.CFlagRGB, ColorFlags: device.CFlagRGB,
State: device.State{}, 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) time.Sleep(time.Millisecond)
@ -78,10 +92,20 @@ func main() {
bus.RunCommand(commands.Assign{ bus.RunCommand(commands.Assign{
Match: "**:Hexagon *", 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("- ID:", dev.ID)
log.Println(" Aliases:", dev.Aliases) 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