Configuring a USB remote control for FakeTV functions

These instructions are a segment of a multi-part series of instructions on the installation and setup of FakeTV, a simulated television broadcast experience.

My remote control works with my TV, sound bar and FakeTV

Setting up the remote to take over for your TV remote

The remote has two modes, 2.4GHz wireless mode — indicated by a green LED — and an infrared, or IR, mode — indicated by a red LED. IR mode acts as expected from a universal television remote. To program the buttons, hold the TV button while in IR mode until the red LED flashes rapidly. Press the button you wish to program and the red LED will start flashing slowly. Aim your TV or other remote at the IR emitter on the top of the remote and press the corresponding button, the red LED will flash rapidly again. Press the TV button again to exit learning mode.

Setting up the remote to execute FakeTV commands

In wireless mode, the remote operates as a USB keyboard (and in fact has a keyboard on the reverse side of the remote). Since the remote is plug and play, there was no setup required to get it working. Some of the commands used for this setup require a connected, running display. Since I have the piTFT display in use as a status screen, I was able to use these commands without issue. I have not had an opportunity to explore another solution to this that doesn’t require an attached screen, but I’m open to suggestions, should you have any.

Mapping the remote control keys

KeyPress event, serial 45, synthetic NO, window 0x2000001,
root 0x1aa, subw 0x0, time 2693485786, (36,-32), root:(38,34),
state 0x0, keycode 173 (keysym 0x1008ff16, XF86AudioPrev), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyRelease event, serial 48, synthetic NO, window 0x2000001,
root 0x1aa, subw 0x0, time 2693485882, (36,-32), root:(38,34),
state 0x0, keycode 173 (keysym 0x1008ff16, XF86AudioPrev), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False

Setting up scripts

Hit ctrl+c to exit xev. Next, you’ll need to configure openbox to trigger the various scripts in the channels/ folder. In my case, I wanted audio feedback to help indicate that a button press has been received and the script executed. So, for each button, I created a script that plays a keypress sound and executes the desired script. Here is a sample script, meant to start channel 1 using a file called audiofile.wav for audio feedback:

#!/bin/bashaplay /home/pi/audiofile.wav
cd /home/pi/channels/ && sudo ./manual.sh 1
aplay /home/pi/audiofile.wav
#!/bin/bashkillall kiosk.sh && service lightdm restart
#!/bin/bashaplay /home/pi/audiofile.wav
sshpass -p 'password' ssh root@rasplex.ip.address xbmc-send --host=127.0.0.1 -a "TakeScreenshot"
aplay /home/pi/audiofile.wav

Setting up openbox to execute scripts on keypress

Now that all of the necessary scripts have been set up, it’s time to map them to the desired keys. For my setup, I use openbox, because I already have an X server running on the attached status display screen. I haven’t looked into options for completely headless systems at this point, so I’m not sure what other options there are for assigning keypresses to execute scripts.

<keybind key="keypress">
<action name="Execute">
<execute>sudo sh /location/of/script.sh</execute>
</action>
</keybind>

A blog to discuss my simulated broadcast television experience using three Raspberry Pis, two hard drives and software/scripting to tie it all together.