pub struct Device { /* private fields */ }Expand description
An object for interacting with system CEC devices.
Implementations§
Source§impl Device
impl Device
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Device>
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.
Sourcepub fn get_poller(&self) -> Result<DevicePoller>
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.
Sourcepub fn poll(&mut self, timeout: PollTimeout) -> Result<Vec<PollResult>>
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.
Sourcepub fn set_blocking(&self, blocking: bool) -> Result<()>
pub fn set_blocking(&self, blocking: bool) -> Result<()>
Set or clear O_NONBLOCK on the underlying fd.
Sourcepub fn get_initiator_mode(&self) -> Result<InitiatorMode>
pub fn get_initiator_mode(&self) -> Result<InitiatorMode>
Get the InitiatorMode of the device.
Sourcepub fn set_initiator_mode(&self, mode: InitiatorMode) -> Result<()>
pub fn set_initiator_mode(&self, mode: InitiatorMode) -> Result<()>
Set the InitiatorMode of the device.
Sourcepub fn get_follower_mode(&self) -> Result<FollowerMode>
pub fn get_follower_mode(&self) -> Result<FollowerMode>
Get the FollowerMode of the device.
Sourcepub fn set_follower_mode(&self, mode: FollowerMode) -> Result<()>
pub fn set_follower_mode(&self, mode: FollowerMode) -> Result<()>
Set the FollowerMode of the device.
Sourcepub fn get_raw_capabilities(&self) -> Result<cec_caps>
pub fn get_raw_capabilities(&self) -> Result<cec_caps>
Get the raw cec_caps struct for the device from the kernel.
Sourcepub fn get_capabilities(&self) -> Result<Capabilities>
pub fn get_capabilities(&self) -> Result<Capabilities>
Get the Capabilities of the device, informing the quirks of
the specific device.
Sourcepub fn get_driver_name(&self) -> Result<OsString>
pub fn get_driver_name(&self) -> Result<OsString>
Get the name of the driver that is backing this device.
Sourcepub fn get_adapter_name(&self) -> Result<OsString>
pub fn get_adapter_name(&self) -> Result<OsString>
Get the name of the adapter that is backing this device.
Sourcepub fn get_physical_address(&self) -> Result<PhysicalAddress>
pub fn get_physical_address(&self) -> Result<PhysicalAddress>
Get the currently configured PhysicalAddress of the device.
Sourcepub fn set_physical_address(&self, phys_addr: PhysicalAddress) -> Result<()>
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.
Sourcepub fn get_logical_addresses(&mut self) -> Result<Vec<LogicalAddress>>
pub fn get_logical_addresses(&mut self) -> Result<Vec<LogicalAddress>>
Get the currently configured LogicalAddresses of the device.
Sourcepub fn set_logical_addresses(
&mut self,
log_addrs: &[LogicalAddressType],
) -> Result<()>
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.
Sourcepub fn set_logical_address(
&mut self,
log_addr: LogicalAddressType,
) -> Result<()>
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.
Sourcepub fn clear_logical_addresses(&mut self) -> Result<()>
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.
Sourcepub fn get_osd_name(&mut self) -> Result<OsString>
pub fn get_osd_name(&mut self) -> Result<OsString>
Get the configured OSD name.
Sourcepub fn set_osd_name(&mut self, name: &str) -> Result<()>
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.
Sourcepub fn get_vendor_id(&mut self) -> Result<Option<VendorId>>
pub fn get_vendor_id(&mut self) -> Result<Option<VendorId>>
Get the VendorId of this device, if configured.
Sourcepub fn set_vendor_id(&mut self, vendor_id: Option<VendorId>) -> Result<()>
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.
Sourcepub fn tx_message(
&self,
message: &Message,
destination: LogicalAddress,
) -> Result<u32>
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.
Sourcepub fn tx_raw_message(&self, message: &mut cec_msg) -> Result<()>
pub fn tx_raw_message(&self, message: &mut cec_msg) -> Result<()>
Transmit a raw system cec_msg directly through the CEC_TRANSMIT ioctl.
Sourcepub fn tx_rx_message(
&self,
message: &Message,
destination: LogicalAddress,
reply: Opcode,
timeout: Timeout,
) -> Result<Envelope>
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.
Sourcepub fn rx_message(&self, timeout: Timeout) -> Result<Envelope>
pub fn rx_message(&self, timeout: Timeout) -> Result<Envelope>
Sourcepub fn rx_raw_message(&self, timeout_ms: u32) -> Result<cec_msg>
pub fn rx_raw_message(&self, timeout_ms: u32) -> Result<cec_msg>
Receive a raw system cec_msg directly through the CEC_RECEIVE ioctl.
Sourcepub fn poll_address(&self, destination: LogicalAddress) -> Result<()>
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.
Sourcepub fn handle_status(&mut self, status: PollStatus) -> Result<Vec<PollResult>>
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.
Sourcepub fn get_connector_info(&self) -> Result<ConnectorInfo>
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.
Sourcepub fn set_active_source(&self, address: Option<PhysicalAddress>) -> Result<()>
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.
Sourcepub fn wake(&self, set_active: bool, text_view: bool) -> Result<()>
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.
Sourcepub fn standby(&self, target: LogicalAddress) -> Result<()>
pub fn standby(&self, target: LogicalAddress) -> Result<()>
Tell a device with the given LogicalAddress to enter standby mode.
Sourcepub fn press_user_control(
&self,
ui_command: UiCommand,
target: LogicalAddress,
) -> Result<()>
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.
Sourcepub fn release_user_control(&self, target: LogicalAddress) -> Result<()>
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.