switch_power/
switch_power.rs1use std::{thread::sleep, time::Duration};
6
7use cec_linux::*;
8
9fn main() -> std::io::Result<()> {
10 let cec = CecDevice::open("/dev/cec0")?;
11 let capas = cec.get_capas()?;
12 println!("capas {:?}", capas);
13
14 let log = CecLogAddrs::default();
16 cec.set_log(log)?;
17
18 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 cec.turn_on(CecLogicalAddress::Playback2, CecLogicalAddress::Audiosystem)?;
30
31 sleep(Duration::from_millis(10000));
32
33 cec.transmit(
35 CecLogicalAddress::Playback2,
36 CecLogicalAddress::Audiosystem,
37 CecOpcode::Standby,
38 )?;
39
40 sleep(Duration::from_millis(10000));
41
42 cec.turn_on(CecLogicalAddress::Playback2, CecLogicalAddress::Tv)?;
44
45 sleep(Duration::from_millis(10000));
46
47 cec.transmit(
49 CecLogicalAddress::Playback2,
50 CecLogicalAddress::Tv,
51 CecOpcode::Standby,
52 )?;
53
54 Ok(())
55}