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.

59 lines
1.1 KiB

  1. package device
  2. import "math/bits"
  3. type SupportFlags uint32
  4. func (f SupportFlags) HasAny(d SupportFlags) bool {
  5. return (f & d) != 0
  6. }
  7. func (f SupportFlags) HasAll(d SupportFlags) bool {
  8. return bits.OnesCount32(uint32(f&d)) == bits.OnesCount32(uint32(d))
  9. }
  10. const (
  11. SFlagPower SupportFlags = 1 << iota
  12. SFlagIntensity
  13. SFlagColor
  14. SFlagTemperature
  15. SFlagSensorButtons
  16. SFlagSensorTemperature
  17. SFlagSensorLightLevel
  18. SFlagSensorPresence
  19. )
  20. // ColorFlag is primarily to detect warm-white lights, as XY/RGB/HS/HSK can convert without trouble.
  21. type ColorFlag uint32
  22. const (
  23. CFlagXY ColorFlag = 1 << iota
  24. CFlagRGB
  25. CFlagHS
  26. CFlagHSK
  27. CFlagKelvin
  28. )
  29. func (f ColorFlag) IsColor() bool {
  30. return f.HasAny(CFlagXY | CFlagRGB | CFlagHS | CFlagHSK)
  31. }
  32. func (f ColorFlag) IsWarmWhite() bool {
  33. return f&CFlagKelvin == CFlagKelvin
  34. }
  35. func (f ColorFlag) IsColorOnly() bool {
  36. return f != 0 && f&CFlagKelvin == 0
  37. }
  38. func (f ColorFlag) IsWarmWhiteOnly() bool {
  39. return f == CFlagKelvin
  40. }
  41. func (f ColorFlag) HasAny(d ColorFlag) bool {
  42. return (f & d) != 0
  43. }
  44. func (f ColorFlag) HasAll(d ColorFlag) bool {
  45. return bits.OnesCount32(uint32(f&d)) == bits.OnesCount32(uint32(d))
  46. }