Pulse-Eight / libcec

USB CEC Adapter communication Library http://libcec.pulse-eight.com/
Other
705 stars 282 forks source link

libcec settings to disable executing incoming turn off signals #565

Closed mghadam closed 3 years ago

mghadam commented 3 years ago

I have a Raspberry PI 4 that is connected to a Samsung TV.

Whenever I turn off the TV, it also turns the Pi off. This is while I want to keep the Pi on all the time.

If I disable this feature called "Auto Standby" in the TV, I will not be able to turn off the TV from the Pi.

So the only way to be able to turn off the TV from the Pi, is to keep the "Auto Standby" setting active in the TV.

Is it possible to configure libcec on to avoid executing turn off signals that it receives from the TV?

popcornmix commented 3 years ago

Is this with Kodi running? Have you changed CEC setting "When the TV is switched off" to "Ignore"? In System/Input/Peripherals/CEC Adapter.

mghadam commented 3 years ago

No, it is running Raspberry Pi OS (Raspbian).

Kodi has the feature you mentioned. However, I can not find how to set this setting in Raspbian.

popcornmix commented 3 years ago

Raspbian won't do anything with CEC if you don't install a package that uses it (kodi is the main one). Are you sure it's CEC? Are you powering the Pi from a USB port on TV?

mghadam commented 3 years ago

Yes it is libcec on raspberry pi :

root@raspberrypi:~# dpkg -l | grep -i cec
ii  cec-utils                            4.0.4+dfsg1-2+rpi1+rpt1                 armhf        USB CEC Adaptor communication Library (utility programs)
ii  libcec4:armhf                        4.0.4+dfsg1-2+rpi1+rpt1                 armhf        USB CEC Adaptor communication Library (shared library)
root@raspberrypi:~# 

The Pi has its own adapter and it is not powered from the USB ports on the TV.

I use cec-utils to control the TV.

libcec supports CEC on the Pi via a VCHIQ service (Source). I checked the codes there and it seems that the signals raspberry receives from the TV are sent to libcec for action:

 case VC_CEC_RX:
    // CEC data received
    {
      // translate into a VC_CEC_MESSAGE_T
      VC_CEC_MESSAGE_T message;
      vc_cec_param2message(header, p0, p1, p2, p3, &message);

      // translate to a cec_command
      cec_command command;
      cec_command::Format(command,
          (cec_logical_address)message.initiator,
          (cec_logical_address)message.follower,
          (cec_opcode)CEC_CB_OPCODE(p0));

      // copy parameters
      for (uint8_t iPtr = 1; iPtr < message.length; iPtr++)
        command.PushBack(message.payload[iPtr]);

      // send to libCEC
      m_callback->OnCommandReceived(command);
    }

So do I need to configure libcec to ignore incoming Poweroff signals (:36)?

popcornmix commented 3 years ago

What code do you believe actually powers off the Pi?

mghadam commented 3 years ago

I think it is the TV that sends a :36 signal via HDMI-CEC to the PI whenever the TV is turned off, and this turns off the Pi. This only happens when the "Auto Standby" feature is enabled in the TV.

I can disable "Auto Standby" in the TV to stop this behavior however this will also prevents the pi to turn off the TV i.e. the TV will ignore :36 signals sent from the Pi. (See note 2 in Samsung row here).

I want to be able to turn off the TV from the Pi, without the Pi getting turned off when the TV sends a turn off signal.

popcornmix commented 3 years ago

and this turns off the Pi

As far as I know libcec only passes the message on that TV hasentered standby. An app (like kodi) can choose what to do with that (it has a menu option with choices like "ignore/pause video/stop video/suspend/power off"). But that is something kodi does rather than libcec.

I'm not aware of cec-client doing that. I wondered if you had some other cec app that did it.

mghadam commented 3 years ago

I could not reproduce this issue.

I enabled "autostandby" in the samsung TV and can turn it off / on using HDMI-CEC, and when I turn the TV off, the raspberry pi remains on which is what I was looking for.

Anyways, I found CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY and bPowerOffOnStandby settings here for future references.