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.

74 lines
1.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. package device
  2. import (
  3. "git.aiterp.net/lucifer3/server/internal/gentools"
  4. "math/bits"
  5. )
  6. type SupportFlags uint32
  7. const (
  8. SFlagPower SupportFlags = 1 << iota
  9. SFlagIntensity
  10. SFlagColor
  11. SFlagTemperature
  12. SFlagSensorButtons
  13. SFlagSensorTemperature
  14. SFlagSensorLightLevel
  15. SFlagSensorPresence
  16. )
  17. var supportFlags = []SupportFlags{SFlagPower, SFlagIntensity, SFlagColor, SFlagTemperature, SFlagSensorButtons, SFlagSensorTemperature, SFlagSensorLightLevel, SFlagSensorPresence}
  18. func (f SupportFlags) String() string {
  19. return gentools.FlagString(f, supportFlags, []string{"P", "I", "C", "T", "SB", "ST", "SLL", "SP"})
  20. }
  21. func (f SupportFlags) HasAny(d SupportFlags) bool {
  22. return (f & d) != 0
  23. }
  24. func (f SupportFlags) HasAll(d SupportFlags) bool {
  25. return bits.OnesCount32(uint32(f&d)) == bits.OnesCount32(uint32(d))
  26. }
  27. // ColorFlags is primarily to detect warm-white lights, as XY/RGB/HS/HSK can convert without trouble.
  28. type ColorFlags uint32
  29. const (
  30. CFlagXY ColorFlags = 1 << iota
  31. CFlagRGB
  32. CFlagHS
  33. CFlagHSK
  34. CFlagKelvin
  35. )
  36. var colorFlags = []ColorFlags{CFlagXY, CFlagRGB, CFlagHS, CFlagHSK, CFlagKelvin}
  37. func (f ColorFlags) String() string {
  38. return gentools.FlagString(f, colorFlags, []string{"XY", "RGB", "HS", "HSK", "K"})
  39. }
  40. func (f ColorFlags) IsColor() bool {
  41. return f.HasAny(CFlagXY | CFlagRGB | CFlagHS | CFlagHSK)
  42. }
  43. func (f ColorFlags) IsWarmWhite() bool {
  44. return f&CFlagKelvin == CFlagKelvin
  45. }
  46. func (f ColorFlags) IsColorOnly() bool {
  47. return f.IsColor() && !f.IsWarmWhite()
  48. }
  49. func (f ColorFlags) IsWarmWhiteOnly() bool {
  50. return f.IsWarmWhite() && !f.IsColor()
  51. }
  52. func (f ColorFlags) HasAny(d ColorFlags) bool {
  53. return (f & d) != 0
  54. }
  55. func (f ColorFlags) HasAll(d ColorFlags) bool {
  56. return bits.OnesCount32(uint32(f&d)) == bits.OnesCount32(uint32(d))
  57. }