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: boolWhether the channel supports short (7 bytes) HID++ messages.
supports_long: boolWhether the channel supports long (20 bytes) HID++ messages.
vendor_id: u16The vendor ID of the connected HID device.
product_id: u16The product ID of the connected HID device.
Implementations§
Source§impl HidppChannel
impl HidppChannel
Sourcepub async fn from_raw_channel(
raw: impl RawHidChannel,
) -> Result<Self, ChannelError>
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.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Whether the underlying HID transport still reports a live connection.
Sourcepub fn set_sw_id(&self, sw_id: U4)
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.
Sourcepub fn set_rotating_sw_id(&self, enable: bool)
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.
Sourcepub fn set_sw_id_lease(&mut self, id: u8, free: fn(u8))
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.
Sourcepub fn get_sw_id(&self) -> U4
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).
Sourcepub fn supports_msg(&self, msg: &HidppMessage) -> bool
pub fn supports_msg(&self, msg: &HidppMessage) -> bool
Checks whether the channel supports the given HID++ message.
Sourcepub async fn send(
&self,
msg: HidppMessage,
response_predicate: impl Fn(&HidppMessage) -> bool + Send + 'static,
) -> Result<HidppMessage, ChannelError>
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.
Sourcepub async fn send_with_timeout(
&self,
msg: HidppMessage,
response_predicate: impl Fn(&HidppMessage) -> bool + Send + 'static,
timeout: Duration,
) -> Result<HidppMessage, ChannelError>
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.
Sourcepub async fn send_and_forget(
&self,
msg: HidppMessage,
) -> Result<(), ChannelError>
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,
Sourcepub async fn write_raw_report(
&self,
report: &[u8],
) -> Result<usize, ChannelError>
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.
Sourcepub fn add_msg_listener(
&self,
listener: impl Fn(HidppMessage, bool) + Send + Sync + 'static,
) -> u32
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.
Sourcepub fn add_msg_listener_guarded(
&self,
listener: impl Fn(HidppMessage, bool) + Send + Sync + 'static,
) -> MessageListenerGuard
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.
Sourcepub fn remove_msg_listener(&self, hdl: u32) -> bool
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
impl HidppChannel
Sourcepub async fn read_register(
&self,
device: u8,
address: u8,
parameters: [u8; 3],
) -> Result<[u8; 3], Hidpp10Error>
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.
Sourcepub async fn write_register(
&self,
device: u8,
address: u8,
payload: [u8; 3],
) -> Result<(), Hidpp10Error>
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.
Sourcepub async fn read_long_register(
&self,
device: u8,
address: u8,
parameters: [u8; 3],
) -> Result<[u8; 16], Hidpp10Error>
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.
Sourcepub async fn write_long_register(
&self,
device: u8,
address: u8,
payload: [u8; 16],
) -> Result<(), Hidpp10Error>
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
impl HidppChannel
Sourcepub async fn send_v20(&self, msg: Message) -> Result<Message, Hidpp20Error>
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.