class RubyHid::Store
Attributes
device[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/ruby_hid/store.rb, line 7 def initialize super init_observers init_device end
Private Class Methods
value_range(key)
click to toggle source
# File lib/ruby_hid/store.rb, line 41 def self.value_range(key) if Axis::DPAD_KEYS.include?(key) -1...1 else 0...255 end end
Public Instance Methods
normalise(key)
click to toggle source
# 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_hash()
click to toggle source
# File lib/ruby_hid/store.rb, line 32 def normalised_hash @table.keys.inject({}) do |result, key| result[key] = normalise(key) result end end
Private Instance Methods
init_device()
click to toggle source
# File lib/ruby_hid/store.rb, line 53 def init_device if device.nil? self.device = Device.new( RubyHid::Device.list[0] ) end device.start_watching end
init_observers()
click to toggle source
# File lib/ruby_hid/store.rb, line 62 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