Giter VIP home page Giter VIP logo

python-lirc's Introduction

python-lirc (deprecated)

Since Linux 4.18, IR is now handled in-kernel and IR events appear just like keyboard or mouse events, making the LIRC daemon and clients (like python-lirc) mostly redundant. The new way to configure keymaps is using ir-keytable which comes with v4l-utils. See #28 (comment)

Next steps:

  • Close issues
  • Close pull requests
  • Archive repo

PyPI

Install

pip3 install python3-lirc

Configure

You need a valid lircrc configuration file. For example:

$ cat ~/.lircrc
begin
  button = 1          # what button is pressed on the remote
  prog = myprogram    # program to handle this command
  config = one, horse # configs are given to program as list
end

begin
  button = 2
  prog = myprogram
  config = two
end

Use

$ python3
>>> import lirc
>>> sockid = lirc.init("myprogram")
>>> lirc.nextcode()  # press 1 on remote after this
['one', 'horse']
>>> lirc.deinit()

Load custom configurations with:

>>> sockid = lirc.init("myprogram", "mylircrc")
>>> lirc.load_config_file("another-config-file") # subsequent configs

Set whether nextcode blocks or not with:

>>> sockid = lirc.init("myprogram", blocking=False)
>>> lirc.set_blocking(True, sockid)  # or this

Building and Installing

If you want to install manually then you may also need to install cython and some dev libraries:

sudo apt install cython gcc liblircclient-dev python{,3}-{dev,setuptools}

Download, compile and install for Python 3 and 2.

git clone https://github.com/tompreston/python-lirc.git
cd python-lirc/
make py3 && sudo python3 setup.py install
make py2 && sudo python setup.py install

Development

  1. Install the dev libraries as above.
  2. Make changes to lirc/lirc.pyx.
  3. Compile with make py3 && python3 setup.py build
  4. Test with python3 tests/tests.py

python-lirc's People

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

Watchers

 avatar  avatar  avatar  avatar  avatar

python-lirc's Issues

Specify lircd socket

It seems there is no way to specify the lirc socket to use. In my case (on OSMC on a rpi), there are two lirc sockets:

  • /var/run/lirc/lircd: uses kernel mapping, irw shows all buttons presses are using the remote linux-input-layer
  • /var/run/lirc/lircd-lirc0: uses a normal lirc client, irw shows the correct remote

This python scripts seems to use /var/run/lirc/lircd, but I can't find a way to change this. Can this be specified somewhere?

setup.py - cythonize call missing?

Hi,

I was just trying to install your python-lirc package directly from the source provided here on Github.
When I executed setup.py it tried to access lirc/lirc.c - a file that has to be generated using cython first, if I understand it correctly.

Therefore I assume that some call to cythonize is missing in setup.py, right? Or is it common that you have to to this manually, before executing setup.py?

lirc.ConfigLoadError: Could not load the config file

Hi,
I can't use this lib... It keeps saying lirc.ConfigLoadError: Could not load the config file (~/.lircrc) .
Of course, it does exist.
The .lircrc file is the same as in ReadMe...
Any idea why ?
Thanks !

Does not work for Python3 on RPI Buster

Got lirc working on buster following these instructions https://www.raspberrypi.org/forums/viewtopic.php?t=235256

system info:
Distro......: Raspbian GNU/Linux 10 (buster)
Kernel......: Linux 4.19.57-v7+

So all lirc tools now working ok but this isn't included in buster and pip3 install with : pip3 install python-lirc results in failure probably down to the changes in LIRC10

Complete output from command

/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-kmzw_0xg/python-lirc/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-72i824mv --python-tag cp37:
  running bdist_wheel
  running build
  running build_ext
  building 'lirc' extension
  creating build
  creating build/temp.linux-armv7l-3.7
  creating build/temp.linux-armv7l-3.7/lirc
  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 -I/usr/include/lirc/ -I/usr/include/python3.7m -c lirc/lirc.c -o build/temp.linux-armv7l-3.7/lirc/lirc.o
  lirc/lirc.c: In function ‘__Pyx__ExceptionSave’:
  lirc/lirc.c:5050:21: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_type’; did you mean ‘curexc_type’?
       *type = tstate->exc_type;
                       ^~~~~~~~

Plus lots more of the same error

Unable to handle Inputs , Wildcards

In documentation you have mentioned that a valid lircrc file is required.
I do not understand Why an empty licrc file should not work.

Basically, I would assume, whatever button declarations are there in my /etc/lircd.conf file should get conveyed into python even without a valid lircrc or .lircrc

Say for example, in my lircd.conf I have the following :
B_POWER 0x28D7
B_MUTE 0x30CF

I amusing this script :


import lirc

sockid = lirc.init("myprogram")
print("Ready")

while True:
    code = lirc.nextcode()
    print(code)
    if code: print(code[0])

When I Press the remote even with an empty lircrc file, it receives the commands from the remote. and generates empty array data like following :
[ ]
[ ]

I would expect it to be actually showing what has been received from the remote.

To prove my point, here is link to a C program that works perfectly fine and send the actual button pressed details to the code.

http://ozzmaker.com/2013/10/24/how-to-control-the-gpio-on-a-raspberry-pi-with-an-ir-remote/?utm_source=feedly , Please scroll down till you see the C code.

If I declare all the Buttons in lircrc file, then everything works well with python, but with empty lircrc file, it just shows empty arrays when the sample python code from above is executed.

I would expect it to show which button I pressed based on data from the .conf file.

Also, does this support wildcards in lircrc ? Typically, I would look for, when I press any button in remote as long as it has a valid entry in the lircd.conf file, that should get passed on to Python and be available to use within python-lirc

Sorry for editing this post so many times, just realized, I had made some mistakes and needed to change them

Error while installing

I tried to install it using pip, but I got the following error:
pi@raspberrypi:~ $ pip install python-lirc DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Defaulting to user installation because normal site-packages is not writeable Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting python-lirc Using cached python-lirc-1.2.3.tar.gz (36 kB) Using legacy setup.py install for python-lirc, since package 'wheel' is not installed. Installing collected packages: python-lirc Running setup.py install for python-lirc ... error ERROR: Command errored out with exit status 1: command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-nTATVo/python-lirc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-nTATVo/python-lirc/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-Pik2vj/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/pi/.local/include/python2.7/python-lirc cwd: /tmp/pip-install-nTATVo/python-lirc/ Complete output (13 lines): running install running build running build_ext building 'lirc' extension creating build creating build/temp.linux-armv7l-2.7 creating build/temp.linux-armv7l-2.7/lirc arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/lirc/ -I/usr/include/python2.7 -c lirc/lirc.c -o build/temp.linux-armv7l-2.7/lirc/lirc.o lirc/lirc.c:276:10: fatal error: lirc/lirc_client.h: Datei oder Verzeichnis nicht gefunden #include "lirc/lirc_client.h" ^~~~~~~~~~~~~~~~~~~~ compilation terminated. error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1 ---------------------------------------- ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-nTATVo/python-lirc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-nTATVo/python-lirc/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-Pik2vj/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/pi/.local/include/python2.7/python-lirc Check the logs for full command output.

lirc.nextcode() gives [] instead of key

Hello, I try to use lirc-1.2.1 on python 3.4 on raspberry pi.
I wrote this code:
import lirc while 1: sockid = lirc.init("myprogram2", blocking = False) codeIR = lirc.nextcode() print (codeIR)//must give one
I have two erros: blocking is true alltime (python 2 hasn't this bug) and print (codeIR) gives [] when i press button on tv remote, not config (in all pythons).
lircrc: begin button = KEY_1 # what button is pressed on the remote prog = myprogram2 # program to handle this command config = one# configs are given to program as list end Please, help

Packaging issue in Pip

Hi. I have been tracking down a bug in another project where unexpected blocking was experienced and I think I isolated it to a packaging issue in the pip page. The tarball associated with this package's pip page contains lirc.c which was compiled by Cython 0.15.1 on Thu Jul 4 13:50:19 2013. I think that file is out of date. A better way to package this would be to put lirc.pyx in the tarball and let the user's system perform the cythoning and building of the library.

LIRC mode2 support

Do you think it would be possible to support mode2 in python-lirc as well?

It's a way of using lirc without lircd, reading just the raw kernel device (try calling "mode2 -r -d /dev/lirc0").

An example is this:

#!/usr/bin/env python

import fcntl
import array
import os
import struct

LIRC_GET_REC_MODE = 0x80046902 # _IOR('i', 0x00000002, __u32)
LIRC_GET_LENGTH = 0x8004690F # _IOR('i', 0x0000000f, __u32)
LIRC_MODE_MODE2 = 0x00000004
PULSE_BIT = 0x01000000
PULSE_MASK = 0x00FFFFFF

result = array.array("I", [0])

lirc_t = "i"

def read(fd):
  rawbuf = os.read(fd, struct.calcsize(lirc_t))
  rawvalue, = struct.unpack(lirc_t, rawbuf)
  pulseflag = rawvalue & PULSE_BIT
  duration = rawvalue & PULSE_MASK
  return (pulseflag != 0, duration)

def main():
  fd = os.open("/dev/lirc0", os.O_RDONLY)
  if fcntl.ioctl(fd, LIRC_GET_REC_MODE, result, True) == -1:
    raise IOError("cannot use {!r} as a raw LIRC device. Is it a
LIRC device?".format(self.device))
  if result[0] != LIRC_MODE_MODE2:
    raise IOError("cannot use {!r} as a raw LIRC device. Is it a
raw (!) LIRC device?".format(self.device))
  print(read(fd))

It would be nice especially to have these strange constants available.

Unable to initialise lirc

Hi,

I installed lirc on raspberry pie using the instructions from the readme page. lirc is not initializing. I get this error. Would you have any idea why this would be occurring?

Traceback (most recent call last):
File "", line 1, in
File "lirc.pyx", line 122, in lirc.init (lirc/lirc.c:1286)
lirc.InitError: Unable to initialise lirc (socket was -1 from C library).

python3 lirc.nextcode() seems to block even when blocking set to False

Wrote very short program to demonstrate this:

import lirc
import time
sockid = lirc.init("python3", ".lircrc". blocking=False)
while True:
    try:
        button = lirc.nextcode()
        print("Looped!")
        if len(button) == 0: continue
        print(button[0])
        time.sleep(1)
    except KeyboardInterrupt:
        lirc.deinit()
        break

This should print "Looped!" every second, and also print the button pressed otherwise. But the program stops (is blocked) at the nextcode() line until a button is pressed. It then passes on the button, and a handful of zero length returns, then goes back to blocking.I've also tried with the separate "set_blocking" line. I can see in the code where it is supposed to set the O_NONBLOCK flag, so maybe it's a bug in LIRC? I'm really new to python, so if I'm misunderstanding something, just let me know please.

Error while installing

I tried to install it using pip, but I got the following error:

pi@raspberrypi:~ $ pip install python-lirc
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting python-lirc
  Using cached python-lirc-1.2.3.tar.gz (36 kB)
Using legacy setup.py install for python-lirc, since package 'wheel' is not installed.
Installing collected packages: python-lirc
    Running setup.py install for python-lirc ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-nTATVo/python-lirc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-nTATVo/python-lirc/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-Pik2vj/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/pi/.local/include/python2.7/python-lirc
         cwd: /tmp/pip-install-nTATVo/python-lirc/
    Complete output (13 lines):
    running install
    running build
    running build_ext
    building 'lirc' extension
    creating build
    creating build/temp.linux-armv7l-2.7
    creating build/temp.linux-armv7l-2.7/lirc
    arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/lirc/ -I/usr/include/python2.7 -c lirc/lirc.c -o build/temp.linux-armv7l-2.7/lirc/lirc.o
    lirc/lirc.c:276:10: fatal error: lirc/lirc_client.h: Datei oder Verzeichnis nicht gefunden
     #include "lirc/lirc_client.h"
              ^~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-nTATVo/python-lirc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-nTATVo/python-lirc/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-Pik2vj/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/pi/.local/include/python2.7/python-lirc Check the logs for full command output.

No code detected by next code()

I try to build a rain sensor using 38 kHz IR transmitter/receiver. I set up the two components and installed LIRC and python-lirc on a Raspberry Pi (running Jessie Debian), and used irrecord to build a configuration (to mimick a TV IR Remote).

The LIRC configuration is OK, as I can use irsend or irw from the shell and get the appropriate code.

Using python-lirc from a small python script, I have no result. The lirc.nextcode() returns an empty list.

import lirc
lirc.init("myprog", blocking = False)  
while (True):
    try:
            list = lirc.nextcode()
            if len(list) != 0: print "match!"
    except KeyboardInterrupt:
            lirc.deinit()
            break;

The /etc/lirc/lircrc file is:

begin
  remote = myRemote
  button = KEY_UP          # what button is pressed on the remote
  prog = myprog    # program to handle this command
  config = KEY_UP # configs are given to program as list
  repeat = 0
end

Does not work for Python3 on rpi Stretch

trying to install on rpi for python3 with Stretch.

With sudo apt-get install python3-lirc
I get:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3-lirc

So I try to download the release files and install.
Python2.7 install worked OK.

But version python3-lirc_1.2.1-1 appeared to install with error messages but in use I cannot import lirc - ImportError: No module named 'lirc'. I note the file size is minuscule so as per previous issue the file appears to be missing the necessary.

I tried to install python3-lirc_1.2.0-1 but I get:
dpkg: warning: downgrading python3-lirc from 1.2.1-1 to 1.2.0-1
(Reading database ... 128412 files and directories currently installed.)
Preparing to unpack python3-lirc_1.2.0-1_armhf.deb ...
Unpacking python3-lirc (1.2.0-1) over (1.2.1-1) ...
dpkg: dependency problems prevent configuration of python3-lirc:
python3-lirc depends on python3 (<< 3.3); however:
Version of python3 on system is 3.5.3-1.
dpkg: error processing package python3-lirc (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
python3-lirc

PIP install fails - README.md does not exist

I'm not able to pip install python-lirc. It's looking for a README.md file that doesn't appear to exist.

Downloading/unpacking python-lirc
Downloading python-lirc-1.2.0.tar.gz
Running setup.py (path:/home/user/.virtualenvs/p4_venv/build/python-lirc/setup.py) egg_info for package python-lirc
Traceback (most recent call last):
File "", line 17, in
File "/home/user/.virtualenvs/p4_venv/build/python-lirc/setup.py", line 22, in
long_description=open('README.md').read() + open('CHANGELOG').read(),
IOError: [Errno 2] No such file or directory: 'README.md'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 17, in

File "/home/user/.virtualenvs/p4_venv/build/python-lirc/setup.py", line 22, in

long_description=open('README.md').read() + open('CHANGELOG').read(),

IOError: [Errno 2] No such file or directory: 'README.md'


Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/user/.virtualenvs/p4_venv/build/python-lirc
Storing debug log for failure in /home/user/.pip/pip.log

Any ideas?

deinit()

Hi Tom
I was using original python lirc module but switched to yours as I needed non-blocking behaviour :)
I was using deinit() as last line in my code which now gives an error (which it didn't with original lirc module)
Do I still need it or is it a bug?

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.