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: u16Implementations§
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 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 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 future resolves to Ok(None) if no response was received.
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 fn add_msg_listener(
&self,
listener: impl Fn(HidppMessage, bool) + Send + 'static,
) -> u32
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.
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.