pub struct Device { /* private fields */ }Expand description
A connection to one bridge.
Implementations§
Source§impl Device
impl Device
Sourcepub fn open(port: Option<&str>) -> Result<Self>
pub fn open(port: Option<&str>) -> Result<Self>
Open the bridge at port, or auto-detect it when None, and check
that it speaks this library’s protocol version.
§Errors
Error::NoDevice or Error::MultipleDevices when auto-detecting
doesn’t find exactly one bridge, Error::Serial/Error::Io if
the port can’t be opened or configured,
Error::ProtocolMismatch if the firmware speaks another protocol
version, and any error from Device::info.
Sourcepub fn from_io(
reader: impl Read + Send + 'static,
writer: impl Write + Send + 'static,
) -> Self
pub fn from_io( reader: impl Read + Send + 'static, writer: impl Write + Send + 'static, ) -> Self
Talk to a device over an arbitrary byte stream (tests, TCP bridges, …).
No handshake is performed; call Device::info to check the version.
Reads returning io::ErrorKind::TimedOut or
io::ErrorKind::WouldBlock are treated as idle periods; EOF or any
other error ends the connection.
§Panics
If the OS can’t spawn the reader thread.
pub fn set_timeout(&mut self, timeout: Duration)
Sourcepub fn call(&self, command: Command) -> Result<Reply>
pub fn call(&self, command: Command) -> Result<Reply>
Send one command and wait for its reply.
§Errors
Error::Encode if the request can’t be encoded, Error::Io if
writing fails, Error::Timeout if no reply arrives in time,
Error::Disconnected if the connection is gone, or
Error::Device if the device reports an error.
§Panics
If an internal lock is poisoned (another thread panicked holding it).
Sourcepub fn ping(&self) -> Result<()>
pub fn ping(&self) -> Result<()>
Check that the device is responding.
§Errors
See Device::call; Error::UnexpectedReply if the device answers
with the wrong reply type.
Sourcepub fn info(&self) -> Result<DeviceInfo>
pub fn info(&self) -> Result<DeviceInfo>
Firmware and protocol version.
§Errors
See Device::call; Error::UnexpectedReply if the device answers
with the wrong reply type.
Sourcepub fn build_info(&self) -> Result<BuildInfo>
pub fn build_info(&self) -> Result<BuildInfo>
Git commit, toolchain and component versions the firmware was built
with. Firmware older than this command drops the request, so this
times out on it; check DeviceInfo::firmware_version first.
§Errors
See Device::call; Error::UnexpectedReply if the device answers
with the wrong reply type.
Sourcepub fn status(&self) -> Result<Status>
pub fn status(&self) -> Result<Status>
Uptime, BLE state, mapping count and current mode.
§Errors
See Device::call; Error::UnexpectedReply if the device answers
with the wrong reply type.
Sourcepub fn keymap(&self) -> Result<Vec<Mapping>>
pub fn keymap(&self) -> Result<Vec<Mapping>>
The full keymap, fetched page by page.
§Errors
See Device::call; Error::UnexpectedReply if the device answers
with the wrong reply type.
Sourcepub fn set_mapping(&self, ir: IrCode, key: HidKey) -> Result<()>
pub fn set_mapping(&self, ir: IrCode, key: HidKey) -> Result<()>
Map ir to key, replacing any existing mapping for ir.
§Errors
See Device::call; Error::Device also covers a full keymap.
Sourcepub fn remove_mapping(&self, ir: IrCode) -> Result<()>
pub fn remove_mapping(&self, ir: IrCode) -> Result<()>
Sourcepub fn clear_keymap(&self) -> Result<()>
pub fn clear_keymap(&self) -> Result<()>
Remove every mapping.
§Errors
See Device::call; Error::UnexpectedReply if the device answers
with the wrong reply type.
Sourcepub fn reset_keymap(&self) -> Result<()>
pub fn reset_keymap(&self) -> Result<()>
Restore the firmware’s built-in default keymap.
§Errors
See Device::call; Error::UnexpectedReply if the device answers
with the wrong reply type.
Sourcepub fn learn(&self, key: HidKey, timeout: Duration) -> Result<Option<Mapping>>
pub fn learn(&self, key: HidKey, timeout: Duration) -> Result<Option<Mapping>>
Put the device in learn mode and block until the next IR code is
bound to key. Returns None if no code arrived within timeout.
Other notifications received while waiting are discarded.
§Errors
See Device::call; Error::Device if the code couldn’t be stored
(e.g. keymap full), Error::Timeout if the device never reports
the outcome.
Sourcepub fn cancel_learn(&self) -> Result<()>
pub fn cancel_learn(&self) -> Result<()>
Leave learn mode without binding anything.
§Errors
See Device::call; Error::UnexpectedReply if the device answers
with the wrong reply type.
Sourcepub fn send_hid(&self, key: HidKey) -> Result<()>
pub fn send_hid(&self, key: HidKey) -> Result<()>
Press and release key over BLE, as if a mapped IR code arrived.
§Errors
See Device::call; Error::UnexpectedReply if the device answers
with the wrong reply type.
Sourcepub fn send_ir(&self, code: IrCode) -> Result<()>
pub fn send_ir(&self, code: IrCode) -> Result<()>
Transmit a NEC code through the IR blaster.
§Errors
See Device::call; Error::UnexpectedReply if the device answers
with the wrong reply type.
Sourcepub fn set_monitor(&self, enabled: bool) -> Result<()>
pub fn set_monitor(&self, enabled: bool) -> Result<()>
Enable/disable Event::IrReceived notifications.
§Errors
See Device::call; Error::UnexpectedReply if the device answers
with the wrong reply type.
Sourcepub fn next_notification(
&self,
timeout: Duration,
) -> Result<Option<Notification>>
pub fn next_notification( &self, timeout: Duration, ) -> Result<Option<Notification>>
Wait up to timeout for the next event, log line or raw output.
Ok(None) means nothing arrived in time.
§Errors
Error::Disconnected once the connection is gone and every
buffered notification has been read.
§Panics
If an internal lock is poisoned (another thread panicked holding it).