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

#normalise(key) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ruby_hid/store.rb', line 13

def normalise(key)
  value = @table[key]
  if value
    if Store.is_button?(key)
      value
    else # it's an axis
      range = Store.value_range(key)
      if range.respond_to?(:size)
        size = range.size
      else
        size = (range.max - range.min).abs + 1
      end
      (value - range.min).to_f / size
    end
  else
    0
  end
end

#normalised_hashObject


32
33
34
35
36
37
# File 'lib/ruby_hid/store.rb', line 32

def normalised_hash
  @table.keys.inject({}) do |result, key|
    result[key] = normalise(key)
    result
  end
end