Skip to main content

Device

Struct Device 

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

An object for interacting with system CEC devices.

Implementations§

Source§

impl Device

Source

pub fn open(path: impl AsRef<Path>) -> Result<Device>

Open a CEC device from a given path. Generally, this will be of the form /dev/cecX.

Source

pub fn get_poller(&self) -> Result<DevicePoller>

Get a new DevicePoller object that can be used to poll the status of the kernel queue without having to borrow the Device object itself.

While the poller can return a PollStatus to say which kinds of events or messages are available, it must be passed to handle_status, which will require borrowing the Device, to get the actual data.

Source

pub fn poll(&mut self, timeout: PollTimeout) -> Result<Vec<PollResult>>

Wait up to timeout for a message or event and process the results. This is a convenience method that combines using a DevicePoller and calling handle_status internally.

Source

pub fn set_blocking(&self, blocking: bool) -> Result<()>

Set or clear O_NONBLOCK on the underlying fd.

Source

pub fn get_initiator_mode(&self) -> Result<InitiatorMode>

Get the InitiatorMode of the device.

Source

pub fn set_initiator_mode(&self, mode: InitiatorMode) -> Result<()>

Set the InitiatorMode of the device.

Source

pub fn get_follower_mode(&self) -> Result<FollowerMode>

Get the FollowerMode of the device.

Source

pub fn set_follower_mode(&self, mode: FollowerMode) -> Result<()>

Set the FollowerMode of the device.

Source

pub fn get_raw_capabilities(&self) -> Result<cec_caps>

Get the raw cec_caps struct for the device from the kernel.

Source

pub fn get_capabilities(&self) -> Result<Capabilities>

Get the Capabilities of the device, informing the quirks of the specific device.

Source

pub fn get_driver_name(&self) -> Result<OsString>

Get the name of the driver that is backing this device.

Source

pub fn get_adapter_name(&self) -> Result<OsString>

Get the name of the adapter that is backing this device.

Source

pub fn get_physical_address(&self) -> Result<PhysicalAddress>

Get the currently configured PhysicalAddress of the device.

Source

pub fn set_physical_address(&self, phys_addr: PhysicalAddress) -> Result<()>

Set the PhysicalAddress of the device. This function will only work if the capability Capabilities::PHYS_ADDR is present.

Source

pub fn get_logical_addresses(&mut self) -> Result<Vec<LogicalAddress>>

Get the currently configured LogicalAddresses of the device.

Source

pub fn set_logical_addresses( &mut self, log_addrs: &[LogicalAddressType], ) -> Result<()>

Set the LogicalAddresses of the device. This function will only work if the capability Capabilities::LOG_ADDRS is present. Note that the device must be configured to act as an initiator via Device::set_initiator_mode, otherwise this function will return an error.

Source

pub fn set_logical_address( &mut self, log_addr: LogicalAddressType, ) -> Result<()>

Set the single LogicalAddress of the device. This function will only work if the capability Capabilities::LOG_ADDRS is present. Note that the device must be configured to act as an initiator via Device::set_initiator_mode, otherwise this function will return an error.

Source

pub fn clear_logical_addresses(&mut self) -> Result<()>

Clear the LogicalAddresses of the device. This function will only work if the capability Capabilities::LOG_ADDRS is present.

Source

pub fn get_osd_name(&mut self) -> Result<OsString>

Get the configured OSD name.

Source

pub fn set_osd_name(&mut self, name: &str) -> Result<()>

Set the advertised OSD name. This is used by TV sets to display the name of connected devices. The maximum length allowed is only 14 bytes, and is defined by the specification to be only ASCII. However, some TV sets will properly display UTF-8 text as well. Note that the encoding does not affect the allowable length of bytes, so using any multi-byte characters will effectively decrease the maximum number of characters.

For the kernel to properly advertise the OSD name on query, you must call this function before calling Device::set_logical_addresses.

§Errors

This function will raise an Error::OutOfRange error if the name passed exceeds 14 bytes.

Source

pub fn get_vendor_id(&mut self) -> Result<Option<VendorId>>

Get the VendorId of this device, if configured.

Source

pub fn set_vendor_id(&mut self, vendor_id: Option<VendorId>) -> Result<()>

Set the advertised VendorId of the device. You should generally use the OUI assigned to your organization, if applicable. You must call this function before calling Device::set_logical_addresses.

Source

pub fn tx_message( &self, message: &Message, destination: LogicalAddress, ) -> Result<u32>

Transmit a Message to a given LogicalAddress. Use LogicalAddress::Broadcast for broadcasting to all attached devices. The sequence number of the submitted message is returned.

Source

pub fn tx_raw_message(&self, message: &mut cec_msg) -> Result<()>

Transmit a raw system cec_msg directly through the CEC_TRANSMIT ioctl.

Source

pub fn tx_rx_message( &self, message: &Message, destination: LogicalAddress, reply: Opcode, timeout: Timeout, ) -> Result<Envelope>

Transmit a Message to a given LogicalAddress and wait for a reply of a given Opcode. Use LogicalAddress::Broadcast for broadcasting to all attached devices. Note that the timeout cannot be 0 or more than 1 second, otherwise they will be coerced to 1 second.

Source

pub fn rx_message(&self, timeout: Timeout) -> Result<Envelope>

Receive a message, waiting up to a Timeout if one is not available in the kernel buffer already. The resulting Envelope will contain the message and associated metadata.

Source

pub fn rx_raw_message(&self, timeout_ms: u32) -> Result<cec_msg>

Receive a raw system cec_msg directly through the CEC_RECEIVE ioctl.

Source

pub fn poll_address(&self, destination: LogicalAddress) -> Result<()>

Poll the bus for the presence of a given LogicalAddress. If the device is present, this returns Ok, otherwise it returns with a specific error detailing the manner of failure. Usually this will be TxError::Nack if the device isn’t present, but other manners of failure are theoretically possible.

Source

pub fn handle_status(&mut self, status: PollStatus) -> Result<Vec<PollResult>>

Handle the PollStatus returned from DevicePoller::poll. This will dequeue any indicated messages or events, handle any internal processing, and return information about the events or Envelopes containing Messages.

Source

pub fn get_connector_info(&self) -> Result<ConnectorInfo>

Get information about the connector for the device, which is usually a card handled by Linux’s DRM subsystem.

Source

pub fn set_active_source(&self, address: Option<PhysicalAddress>) -> Result<()>

Tell the TV to switch to the given phyiscal address for its input. If the address is None, it uses the physical address of the device itself.

Source

pub fn wake(&self, set_active: bool, text_view: bool) -> Result<()>

Wake the TV and optionally tell the TV to make this device the active source via the One Touch Play feature.

HDMI CEC specifies two messages for how to handle device switching: Image View and Text View. The Image View is simply the video input, with the possibility of menus or infoboxes (the Text View) displayed over it. If text_view is set to true, the device will request both and the TV should dismiss any active menus.

Source

pub fn standby(&self, target: LogicalAddress) -> Result<()>

Tell a device with the given LogicalAddress to enter standby mode.

Source

pub fn press_user_control( &self, ui_command: UiCommand, target: LogicalAddress, ) -> Result<()>

Convenience method for sending a user control command to a given LogicalAddress by generating a UserControlPressed message. These generally correspond to the buttons on a remote control that are relayed to other devices. This must be matched with a call to Device::release_user_control.

Source

pub fn release_user_control(&self, target: LogicalAddress) -> Result<()>

Convenience method for terminating a user control command, as started with Device::press_user_control. Internally, this just creates and sends a UserControlReleased message to the given LogicalAddress.

Trait Implementations§

Source§

impl Debug for Device

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Device> for AsyncDevice

Source§

fn from(device: Device) -> AsyncDevice

Converts to this type from the input type.
Source§

impl TryFrom<File> for Device

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(file: File) -> Result<Device>

Performs the conversion.

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