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
59 lines
1.1 KiB
package device
|
|
|
|
import "math/bits"
|
|
|
|
type SupportFlags uint32
|
|
|
|
func (f SupportFlags) HasAny(d SupportFlags) bool {
|
|
return (f & d) != 0
|
|
}
|
|
|
|
func (f SupportFlags) HasAll(d SupportFlags) bool {
|
|
return bits.OnesCount32(uint32(f&d)) == bits.OnesCount32(uint32(d))
|
|
}
|
|
|
|
const (
|
|
SFlagPower SupportFlags = 1 << iota
|
|
SFlagIntensity
|
|
SFlagColor
|
|
SFlagTemperature
|
|
SFlagSensorButtons
|
|
SFlagSensorTemperature
|
|
SFlagSensorLightLevel
|
|
SFlagSensorPresence
|
|
)
|
|
|
|
// ColorFlag is primarily to detect warm-white lights, as XY/RGB/HS/HSK can convert without trouble.
|
|
type ColorFlag uint32
|
|
|
|
const (
|
|
CFlagXY ColorFlag = 1 << iota
|
|
CFlagRGB
|
|
CFlagHS
|
|
CFlagHSK
|
|
CFlagKelvin
|
|
)
|
|
|
|
func (f ColorFlag) IsColor() bool {
|
|
return f.HasAny(CFlagXY | CFlagRGB | CFlagHS | CFlagHSK)
|
|
}
|
|
|
|
func (f ColorFlag) IsWarmWhite() bool {
|
|
return f&CFlagKelvin == CFlagKelvin
|
|
}
|
|
|
|
func (f ColorFlag) IsColorOnly() bool {
|
|
return f != 0 && f&CFlagKelvin == 0
|
|
}
|
|
|
|
func (f ColorFlag) IsWarmWhiteOnly() bool {
|
|
return f == CFlagKelvin
|
|
}
|
|
|
|
func (f ColorFlag) HasAny(d ColorFlag) bool {
|
|
return (f & d) != 0
|
|
}
|
|
|
|
func (f ColorFlag) HasAll(d ColorFlag) bool {
|
|
return bits.OnesCount32(uint32(f&d)) == bits.OnesCount32(uint32(d))
|
|
}
|