Class: Artoo::Drivers::Xbox360

Inherits:
Joystick
  • Object
show all
Defined in:
lib/artoo/drivers/xbox360.rb

Overview

The Xbox360 controller driver behaviors

Constant Summary

Constants inherited from Joystick

Joystick::COMMANDS

Instance Attribute Summary

Attributes inherited from Joystick

#button_values

Instance Method Summary collapse

Methods inherited from Joystick

#handle_buttons, #handle_message_events, #handle_trackball, #publish_joystick, #start_driver

Instance Method Details

#axis_mapObject



55
56
57
# File 'lib/artoo/drivers/xbox360.rb', line 55

def axis_map
  BINDING_MAP[:xbox360][:axis_map]
end

#button_mapObject



51
52
53
# File 'lib/artoo/drivers/xbox360.rb', line 51

def button_map
  BINDING_MAP[:xbox360][:button_map]
end

#currently_pressed?(b) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
# File 'lib/artoo/drivers/xbox360.rb', line 8

def currently_pressed?(b)
  if button_map.has_value?(b)
    button_values[button_map.key(b)]
  else
    super b
  end
end

#handle_joystickObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/artoo/drivers/xbox360.rb', line 16

def handle_joystick
  x0 = connection.axis(axis_map[:j0_x])
  y0 = connection.axis(axis_map[:j0_y])
  publish_joystick(0, x0, y0)

  x1 = connection.axis(axis_map[:j1_x])
  y1 = connection.axis(axis_map[:j1_y])
  publish_joystick(1, x1, y1)

  handle_trigger
end

#handle_triggerObject



28
29
30
31
32
33
34
35
36
# File 'lib/artoo/drivers/xbox360.rb', line 28

def handle_trigger
  unless axis_map[:lt].nil?
    publish_trigger(:lt, connection.axis(axis_map[:lt]))
  end

  unless axis_map[:rt].nil?
    publish_trigger(:rt, connection.axis(axis_map[:rt]))
  end
end

#publish_button(b) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/artoo/drivers/xbox360.rb', line 42

def publish_button(b)
  if button_values[b] == 1
    publish(event_topic_name("button_#{button_map[b]}"))
  else
    publish(event_topic_name("button_up_#{button_map[b]}"))
  end
  super
end

#publish_trigger(t, v) ⇒ Object



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

def publish_trigger(t, v)
  publish(event_topic_name("trigger_#{t}"), v)
end