Class: Rlirc

Inherits:
Object
  • Object
show all
Defined in:
lib/rlirc.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Rlirc

Returns a new instance of Rlirc.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rlirc.rb', line 23

def initialize(args)
    

    # main thread
    @sock_thread = Thread.new do
        
        # open connection to lirc device
        lsock = Socket.new(Socket::PF_UNIX, Socket::SOCK_STREAM, 0)
        lsock.connect(Socket::sockaddr_un($device))
      
        # trap quit signals
        [ 'INT', 'KILL'].each do |sig|
            trap(sig) do quit end
        end

        # read and proces lirc events
        while true do 
            # read pressed buttons
            btn_code = lsock.gets
            puts "new event: #{btn_code}" if $debug
            Event.new(btn_code)
        end

        # close connection
        lsock.close
    end

    
    @sock_thread.join
end

Instance Method Details

#quitObject



54
55
56
57
# File 'lib/rlirc.rb', line 54

def quit
    puts 'stopping rlirc...'
    @sock_thread.exit
end