Sha256: 43dbc411ca18f17fe3c4f9a6703c4b4a2f063b96804e83a590087572cd5ce811

Contents?: true

Size: 911 Bytes

Versions: 2

Compression:

Stored size: 911 Bytes

Contents

require 'artoo/drivers/joystick'

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 handle_joystick
        x0 = connection.axis(0)
        y0 = connection.axis(1)
        publish_joystick(0, x0, y0)

        x1 = connection.axis(2)
        y1 = connection.axis(3)
        publish_joystick(1, x1, y1)        
      end

      def publish_button(b)
        publish(event_topic_name("button_#{button_letter(b)}"))
        super
      end

      def button_letter(b)
        BUTTON_MAP[b]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
artoo-joystick-0.3.0 lib/artoo/drivers/ps3.rb
artoo-joystick-0.2.0 lib/artoo/drivers/ps3.rb