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

1 year ago
1 year ago
1 year ago
  1. package effects
  2. import (
  3. "fmt"
  4. "git.aiterp.net/lucifer3/server/device"
  5. "time"
  6. )
  7. type VRange struct {
  8. States []device.State `json:"states"`
  9. Variable string `json:"variable"`
  10. Min float64 `json:"min"`
  11. Max float64 `json:"max"`
  12. Interpolate bool `json:"interpolate"`
  13. }
  14. func (e VRange) VariableName() string {
  15. return e.Variable
  16. }
  17. func (e VRange) VariableState(_, _ int, value float64) device.State {
  18. if value <= e.Min {
  19. return e.States[0]
  20. } else if value >= e.Max {
  21. return e.States[len(e.States)-1]
  22. }
  23. return gradientStateFactor(e.States, e.Interpolate, (value-e.Min)/(e.Max-e.Min))
  24. }
  25. func (e VRange) State(_, _, _ int) device.State {
  26. if len(e.States) == 0 {
  27. return device.State{}
  28. }
  29. return e.States[0]
  30. }
  31. func (e VRange) Frequency() time.Duration {
  32. return 0
  33. }
  34. func (e VRange) EffectDescription() string {
  35. return fmt.Sprintf(
  36. "VRange(states:%s, name:%s, range:%.1f..%.1f)",
  37. statesDescription(e.States), e.Variable, e.Min, e.Max,
  38. )
  39. }