Class: Artoo::Drivers::Wiichuck

Inherits:
Wiidriver show all
Defined in:
lib/artoo/drivers/wiichuck.rb

Overview

Wiichuck driver behaviors for Firmata

Instance Attribute Summary

Attributes inherited from Wiidriver

#data, #joystick

Attributes inherited from Driver

#parent

Instance Method Summary collapse

Methods inherited from Wiidriver

#address, #initialize, #start_driver

Methods inherited from Driver

#connection, #event_topic_name, #initialize, #interval, #method_missing, #pin, #start_driver

Methods included from Celluloid

#timers

Constructor Details

This class inherits a constructor from Artoo::Drivers::Wiidriver

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Artoo::Drivers::Driver

Instance Method Details

#adjust_originsObject



22
23
24
25
# File 'lib/artoo/drivers/wiichuck.rb', line 22

def adjust_origins
  set_joystick_default_value(:sy_origin, data[:sy])
  set_joystick_default_value(:sx_origin, data[:sx])
end

#update(value) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/artoo/drivers/wiichuck.rb', line 7

def update(value)
  begin
    super

    adjust_origins
    update_buttons
    update_joystick

  rescue Exception => e
    Logger.error "wiichuck update exception!"
    Logger.error e.message
    Logger.error e.backtrace.inspect
  end
end

#update_buttonsObject



27
28
29
30
# File 'lib/artoo/drivers/wiichuck.rb', line 27

def update_buttons
  publish(event_topic_name("c_button")) if data[:c] == true
  publish(event_topic_name("z_button")) if data[:z] == true
end

#update_joystickObject



32
33
34
# File 'lib/artoo/drivers/wiichuck.rb', line 32

def update_joystick
  publish(event_topic_name("joystick"), {:x => calculate_joystick_value(:sx, :sx_origin), :y => calculate_joystick_value(:sy, :sy_origin)})
end