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.

46 lines
956 B

  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,omitempty"`
  9. Variable string `json:"variable"`
  10. Min float64 `json:"min"`
  11. Max float64 `json:"max"`
  12. }
  13. func (e VRange) VariableName() string {
  14. return e.Variable
  15. }
  16. func (e VRange) VariableState(_, _ int, value float64) device.State {
  17. if value <= e.Min {
  18. return e.States[0]
  19. } else if value >= e.Max {
  20. return e.States[len(e.States)-1]
  21. }
  22. return gradientStateFactor(e.States, true, (value-e.Min)/(e.Max-e.Min))
  23. }
  24. func (e VRange) State(_, _, _ int) device.State {
  25. if len(e.States) == 0 {
  26. return device.State{}
  27. }
  28. return e.States[0]
  29. }
  30. func (e VRange) Frequency() time.Duration {
  31. return 0
  32. }
  33. func (e VRange) EffectDescription() string {
  34. return fmt.Sprintf(
  35. "VRange(states:%s, name:%s, range:%.1f..%.1f)",
  36. statesDescription(e.States), e.Variable, e.Min, e.Max,
  37. )
  38. }