package device import ( "git.aiterp.net/lucifer3/server/internal/gentools" "math/bits" ) type SupportFlags uint32 const ( SFlagPower SupportFlags = 1 << iota SFlagIntensity SFlagColor SFlagTemperature SFlagSensorButtons SFlagSensorTemperature SFlagSensorLightLevel SFlagSensorPresence ) var supportFlags = []SupportFlags{SFlagPower, SFlagIntensity, SFlagColor, SFlagTemperature, SFlagSensorButtons, SFlagSensorTemperature, SFlagSensorLightLevel, SFlagSensorPresence} func (f SupportFlags) String() string { return gentools.FlagString(f, supportFlags, []string{"P", "I", "C", "T", "SB", "ST", "SLL", "SP"}) } 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)) } // 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 ) var colorFlags = []ColorFlag{CFlagXY, CFlagRGB, CFlagHS, CFlagHSK, CFlagKelvin} func (f ColorFlag) String() string { return gentools.FlagString(f, colorFlags, []string{"XY", "RGB", "HS", "HSK", "K"}) } 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.IsColor() && !f.IsWarmWhite() } func (f ColorFlag) IsWarmWhiteOnly() bool { return f.IsWarmWhite() && !f.IsColor() } 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)) }