Class: RubyHid::Store

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/ruby_hid/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



7
8
9
10
11
# File 'lib/ruby_hid/store.rb', line 7

def initialize
  super
  init_observers
  init_device
end

Instance Attribute Details

#deviceObject

Returns the value of attribute device.



5
6
7
# File 'lib/ruby_hid/store.rb', line 5

def device
  @device
end

Instance Method Details

#init_deviceObject



13
14
15
16
17
18
19
20
# File 'lib/ruby_hid/store.rb', line 13

def init_device
  if device.nil?
    self.device = Device.new(
      RubyHid::Device.list[0]
    )
  end
  device.start_watching
end

#init_observersObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_hid/store.rb', line 22

def init_observers
  events = Axis::EVENTS.values + Button::EVENTS.values
  store = self
  events.each do |name|
    send("#{name}=", 0)
    control = Axis.find_by_name(name)
    control ||= Button.find_by_name(name)
    control.add_event(
      lambda {|val| store.send("#{name}=", val)}
    )
  end
end