2006-06-25 01:33:43 +02: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
|
|
|
|
@repeat = repeat.to_i
|
|
|
|
end
|
|
|
|
def repeat?
|
|
|
|
@repeat > 0
|
|
|
|
end
|
2006-06-25 01:37:36 +02:00
|
|
|
def to_s
|
|
|
|
sprintf("%016x %02d %s %s", @code, @repeat, @name, @remote)
|
|
|
|
end
|
2006-06-25 01:33:43 +02:00
|
|
|
end
|
|
|
|
end
|