cec.EVENT_KEYPRESS not working after updating to 0.2.7
superuser789 opened this issue · comments
Hi,
In previous cec 0.2.6, the following code was working fine. But it is not working now after updating to 0.2.7.
import cec
import time
cec.init()
print("Ready")
def onkey(event, key , state):
if state > 0:
print("Got key", key, "state", state)
cec.add_callback(onkey, cec.EVENT_KEYPRESS)
while True:
time.sleep(9e8)
What changes should I do to make it work again ?
Thanks.
Sorry for late reply. Could you be more specific? I just tried your code and it works fine.
I just tried this on my Raspberry Pi 4 I'm also getting no events with 2.7. I also tried with EVENT_ALL, but I don't receive anyting, but power_on and standby are working. Any idea what could be the problem?
Edit: I found keys that are working, but I'm looking for an event when the device enters standby or is powered on externally. Is this already possible?
@TheNetStriker Yes, for example my TV broadcasts CEC_OPCODE_ROUTING_CHANGE
(with new address parameter set to 1.0.0.0
) after it's powered on, and it broadcasts CEC_OPCODE_STANDBY
when it enters standby. So just use EVENT_COMMAND
callback and monitor commands your device broadcasts.
I just tested this with the following code:
def onCommand(event, cmd, convert_cmd):
print("cmd", cmd, "convert_cmd", convert_cmd)
cec.add_callback(onCommand, cec.EVENT_COMMAND)
But I don't get any events. Is there any way to debug this?
There are only two arguments to the callback, you should use def onCommand(event, cmd):
.
Set up a log callback, or run cec-client
from libcec and examine the logs, all communication should be there.
Thanks for the quick help. I managed to the the power events with this code:
def onCommand(event, cmd):
#print("event", event, "cmd", cmd)
opcode = cmd["opcode"]
parameters = cmd["parameters"]
if opcode == cec.CEC_OPCODE_STANDBY:
PublishTvIsOn(False)
if opcode == cec.CEC_OPCODE_ROUTING_CHANGE and parameters == b'\x00\x00@\x00':
PublishTvIsOn(True)