1use num_enum::{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, TryFromPrimitive)]
100#[cfg_attr(feature = "serde", derive(serde::Serialize))]
101#[non_exhaustive]
102#[repr(u8)]
103pub enum ActivityEventType {
104 NoActivityTimeoutReached = 0,
106 UserActivityDetected = 1,
108}
109
110bitflags::bitflags! {
111 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
114 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
115 pub struct RgbPersistence: u8 {
116 const VOLATILE = 1 << 0;
118 const NON_VOLATILE = 1 << 1;
120 }
121}
122
123bitflags::bitflags! {
124 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
126 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
127 pub struct RgbExtCapabilities: u16 {
128 const GET_ZONE_EFFECT = 1 << 0;
130 const SET_LED_BIN_INFO = 1 << 2;
132 const MONOCHROME_ONLY = 1 << 3;
134 const NO_EFFECT_SYNC = 1 << 4;
136 const SHUTDOWN = 1 << 5;
138 const CLUSTER_CHANGED_EVENT = 1 << 6;
140 }
141}
142
143bitflags::bitflags! {
144 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
146 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
147 pub struct RgbNvCapabilities: u16 {
148 const BOOT_UP_EFFECT = 1 << 0;
150 const DEMO = 1 << 1;
152 const USER_DEMO_MODE = 1 << 2;
154 const EVENTS_DISPLAY = 1 << 3;
156 const ACTIVE_DIMMING = 1 << 4;
158 const RAMP_DOWN_TO_OFF = 1 << 5;
160 const SHUTDOWN_EFFECT = 1 << 6;
162 }
163}
164
165bitflags::bitflags! {
166 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
168 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
169 pub struct SwControlFlags: u8 {
170 const ALL_CLUSTERS = 1 << 0;
172 const POWER_MODES = 1 << 1;
174 }
175}
176
177bitflags::bitflags! {
178 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
180 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
181 pub struct EventsNotificationFlags: u8 {
182 const EFFECTS_SYNC = 1 << 0;
184 const USER_ACTIVITY = 1 << 1;
186 const NO_USER_ACTIVITY_TIMEOUT = 1 << 2;
188 }
189}
190
191bitflags::bitflags! {
192 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
194 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
195 pub struct DisplayPersistencyCapabilities: u8 {
196 const ALWAYS_ON = 1 << 0;
198 const ALWAYS_OFF = 1 << 1;
200 const ON_THEN_OFF = 1 << 2;
202 }
203}
204
205#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
208#[cfg_attr(feature = "serde", derive(serde::Serialize))]
209#[non_exhaustive]
210pub struct RgbDeviceInfo {
211 pub cluster_count: u8,
213 pub nv_capabilities: RgbNvCapabilities,
215 pub ext_capabilities: RgbExtCapabilities,
217 pub multicluster_effect_count: u8,
219}
220
221impl RgbDeviceInfo {
222 pub(super) fn from_payload(payload: &[u8; 16]) -> Self {
223 Self {
224 cluster_count: payload[2],
225 nv_capabilities: RgbNvCapabilities::from_bits_retain(be16(payload, 3)),
226 ext_capabilities: RgbExtCapabilities::from_bits_retain(be16(payload, 5)),
227 multicluster_effect_count: payload[7],
228 }
229 }
230}
231
232#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
235#[cfg_attr(feature = "serde", derive(serde::Serialize))]
236#[non_exhaustive]
237pub struct RgbClusterInfo {
238 pub cluster_index: u8,
240 pub location: u16,
242 pub effects_number: u8,
244 pub display_persistency: DisplayPersistencyCapabilities,
246 pub effect_persistency: bool,
248 pub multiled_pattern: bool,
250}
251
252impl RgbClusterInfo {
253 pub(super) fn from_payload(payload: &[u8; 16]) -> Self {
254 Self {
255 cluster_index: payload[0],
256 location: be16(payload, 2),
257 effects_number: payload[4],
258 display_persistency: DisplayPersistencyCapabilities::from_bits_retain(payload[5]),
259 effect_persistency: payload[6] != 0,
260 multiled_pattern: payload[7] != 0,
261 }
262 }
263}
264
265#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
268#[cfg_attr(feature = "serde", derive(serde::Serialize))]
269#[non_exhaustive]
270pub struct RgbEffectInfo {
271 pub cluster_index: u8,
273 pub cluster_effect_index: u8,
275 pub effect_id: u16,
277 pub effect_capabilities: u16,
280 pub effect_period: u16,
282}
283
284impl RgbEffectInfo {
285 pub(super) fn from_payload(payload: &[u8; 16]) -> Self {
286 Self {
287 cluster_index: payload[0],
288 cluster_effect_index: payload[1],
289 effect_id: be16(payload, 2),
290 effect_capabilities: be16(payload, 4),
291 effect_period: be16(payload, 6),
292 }
293 }
294}
295
296#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
299#[cfg_attr(feature = "serde", derive(serde::Serialize))]
300#[non_exhaustive]
301pub struct RgbSwControl {
302 pub control: SwControlFlags,
304 pub events: EventsNotificationFlags,
306}
307
308#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
311#[cfg_attr(feature = "serde", derive(serde::Serialize))]
312#[non_exhaustive]
313pub struct RgbNvConfig {
314 pub capability: RgbNvCapabilities,
316 pub state: u8,
319 pub param1: u8,
321 pub param2: u8,
323}
324
325#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
328#[cfg_attr(feature = "serde", derive(serde::Serialize))]
329#[non_exhaustive]
330pub struct RgbPowerModeConfig {
331 pub flags: u16,
333 pub no_activity_timeout_to_power_save: u16,
335 pub no_activity_timeout_to_off: u16,
337}
338
339impl RgbPowerModeConfig {
340 pub(super) fn from_payload(payload: &[u8; 16]) -> Self {
341 Self {
342 flags: be16(payload, 1),
343 no_activity_timeout_to_power_save: be16(payload, 3),
344 no_activity_timeout_to_off: be16(payload, 5),
345 }
346 }
347}