class BBB::Components::Nunchuck::Controls

Public Class Methods

new() click to toggle source
# File lib/BBB/components/nunchuck.rb, line 90
def initialize
  initialize_buttons
  initialize_axis
end

Public Instance Methods

c() click to toggle source
# File lib/BBB/components/nunchuck.rb, line 101
def c
  @buttons[:c]
end
initialize_axis() click to toggle source
# File lib/BBB/components/nunchuck.rb, line 109
def initialize_axis
  @axis = Hash.new
  @axis[:x] = ControlAxis.new
  @axis[:y] = ControlAxis.new
end
initialize_buttons() click to toggle source
# File lib/BBB/components/nunchuck.rb, line 95
def initialize_buttons
  @buttons = Hash.new
  @buttons[:z] = Button.new
  @buttons[:c] = Button.new
end
update(bytes) click to toggle source
# File lib/BBB/components/nunchuck.rb, line 115
def update(bytes)
  update_buttons(bytes)
  update_axis(bytes)
end
update_axis(bytes) click to toggle source
# File lib/BBB/components/nunchuck.rb, line 128
def update_axis(bytes)
  @axis[:x].update(bytes[0])
  @axis[:y].update(bytes[1])
end
update_buttons(bytes) click to toggle source
# File lib/BBB/components/nunchuck.rb, line 120
def update_buttons(bytes)
  x = bytes[5] & 0b00000010 >> 1
  y = bytes[5] & 0b00000001

  @buttons[:x].update(x)
  @buttons[:y].update(y)
end
z() click to toggle source
# File lib/BBB/components/nunchuck.rb, line 105
def z
  @buttons[:z]
end