1use num_enum::{FromPrimitive, IntoPrimitive, TryFromPrimitive};
4
5pub const CLUSTER_EFFECT_PARAM_COUNT: usize = 10;
7pub const ONBOARD_INFO_PARAM_COUNT: usize = 13;
9pub const LED_BIN_PARAM_COUNT: usize = 8;
11
12pub const ALL_CLUSTERS: u8 = 0xff;
14pub const ALL_EFFECTS: u8 = 0xff;
16
17pub(super) fn be16(payload: &[u8; 16], offset: usize) -> u16 {
19 u16::from_be_bytes([payload[offset], payload[offset + 1]])
20}
21
22#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive)]
24#[repr(u8)]
25pub(super) enum GetOrSet {
26 Get = 0,
27 Set = 1,
28}
29
30#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive, TryFromPrimitive)]
32#[cfg_attr(feature = "serde", derive(serde::Serialize))]
33#[non_exhaustive]
34#[repr(u8)]
35pub enum SlotInfoType {
36 SlotState = 0,
38 Defaults = 1,
40 Uuid0To10 = 2,
42 Uuid11To16 = 3,
44 EffectName0To10 = 4,
46 EffectName11To21 = 5,
48 EffectName21To31 = 6,
50}
51
52#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive, TryFromPrimitive)]
54#[cfg_attr(feature = "serde", derive(serde::Serialize))]
55#[non_exhaustive]
56#[repr(u8)]
57pub enum RgbPowerMode {
58 FullRgb = 1,
60 PowerSave = 2,
62 PowerOff = 3,
64}
65
66#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive, TryFromPrimitive)]
68#[cfg_attr(feature = "serde", derive(serde::Serialize))]
69#[non_exhaustive]
70#[repr(u8)]
71pub enum PowerModeTarget {
72 FullPower = 0,
74 PowerSave = 1,
76}
77
78#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive, TryFromPrimitive)]
80#[cfg_attr(feature = "serde", derive(serde::Serialize))]
81#[non_exhaustive]
82#[repr(u8)]
83pub enum LedBinIndex {
84 BinValueBrightness = 0,
86 BinValueColor = 1,
88 CalibrationFactors = 2,
90 Brightness = 3,
92 ColorimetricX = 4,
94 ColorimetricY = 5,
96}
97
98#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive, FromPrimitive)]
100#[cfg_attr(feature = "serde", derive(serde::Serialize))]
101#[non_exhaustive]
102#[repr(u8)]
103pub enum ActivityEventType {
104 NoActivityTimeoutReached = 0,
106 UserActivityDetected = 1,
108 #[num_enum(catch_all)]
110 Other(u8),
111}
112
113bitflags::bitflags! {
114 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
117 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
118 pub struct RgbPersistence: u8 {
119 const VOLATILE = 1 << 0;
121 const NON_VOLATILE = 1 << 1;
123 }
124}
125
126bitflags::bitflags! {
127 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
129 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
130 pub struct RgbExtCapabilities: u16 {
131 const GET_ZONE_EFFECT = 1 << 0;
133 const SET_LED_BIN_INFO = 1 << 2;
135 const MONOCHROME_ONLY = 1 << 3;
137 const NO_EFFECT_SYNC = 1 << 4;
139 const SHUTDOWN = 1 << 5;
141 const CLUSTER_CHANGED_EVENT = 1 << 6;
143 }
144}
145
146bitflags::bitflags! {
147 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
149 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
150 pub struct RgbNvCapabilities: u16 {
151 const BOOT_UP_EFFECT = 1 << 0;
153 const DEMO = 1 << 1;
155 const USER_DEMO_MODE = 1 << 2;
157 const EVENTS_DISPLAY = 1 << 3;
159 const ACTIVE_DIMMING = 1 << 4;
161 const RAMP_DOWN_TO_OFF = 1 << 5;
163 const SHUTDOWN_EFFECT = 1 << 6;
165 }
166}
167
168bitflags::bitflags! {
169 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
171 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
172 pub struct SwControlFlags: u8 {
173 const ALL_CLUSTERS = 1 << 0;
175 const POWER_MODES = 1 << 1;
177 }
178}
179
180bitflags::bitflags! {
181 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
183 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
184 pub struct EventsNotificationFlags: u8 {
185 const EFFECTS_SYNC = 1 << 0;
187 const USER_ACTIVITY = 1 << 1;
189 const NO_USER_ACTIVITY_TIMEOUT = 1 << 2;
191 }
192}
193
194bitflags::bitflags! {
195 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
197 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
198 pub struct DisplayPersistencyCapabilities: u8 {
199 const ALWAYS_ON = 1 << 0;
201 const ALWAYS_OFF = 1 << 1;
203 const ON_THEN_OFF = 1 << 2;
205 }
206}
207
208#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
211#[cfg_attr(feature = "serde", derive(serde::Serialize))]
212#[non_exhaustive]
213pub struct RgbDeviceInfo {
214 pub cluster_count: u8,
216 pub nv_capabilities: RgbNvCapabilities,
218 pub ext_capabilities: RgbExtCapabilities,
220 pub multicluster_effect_count: u8,
222}
223
224impl RgbDeviceInfo {
225 pub(super) fn from_payload(payload: &[u8; 16]) -> Self {
226 Self {
227 cluster_count: payload[2],
228 nv_capabilities: RgbNvCapabilities::from_bits_retain(be16(payload, 3)),
229 ext_capabilities: RgbExtCapabilities::from_bits_retain(be16(payload, 5)),
230 multicluster_effect_count: payload[7],
231 }
232 }
233}
234
235#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
238#[cfg_attr(feature = "serde", derive(serde::Serialize))]
239#[non_exhaustive]
240pub struct RgbClusterInfo {
241 pub cluster_index: u8,
243 pub location: u16,
245 pub effects_number: u8,
247 pub display_persistency: DisplayPersistencyCapabilities,
249 pub effect_persistency: bool,
251 pub multiled_pattern: bool,
253}
254
255impl RgbClusterInfo {
256 pub(super) fn from_payload(payload: &[u8; 16]) -> Self {
257 Self {
258 cluster_index: payload[0],
259 location: be16(payload, 2),
260 effects_number: payload[4],
261 display_persistency: DisplayPersistencyCapabilities::from_bits_retain(payload[5]),
262 effect_persistency: payload[6] != 0,
263 multiled_pattern: payload[7] != 0,
264 }
265 }
266}
267
268#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
271#[cfg_attr(feature = "serde", derive(serde::Serialize))]
272#[non_exhaustive]
273pub struct RgbEffectInfo {
274 pub cluster_index: u8,
276 pub cluster_effect_index: u8,
278 pub effect_id: u16,
280 pub effect_capabilities: u16,
283 pub effect_period: u16,
285}
286
287impl RgbEffectInfo {
288 pub(super) fn from_payload(payload: &[u8; 16]) -> Self {
289 Self {
290 cluster_index: payload[0],
291 cluster_effect_index: payload[1],
292 effect_id: be16(payload, 2),
293 effect_capabilities: be16(payload, 4),
294 effect_period: be16(payload, 6),
295 }
296 }
297}
298
299#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
302#[cfg_attr(feature = "serde", derive(serde::Serialize))]
303#[non_exhaustive]
304pub struct RgbSwControl {
305 pub control: SwControlFlags,
307 pub events: EventsNotificationFlags,
309}
310
311#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
314#[cfg_attr(feature = "serde", derive(serde::Serialize))]
315#[non_exhaustive]
316pub struct RgbNvConfig {
317 pub capability: RgbNvCapabilities,
319 pub state: u8,
322 pub param1: u8,
324 pub param2: u8,
326}
327
328#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
331#[cfg_attr(feature = "serde", derive(serde::Serialize))]
332#[non_exhaustive]
333pub struct RgbPowerModeConfig {
334 pub flags: u16,
336 pub no_activity_timeout_to_power_save: u16,
338 pub no_activity_timeout_to_off: u16,
340}
341
342impl RgbPowerModeConfig {
343 pub(super) fn from_payload(payload: &[u8; 16]) -> Self {
344 Self {
345 flags: be16(payload, 1),
346 no_activity_timeout_to_power_save: be16(payload, 3),
347 no_activity_timeout_to_off: be16(payload, 5),
348 }
349 }
350}