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)) } // ColorFlags is primarily to detect warm-white lights, as XY/RGB/HS/HSK can convert without trouble. type ColorFlags uint32 const ( CFlagXY ColorFlags = 1 << iota CFlagRGB CFlagHS CFlagHSK CFlagKelvin ) var colorFlags = []ColorFlags{CFlagXY, CFlagRGB, CFlagHS, CFlagHSK, CFlagKelvin} func (f ColorFlags) String() string { return gentools.FlagString(f, colorFlags, []string{"XY", "RGB", "HS", "HSK", "K"}) } func (f ColorFlags) IsColor() bool { return f.HasAny(CFlagXY | CFlagRGB | CFlagHS | CFlagHSK) } func (f ColorFlags) IsWarmWhite() bool { return f&CFlagKelvin == CFlagKelvin } func (f ColorFlags) IsColorOnly() bool { return f.IsColor() && !f.IsWarmWhite() } func (f ColorFlags) IsWarmWhiteOnly() bool { return f.IsWarmWhite() && !f.IsColor() } func (f ColorFlags) HasAny(d ColorFlags) bool { return (f & d) != 0 } func (f ColorFlags) HasAll(d ColorFlags) bool { return bits.OnesCount32(uint32(f&d)) == bits.OnesCount32(uint32(d)) }