Skip to main content

HidppChannel

Struct HidppChannel 

Source
pub struct HidppChannel {
    pub supports_short: bool,
    pub supports_long: bool,
    pub vendor_id: u16,
    pub product_id: u16,
    /* private fields */
}
Expand description

Represents a HID communication channel supporting HID++.

Fields§

§supports_short: bool

Whether the channel supports short (7 bytes) HID++ messages.

§supports_long: bool

Whether the channel supports long (20 bytes) HID++ messages.

§vendor_id: u16

The vendor ID of the connected HID device.

§product_id: u16

Implementations§

Source§

impl HidppChannel

Source

pub async fn from_raw_channel( raw: impl RawHidChannel, ) -> Result<Self, ChannelError>

Tries to construct a HID++ channel from a raw HID channel.

If the given HID channel does not support HID++, ChannelError::HidppNotSupported will be returned.

Source

pub fn set_sw_id(&self, sw_id: U4)

Sets the software ID that should be returned by the next call to Self::get_sw_id.

Using software ID 0 is highly discouraged as it is used for device notifications.

Source

pub fn set_rotating_sw_id(&self, enable: bool)

Sets whether the software ID returned by a call to Self::get_sw_id should increment (and potentially wrap around) after each call.

This comes in handy when trying to map responses to requests consistently.

Software ID 0 will be skipped in the rotation process as it is reserved for device notifications.

Source

pub fn get_sw_id(&self) -> U4

Provides a software ID that can be used to send a HID++ message across the channel.

This method should be called separately for every message to send as it may rotate (as indicated by Self::set_rotating_sw_id).

Source

pub fn supports_msg(&self, msg: &HidppMessage) -> bool

Checks whether the channel supports the given HID++ message.

Source

pub async fn send( &self, msg: HidppMessage, response_predicate: impl Fn(&HidppMessage) -> bool + Send + 'static, ) -> Result<HidppMessage, ChannelError>

Sends a HID++ message across the channel and waits for a response.

If no response is expected/required, use Self::send_and_forget.

The future resolves to Ok(None) if no response was received.

Source

pub async fn send_and_forget( &self, msg: HidppMessage, ) -> Result<(), ChannelError>

Sends a HID++ message across the channel and does not wait for a response.

If a response is expected, use Self::send,

Source

pub fn add_msg_listener( &self, listener: impl Fn(HidppMessage, bool) + Send + 'static, ) -> u32

Registers a listener that will be called for every incoming message.

Returns a handle that can be used to remove the listener using a call to Self::remove_msg_listener.

Source

pub fn remove_msg_listener(&self, hdl: u32) -> bool

Removes a previously registered message listener.

Returns whether a listener was found using the given handle.

Source§

impl HidppChannel

Source

pub async fn read_register( &self, device: u8, address: u8, parameters: [u8; 3], ) -> Result<[u8; 3], Hidpp10Error>

Reads the data from a short 3-byte register using HID++1.0/RAP.

Source

pub async fn write_register( &self, device: u8, address: u8, payload: [u8; 3], ) -> Result<(), Hidpp10Error>

Writes data to a short 3-byte register using HID++1.0/RAP.

Source

pub async fn read_long_register( &self, device: u8, address: u8, parameters: [u8; 3], ) -> Result<[u8; 16], Hidpp10Error>

Reads the data from a long 16-byte register using HID++1.0/RAP.

Source

pub async fn write_long_register( &self, device: u8, address: u8, payload: [u8; 16], ) -> Result<(), Hidpp10Error>

Writes data to a long 16-byte register using HID++1.0/RAP.

Source§

impl HidppChannel

Source

pub async fn send_v20(&self, msg: Message) -> Result<Message, Hidpp20Error>

Sends a HID++2.0 message across the channel and waits for a response that matches the message header.

This method simply calls Self::send with a pre-built response predicate comparing the headers of the outgoing and incoming message.

Trait Implementations§

Source§

impl Drop for HidppChannel

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V