pub struct LampArrayDevice<'a> { /* private fields */ }Expand description
HID LampArray (Usage Page 0x59) control.
Implements the LampArray operation flow per HUT v1.4 Section 26.6: interrogation -> disable autonomous -> update lamps -> (re-enable autonomous)
Report IDs and sizes come from descriptor parsing, not hardcoded.
Implementations§
Source§impl<'a> LampArrayDevice<'a>
impl<'a> LampArrayDevice<'a>
pub fn new(info: &'a DeviceInfo) -> Self
Sourcepub fn get_attributes(&self) -> Result<LampArrayAttributes>
pub fn get_attributes(&self) -> Result<LampArrayAttributes>
Read LampArrayAttributesReport (Section 26.2).
Returns lamp count, bounding box dimensions, device kind, and minimum update interval.
Sourcepub fn get_lamp(&self, index: u16) -> Result<LampAttributes>
pub fn get_lamp(&self, index: u16) -> Result<LampAttributes>
Read attributes for a single lamp (Section 26.3).
Sends LampAttributesRequestReport with the lamp index, then reads LampAttributesResponseReport.
Sourcepub fn get_attributes_and_lamps(
&self,
) -> Result<(LampArrayAttributes, Vec<LampAttributes>)>
pub fn get_attributes_and_lamps( &self, ) -> Result<(LampArrayAttributes, Vec<LampAttributes>)>
Read attributes and all lamp info using a single fd.
Uses the auto-increment mechanism (Section 26.8.2) to read all lamp attributes efficiently with a single request followed by sequential responses.
Sourcepub fn set_autonomous(&self, enabled: bool) -> Result<()>
pub fn set_autonomous(&self, enabled: bool) -> Result<()>
Toggle AutonomousMode (Section 26.5, 26.10.1).
When true: device controls lamps autonomously (built-in effects).
When false: host has exclusive control, device ignores its own effects.
Default device state is true (autonomous).
Sourcepub fn get_autonomous(&self) -> Result<bool>
pub fn get_autonomous(&self) -> Result<bool>
Read current AutonomousMode state (Section 26.5, 26.10.1).
Returns true if the device is in autonomous mode (device controls),
false if the host has exclusive control.
The LampArrayControlReport is a Feature report, so it supports both
GET (read) and SET (write) via HIDRAW ioctl.
Sourcepub fn set_color(&self, r: u8, g: u8, b: u8, intensity: u8) -> Result<()>
pub fn set_color(&self, r: u8, g: u8, b: u8, intensity: u8) -> Result<()>
Set all lamps to a uniform color.
Disables autonomous mode, reads all lamp attributes, scales the RGBI values to the device’s LevelCounts (Section 26.9), then sends a LampRangeUpdate covering all lamps with LampUpdateComplete=1.
RGB values are scaled to the minimum LevelCount across all Programmable lamps in the range (FixedColor lamps’ RGB channels are ignored by the device per Section 26.11.2). Intensity is scaled to the minimum IntensityLevelCount across all lamps.
Opens the fd once for the entire sequence.
Note: Callers performing rapid sequential updates should respect
the device’s min_update_interval_us (from [get_attributes()])
between calls. Per Section 26.11, the spec requires no more than
one LampUpdateComplete per MinUpdateIntervalInMicroseconds.
Sourcepub fn set_lamp_colors(&self, colors: &[LampColor]) -> Result<()>
pub fn set_lamp_colors(&self, colors: &[LampColor]) -> Result<()>
Set individual lamp colors using LampMultiUpdateReport (Section 26.11.1).
Each entry is (lamp_id, red, green, blue, intensity).
Before sending, this method:
- Validates all LampIds are within the device’s LampCount range (Section 26.11.1: “Any LampId >= Device LampCount” is an error)
- Rejects duplicate LampIds within a single call (Section 26.11.1: “Identical LampId in multiple slots” is an error)
- Scales RGBI values to each lamp’s declared LevelCounts (Section 26.9)
- Zeros RGB channels for FixedColor lamps (Section 26.11.1 best practice)
Colors are batched into reports based on the device’s slot count. Intermediate batches set LampUpdateComplete=0; the final batch sets LampUpdateComplete=1 so the device applies all updates atomically.
Requires the device descriptor to include a multi_update report.
Note: Callers performing rapid sequential updates should respect
the device’s min_update_interval_us (from [get_attributes()])
between calls. Per Section 26.11, the spec requires no more than
one LampUpdateComplete per MinUpdateIntervalInMicroseconds.