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

The product ID of the connected HID device.

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 is_connected(&self) -> bool

Whether the underlying HID transport still reports a live connection.

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 set_sw_id_lease(&mut self, id: u8, free: fn(u8))

Lease software id id until this channel is dropped, then call free(id).

Replaces any previous lease. Used by OpenLogi so concurrent opens of the same HID node hold distinct correlation ids for their full lifetime.

OpenLogi local addition.

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 whole request — the report write plus the wait for a matching response — is bounded by SEND_RESPONSE_TIMEOUT; the future resolves to ChannelError::Timeout on elapse. Use Self::send_with_timeout to choose a different budget.

Source

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

Sends a HID++ message across the channel and waits for a response, bounding the whole request — the report write plus the wait for a matching response — by timeout.

On elapse the request’s pending entry is removed (concurrent in-flight requests are unaffected) and ChannelError::Timeout is returned; a response that still arrives later reaches message listeners as an unmatched message.

Self::send uses this with SEND_RESPONSE_TIMEOUT, which suits requests to a device that may be asleep. Requests that should fail faster — e.g. probing a receiver that answers immediately or not at all — can pass a tighter budget.

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 async fn write_raw_report( &self, report: &[u8], ) -> Result<usize, ChannelError>

Write one raw HID report through this channel’s already-owned transport.

Reports must contain 1..=64 bytes, including their report ID. The operation is bounded by SEND_RESPONSE_TIMEOUT and returns the exact byte count reported by the transport. This is intended for HID++ report widths such as the 64-byte 0x12 lighting frame that HidppMessage cannot represent.

Source

pub fn add_msg_listener( &self, listener: impl Fn(HidppMessage, bool) + Send + Sync + '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 add_msg_listener_guarded( &self, listener: impl Fn(HidppMessage, bool) + Send + Sync + 'static, ) -> MessageListenerGuard

Registers a listener that is automatically removed when the returned guard is dropped.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more