first pass

darcs-hash:20060624233343-28bda-44e213062ac8cd192c68ce882c59d15ea938ada4.gz
This commit is contained in:
hans 2006-06-24 17:33:43 -06:00
commit 5ab38cf0ec
3 changed files with 52 additions and 0 deletions

4
Rakefile Normal file
View file

@ -0,0 +1,4 @@
require 'rake/testtask'
Rake::TestTask.new do |t|
end

23
lib/lirc.rb Normal file
View file

@ -0,0 +1,23 @@
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
end
end

25
test/test_lirc.rb Normal file
View file

@ -0,0 +1,25 @@
require 'test/unit'
require 'lirc'
class TC_LIRC < Test::Unit::TestCase
include LIRC
def setup
end
def teardown
end
def test_event
e = Event.new("00000000000a8b59 00 power Sony-838")
assert_equal 0xa8b59, e.code
assert_equal 0, e.repeat
assert ! e.repeat?
assert_equal "power", e.name
assert_equal "Sony-838", e.remote
e = Event.new("00000000000a8b59 01 power Sony-838")
assert_equal 0xa8b59, e.code
assert_equal 1, e.repeat
assert e.repeat?
assert_equal "power", e.name
assert_equal "Sony-838", e.remote
end
end