Skip to content
project-owner edited this page Sep 1, 2019 · 8 revisions

Pylirc is LIRC Python wrapper and it's required to access LIRC from Python programs. To install Pylirc you should complete the following steps.

Install Pylirc dependencies:

sudo apt-get install python3-dev
sudo apt-get install liblircclient-dev

Install Pylirc:

wget https://files.pythonhosted.org/packages/a9/e1/a19ed9cac5353ec07294be7b1aefc8f89985987b356e916e2c39b5b03d9a/pylirc2-0.1.tar.gz
tar xvf pylirc2-0.1.tar.gz
cd pylirc2-0.1

There is currently incompatibility between Python 3 and Pylirc. The problem was explained here. To fix the problem you should either follow the steps described here or just download the file pylircmodule.c which I prepared using those instructions. The file should be placed in folder /home/pi/pylirc2-0.1. Then Pylirc should be recompiled and installed.

Replace file pylircmodule.c:

rm pylircmodule.c
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/pylircmodule.c

Install Pylirc (assuming that Python 3.7 is in use):

sudo python3 setup.py install
sudo mv /usr/local/lib/python3.7/dist-packages/pylircmodule.cpython-37m-arm-linux-gnueabihf.so /usr/local/lib/python3.7/dist-packages/pylirc.cpython-37m-arm-linux-gnueabihf.so

After completing all these steps you can test Pylirc by running my testing program test-pylirc.py and pressing buttons on your IR remote control. The output in the console means that Pylirc works fine:

pi@raspberrypi ~ $ python test-lirc.py
['ok']
['up']
['down']

How It Works

Separate file /etc/lirc/lircrc should be created to support IR remote control in Python applications. Each button used to control application should be defined in that file. Here is the example of button definition:

begin
button=KEY_POWER
prog=radio
config=power
end

Here begin and end define the boundaries for each button definition.

KEY_POWER defines the button code. It should be the same as defined in file lircd.conf:

KEY_POWER 0x48B7

The application name radio should be specified as a parameter during pylirc initialization in file /home/pi/Peppy/event/dispatcher.py:

self.lirc.init("radio")

And finally power is the key code received by application in lirc event.

To simplify event handling Peppy player maps all remote control events to the keyboard keys using dictionary lirc_keyboard_map in file /home/pi/Peppy/event/dispatcher.py. Here is the example of mapping remote control code power to the keyboard key end:

"power" : pygame.K_END

When Peppy player receives remote control event it generates two keyboard events: key down and key up:

d[KEY_ACTION] = pygame.KEYDOWN
event = pygame.event.Event(USER_EVENT_TYPE, **d)
pygame.event.post(event)
d[KEY_ACTION] = pygame.KEYUP
event = pygame.event.Event(USER_EVENT_TYPE, **d)
pygame.event.post(event)

<<Previous | Next>>

Clone this wiki locally