Class: Gyruby::Remote

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

Direct Known Subclasses

MplayerController

Instance Method Summary collapse

Constructor Details

#initializeRemote

Returns a new instance of Remote.



22
23
24
25
26
27
# File 'lib/gyruby/remote.rb', line 22

def initialize
  @subscribed_buttons = {}
  @pressed_buttons = {}
  @mouse_buttons = {}
  @listening = false
end

Instance Method Details

#listenObject



52
53
54
55
56
57
58
59
# File 'lib/gyruby/remote.rb', line 52

def listen
  claim_device unless claimed_device?
  loop do
    handle_usb_event if claimed_device?
    handle_mouse_event if grabbed_mouse?
    sleep(0.001)
  end
end

#record(&block) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/gyruby/remote.rb', line 43

def record(&block)
  claim_device unless claimed_device?
  loop do
    event = fetch_usb_event
    yield event unless event.nil?
    sleep(0.001)
  end
end

#subscribe(button, release = false, frequency = 10, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gyruby/remote.rb', line 29

def subscribe(button, release = false, frequency = 10, &block)
  if release
    @mouse_buttons[button] = {
      :action => :press, 
      :block => block, 
      :frequency => frequency,
      :last => nil
    }
    @mouse_buttons[release] = {:action => :release, :press => button}
  else
    @subscribed_buttons[button] = block
  end
end