class BBB::Components::Nunchuck
Attributes
accelerometer[R]
controls[R]
Public Class Methods
new(options={})
click to toggle source
# File lib/BBB/components/nunchuck.rb, line 9 def initialize(options={}) @started = false @positions = options[:i2c] || [] @accelerometer = Accelerometer.new @controls = Controls.new @decoder = Decoder.new end
Public Instance Methods
accel()
click to toggle source
# File lib/BBB/components/nunchuck.rb, line 44 def accel; accelerometer; end
c()
click to toggle source
# File lib/BBB/components/nunchuck.rb, line 41 def c; controls.c; end
raw_read()
click to toggle source
# File lib/BBB/components/nunchuck.rb, line 36 def raw_read decoder.decode i2c.read(0x52, 6, 0x00) end
start()
click to toggle source
# File lib/BBB/components/nunchuck.rb, line 17 def start begin raw_read rescue I2C::AckError i2c.write(0x52, 0x40, 0x00) end @started = true end
started?()
click to toggle source
# File lib/BBB/components/nunchuck.rb, line 26 def started? @started end
update()
click to toggle source
# File lib/BBB/components/nunchuck.rb, line 30 def update bytes = raw_read.bytes.to_a @accelerometer.update(bytes) @controls.update(bytes) end
x()
click to toggle source
# File lib/BBB/components/nunchuck.rb, line 42 def x; controls.x; end
y()
click to toggle source
# File lib/BBB/components/nunchuck.rb, line 43 def y; controls.z; end
z()
click to toggle source
# File lib/BBB/components/nunchuck.rb, line 40 def z; controls.z; end