Using the LIRC client for Ruby

I stumbled across this code this evening which allows me to use Ruby to listen for IR commands using LIRC:

require 'lirc'

lirc = LIRC::Client.new
event = lirc.next
p event
if event.name == "play"
    system "xmms", "/av/music/3.mod"
end

To receiv e the events in a loop:

lirc.each_event {|e| p e }

Here's what events look like:

#<LIRC::Event:0x0b6688 @name="KEY_DOWN", @remote="/home/james/lircd.conf\n", @code=2, @repeat=1<
#<LIRC::Event:0x0b63d0 @name="KEY_DOWN", @remote="/home/james/lircd.conf\n", @code=2, @repeat=0&glt;
#<LIRC::Event:0x0b6178 @name="KEY_DOWN", @remote="/home/james/lircd.conf\n", @code=2, @repeat=1&glt;
#<LIRC::Event:0x0b5f50 @name="KEY_DOWN", @remote="/home/james/lircd.conf\n", @code=2, @repeat=2&glt;
#<LIRC::Event:0x0b5c38 @name="KEY_CHANNELUP", @remote="/home/james/lircd.conf\n", @code=1, @repeat=0&glt;
#<LIRC::Event:0x0b5998 @name="KEY_CHANNELUP", @remote="/home/james/lircd.conf\n", @code=1, @repeat=1&glt;
#<LIRC::Event:0x0b5740 @name="KEY_CHANNELUP", @remote="/home/james/lircd.conf\n", @code=1, @repeat=2&glt;

To reference an event by it's property you can use name, remote, code, repeat, or repeat?.

Resources

Tags:
Source:
0028hrs.txt
Published:
19-05-2013 00:28