Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cec.EVENT_KEYPRESS not working after updating to 0.2.7 #33

Open
superuser789 opened this issue Apr 25, 2019 · 6 comments
Open

cec.EVENT_KEYPRESS not working after updating to 0.2.7 #33

superuser789 opened this issue Apr 25, 2019 · 6 comments

Comments

@superuser789
Copy link

superuser789 commented Apr 25, 2019

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.

@nforro
Copy link
Collaborator

nforro commented May 5, 2019

Sorry for late reply. Could you be more specific? I just tried your code and it works fine.

@TheNetStriker
Copy link

TheNetStriker commented Sep 19, 2019

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?

@nforro
Copy link
Collaborator

nforro commented Sep 20, 2019

@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.

@TheNetStriker
Copy link

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?

@nforro
Copy link
Collaborator

nforro commented Sep 20, 2019

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.

@TheNetStriker
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants