==============================
Using the USB IR Toy with LIRC
==============================
:CreationDate: 2012-10-08 10:49:07
:Id: SW/usb-ir-toy-lirc
:tags: - software
- configs
So I got myself a `programmable remote control in the shape of
Eleven's sonic screwdriver
<https://www.thewandcompany.com/eleventh-doctors-sonic/>`_ (sorry,
horrible in-accessible website). Of course I want to control my PC
with it!
To do that, I needed a IR receiver and `LIRC
<https://www.lirc.org/>`_. Since I sometimes like being overly generic,
I bought `Dangerous Prototypes <http://dangerousprototypes.com/>`_
`USB Infrared Toy
<http://dangerousprototypes.com/docs/USB_Infrared_Toy>`_, which allows
me to send & receive any kind of IR pulse stream.
Getting the three pieces (remote, toy, LIRC) to play together was more
effort than I'd really liked, so here's what I did, to help everybody
else.
Flash a newer firmware
======================
Your IR Toy is probably running an old version of the firmware. If
you're running Windows, the `instructions provided
<http://dangerousprototypes.com/docs/USB_IR_Toy_firmware_update>`_ may
work; otherwise, you have to dig deeper. The source code for the
``fw_update`` program that you can get from those pages (or from `the
Subversion repository
<http://dangerous-prototypes-open-hardware.googlecode.com/svn/trunk/Bootloaders/USB-HID-Diolan/18F24J50/fw_update/>`_)
does not even compile (it "forgets" to include half the header files
it needs), and when you get it to compile it segfaults. User
"JessH" of the Dangerous Prototypes forums `posted a working version
<http://dangerousprototypes.com/forum/viewtopic.php?t=3697&p=37398#p37371>`_
(`here's the patch <JessH.patch>`_ if you want to see it, it should
apply to the SVN version).
.. note::
Yes, I know I'm pointing at the updater source for the 18F24J50, but
the chip on the actual IR Toy says "18F2550". What can I say, it
works!
Having compiled it, I was able to update the firmware to version 22::
$ echo '$' > /dev/ttyACM0
$ ./fw_update -e -w -v -m all -vid 0x04D8 -pid 0xFD0B \
-ix ~/src/dangerous-prototypes-open-hardware/USB_IR_Toy/package/firmware/USBIRToy.v22.hex
Unplug, re-plug, and we're set.
Patching LIRC
=============
.. note::
``lircd`` 0.10 has native support for the USB IR Toy, using the
``irtoy`` driver
LIRC can use the IR Toy in ``irman`` compatibility mode, but I needed
full send capability, to program the sonic screwdriver. I found `a
patch to add full support
<https://sourceforge.net/mailarchive/forum.php?thread_name=4ebf97df-17f8-48bb-ba65-32e4b9983ac4%40devleno&forum_name=lirc-list>`_,
thanks to Peter Kooiman. If you're running Gentoo, you can add `my
overlay <https://www.thenautilus.net/cgit/gentoo-overlay/>`_ and
install `my patched LIRC
<https://www.thenautilus.net/cgit/gentoo-overlay/tree/app-misc/lirc/>`_.
Configuring LIRC
================
This may well be written down somewhere, but I had problems finding a
useful guide, so I'll just show what I did:
1) get a full Philips RC-5 code list from `the LIRC remotes repository
<https://lirc.sourceforge.net/remotes/rc-5/>`_
2) assign, arbitrarily, the first 39 codes to the 13 gestures on 3
memory banks of the screwdriver::
begin remote
name sonic
# snip
begin codes
b1_tap_top 0x1000
b1_tap_left 0x1001
#etc etc
Programming the remote
======================
I wrote `a simple Perl program to send the IR codes <send>`_. Run it
with ``lircd`` running and ``irsend`` in your path. When it say
``Ready to send $something``, press "enter" to send it, ``a`` to go
back to the previous code (useful if the screwdriver didn't get it),
``n`` to go the next code without sending anything.
I put the screwdriver in programming mode, performed all 39 gestures
one after the other, and programmed all of them. LIRC now uses
sensible names for the 39 gestures.
Using it
========
Finally, I re-compiled `vlc <https://www.videolan.org/>`_ with LIRC
support, and wrote `a |lircrc| for vlc <lircrc>`_. With that, I can
control ``vlc`` with my sonic screwdriver!
.. |lircrc| replace:: ``~/.lircrc``