Example #1
0
func (a *Action) doGradient(setter Setter, lights []int, e *tasks.Execution) {
	startTime := e.Now()
	var currentD time.Duration
	var properties gohue.LightProperties
	if a.On {
		properties.On.Set(true)
	}
	idx := 1
	last := &a.G.Cds[len(a.G.Cds)-1]
	for idx < len(a.G.Cds) {
		if currentD >= a.G.Cds[idx].D {
			idx++
			continue
		}
		first := &a.G.Cds[idx-1]
		second := &a.G.Cds[idx]
		ratio := float64(currentD-first.D) / float64(second.D-first.D)
		acolor := maybeBlendColor(first.C, second.C, ratio)
		aBrightness := maybeBlendBrightness(first.Bri, second.Bri, ratio)
		properties.C = acolor
		properties.Bri = aBrightness
		multiSet(e, setter, lights, &properties)
		properties.On.Clear()
		if e.Error() != nil {
			return
		}
		if !e.Sleep(a.G.Refresh) {
			return
		}
		currentD = e.Now().Sub(startTime)
	}
	properties.C = last.C
	properties.Bri = last.Bri
	multiSet(e, setter, lights, &properties)
}
Example #2
0
func (a *Action) doOnOff(setter Setter, lights []int, e *tasks.Execution) {
	var properties gohue.LightProperties
	if a.On {
		properties.On.Set(true)
	} else if a.Off {
		properties.On.Set(false)
	}
	properties.C = a.C
	properties.Bri = a.Bri
	properties.TransitionTime = a.TransitionTime
	multiSet(e, setter, lights, &properties)
}