You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

47 lines
1016 B

package effects
import (
"fmt"
"git.aiterp.net/lucifer3/server/device"
"time"
)
type VRange struct {
States []device.State `json:"states"`
Variable string `json:"variable"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Interpolate bool `json:"interpolate"`
}
func (e VRange) VariableName() string {
return e.Variable
}
func (e VRange) VariableState(_, _ int, value float64) device.State {
if value <= e.Min {
return e.States[0]
} else if value >= e.Max {
return e.States[len(e.States)-1]
}
return gradientStateFactor(e.States, e.Interpolate, (value-e.Min)/(e.Max-e.Min))
}
func (e VRange) State(_, _, _ int) device.State {
if len(e.States) == 0 {
return device.State{}
}
return e.States[0]
}
func (e VRange) Frequency() time.Duration {
return 0
}
func (e VRange) EffectDescription() string {
return fmt.Sprintf(
"VRange(states:%s, name:%s, range:%.1f..%.1f)",
statesDescription(e.States), e.Variable, e.Min, e.Max,
)
}