Class: Artoo::Adaptors::Joystick
- Inherits:
-
Adaptor
- Object
- Adaptor
- Artoo::Adaptors::Joystick
- Defined in:
- lib/artoo/adaptors/joystick.rb
Overview
Connect to a joystick device
Instance Attribute Summary collapse
-
#joystick ⇒ Object
readonly
Returns the value of attribute joystick.
Instance Method Summary collapse
- #axis(n) ⇒ Object
- #ball(n) ⇒ Object
- #button(n) ⇒ Object
-
#connect ⇒ Boolean
Creates a connection with device.
-
#disconnect ⇒ Boolean
Closes connection with device.
-
#firmware_name ⇒ String
Name of device.
- #hat(n) ⇒ Object
- #num_axes ⇒ Object
- #num_balls ⇒ Object
- #num_buttons ⇒ Object
- #num_hats ⇒ Object
- #num_joysticks ⇒ Object
- #poll ⇒ Object
-
#version ⇒ String
Version of device.
Instance Attribute Details
#joystick ⇒ Object (readonly)
Returns the value of attribute joystick.
8 9 10 |
# File 'lib/artoo/adaptors/joystick.rb', line 8 def joystick @joystick end |
Instance Method Details
#axis(n) ⇒ Object
55 56 57 |
# File 'lib/artoo/adaptors/joystick.rb', line 55 def axis(n) ::SDL.JoystickGetAxis(joystick, n) end |
#ball(n) ⇒ Object
63 64 65 |
# File 'lib/artoo/adaptors/joystick.rb', line 63 def ball(n) ::SDL.JoystickGetBall(joystick, n) end |
#button(n) ⇒ Object
79 80 81 |
# File 'lib/artoo/adaptors/joystick.rb', line 79 def (n) ::SDL.JoystickGetButton(joystick, n) end |
#connect ⇒ Boolean
Creates a connection with device
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/artoo/adaptors/joystick.rb', line 12 def connect require 'ruby-sdl-ffi' unless defined?(::SDL) ::SDL.Init( ::SDL::INIT_JOYSTICK ) raise "No SDL joystick available" if num_joysticks == 0 @joystick = ::SDL.JoystickOpen(0) # TODO: allow user to choose which joystick super end |
#disconnect ⇒ Boolean
Closes connection with device
26 27 28 29 |
# File 'lib/artoo/adaptors/joystick.rb', line 26 def disconnect ::SDL.JoystickClose(joystick) super end |
#firmware_name ⇒ String
Name of device
33 34 35 |
# File 'lib/artoo/adaptors/joystick.rb', line 33 def firmware_name ::SDL.JoystickName(0) end |
#hat(n) ⇒ Object
71 72 73 |
# File 'lib/artoo/adaptors/joystick.rb', line 71 def hat(n) ::SDL.JoystickGetHat(joystick, n) end |
#num_axes ⇒ Object
51 52 53 |
# File 'lib/artoo/adaptors/joystick.rb', line 51 def num_axes ::SDL.JoystickNumAxes(joystick) end |
#num_balls ⇒ Object
59 60 61 |
# File 'lib/artoo/adaptors/joystick.rb', line 59 def num_balls ::SDL.JoystickNumBalls(joystick) end |
#num_buttons ⇒ Object
75 76 77 |
# File 'lib/artoo/adaptors/joystick.rb', line 75 def ::SDL.JoystickNumButtons(joystick) end |
#num_hats ⇒ Object
67 68 69 |
# File 'lib/artoo/adaptors/joystick.rb', line 67 def num_hats ::SDL.JoystickNumHats(joystick) end |
#num_joysticks ⇒ Object
47 48 49 |
# File 'lib/artoo/adaptors/joystick.rb', line 47 def num_joysticks ::SDL.NumJoysticks end |
#poll ⇒ Object
43 44 45 |
# File 'lib/artoo/adaptors/joystick.rb', line 43 def poll ::SDL.JoystickUpdate end |