2006-06-24 17:33:43 -06:00
|
|
|
require 'socket'
|
|
|
|
|
|
|
|
module LIRC
|
|
|
|
class Client
|
|
|
|
def initialize(dev="/dev/lircd")
|
|
|
|
@sock = UNIXSocket.open(dev)
|
|
|
|
end
|
|
|
|
def next
|
|
|
|
Event.new(@sock.readline)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class Event
|
|
|
|
attr_reader :code, :repeat, :name, :remote
|
|
|
|
def initialize(str)
|
|
|
|
code, repeat, @name, @remote = str.split(' ', 4)
|
|
|
|
@code = code.hex
|
2006-06-24 17:43:10 -06:00
|
|
|
@repeat = repeat.hex
|
2006-06-24 17:33:43 -06:00
|
|
|
end
|
|
|
|
def repeat?
|
|
|
|
@repeat > 0
|
|
|
|
end
|
2006-06-24 17:37:36 -06:00
|
|
|
def to_s
|
2006-06-24 17:43:10 -06:00
|
|
|
sprintf("%016x %02x %s %s", @code, @repeat, @name, @remote)
|
2006-06-24 17:37:36 -06:00
|
|
|
end
|
2006-06-24 17:33:43 -06:00
|
|
|
end
|
|
|
|
end
|