Ejemplo n.º 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)
}
Ejemplo n.º 2
0
func (ft *fakeTask) Do(e *tasks.Execution) {
	ft.timeStamps = append(ft.timeStamps, e.Now())
	if ft.err != nil {
		e.SetError(ft.err)
	}
	if ft.runDuration > 0 {
		e.Sleep(ft.runDuration)
	}
	ft.timesRun++
}