#[repr(C)]pub struct CecLogAddrs {
pub cec_version: Version,
pub vendor_id: u32,
pub flags: CecLogAddrFlags,
pub osd_name: OSDStr<15>,
pub all_device_types: [u8; 4],
pub features: [[u8; 4]; 12],
/* private fields */
}
Expand description
CEC logical addresses structure used by CecDevice::set_log and CecDevice::get_log
Fields§
§cec_version: Version
the CEC version that the adapter should implement. Set by the caller. Used to implement the CecOpcode::CecVersion and CecOpcode::ReportFeatures messages.
vendor_id: u32
the vendor ID of the device. Set by the caller.
flags: CecLogAddrFlags
§osd_name: OSDStr<15>
the OSD name of the device. Set by the caller Used for CecOpcode::SetOsdName
all_device_types: [u8; 4]
CEC 2.0: all device types represented by the logical address. Set by the caller. Used in CecOpcode::ReportFeatures.
features: [[u8; 4]; 12]
CEC 2.0: The logical address features. Set by the caller. Used in CecOpcode::ReportFeatures.
Implementations§
Source§impl CecLogAddrs
impl CecLogAddrs
Sourcepub fn addresses(&self) -> &[CecLogicalAddress]
pub fn addresses(&self) -> &[CecLogicalAddress]
Examples found in repository?
8fn main() -> std::io::Result<()> {
9 let cec = CecDevice::open("/dev/cec0")?;
10
11 cec.set_mode(CecModeInitiator::Send, CecModeFollower::ExclusivePassthru)?;
12
13 let physical_addr = cec.get_phys()?;
14
15 loop {
16 let msg = cec.rec()?;
17 match msg.opcode() {
18 Some(Ok(CecOpcode::ActiveSource))
19 | Some(Ok(CecOpcode::RoutingInformation))
20 | Some(Ok(CecOpcode::SetStreamPath))
21 if physical_addr == msg.parameters() =>
22 {
23 // this is not done by the core
24 println!("THIS IS US {:?}", msg.opcode().unwrap().unwrap());
25 cec.transmit_data(
26 CecLogicalAddress::Playback2,
27 CecLogicalAddress::UnregisteredBroadcast,
28 CecOpcode::ActiveSource,
29 &physical_addr.to_bytes(),
30 )?;
31 }
32 Some(Ok(CecOpcode::ReportPhysicalAddr)) => {} //core is still taking care of that
33 Some(Ok(opcode)) if msg.destination() == CecLogicalAddress::UnregisteredBroadcast => {
34 //dont answer brodcasts
35 println!(
36 "{:?}: {:?} {:x?}",
37 msg.initiator(),
38 opcode,
39 msg.parameters()
40 );
41 }
42 Some(Ok(CecOpcode::GetCecVersion)) => {
43 cec.transmit_data(
44 msg.destination(),
45 msg.initiator(),
46 CecOpcode::CecVersion,
47 &[Version::V1_3A.into()],
48 )?;
49 }
50 Some(Ok(CecOpcode::GiveDeviceVendorId)) => {
51 cec.transmit_data(
52 msg.destination(),
53 msg.initiator(),
54 CecOpcode::FeatureAbort,
55 &[
56 CecOpcode::GiveDeviceVendorId.into(),
57 CecAbortReason::Unrecognized.into(),
58 ],
59 )?; /*
60 cec.transmit_data(
61 msg.destination(),
62 msg.initiator(),
63 CecOpcode::DeviceVendorId,
64 &[0,0,0])?;*/
65 }
66 Some(Ok(CecOpcode::Abort)) => {
67 cec.transmit_data(
68 msg.destination(),
69 msg.initiator(),
70 CecOpcode::FeatureAbort,
71 &[CecOpcode::Abort.into(), CecAbortReason::Other.into()],
72 )?;
73 }
74 Some(Ok(CecOpcode::GivePhysicalAddr)) => {
75 let l = cec.get_log()?;
76 let mut addr = Vec::with_capacity(3);
77 if let Some(log) = l.addresses().first() {
78 addr.extend_from_slice(&physical_addr.to_bytes());
79 addr.push((*log).into());
80
81 cec.transmit_data(
82 msg.destination(),
83 msg.initiator(),
84 CecOpcode::ReportPhysicalAddr,
85 &addr,
86 )?;
87 } //else no address yet?!?!?
88 }
89 Some(Ok(CecOpcode::GiveOsdName)) => {
90 cec.transmit_data(
91 msg.destination(),
92 msg.initiator(),
93 CecOpcode::SetOsdName,
94 b"pi4",
95 )?;
96 }
97 Some(Ok(CecOpcode::GiveDevicePowerStatus)) => {
98 cec.transmit_data(
99 msg.destination(),
100 msg.initiator(),
101 CecOpcode::ReportPowerStatus,
102 &[CecPowerStatus::On.into()],
103 )?;
104 }
105 Some(Ok(CecOpcode::GiveFeatures)) => {}
106 Some(Ok(opcode)) => {
107 println!(
108 "{:?} -> {:?} : {:?} {:x?}",
109 msg.initiator(),
110 msg.destination(),
111 opcode,
112 msg.parameters()
113 );
114 }
115 _ => {
116 println!("{:?}", msg);
117 }
118 }
119 }
120}
pub fn mask(&self) -> CecLogAddrMask
Sourcepub fn new(
vendor_id: u32,
cec_version: Version,
osd_name: OSDStr<15>,
primary_type: &[CecPrimDevType],
addr_type: &[CecLogAddrType],
) -> CecLogAddrs
pub fn new( vendor_id: u32, cec_version: Version, osd_name: OSDStr<15>, primary_type: &[CecPrimDevType], addr_type: &[CecLogAddrType], ) -> CecLogAddrs
Request certain address type on the CEC Bus.
The claimed CecLogicalAddresses will also depend on the other devices on the bus.
The length of the Type slices must be ≤ CecCaps::available_log_addrs. Note that the CEC 2.0 standard allows for a maximum of 2 logical addresses, although some hardware has support for more. The driver will return the actual number of logical addresses it could claim, which may be less than what was requested.
The provided values are also used by responses sent from the core (see CecModeFollower::ExclusivePassthru):
Param | used as reply to | Info |
---|---|---|
vendor_id | CecOpcode::GiveDeviceVendorId | Use VendorID::NONE to disable the feature |
cec_version | CecOpcode::GetCecVersion | |
osd_name | CecOpcode::GiveOsdName |
Examples found in repository?
9fn main() -> std::io::Result<()> {
10 let cec = CecDevice::open("/dev/cec0")?;
11 let capas = cec.get_capas()?;
12 println!("capas {:?}", capas);
13
14 // clear existing logical addresses
15 let log = CecLogAddrs::default();
16 cec.set_log(log)?;
17
18 // set new address (PLAYBACK)
19 let log = CecLogAddrs::new(
20 VendorID::NONE,
21 Version::V1_4,
22 "pi4".to_string().try_into().unwrap(),
23 &[CecPrimDevType::PLAYBACK],
24 &[CecLogAddrType::PLAYBACK],
25 );
26 cec.set_log(log)?;
27
28 // ask Audiosystem to turn on (from standby)
29 cec.turn_on(CecLogicalAddress::Playback2, CecLogicalAddress::Audiosystem)?;
30
31 sleep(Duration::from_millis(10000));
32
33 // ask Audiosystem to switch to standby
34 cec.transmit(
35 CecLogicalAddress::Playback2,
36 CecLogicalAddress::Audiosystem,
37 CecOpcode::Standby,
38 )?;
39
40 sleep(Duration::from_millis(10000));
41
42 // ask TV to turn on
43 cec.turn_on(CecLogicalAddress::Playback2, CecLogicalAddress::Tv)?;
44
45 sleep(Duration::from_millis(10000));
46
47 // ask TV to switch to standby
48 cec.transmit(
49 CecLogicalAddress::Playback2,
50 CecLogicalAddress::Tv,
51 CecOpcode::Standby,
52 )?;
53
54 Ok(())
55}