Class: Artoo::Drivers::Joystick
- Inherits:
-
Driver
- Object
- Driver
- Artoo::Drivers::Joystick
- Includes:
- Utility
- Defined in:
- lib/artoo/drivers/joystick.rb
Overview
The sdl-joystick driver behaviors
Constant Summary collapse
- COMMANDS =
[:currently_pressed?].freeze
Instance Attribute Summary collapse
-
#button_values ⇒ Object
readonly
Returns the value of attribute button_values.
Instance Method Summary collapse
- #currently_pressed?(b) ⇒ Boolean
- #handle_buttons ⇒ Object
- #handle_joystick ⇒ Object
- #handle_message_events ⇒ Object
- #handle_trackball ⇒ Object
- #publish_button(b) ⇒ Object
- #publish_joystick(s, x, y) ⇒ Object
-
#start_driver ⇒ Object
Start driver and any required connections.
Instance Attribute Details
#button_values ⇒ Object (readonly)
Returns the value of attribute button_values.
11 12 13 |
# File 'lib/artoo/drivers/joystick.rb', line 11 def @button_values end |
Instance Method Details
#currently_pressed?(b) ⇒ Boolean
40 41 42 |
# File 'lib/artoo/drivers/joystick.rb', line 40 def currently_pressed?(b) [b] end |
#handle_buttons ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/artoo/drivers/joystick.rb', line 71 def connection..times {|b| currently_pressed = connection.(b) if [b] != currently_pressed [b] = currently_pressed (b) end } end |
#handle_joystick ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/artoo/drivers/joystick.rb', line 52 def handle_joystick number_sticks = connection.num_axes / 2 number_sticks.times {|s| x = connection.axis(s * 2) y = connection.axis(s * 2 + 1) publish_joystick(s, x, y) } end |
#handle_message_events ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/artoo/drivers/joystick.rb', line 44 def connection.poll handle_joystick # TODO: handle_trackball # TODO: handle_hats end |
#handle_trackball ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/artoo/drivers/joystick.rb', line 62 def handle_trackball if connection.num_balls == 1 x, y = connection.ball(0) publish(event_topic_name("update"), "trackball", {:x => x, :y => y}) publish(event_topic_name("trackball"), {:x => x, :y => y}) end end |
#publish_button(b) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/artoo/drivers/joystick.rb', line 87 def (b) if [b] == 1 publish(event_topic_name("update"), "button", b) publish(event_topic_name("button"), b) publish(event_topic_name("button_#{b}")) end end |
#publish_joystick(s, x, y) ⇒ Object
81 82 83 84 85 |
# File 'lib/artoo/drivers/joystick.rb', line 81 def publish_joystick(s, x, y) publish(event_topic_name("update"), "joystick", {:x => x, :y => y, :s => s}) publish(event_topic_name("joystick"), {:x => x, :y => y, :s => s}) publish(event_topic_name("joystick_#{s}"), {:x => x, :y => y}) end |
#start_driver ⇒ Object
Start driver and any required connections
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/artoo/drivers/joystick.rb', line 14 def start_driver puts os case os when :linux require 'artoo/drivers/linux_binding_map' when :macosx require 'artoo/drivers/macosx_binding_map' else # raise error ? end @button_values = {} begin every(interval) do end super rescue Exception => e Logger.error "Error starting SdlJoystick driver!" Logger.error e. Logger.error e.backtrace.inspect end end |