Class: Artoo::Drivers::Wiichuck

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

Overview

Wiichuck driver behaviors for Firmata

Constant Summary

Constants inherited from Driver

Driver::COMMANDS

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

#command, #commands, #connection, #event_topic_name, #initialize, #interval, #known_command?, #method_missing, #pin, #start_driver

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

Adjust x, y origin values



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

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

#update(value) ⇒ Object

Update button and joystick values

Parameters:

  • value (Object)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/artoo/drivers/wiichuck.rb', line 10

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

Publishes events for c and z buttons



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

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

Publishes event for joystick



38
39
40
# File 'lib/artoo/drivers/wiichuck.rb', line 38

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