lib/artoo/drivers/ps3.rb in artoo-joystick-0.3.0 vs lib/artoo/drivers/ps3.rb in artoo-joystick-0.4.0
- old
+ new
@@ -2,42 +2,44 @@
module Artoo
module Drivers
# The Ps3 controller driver behaviors
class Ps3 < Artoo::Drivers::Joystick
- BUTTON_MAP = {
- 0 => 'square',
- 1 => 'x',
- 2 => 'circle',
- 3 => 'triangle',
- 4 => 'l1',
- 5 => 'r1',
- 6 => 'l2',
- 7 => 'r2',
- 8 => 'select',
- 9 => 'start',
- 10 => 'left_joystick',
- 11 => 'right_joystick',
- 12 => 'home'
- }
+ def currently_pressed?(b)
+ if button_map.has_value?(b)
+ button_values[button_map.key(b)]
+ else
+ super b
+ end
+ end
+
def handle_joystick
- x0 = connection.axis(0)
- y0 = connection.axis(1)
+ x0 = connection.axis(axis_map[:j0_x])
+ y0 = connection.axis(axis_map[:j0_y])
publish_joystick(0, x0, y0)
- x1 = connection.axis(2)
- y1 = connection.axis(3)
+ x1 = connection.axis(axis_map[:j1_x])
+ y1 = connection.axis(axis_map[:j1_y])
publish_joystick(1, x1, y1)
end
def publish_button(b)
- publish(event_topic_name("button_#{button_letter(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
- def button_letter(b)
- BUTTON_MAP[b]
+ def button_map
+ BINDING_MAP[:ps3][:button_map]
end
+
+ def axis_map
+ BINDING_MAP[:ps3][:axis_map]
+ end
+
end
end
end