052f32a3f7
darcs-hash:20060624234310-28bda-14a724547ba30575d24d7a982a8100cbb712baf3.gz
26 lines
521 B
Ruby
26 lines
521 B
Ruby
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
|
|
@repeat = repeat.hex
|
|
end
|
|
def repeat?
|
|
@repeat > 0
|
|
end
|
|
def to_s
|
|
sprintf("%016x %02x %s %s", @code, @repeat, @name, @remote)
|
|
end
|
|
end
|
|
end
|