Giter Club home page Giter Club logo

python-cec's Introduction

python-cec - libcec bindings for Python

python-cec allows you to control your TV, reciever and other CEC-compliant HDMI devices from a python script on a computer. Most computer graphics cards don't support CEC; you'll need a Pulse-Eight USB-CEC adapter or a Raspberry Pi (tested on Raspberry Pi 3 Model B Rev 1.2).

Installing:

Install dependencies

To build python-cec, you need version 1.6.1 or later of the libcec development libraries:

On Gentoo:

sudo emerge libcec

On OS X:

brew install libcec

Ubuntu, Debian and Raspbian:

sudo apt-get install libcec-dev build-essential python-dev

Install from PIP

pip install cec

Installing on Windows

You need to build libcec from source, because libcec installer doesn't provide cec.lib that is necessary for linking.

Then you just need to set up your paths, e.g.:

set INCLUDE=path_to_libcec\build\amd64\include
set LIB=path_to_libcec\build\amd64

Getting Started

A simple example to turn your TV on:

import cec

cec.init()

tv = cec.Device(cec.CECDEVICE_TV)
tv.power_on()

API

import cec

adapters = cec.list_adapters() # may be called before init()

cec.init() # use default adapter
cec.init(adapter) # use a specific adapter

cec.close()  # close the current adapter

cec.add_callback(handler, events)
# the list of events is specified as a bitmask of the possible events:
cec.EVENT_LOG
cec.EVENT_KEYPRESS
cec.EVENT_COMMAND
cec.EVENT_CONFIG_CHANGE # not implemented yet
cec.EVENT_ALERT
cec.EVENT_MENU_CHANGED
cec.EVENT_ACTIVATED
cec.EVENT_ALL
# the callback will receive a varying number and type of arguments that are
# specific to the event. Contact me if you're interested in using specific
# callbacks

cec.remove_callback(handler, events)

devices = cec.list_devices()

class Device:
   __init__(id)
   is_on()
   power_on()
   standby()
   address
   physical_address
   vendor
   osd_string
   cec_version
   language
   is_active()
   set_av_input(input)
   set_audio_input(input)
   transmit(opcode, parameters)

cec.is_active_source(addr)
cec.set_active_source() # use default device type
cec.set_active_source(device_type) # use a specific device type
cec.set_inactive_source()  # not implemented yet

cec.volume_up()
cec.volume_down()
cec.toggle_mute()
# TODO: audio status

cec.set_physical_address(addr)
cec.can_persist_config()
cec.persist_config()
cec.set_port(device, port)

# set arbitrary active source (in this case 2.0.0.0)
destination = cec.CECDEVICE_BROADCAST
opcode = cec.CEC_OPCODE_ACTIVE_SOURCE
parameters = b'\x20\x00'
cec.transmit(destination, opcode, parameters)

Changelog

0.2.8 ( 2022-01-05 )

  • Add support for libCEC >= 5
  • Windows support
  • Support for setting CEC initiator
  • Python 3.10 compatibility

0.2.7 ( 2018-11-09 )

  • Implement cec.EVENT_COMMAND callback
  • Fix several crashes/memory leaks related to callbacks
  • Add possibility to use a method as a callback
  • Limit maximum number of parameters passed to transmit()
  • Fix compilation error with GCC >= 8

0.2.6 ( 2017-11-03 )

  • Python 3 support ( @nforro )
  • Implement is_active_source, set_active_source, transmit ( @nforro )
  • libcec4 compatibility ( @nforro )

0.2.5 ( 2016-03-31 )

  • re-release of version 0.2.4. Original release failed and version number is now lost

0.2.4 ( 2016-03-31 )

  • libcec3 compatibility

0.2.3 ( 2014-12-28 )

  • Add device.h to manifest
  • Initial pip release

0.2.2 ( 2014-06-08 )

  • Fix deadlock
  • Add repr for Device

0.2.1 ( 2014-03-03 )

  • Fix deadlock in Device

0.2.0 ( 2014-03-03 )

  • Add initial callback implementation
  • Fix libcec 1.6.0 backwards compatibility support

0.1.1 ( 2013-11-26 )

  • Add libcec 1.6.0 backwards compatibility
  • Known Bug: no longer compatible with libcec 2.1.0 and later

0.1.0 ( 2013-11-03 )

  • First stable release

Copyright

Copyright (C) 2013 Austin Hendrix [email protected]

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

python-cec's People

Contributors

264768502 avatar ahendrix avatar camilo-celis avatar gilbertbw avatar janhouse avatar jonathancyu avatar nforro avatar randomrumble avatar trainman419 avatar wjwwood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-cec's Issues

Set audio input?

How do i set audio input? Or whats the argument i need to give.

The function is_on() always return True

Hello,

i am not good in programming and C is the hardest language is see.

I used the function is_on() for my Samsung TV. This function returns always True, even the TV is on Standby.

Can anyone help? You need more information i can give you input.

Here the ouptut of the testscript in your repro. You can see if the script send the TV to Standby the state become False.

Using Adapter RPI  
Devices: {0: Device(0), 1: Device(1), 8: Device(8)}
Address: 0
Physical Address: 0.0.0.0
Vendor ID: 0000F0
OSD: TV
CEC Version: Unknown
Language: ger
ON: True                <- THE TV was in STANDBY
Powering device on
True
Sleeping to allow device to power on
True                       <- THE TV was in ON
Powering device off
True
Sleeping to allow device to power off
False                     <- THE TV was in STANDBY
Success!

Thx

Please help fix error

Hi @trainman419 I hope you can help me fix this. I receive this error when trying the example code in the readme.

<module '_cec' from '/usr/lib/python3/dist-packages/_cec.cpython-38-x86_64-linux-gnu.so'>Exception "unhandled AttributeError" module 'cec' has no attribute 'init' File: /home/user/Documents/Python works/cec codes/my_pycecclient2.py, Line: 4

Use the librarys in built SendKeyPress function

Im trying to modify your library so it supports the inbuilt sendkeypress (and sendkeyrelease), but am having issues, here is what I have come up with so far (it appears to work, but nothing happens and it crashes with a stack smash):

static PyObject * Device_send_key_press(Device * self, PyObject * args) {
   unsigned char keycode;
   bool bWait;
   cec_user_control_code keypress;
   if( PyArg_ParseTuple(args, "bp:sendkeypress", &keycode,
         &bWait) ) {
      keypress = (cec_user_control_code) keycode;
      bool success;
      Py_BEGIN_ALLOW_THREADS
      cec_logical_address destination = self->addr;
      success = adapter->SendKeypress(destination, keypress, bWait);
      Py_END_ALLOW_THREADS
      if( success ) {
         Py_RETURN_TRUE;
      } else {
         Py_RETURN_FALSE;
      }
   } else {
      return NULL;
   }
}

cec.transmit() doesn't send correct parameters

I'm trying to transmit the cec frame 15:44:44 with the code below. However, the cec frame that I see being sent by my pulse-eight adapter is 15:44:36:35. Any help on this issue would be appreciated.

destination = 0x5
opcode = 0x44
parameters = bytes(0x41)
cec.transmit(destination, opcode, parameters)

Problems on rPI Raspbian 7

Hello,
While trying to compile on Raspbian:

root@smarthome:/usr/src/python-cec# python setup.py install
running install
running build
running build_ext
building 'cec' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC -I/usr/include/python2.7 -c cec.cpp -o build/temp.linux-armv6l-2.7/cec.o
cec.cpp: In function ‘void initcec()’:
cec.cpp:647:37: error: invalid conversion from ‘int ()(void, CEC::cec_log_message)’ to ‘CEC::CBCecLogMessageType {aka int ()(void, const CEC::cec_log_message&)}’ [-fpermissive]
cec.cpp:648:35: error: invalid conversion from ‘int ()(void, CEC::cec_keypress)’ to ‘CEC::CBCecKeyPressType {aka int ()(void, const CEC::cec_keypress&)}’ [-fpermissive]
cec.cpp:649:34: error: invalid conversion from ‘int ()(void, CEC::cec_command)’ to ‘CEC::CBCecCommandType {aka int ()(void, const CEC::cec_command&)}’ [-fpermissive]
cec.cpp:650:47: error: invalid conversion from ‘int ()(void, CEC::libcec_configuration)’ to ‘CEC::CBCecConfigurationChangedType {aka int ()(void, const CEC::libcec_configuration&)}’ [-fpermissive]
cec.cpp:651:32: error: invalid conversion from ‘int ()(void, CEC::libcec_alert, CEC::libcec_parameter)’ to ‘CEC::CBCecAlertType {aka int ()(void, CEC::libcec_alert, const CEC::libcec_parameter&)}’ [-fpermissive]
cec.cpp:653:19: error: ‘CEC::ICECCallbacks’ has no member named ‘CBCecSourceActivated’
cec.cpp:696:10: error: ‘CEC_ALERT_PERMISSION_ERROR’ was not declared in this scope
cec.cpp:698:10: error: ‘CEC_ALERT_PORT_BUSY’ was not declared in this scope
cec.cpp:700:10: error: ‘CEC_ALERT_PHYSICAL_ADDRESS_ERROR’ was not declared in this scope
cec.cpp:702:10: error: ‘CEC_ALERT_TV_POLL_FAILED’ was not declared in this scope
error: command 'gcc' failed with exit status 1

Any error on my side ?

Audio Status

Has there been any progress on implementing the get audio status functionality?

Change HDMI Source on TV (Device 0)

Thank you for your great work!

Is there an API function, using the current bindings, that lets me select the source to be displayed on the TV?
ActiveSource chooses "self", but I want to be able to tell the TV choose HDMI1, HDMI2 or HDMI3 using the API.

Thanks again.
pimok

OSError: Power status not found

When extracting details about found devices the code below:

import cec

cec.init()

devices = cec.list_devices()

for i in range(len(devices)):
    d = cec.Device(i)
    print('{0} : {1} | Active: {2} | ON: {3}'.format(i, d.osd_string, d.is_active(), d.is_on()))

gives the following output:

0 : TV | Active: False | ON: False
1 : python-cec | Active: False | ON: True
Traceback (most recent call last):
File "/home/pi/subwoofer_switch/cec_script.py", line 9, in
print('{0} : {1} | Active: {2} | ON: {3}'.format(i, d.osd_string, d.is_active(), d.is_on()))
OSError: Power status not found

However, just checking if they are active works fine:

import cec

cec.init()

devices = cec.list_devices()

for i in range(len(devices)):
    d = cec.Device(i)
    print('{0} : {1} | Active: {2}'.format(i, d.osd_string, d.is_active()))

Output:

0 : TV | Active: False
1 : python-cec | Active: False
2 : Recorder 2 | Active: False
3 : Tuner 1 | Active: False
4 : PlayStation 4 | Active: False

I got a script that checks for TV being turned on or off every 2 seconds and it seems to work for for few hours or so but then always crashes with an error OSError: Power status not found any idea what could be causing this?
Thank you

`Illegal instruction` on import on raspberry pi after pip install

Hi !

Python crashes on import cec on my freshly installed raspberry pi zero on raspbian, with the library installed through pip.

Here are the steps to reproduce.

System: Raspbian GNU/Linux 11 (bullseye)
Model: Raspberry Pi Zero W Rev 1.1

$ sudo apt-get install libcec-dev build-essential python3-dev python3-pip
...

$ pip install cec
...

$ python -c "import cec"
Illegal instruction
# exit code 132

Note that it seems to work when built locally.

API breaks on "logical address changed to Broadcast (f)"

I'm running python 3.7.3, the latest python-cec from pip and libCEC 4.0.4.

I've written a simple script to turn on kodi when the TV turns on, and turns kodi off when the TV turns off.
It's gotten a bit complicated because I've been trying to work around this bug. I first found it when I used while tv.is_on():; it goes to the unknown state after kodi closes and breaks (it should remember the state of off until it becomes on again, so it always returns false if the TV is off right?).
I worked around it by using the callback function to listen for TV on and off messages. It still can't restart after kodi has been stopped. When I watch the log, it always ends like this:
`

0f:36
TV is off
tv is off. stopping kodi
sleep while off
logical address changed to Broadcast (f)`

and I've narrowed the bug down to the address change - it seems the cec client just dies at this point.
It's probably because my TV goes to deep sleep and it confuses the cec client so much that it disconnects without being able to reconnect without being reinitialised - this workaround is currently in my code, but it's pretty messy.

This issue only appears when kodi exits by the way. I've seen similar reports on the internet when googling logical address changed to Broadcast (f)

Here is my code.

is_on() sometimes freezes cec

When using is_on() on a Raspberry Pi, the cec driver sometimes freezes completely so a reboot of the Raspi is needed to recover cec functionality.
Possibly this crash is caused when my TV does not respond to the request.
May be it is a problem in libcec or the raspi kernel driver (?) but I had a quick look in this projects device.cpp file on function Device_is_on(Device * self) and saw that a reference counting is done on a local variable. Isn't this wrong?

I suggest following correction:

--- device.cpp	2020-12-16 17:50:54.178413383 +0100
+++ b.cpp	2020-12-16 17:52:34.042359608 +0100
@@ -85,23 +85,20 @@
    Py_BEGIN_ALLOW_THREADS
    power = adapter->GetDevicePowerStatus(self->addr);
    Py_END_ALLOW_THREADS
-   PyObject * ret;
    switch(power) {
       case CEC_POWER_STATUS_ON:
       case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
-         ret = Py_True;
+         Py_RETURN_TRUE;
          break;
       case CEC_POWER_STATUS_STANDBY:
       case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
-         ret = Py_False;
+         Py_RETURN_FALSE;
          break;
       case CEC_POWER_STATUS_UNKNOWN:
       default:
          PyErr_SetString(PyExc_IOError, "Power status not found");
          return NULL;
    }
-   Py_INCREF(ret);
-   return ret;
 }

Samsung source select: cec-client works, but python-cec doesn't

I can change the source on my RPI2 connected SAMSUNG TV like:

echo "tx 4F:82:30:00" | cec-client -s

But running what I think is equivalent code using python-cec does nothing:

import cec
destination = cec.CECDEVICE_BROADCAST
opcode = cec.CEC_OPCODE_ACTIVE_SOURCE
cec.init()
cec.transmit(destination, opcode, bytes([0x30,0x00])) # Returns True, but does nothing

Both are compiled against libcec4.0.2. Using set_active_source does change to the RPI2 HDMI input if it's not active, so I know they're communicating. Is there something I'm missing? Thanks for this package.

cec.init() fails to open with garbage error message.

On a raspberry pi zero, I get the following error on open. Python-cec was installed using the README.md 0.2.5 recipe (wget... to pip install cec).

cec-client works fine on same pi, tv, etc.

pi@raspberrypi:/tmp $ python
Python 2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import cec
cec.init()
Traceback (most recent call last):
File "", line 1, in
IOError: CEC failed to open P
����붘����jq

Requesting a function get get power status

I'm using python-cec with home assistant to detect whether my television is on or off. The is_on() function satisfies this but I find it illogical that transitioning to on is considered 'off' and transitioning to standby is considered 'on'. For my purposes, transitioning to on means that the tv has been turned on, and anyway, if the tv is not 'on' when transitioning to on then I would expect the same when transitioning to off.
If there was a function that returned the power status including these transition states rather than just the boolean true/false of is_on() then I could apply my own logic to these states.

e.g. something along these lines:

static PyObject * Device_power_status(Device * self) {
   cec_power_status power;
   Py_BEGIN_ALLOW_THREADS
   power = adapter->GetDevicePowerStatus(self->addr);
   Py_END_ALLOW_THREADS
   PyObject * ret;
   switch(power) {
      case CEC_POWER_STATUS_ON:
	 ret = "CEC_POWER_STATUS_ON";
         break;
      case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
         ret = "CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY";
         break;
      case CEC_POWER_STATUS_STANDBY:
	 ret = "CEC_POWER_STATUS_STANDBY"
	 break;
      case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
         ret = "CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON";
         break;
      case CEC_POWER_STATUS_UNKNOWN:
      default:
         PyErr_SetString(PyExc_IOError, "Power status not found");
         return NULL;
   }
   Py_INCREF(ret);
   return ret;
}

IOError: CEC failed to open ▒▒▒▒

Installed through pip on raspbian jessie

Traceback (most recent call last): File "tvhandler.py", line 6, in <module> cec.init() IOError: CEC failed to open ▒▒▒▒

Another issue already created whoops.

list_devices() does not return all of the devices on RaspberyPI

Hello,
Thank you for the great library it has really helped me out :) I ran into an issue and I was hoping you could help?

When I run code below I only get 5 devices back:

import cec

adapters = cec.list_adapters()

if len(adapters) > 0:
    adapter = adapters[0]

    print('Adapter: {0}'.format(adapter))

    cec.init(adapter)
    
    devices = cec.list_devices()

    for i in range(len(devices)):
        d = cec.Device(i)
        print('{0} : {1} '.format(i, d.osd_string))

Which shows this:

Adapter: RPI
0 : TV
1 : python-cec
2 : Recorder 2
3 : Tuner 1
4 : PlayStation 4

However there is an AV Receiver that the raspberry pi is plugged into and if I run the following:

d = cec.Device(5)
print('{0} | Active: {1} | ON: {2}'.format(d.osd_string, d.is_active(), d.is_on()))

I get:

AVR-X1600H | Active: False | ON: False

Which means it does see the receiver. Is the list_devices limited to how many it can return?
Also is there any example code of how to use cec.EVENT_COMMAND callback? I want to have a callback that will run once a device is turned off or on.

Thank you

pip3 install fail Raspbian

I have problem with installation on Raspbery Pi 3

pip3 install cec
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting cec
Using cached https://files.pythonhosted.org/packages/ca/4e/84fae96b6744131a293ec8611dec173a22e06d9f228abc7f0f58f387f9d2/cec-0.2.6.tar.gz
Building wheels for collected packages: cec
Running setup.py bdist_wheel for cec ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-n9uavnwn/cec/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/pip-wheel-oxwron19 --python-tag cp37:
running bdist_wheel
running build
running build_ext
building 'cec' extension
creating build
creating build/temp.linux-armv7l-3.7
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Iinclude -I/usr/include/python3.7m -c cec.cpp -o build/temp.linux-armv7l-3.7/cec.o
cec.cpp: In function ?PyObject* set_stream_path(PyObject*, PyObject*)?:
cec.cpp:487:41: error: invalid conversion from ?const char*? to ?char*? [-fpermissive]
char * arg_s = PyUnicode_AsUTF8(arg);
~~~~~~~~~~~~~~~~^~~~~
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1


Failed building wheel for cec
Running setup.py clean for cec
Failed to build cec
Installing collected packages: cec
Running setup.py install for cec ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-n9uavnwn/cec/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-9gzk5_g6/install-record.txt --single-version-externally-managed --compile --user --prefix=:
running install
running build
running build_ext
building 'cec' extension
creating build
creating build/temp.linux-armv7l-3.7
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Iinclude -I/usr/include/python3.7m -c cec.cpp -o build/temp.linux-armv7l-3.7/cec.o
cec.cpp: In function ?PyObject* set_stream_path(PyObject*, PyObject*)?:
cec.cpp:487:41: error: invalid conversion from ?const char*? to ?char*? [-fpermissive]
char * arg_s = PyUnicode_AsUTF8(arg);
~~~~~~~~~~~~~~~~^~~~~
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

----------------------------------------

Command "/usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-n9uavnwn/cec/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-9gzk5_g6/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-install-n9uavnwn/cec/

Add python-cec to pip repo

Any chance on getting this added to the Python Package Index? It looks like the only version on there is pretty old.

Failed Installing python-CEC

I'm running on a RP2 running Raspbian Jessie. I'm getting an error when I try to use the command sudo pip install cec command.

Failed to build cec
Installing collected packages: cec
  Running setup.py install for cec ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/     tmp/pip-build-f7e5ro0h/cec/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read     ().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-lv2te9fx-record/install-     record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'cec' extension
    creating build
    creating build/temp.linux-armv7l-3.4
    arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -     Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -Iinclude -I/usr/include/python3.4m -c      cec.cpp -o build/temp.linux-armv7l-3.4/cec.o
    cec.cpp: In function ‘PyObject* set_stream_path(PyObject*, PyObject*)’:
    cec.cpp:411:25: error: ‘PyInt_Check’ was not declared in this scope
           if(PyInt_Check(arg)) {
                             ^
    cec.cpp:412:39: error: ‘PyInt_AsLong’ was not declared in this scope
              long arg_l = PyInt_AsLong(arg);
                                           ^
    cec.cpp:420:35: error: ‘PyString_Check’ was not declared in this scope
           } else if(PyString_Check(arg)) {
                                       ^
    cec.cpp:421:46: error: ‘PyString_AsString’ was not declared in this scope
              char * arg_s = PyString_AsString(arg);
                                                  ^
    cec.cpp: In function ‘PyObject* initcec()’:
    cec.cpp:671:7: error: return-statement with no value, in function returning ‘PyObject* {aka      _object*}’ [-fpermissive]
           return;
           ^
    cec.cpp:681:31: error: return-statement with no value, in function returning ‘PyObject* {aka      _object*}’ [-fpermissive]
        if(PyType_Ready(dev) < 0 ) return;
                                   ^
    cec.cpp:683:50: error: ‘Py_InitModule’ was not declared in this scope
        PyObject * m = Py_InitModule("cec", CecMethods);
                                                      ^
    cec.cpp:685:20: error: return-statement with no value, in function returning ‘PyObject* {aka      _object*}’ [-fpermissive]
        if( m == NULL ) return;
                        ^
    error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

If I try sudo pip2 install cec, it installs correctly, but when calling a python script it fails with

sudo python /var/opt/homeassistant/bruh2/cecscript/allon.py
Traceback (most recent call last):
  File "/var/opt/homeassistant/bruh2/cecscript/allon.py", line 4, in <module>
    cec.init()
IOError: CEC failed to open ▒▒▒▒

Libcec3.0 is installed and working correctly.

libCEC version: 3.0.1,  compiled on Fri Jul  3 19:20:43 UTC 2015 by pbuilder@mgo                     rven-pc.thefacebook.com on Linux 3.16.0-41-generic (armv7l), features: P8_USB, P                     8_detect, 'RPi'
Found devices: 1

device:              1
com port:            RPI
vendor id:           2708
product id:          1001
firmware version:    1
type:                Raspberry Pi

Any ideas?

Keypress callback sometimes does not trigger on key release

I noticed that sometimes my IR remote key gets stuck in pressed state. After some debugging it seems like it happens in python-cec.

To reproduce - click the same button after the initial click quickly. Quite frequently it triggers a situation where it registers only key down and does not send key up.

It does however still trigger command callback, so I'll use that for now as a workaround.

Here is some debug log from cecdaemon.

CEC DEBUG: got command callback
Got event 4 with data ({'initiator': 0, 'destination': 1, 'ack': False, 'eom': True, 'opcode': 68, 'parameters': b'\x03', 'opcode_set': True, 'transmit_timeout': 1000},)
CEC DEBUG: Callback succeeded
CEC DEBUG: got keypress callback
DEBUG:root:3 is mapped to KEY_LEFT
DEBUG:root:Key 3 down
CEC DEBUG: Callback succeeded
CEC DEBUG: got command callback
Got event 4 with data ({'initiator': 0, 'destination': 1, 'ack': False, 'eom': True, 'opcode': 69, 'parameters': b'', 'opcode_set': True, 'transmit_timeout': 1000},)
CEC DEBUG: Callback succeeded

Compilation error on macOS

I am getting the following error when trying to install on macOS Mojave:

    running install
    running build
    running build_ext
    building 'cec' extension
    creating build
    creating build/temp.macosx-10.13-x86_64-3.7
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Iinclude -I/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c cec.cpp -o build/temp.macosx-10.13-x86_64-3.7/cec.o
    cec.cpp:487:17: error: cannot initialize a variable of type 'char *' with an rvalue of type 'const char *'
             char * arg_s = PyUnicode_AsUTF8(arg);
                    ^       ~~~~~~~~~~~~~~~~~~~~~
    1 error generated.
    error: command 'clang' failed with exit status 1

    ----------------------------------------

Error:  An error occurred while installing cec!
  Failed building wheel for cec

Compilation error for libcec-4.0.2

It seems to be generated due to changes on libcec API. According to their Changelog, since version 4 FindAdapters has been removed.

cec.cpp:102:27: error: ‘class CEC::ICECAdapter’ has no member named ‘FindAdapters’
    #define CEC_FIND_ADAPTERS FindAdapters

Exception: No default adapter found

I get an exception when calling cec.init() on my RaspberryPi. I've included the terminal output below.

    pi@raspberrypi ~ $ sudo python
    Python 2.7.3 (default, Jan 13 2013, 11:20:46) 
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import cec
    >>> cec.init()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    Exception: No default adapter found
    >>> 

cec.EVENT_KEYPRESS not working after updating to 0.2.7

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.

python-cec does not work with libcec 3.x

Hi,

I've tried to build python-cec against libcec 3.0.1-1 but the compilation fails as the CEC_CLIENT_VERSION_* constants are no longer defined in libcec's cectypes.h header file.

Are there any plans to support this newer version of libcec?

Cheers,

Neil.

cec.set_physical_addr(addr)

Hello,

I'm trying to work with my CEC adapter which constantly loses its physical address and causes the rest of my system to spas out. I need to set its address as 4.4.0.0, as it's connected to the 4th input of my AVR which is connected to the 4th input of the TV. I pass this in to this function and I get a variable type error, where the function is expecting a string. How are we supposed to format the address to pass into this function? (I've tried having it as 4.4.0.0, 4400, 0x4400)

Thanks!

Volume up and Volume down don't work

Okay, so they probably do work... But I'm not sure how. They aren't part of the device class, so I'm not 100% sure what they do. I can't run, for example tv.volume_up(), and running cec.volume_up() just returns true.
Should these be able to send volume up and down commands to the TV?

UnicodeDecodeError on list_devices

Using Ubuntu 18.04 64-bit the following python3 code suddenly crashes, though it worked fine a few days ago.

import cec
cec.init()
cec.list_devices()

with the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb7 in position 4: invalid start byte

However the same code works on python2, which is getting deprecated.

Pypi update

Is there any chance you could do a version bump and upload to pypi? The current version on Pypi doesn't have commit fb230ae, so it won't compile when installing with pip.

Thanks in advance

python-cec is not compatible with libcec >= 5

Following updates to libcec (Pulse-Eight/libcec@24fc926#diff-d570731a39a39af80ff1ab9d9c3e442b), python-cec does not build against the latest version.

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -march=x86-64 -mtune=generic -O3 -pipe -fno-plt -fno-semantic-interposition -march=x86-64 -mtune=generic -O3 -pipe -fno-plt -march=x86-64 -mtune=generic -O3 -pipe -fno-plt -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -D_FORTIFY_SOURCE=2 -fPIC -Iinclude -I/usr/include/python3.8 -c cec.cpp -o build/temp.linux-x86_64-3.8/cec.o
cec.cpp: In function ‘PyObject* can_persist_config(PyObject*, PyObject*)’:
cec.cpp:614:32: error: ‘class CEC::ICECAdapter’ has no member named ‘CanPersistConfiguration’; did you mean ‘CanSaveConfiguration’?
  614 |       RETURN_BOOL(CEC_adapter->CanPersistConfiguration());
      |                                ^~~~~~~~~~~~~~~~~~~~~~~
cec.cpp:120:13: note: in definition of macro ‘RETURN_BOOL’
  120 |   result = (arg); \
      |             ^~~
cec.cpp: In function ‘PyObject* persist_config(PyObject*, PyObject*)’:
cec.cpp:621:26: error: ‘class CEC::ICECAdapter’ has no member named ‘CanPersistConfiguration’; did you mean ‘CanSaveConfiguration’?
  621 |       if( ! CEC_adapter->CanPersistConfiguration() ) {
      |                          ^~~~~~~~~~~~~~~~~~~~~~~
      |                          CanSaveConfiguration
cec.cpp:631:32: error: ‘class CEC::ICECAdapter’ has no member named ‘PersistConfiguration’; did you mean ‘SetConfiguration’?
  631 |       RETURN_BOOL(CEC_adapter->PersistConfiguration(&config));
      |                                ^~~~~~~~~~~~~~~~~~~~
cec.cpp:120:13: note: in definition of macro ‘RETURN_BOOL’
  120 |   result = (arg); \
      |             ^~~
error: command 'gcc' failed with exit status 1
==> ERROR: A failure occurred in build().
    Aborting...

cec.init freezes when fails, suggested fix

The CEC adapter can only be open by one caller at any one time.

If init() is called when the adapter is already open, the current code is meant to destroy the adapter resource and then raise an exception. However, I found that the code freezes when it attempts to destroy the adapter.

CECDestroy(CEC_adapter);
CEC_adapter = NULL;

I found the following code fixed it for me:

Py_BEGIN_ALLOW_THREADS
CECDestroy(CEC_adapter);
CEC_adapter = NULL;
Py_END_ALLOW_THREADS

Error during Setup on Raspberry Pi

Hi,

I installed the dependencies on my nearly out of the box Raspberry Pi. Unfortunately I am getting a compile error in the setup script. Maybe I am missing something. I have tried running it in sudo mode too - but not luck. Any help would be much appreciated.

$ python setup.py install
running install
running build
running build_ext
building 'cec' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c cec.cpp -o build/temp.linux-armv6l-2.7/cec.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c device.cpp -o build/temp.linux-armv6l-2.7/device.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
device.cpp: In function ‘PyObject* Device_new(PyTypeObject*, PyObject*, PyObject*)’:
device.cpp:180:37: error: expected ‘)’ before ‘PRIX64’
device.cpp:180:51: warning: conversion lacks type at end of format [-Wformat]
device.cpp:180:51: warning: too many arguments for format [-Wformat-extra-args]
device.cpp:180:51: warning: conversion lacks type at end of format [-Wformat]
device.cpp:180:51: warning: too many arguments for format [-Wformat-extra-args]
error: command 'gcc' failed with exit status 1

Can't get the raspberry pi instructions to work on buster

Trying to install cec for raspberry pi 4 on buster.

Firstly, after adding the repo I get this:

$ sudo apt-get update
Hit:1 http://archive.raspberrypi.org/debian buster InRelease
Get:2 http://packages.namniart.com/repos/pi wheezy InRelease [2083 B]
Get:3 http://raspbian.raspberrypi.org/raspbian buster InRelease [15.0 kB]
Err:2 http://packages.namniart.com/repos/pi wheezy InRelease
  The following signatures were invalid: 15A0B3807025FB9CC17EA6FF17BF1CB1D6FC98DF

Proceed anyway, and when trying to pip install (possibly since the apt-get install didn't pick up the modified version of libcec-dev)

$ sudo pip3 install cec
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting cec
  Using cached https://files.pythonhosted.org/packages/ca/4e/84fae96b6744131a293ec8611dec173a22e06d9f228abc7f0f58f387f9d2/cec-0.2.6.tar.gz
Building wheels for collected packages: cec
  Running setup.py bdist_wheel for cec ... error
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-o4d81v2m/cec/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-a5xniwbe --python-tag cp37:
  running bdist_wheel
  running build
  running build_ext
  building 'cec' extension
  creating build
  creating build/temp.linux-armv7l-3.7
  arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Iinclude -I/usr/include/python3.7m -c cec.cpp -o build/temp.linux-armv7l-3.7/cec.o
  cec.cpp: In function ‘PyObject* set_stream_path(PyObject*, PyObject*)’:
  cec.cpp:487:41: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
            char * arg_s = PyUnicode_AsUTF8(arg);
                           ~~~~~~~~~~~~~~~~^~~~~
  error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for cec
  Running setup.py clean for cec
Failed to build cec
Installing collected packages: cec
  Running setup.py install for cec ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-o4d81v2m/cec/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-7bi8jxk2/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'cec' extension
    creating build
    creating build/temp.linux-armv7l-3.7
    arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Iinclude -I/usr/include/python3.7m -c cec.cpp -o build/temp.linux-armv7l-3.7/cec.o
    cec.cpp: In function ‘PyObject* set_stream_path(PyObject*, PyObject*)’:
    cec.cpp:487:41: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
              char * arg_s = PyUnicode_AsUTF8(arg);
                             ~~~~~~~~~~~~~~~~^~~~~
    error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-o4d81v2m/cec/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-7bi8jxk2/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-o4d81v2m/cec/

Any chance of a fix to the repo?

Segmentation fault on Raspberry Pi

Hello,

I am trying to use your lib on a Raspberry Pi. I tested the master and the devel branch and I am always getting a segmentation fault error.

Setup is Raspberry Pi model B
Running cec-client gives:
CEC Parser created - libCEC version 2.1.4
no serial port given. trying autodetect:
path: Raspberry Pi
com port: RPI

This is what I do in python interpreter:

Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import cec
cec.list_adapters()
['RPI']
cec.list_devices()
.
.
Lot of CEC DEBUG message
.
.
{} 'Looks like no devices are found

cec.init()
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content unregistering all CEC clients
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content TV (0): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Recorder 1 (1): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Recorder 2 (2): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Tuner 1 (3): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Playback 1 (4): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Audio (5): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Tuner 2 (6): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Tuner 3 (7): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Playback 2 (8): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Recorder 3 (9): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Tuner 4 (A): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Playback 3 (B): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Reserved 1 (C): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Reserved 2 (D): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Free use (E): device status changed into 'unknown'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content Broadcast (F): osd name set to 'Broadcast'
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content InitHostCEC - vchiq_initialise succeeded
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content InitHostCEC - vchi_initialise succeeded
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content InitHostCEC - vchi_connect succeeded
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
CEC DEBUG: got log callback
CEC DEBUG: GIL acquired
CEC DEBUG: Message level 16
CEC DEBUG: Message time 0
CEC DEBUG: Message content logical address changed to Broadcast (f)
CEC DEBUG: argument PyObject created
CEC DEBUG: Triggering event 1
CEC DEBUG: Event trigger done
Segmentation fault

Did I missed something on the process ?

Sorry for this long post !

Regards

cec.h not found error

error when trying to install w\ windows 64 python 2.7

C:\Users\itamar\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\bin>python2 -m pip install cec
Collecting cec
  Using cached cec-0.2.6.tar.gz
Installing collected packages: cec
  Running setup.py install for cec ... error
    Complete output from command C:\Python27\python2.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\itamar\\appdata\\local\\temp\\pip-build-qof5p5\\cec\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\itamar\appdata\local\temp\pip-t_dwzd-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'cec' extension
    creating build
    creating build\temp.win32-2.7
    creating build\temp.win32-2.7\Release
    C:\Users\itamar\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Iinclude -IC:\Python27\include -IC:\Python27\PC /Tpcec.cpp /Fobuild\temp.win32-2.7\Release\cec.obj
    cec.cpp
    cec.cpp(32) : fatal error C1083: Cannot open include file: 'libcec/cec.h': No such file or directory
    error: command 'C:\\Users\\itamar\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status 2

    ----------------------------------------
Command "C:\Python27\python2.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\itamar\\appdata\\local\\temp\\pip-build-qof5p5\\cec\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\itamar\appdata\local\temp\pip-t_dwzd-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\itamar\appdata\local\temp\pip-build-qof5p5\cec\

Data from such a repository can't be authenticated

I'm getting the following authentication error when trying to run your custom install steps for a Raspberry Pi.

W: GPG error: http://packages.namniart.com/repos/pi wheezy InRelease: The following signatures were invalid: 15A0B3807025FB9CC17EA6FF17BF1CB1D6FC98DF
W: The repository 'http://packages.namniart.com/repos/pi wheezy InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.

I did try to use the "--allow-unauthenticated" flag, but that didn't work either. I'm a Raspberry Pi and Python newbie, so I'm probably missing something easy.

version.h file not found error

while running the sample program getting error "cannot open file version.h : No such file or directory exists" .
This is the output.
C:\Python27>pip install cec
Collecting cec
Using cached cec-0.2.5.tar.gz
Installing collected packages: cec
Running setup.py install for cec ... error
Complete output from command c:\python27\python.exe -u -c "import setuptools
, tokenize;file='c:\users\unameit\appdata\local\temp\pip-build-cfwkhz
\cec\setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().re
place('\r\n', '\n'), file, 'exec'))" install --record c:\users\unameit\appda
ta\local\temp\pip-m0b6sp-record\install-record.txt --single-version-externally-m
anaged --compile:
running install
running build
running build_ext
building 'cec' extension
creating build
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo
/Ox /MD /W3 /GS- /DNDEBUG -Iinclude -Ic:\python27\include -Ic:\python27\PC /Tpce
c.cpp /Fobuild\temp.win32-2.7\Release\cec.obj
cec.cpp
c:\python27\include\libcec\cectypes.h(37) : fatal error C1083: Cannot open i
nclude file: 'version.h': No such file or directory
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BI
N\cl.exe' failed with exit status 2

How do you know if TV is cec compliant?

Not an issue related to the library, but, I thought it pertinent to ask here. The TV is not a very popular brand (westway). But its got two hdmi inputs. And in the TV we have the provision to select which hdmi input we want to watch from.

So if a TV has two hdmi inputs does it mean that probably its not CEC compliant?

The original idea I had in mind was to keep the TV awake via a rpi program. Now the TV does turnoff automatically unless some input from its remote is received. That's where this question actually came from.

Getting an invalid signature on 'sudo apt-get update' while installing on Raspbian

Err:2 http://packages.namniart.com/repos/pi wheezy InRelease
The following signatures were invalid: 15A0B3807025FB9CC17EA6FF17BF1CB1D6FC98DF
Reading package lists... Done
W: GPG error: http://packages.namniart.com/repos/pi wheezy InRelease: The following signatures were invalid: 15A0B3807025FB9CC17EA6FF17BF1CB1D6FC98DF
E: The repository 'http://packages.namniart.com/repos/pi wheezy InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.

Any suggestion would be appreciated - Tom

race condition in command_cb

I've added some code to command_cb() so that my Python program may receive raw CEC messages. I've added a call to a Python method in between the PyGILState_Ensure() and PyGILState_Release() statements .

The method typically doesn't produce any noticeable action, unless that action is very quick. For example, I can print a hard-coded string like 'CEC message received', but I can't print str(some_object). This behavior occurs even when I run the program under gdb.

I think this qualifies as a race condition. I don't see how, I thought that the PyGILState_Ensure() would take care of this.

Any ideas? Thanks in advance.

Support for setting the `python-cec` device to audio system

Background: I'm trying to pretend to be an ARC device so that I can intercept volume commands from my TCL635 TV and send IR codes for my Vizio soundbar. I'm able to convince my TV to send me volume commands using cec-client -t a (advertise as an audio device) and then sending txn 50:C3 (CEC_OPCODE_REPORT_ARC_STARTED) right after startup. I'm trying to do the same thing with this library.

Is there a way to configure the python-cec device as an audio device?

Reading though the code I think this is the relevant line. If I'm right, it looks like it's not configurable. I'd be interested in making this change, but wanted to see if you had any thoughts first.

pip install fails

The library fails to install. What can I do?

$ pip install cec
Collecting cec
Using cached https://files.pythonhosted.org/packages/ca/4e/84fae96b6744131a293ec8611dec173a22e06d9f228abc7f0f58f387f9d2/cec-0.2.6.tar.gz
Installing collected packages: cec
Running setup.py install for cec ... error
ERROR: Command errored out with exit status 1:
command: 'c:\users\kasper\appdata\local\programs\python\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Kasper\AppData\Local\Temp\pip-install-hgdgq3nw\cec\setup.py'"'"'; file='"'"'C:\Users\Kasper\AppData\Local\Temp\pip-install-hgdgq3nw\cec\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\Kasper\AppData\Local\Temp\pip-record-2ixthcny\install-record.txt' --single-version-externally-managed --compile
cwd: C:\Users\Kasper\AppData\Local\Temp\pip-install-hgdgq3nw\cec
Complete output (11 lines):
running install
running build
running build_ext
building 'cec' extension
creating build
creating build\temp.win-amd64-3.7
creating build\temp.win-amd64-3.7\Release
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Iinclude -Ic:\users\kasper\appdata\local\programs\python\python37\include -Ic:\users\kasper\appdata\local\programs\python\python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /EHsc /Tpcec.cpp /Fobuild\temp.win-amd64-3.7\Release\cec.obj
cec.cpp
cec.cpp(32): fatal error C1083: Cannot open include file: 'libcec/cec.h': No such file or directory
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\kasper\appdata\local\programs\python\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Kasper\AppData\Local\Temp\pip-install-hgdgq3nw\cec\setup.py'"'"'; file='"'"'C:\Users\Kasper\AppData\Local\Temp\pip-install-hgdgq3nw\cec\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\Kasper\AppData\Local\Temp\pip-record-2ixthcny\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

remove_callback "error return without exception set"

I am getting this error whenever I try to call the remove_callback method, I am succesful to initialize and add callbacks to my functions, however, after I am done with the CEC controls, I am unable to remove the callbacks.

This is being used in a raspberry pi boot up menu, and it runs continuously, after the user selects the boot option, I would like to disable the cec controls, thus, this script is never going to quit / finish.

Is there any special consideration to remove callbacks?

Here's the code used:

import cec
from time import sleep
import uinput

#cec.init()

#tv = cec.Device(cec.CECDEVICE_TV)
#tv.power_off()
#sleep(5)
#tv.power_on()

device = uinput.Device([
    uinput.KEY_DOWN,
    uinput.KEY_UP,
    uinput.KEY_A,
    uinput.KEY_ENTER,
    uinput.KEY_RED,
    uinput.KEY_1,
    uinput.KEY_2,
    uinput.KEY_3,
    uinput.KEY_4,
    uinput.KEY_5,
    uinput.KEY_6
    ])

keymap = {
    1: uinput.KEY_1,
    2: uinput.KEY_2,
    3: uinput.KEY_3,
    4: uinput.KEY_4,
    5: uinput.KEY_5,
    6: uinput.KEY_6,
    7: uinput.KEY_ENTER,
    8: uinput.KEY_DOWN,
    9: uinput.KEY_UP
    }

def __keypress_cb__(event, *args):
    print("Got event", event, "with data", args)
    #placeholder code below
    #keycode = 1
    #device.emit_click(keymap[keycode])

def start():
    global started
    if started==False:
        cec.add_callback(__keypress_cb__, cec.EVENT_KEYPRESS)
        started=True

def stop():
    global started
    if started==True:
        cec.remove_callback(__keypress_cb__, cec.EVENT_KEYPRESS)
        started=False
   
cec.init()
cec.remove_callback(
tv = cec.Device(0)
started=False

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.