Skip to main content

Device

Struct Device 

Source
pub struct Device { /* private fields */ }
Expand description

A connection to one bridge.

Implementations§

Source§

impl Device

Source

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.

Source

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.

Source

pub fn set_timeout(&mut self, timeout: Duration)

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn remove_mapping(&self, ir: IrCode) -> Result<()>

Remove the mapping for ir.

§Errors

See Device::call; Error::Device also covers ir not being mapped.

Source

pub fn clear_keymap(&self) -> Result<()>

Remove every mapping.

§Errors

See Device::call; Error::UnexpectedReply if the device answers with the wrong reply type.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

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.