User65k / cec_linux

A pure rust interface to linux CEC API
MIT License
1 stars 0 forks source link

How to register connection as a playback device? #4

Open MarcoBrieden opened 3 months ago

MarcoBrieden commented 3 months ago

When trying to control (on/off/change input) a TV connected to a Raspberry Pi 5 I'm getting: Invalid argument (os error 22)

It seems to be that the CEC connection isn't registered as a playback device? The thing that would be done on the CLI with: cec-ctl --playback

I obviously don't fully understand the CEC protocol, but would be very thankful for any tips on how to do this correctly.

The relevant code is:

    let cec = match CecDevice::open("/dev/cec0") {
        Ok(cec) => cec,
        Err(err) => {
            println!("CecDevice::open {}", err);
            return None;
        }
    };
    match cec.set_mode(CecModeInitiator::Send, CecModeFollower::All) {
        Ok(_) => {}
        Err(err) => {
            println!("cec.set_mode {}", err);
            return None;
        }
    };
    match cec.get_log(){
        Ok(resp) => {
            if resp.mask() != CecLogAddrMask::Playback1 {
                let name: OSDStr<15> = "test".to_string().try_into().unwrap_or(OSDStr::default());
                match cec.set_log(CecLogAddrs::new(VendorID::NONE, Version::V2_0, name, &[CecPrimDevType::PLAYBACK], &[CecLogAddrType::PLAYBACK])) {
                    Ok(log) => {
                        println!("cec.set_log ok");
                    }
                    Err(err) => {
                        println!("cec.set_log {}", err);
                    }
                }
            }
        }
        Err(err) => {
            println!("cec.get_log {}", err);
            return None;
        }
    };
    match cec.transmit(
        CecLogicalAddress::Playback1,
        CecLogicalAddress::Tv,
        CecOpcode::ImageViewOn,
    ){
        Ok(_) => {}
        Err(err) => {
            println!("cec.transmit {}", err);
            return None;
        }
    };
User65k commented 3 months ago

Hi, I am and will be on parental leave and only have my mobile with me, so my support capabilities are rather limited.

Where exactly are you getting the error?

The HDMI playback device should be provided by the driver and show up in pipewire/pulse/alsa regardless of what this crate is doing.

You can however use this crate to power on, query the audio capabilities, set SystemAudioMode, set the right channel on your TV,...

You can (at least on a pi4) set the HDMI audio capabilities in /boot/config.txt in case auto detection does not work (I think its only performed once at boot). Can't google it right now, the wifi here is bad.

I don't know if it helps, but this is how I use this crate on my pi4 to switch my AVR: cecremote