#each added, Rakefile modified for gems, README -> README.md

This commit is contained in:
Denis Knauf 2010-04-04 02:07:59 +02:00
parent 911e513d44
commit 42ac14e09d
4 changed files with 103 additions and 1583 deletions

View file

@ -1,26 +1,38 @@
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
class Client
def initializer dev = nil
dev ||= "/dev/lircd"
@sock = UNIXSocket.open dev
end
def next
Event.new @sock.readline
end
def each_event
return Enumerator.new( self, :each_event) unless block_given?
loop { yield self.next }
end
alias each each_event
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
"%016x %02x %s %s" % [@code, @repeat, @name, @remote]
end
end
end