One of the things that made the biggest impression on me when I borrowed rpi from Tomek was that I could control this tiny computer with my tv remote. Now it may sound a bit silly :), but that was over a year ago. Now, with our Lightberry and possibility to have ambilight effect even for external source, I was wondering how to turn off or on the leds. The only thing I had was rasbian with hyperion and drivers for the grabber installed. TV remote does not work out of the box with such setup :). We all know that XBMC can be controlled with TV remote via CEC, so I thought there had to be a way to make use of my remote to turn hyperion-v4l2 on and off. Of course, there is :) This is how you do that….
In theory everything is written on cec website, but it took me a while to understand what packages I need to install via app-get or what parameters I need to pass to compile it correctly. After gathering information from many forums it gets very easy at the end…
In order to install cec for pulse-eight adapter on Rpi you need to compile it on rpi with certain parameters and, before that, you need to have few other packages and development headers installed.
Here is step-by-step instruction that works perfectly on Raspbian:
1 2 3 4 5 6 7 8 9 |
sudo apt-get update sudo apt-get -y install udev libudev-dev autoconf automake libtool gcc liblockdev1 pkg-config liblockdev1-dev git clone https://github.com/Pulse-Eight/libcec cd libcec/ ./bootstrap ./configure --with-rpi-include-path=/opt/vc/include --with-rpi-lib-path=/opt/vc/lib --enable-rpi make sudo make install sudo ldconfig |
Ok so we have it installed – lets run it and let’s press some buttons on the tv remote.
Here is how you start it:
1 2 |
pi@raspberrypi ~ $ cec-client (...) |
Now, let’s press “play” button on the remote… This is what happens at cec-client:
1 2 3 4 5 6 |
TRAFFIC: [ 19477] >> 01:44:44 DEBUG: [ 19480] >> TV (0) -> Recorder 1 (1): user control pressed (44) DEBUG: [ 19482] key pressed: play (44) TRAFFIC: [ 19549] >> 01:8b:44 DEBUG: [ 19550] >> TV (0) -> Recorder 1 (1): vendor remote button up (8B) DEBUG: [ 19551] key released: play (44) |
Now, Let’s press “2” on remote…
1 2 3 4 5 6 |
TRAFFIC: [ 22977] >> 01:44:22 DEBUG: [ 22979] >> TV (0) -> Recorder 1 (1): user control pressed (44) DEBUG: [ 22981] key pressed: 2 (22) TRAFFIC: [ 23056] >> 01:8b:22 DEBUG: [ 23056] >> TV (0) -> Recorder 1 (1): vendor remote button up (8B) DEBUG: [ 23056] key released: 2 (22) |
Ok, cool. So we can see what buttons we use, but how to execute a script depending on what button was pressed?
Here is how I did it although my gut feeling is that there has to be more elegant way of achieving the same result :) any suggestions are very welcomed.
First you run cec-client with -sf (file)
switch… It will make cec-client to log user actions into the (file). Then I wrote simple script that scans through the log file ( ${1}
) and searches for user interaction:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
echo "" > ${1} while true do if grep -q "key pressed: left" ${1} then echo "You pressed LEFT" fi if grep -q "key pressed: right" ${1} then echo "You pressed RIGHT" exit 0 fi echo "" > ${1} sleep 1s done |
Now instead of “echo” command just put some scripts there and you can do everything with your TV remote :)
ENJOY!
