Skip to main content

LampArrayDevice

Struct LampArrayDevice 

Source
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>

Source

pub fn new(info: &'a DeviceInfo) -> Self

Source

pub fn path(&self) -> &str

The device path (e.g. /dev/hidraw0).

Source

pub fn name(&self) -> &str

The device name from sysfs.

Source

pub fn get_attributes(&self) -> Result<LampArrayAttributes>

Read LampArrayAttributesReport (Section 26.2).

Returns lamp count, bounding box dimensions, device kind, and minimum update interval.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn summary(&self) -> &'static str

One-line summary for CLI listing.

Returns a static description based on descriptor info only — does not open the device or perform any ioctl calls.

Auto Trait Implementations§

§

impl<'a> Freeze for LampArrayDevice<'a>

§

impl<'a> RefUnwindSafe for LampArrayDevice<'a>

§

impl<'a> Send for LampArrayDevice<'a>

§

impl<'a> Sync for LampArrayDevice<'a>

§

impl<'a> Unpin for LampArrayDevice<'a>

§

impl<'a> UnsafeUnpin for LampArrayDevice<'a>

§

impl<'a> UnwindSafe for LampArrayDevice<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.