artoo-joystick 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 286793d7267dda24af042bd17b55ff0aeb5ca777
4
- data.tar.gz: da69d24c572e50ebd37a0e39a33eff29428861e0
3
+ metadata.gz: 60dac15d48edeac91173b1895a2145cea948ff77
4
+ data.tar.gz: e6f673680673e7d455ee7daf932290545f273d7c
5
5
  SHA512:
6
- metadata.gz: d302f72134b42cc08cbb3f3adff65a93a5f3a1662124a37116503e631a834d8b1aacaf283af64ad7049c6b6275f2d17f078420519510a5fb62d1dda8e3973634
7
- data.tar.gz: 6fecde154a335843c8e3dacfb29027f8b57c6e61e9daa24459f95d8b7780c874654ee44bb4b0f4d2e32d661fb7ea0e738c258ab2e1ecd584b0b7a85a986582cd
6
+ metadata.gz: 132cef0bc36aa67b3dd437cd5612781118baeaab22e83126f2b2bce47964d71936fe6d1df32e42afcd186d6c78080a697937a198977b7dcd158d8b74150b2c6e
7
+ data.tar.gz: 6691aa023487791f8284b66479323e3eebe092c4a2e73cbda070a170b202e8e1aa27a32f6b142511d5c8301516d5fb51220490a9a99d445142810bd25343182f
@@ -0,0 +1 @@
1
+ .rvmrc
@@ -1,9 +1,13 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.1.0
3
4
  - 2.0.0
4
5
  - 1.9.3
5
- - jruby-1.7.4
6
- - rbx-19mode
6
+ - jruby-1.7.9
7
+ - rbx-2.1.1
7
8
  matrix:
8
9
  allow_failures:
9
- - rvm: jruby-1.7.4
10
+ - rvm: jruby-1.7.9
11
+ before_install:
12
+ - sudo apt-get update -qq
13
+ - sudo apt-get install -qq libsdl1.2-dev
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in artoo-sdl-joystick.gemspec
4
3
  gemspec
@@ -1,72 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- artoo-joystick (0.3.0)
5
- artoo (>= 1.4.0)
4
+ artoo-joystick (0.4.0)
5
+ artoo (>= 1.6.0)
6
6
  hybridgroup-ruby-sdl-ffi
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- artoo (1.4.1)
11
+ artoo (1.6.0)
12
12
  celluloid (~> 0.15.0)
13
13
  celluloid-io (~> 0.15.0)
14
14
  multi_json (~> 1.6)
15
15
  pry (~> 0.9)
16
16
  rake
17
17
  reel (~> 0.4.0)
18
+ robeaux (~> 0.0.3)
18
19
  thor (~> 0.18.1)
19
20
  celluloid (0.15.2)
20
21
  timers (~> 1.1.0)
21
22
  celluloid-io (0.15.0)
22
23
  celluloid (>= 0.15.0)
23
24
  nio4r (>= 0.5.0)
24
- coderay (1.0.9)
25
- ffi (1.9.0)
26
- ffi (1.9.0-java)
25
+ coderay (1.1.0)
26
+ ffi (1.9.3)
27
27
  http (0.5.0)
28
28
  http_parser.rb
29
- http_parser.rb (0.6.0.beta.2)
30
- http_parser.rb (0.6.0.beta.2-java)
31
- hybridgroup-ruby-sdl-ffi (0.4.1)
32
- nice-ffi (>= 0.2)
33
- metaclass (0.0.1)
29
+ http_parser.rb (0.6.0)
30
+ hybridgroup-ruby-sdl-ffi (0.4.2)
31
+ nice-ffi
32
+ metaclass (0.0.2)
34
33
  method_source (0.8.2)
35
- minitest (5.0.8)
34
+ minitest (5.2.2)
36
35
  minitest-happy (1.0.0)
37
- mocha (0.14.0)
36
+ mocha (1.0.0)
38
37
  metaclass (~> 0.0.1)
39
- multi_json (1.8.2)
38
+ multi_json (1.8.4)
40
39
  nice-ffi (0.4)
41
40
  ffi (>= 0.5.0)
42
- nio4r (0.5.0)
43
- nio4r (0.5.0-java)
44
- pry (0.9.12.2)
45
- coderay (~> 1.0.5)
41
+ nio4r (1.0.0)
42
+ pry (0.9.12.6)
43
+ coderay (~> 1.0)
46
44
  method_source (~> 0.8)
47
45
  slop (~> 3.4)
48
- pry (0.9.12.2-java)
49
- coderay (~> 1.0.5)
50
- method_source (~> 0.8)
51
- slop (~> 3.4)
52
- spoon (~> 0.0)
53
- rake (10.1.0)
46
+ rake (10.1.1)
54
47
  reel (0.4.0)
55
48
  celluloid (>= 0.15.1)
56
49
  celluloid-io (>= 0.15.0)
57
50
  http (>= 0.5.0)
58
51
  http_parser.rb (>= 0.6.0.beta.2)
59
52
  websocket_parser (>= 0.1.4)
60
- slop (3.4.6)
61
- spoon (0.0.4)
62
- ffi
53
+ robeaux (0.0.3)
54
+ slop (3.4.7)
63
55
  thor (0.18.1)
64
56
  timers (1.1.0)
65
- websocket_parser (0.1.4)
66
- http
57
+ websocket_parser (0.1.6)
67
58
 
68
59
  PLATFORMS
69
- java
70
60
  ruby
71
61
 
72
62
  DEPENDENCIES
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 The Hybrid Group
1
+ Copyright (c) 2013-2014 The Hybrid Group
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -1,21 +1,35 @@
1
1
  # Artoo Adaptor For Joysticks & Game Controllers
2
2
 
3
- This repository contains the Artoo (http://artoo.io/) adaptor for the PS3 game controller, XBox360 game controller, or any other joysticks and game controllers that are compatible with Simple DirectMedia Layer (SDL) (http://www.libsdl.org/).
3
+ This repository contains the Artoo (http://artoo.io/) adaptor for the PS3 controller, Xbox 360 controller, or any other joysticks and game controllers that are compatible with Simple DirectMedia Layer (SDL) (http://www.libsdl.org/).
4
4
 
5
5
  Artoo is a open source micro-framework for robotics using Ruby.
6
6
 
7
7
  For more information about Artoo, check out our repo at https://github.com/hybridgroup/artoo
8
8
 
9
- The artoo-joystick adaptor uses the rubysdl gem (http://www.kmc.gr.jp/~ohai/rubysdl.en.html).
9
+ The artoo-joystick adaptor uses the ruby-sdl-ffi gem (https://github.com/hybridgroup/ruby-sdl-ffi).
10
10
 
11
11
  [![Code Climate](https://codeclimate.com/github/hybridgroup/artoo-joystick.png)](https://codeclimate.com/github/hybridgroup/artoo-joystick) [![Build Status](https://travis-ci.org/hybridgroup/artoo-joystick.png?branch=master)](https://travis-ci.org/hybridgroup/artoo-joystick)
12
12
 
13
13
  ## Installing
14
14
 
15
+ ### OSX
16
+
17
+ ```
18
+ brew install sdl
19
+ gem install artoo-joystick
20
+ ```
21
+
22
+ Mac OS X does not provide native support for XBox 360 controllers. A third-party driver is available from http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver
23
+
24
+
25
+ ### Ubuntu
26
+
15
27
  ```
28
+ sudo apt-get install libsdl1.2-dev
16
29
  gem install artoo-joystick
17
30
  ```
18
31
 
32
+
19
33
  ## Using
20
34
 
21
35
  ```ruby
@@ -45,12 +59,49 @@ end
45
59
 
46
60
  ## Connecting to USB Joysticks and Game Controllers
47
61
 
48
- Plus your USB joystick or game controller into your USB port. If your device is supported by SDL, you are now ready.
62
+ Plug your USB joystick or game controller into your USB port. If your device is supported by SDL, you are now ready.
63
+
64
+ ### Additional XBox 360 Controller Information
65
+
66
+ Trigger button events are published to :trigger_lt and :trigger_rt for the XBox 360 controller.
67
+
68
+ ```ruby
69
+ require 'artoo'
70
+
71
+ connection :joystick, :adaptor => :joystick
72
+ device :controller, :driver => :xbox360, :connection => :joystick, :interval => 0.1
73
+
74
+ work do
75
+ on controller, :trigger_lt => proc { |*value|
76
+ puts "trigger lt: #{value[1]}"
77
+ }
78
+ on controller, :trigger_rt => proc { |*value|
79
+ puts "trigger rt: #{value[1]}"
80
+ }
81
+ end
82
+ ```
83
+
84
+ ## Documentation
85
+
86
+ Check out our [documentation](http://artoo.io/documentation/) for lots of information about how to use Artoo.
87
+
88
+ ## IRC
89
+
90
+ Need more help? Just want to say "Hello"? Come visit us on IRC freenode #artoo
49
91
 
50
92
  ## Contributing
51
93
 
52
- 1. Fork it
53
- 2. Create your feature branch (`git checkout -b my-new-feature`)
54
- 3. Commit your changes (`git commit -am 'Add some feature'`)
55
- 4. Push to the branch (`git push origin my-new-feature`)
56
- 5. Create new Pull Request
94
+ * All patches must be provided under the Apache 2.0 License
95
+ * Please use the -s option in git to "sign off" that the commit is your work and you are providing it under the Apache 2.0 License
96
+ * Submit a Github Pull Request to the appropriate branch and ideally discuss the changes with us in IRC.
97
+ * We will look at the patch, test it out, and give you feedback.
98
+ * Avoid doing minor whitespace changes, renamings, etc. along with merged content. These will be done by the maintainers from time to time but they can complicate merges and should be done seperately.
99
+ * Take care to maintain the existing coding style.
100
+ * Add unit tests for any new or changed functionality.
101
+ * All pull requests should be "fast forward"
102
+ * If there are commits after yours use “git rebase -i <new_head_branch>”
103
+ * If you have local changes you may need to use “git stash”
104
+ * For git help see [progit](http://git-scm.com/book) which is an awesome (and free) book on git
105
+
106
+
107
+ (c) 2012-2014 The Hybrid Group
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = "artoo-joystick"
7
7
  s.version = Artoo::Joystick::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Ron Evans"]
9
+ s.authors = ["Ron Evans", "Andrew Stewart"]
10
10
  s.email = ["artoo@hybridgroup.com"]
11
11
  s.homepage = "https://github.com/hybridgroup/artoo-joystick"
12
12
  s.summary = %q{Artoo adaptor and driver for SDL joysticks and game controllers}
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
21
  s.require_paths = ["lib"]
22
22
 
23
- s.add_runtime_dependency 'artoo', '>= 1.4.0'
23
+ s.add_runtime_dependency 'artoo', '>= 1.6.0'
24
24
  s.add_runtime_dependency 'hybridgroup-ruby-sdl-ffi'
25
25
  s.add_development_dependency 'minitest', '>= 5.0'
26
26
  s.add_development_dependency 'minitest-happy'
@@ -0,0 +1,9 @@
1
+ # Events
2
+
3
+ ## joystick
4
+
5
+ Get's triggered every "interval" amount of time if a joystick event occured, you can access values x, y, s.
6
+
7
+ ## button
8
+
9
+ Get's triggered every "interval" amount of time if the button was pressed, you can access the value of the pressed button.
@@ -0,0 +1,65 @@
1
+ # Events
2
+
3
+ ## button_left_joystick
4
+
5
+ Gets triggered every interval amount of time if a left joystick click event occured.
6
+
7
+ ## button_right_joystick
8
+
9
+ Gets triggered every interval amount of time if a right joystick click event occured.
10
+
11
+ ## button_square
12
+
13
+ Gets triggered every interval amount of time if the square button was pressed.
14
+
15
+ ## button_x
16
+
17
+ Gets triggered every interval amount of time if the 'x' button was pressed.
18
+
19
+ ## button_circle
20
+
21
+ Gets triggered every interval amount of time if the circle button was pressed.
22
+
23
+ ## button_triangle
24
+
25
+ Gets triggered every interval amount of time if the triangle button was pressed.
26
+
27
+ ## button_l1
28
+
29
+ Gets triggered every interval amount of time if the l1 button was pressed.
30
+
31
+ ## button_l2
32
+
33
+ Gets triggered every interval amount of time if the l2 button was pressed.
34
+
35
+ ## button_r1
36
+
37
+ Gets triggered every interval amount of time if the r1 button was pressed.
38
+
39
+ ## button_r2
40
+
41
+ Gets triggered every interval amount of time if the r2 button was pressed.
42
+
43
+ ## button_start
44
+
45
+ Gets triggered every interval amount of time if the start button was pressed.
46
+
47
+ ## button_select
48
+
49
+ Gets triggered every interval amount of time if the select button was pressed.
50
+
51
+ ## button_home
52
+
53
+ Gets triggered every interval amount of time if the home button was pressed.
54
+
55
+ ## joystick
56
+
57
+ Gets triggered every interval amount of time if a joystick event occured, you can access values x, y, s(joystick number, 0 and 1 for left and right).
58
+
59
+ ## joystick_0
60
+
61
+ Gets triggered every interval amount of time if a joystick_0 event occured, you can access values x, y.
62
+
63
+ ## joystick_1
64
+
65
+ Gets triggered every interval amount of time if a joystick_1 event occured, you can access values x, y.
@@ -0,0 +1,45 @@
1
+ # Events
2
+
3
+ ## button_a
4
+
5
+ Gets triggered every interval amount of time if the a button is pressed.
6
+
7
+ ## button_b
8
+
9
+ Gets triggered every interval amount of time if the b button is pressed.
10
+
11
+ ## button_x
12
+
13
+ Gets triggered every interval amount of time if the x button is pressed.
14
+
15
+ ## button_y
16
+
17
+ Gets triggered every interval amount of time if the y button is pressed.
18
+
19
+ ## button_lb
20
+
21
+ Gets triggered every interval amount of time if the left bumper button is pressed.
22
+
23
+ ## button_rb
24
+
25
+ Gets triggered every interval amount of time if the right bumper button is pressed.
26
+
27
+ ## button_start
28
+
29
+ Gets triggered every interval amount of time if the start button is pressed.
30
+
31
+ ## button_back
32
+
33
+ Gets triggered every interval amount of time if the back button is pressed.
34
+
35
+ ## joystick
36
+
37
+ Gets triggered every interval amount of time if a joystick event occured, you can access values x, y, s(joystick number, 0 and 1 for left and right).
38
+
39
+ ## joystick_0
40
+
41
+ Get's triggered every interval amount of time if a joystick_0 event occured, you can access values x, y.
42
+
43
+ ## joystick_1
44
+
45
+ Gets triggered every interval amount of time if a joystick_1 event occured, you can access values x, y.
@@ -0,0 +1,37 @@
1
+ require 'artoo'
2
+
3
+ connection :joystick, :adaptor => :joystick
4
+ device :controller, :driver => :xbox360, :connection => :joystick, :interval => 0.1
5
+
6
+ work do
7
+ on controller, :joystick_0 => proc { |*value|
8
+ puts "joystick 0 - x:#{value[1][:x]} y:#{value[1][:y]}"
9
+ }
10
+ on controller, :joystick_1 => proc { |*value|
11
+ puts "joystick 1 - x:#{value[1][:x]} y:#{value[1][:y]}"
12
+ }
13
+ on controller, :trigger_lt => proc { |*value|
14
+ puts "left trigger: #{value[1]}"
15
+ }
16
+ on controller, :trigger_rt => proc { |*value|
17
+ puts "right trigger: #{value[1]}"
18
+ }
19
+ on controller, :button_a => proc { |*value|
20
+ puts "ayyyy!"
21
+ }
22
+ on controller, :button_b => proc { |*value|
23
+ puts "bee!"
24
+ }
25
+ on controller, :button_x => proc { |*value|
26
+ puts "exxx!"
27
+ }
28
+ on controller, :button_y => proc { |*value|
29
+ puts "why!"
30
+ }
31
+ on controller, :button_rb => proc { |*value|
32
+ puts "Right Button down"
33
+ }
34
+ on controller, :button_up_rb => proc { |*value|
35
+ puts "Right Button up"
36
+ }
37
+ end
@@ -1,5 +1,5 @@
1
1
  module Artoo
2
2
  module Joystick
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -4,10 +4,24 @@ module Artoo
4
4
  module Drivers
5
5
  # The sdl-joystick driver behaviors
6
6
  class Joystick < Driver
7
+ include Artoo::Utility
8
+
9
+ COMMANDS = [:currently_pressed?].freeze
10
+
7
11
  attr_reader :button_values
8
12
 
9
13
  # Start driver and any required connections
10
14
  def start_driver
15
+ puts os
16
+ case os
17
+ when :linux
18
+ require 'artoo/drivers/linux_binding_map'
19
+ when :macosx
20
+ require 'artoo/drivers/macosx_binding_map'
21
+ else
22
+ # raise error ?
23
+ end
24
+
11
25
  @button_values = {}
12
26
 
13
27
  begin
@@ -23,6 +37,10 @@ module Artoo
23
37
  end
24
38
  end
25
39
 
40
+ def currently_pressed?(b)
41
+ button_values[b]
42
+ end
43
+
26
44
  def handle_message_events
27
45
  connection.poll
28
46
  handle_joystick
@@ -36,7 +54,7 @@ module Artoo
36
54
  number_sticks.times {|s|
37
55
  x = connection.axis(s * 2)
38
56
  y = connection.axis(s * 2 + 1)
39
-
57
+
40
58
  publish_joystick(s, x, y)
41
59
  }
42
60
  end
@@ -44,7 +62,7 @@ module Artoo
44
62
  def handle_trackball
45
63
  if connection.num_balls == 1
46
64
  x, y = connection.ball(0)
47
-
65
+
48
66
  publish(event_topic_name("update"), "trackball", {:x => x, :y => y})
49
67
  publish(event_topic_name("trackball"), {:x => x, :y => y})
50
68
  end
@@ -55,9 +73,7 @@ module Artoo
55
73
  currently_pressed = connection.button(b)
56
74
  if button_values[b] != currently_pressed
57
75
  button_values[b] = currently_pressed
58
- if currently_pressed == 1
59
- publish_button(b)
60
- end
76
+ publish_button(b)
61
77
  end
62
78
  }
63
79
  end
@@ -69,9 +85,11 @@ module Artoo
69
85
  end
70
86
 
71
87
  def publish_button(b)
72
- publish(event_topic_name("update"), "button", b)
73
- publish(event_topic_name("button"), b)
74
- publish(event_topic_name("button_#{b}"))
88
+ if button_values[b] == 1
89
+ publish(event_topic_name("update"), "button", b)
90
+ publish(event_topic_name("button"), b)
91
+ publish(event_topic_name("button_#{b}"))
92
+ end
75
93
  end
76
94
  end
77
95
  end
@@ -0,0 +1,43 @@
1
+ BINDING_MAP = {
2
+ :ps3 => {
3
+ :button_map => {
4
+ 0 => :square,
5
+ 1 => :x,
6
+ 2 => :circle,
7
+ 3 => :triangle,
8
+ 4 => :l1,
9
+ 5 => :r1,
10
+ 6 => :l2,
11
+ 7 => :r2,
12
+ 8 => :select,
13
+ 9 => :start,
14
+ 10 => :left_joystick,
15
+ 11 => :right_joystick,
16
+ 12 => :home
17
+ },
18
+ :axis_map => {
19
+ :j0_x => 0,
20
+ :j0_y => 1,
21
+ :j1_x => 2,
22
+ :j1_y => 3
23
+ }
24
+ },
25
+ :xbox360 => {
26
+ :button_map => {
27
+ 0 => :a,
28
+ 1 => :b,
29
+ 2 => :x,
30
+ 3 => :y,
31
+ 4 => :lb,
32
+ 5 => :rb,
33
+ 6 => :back,
34
+ 7 => :start
35
+ },
36
+ :axis_map => {
37
+ :j0_x => 0,
38
+ :j0_y => 1,
39
+ :j1_x => 3,
40
+ :j1_y => 4
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,56 @@
1
+ BINDING_MAP = {
2
+ :ps3 => {
3
+ :button_map => {
4
+ 0 => :select,
5
+ 1 => :j0,
6
+ 2 => :j1,
7
+ 3 => :start,
8
+ 4 => :dpad_up,
9
+ 5 => :dpad_right,
10
+ 6 => :dpad_down,
11
+ 7 => :dpad_left,
12
+ 8 => :l2,
13
+ 9 => :r2,
14
+ 10 => :l1,
15
+ 11 => :r1,
16
+ 12 => :triangle,
17
+ 13 => :circle,
18
+ 14 => :x,
19
+ 15 => :square,
20
+ 16 => :ps3
21
+ },
22
+ :axis_map => {
23
+ :j0_x => 0,
24
+ :j0_y => 1,
25
+ :j1_x => 2,
26
+ :j1_y => 3
27
+ }
28
+ },
29
+ :xbox360 => {
30
+ :button_map => {
31
+ 0 => :dpad_up,
32
+ 1 => :dpad_down,
33
+ 2 => :dpad_left,
34
+ 3 => :dpad_right,
35
+ 4 => :start,
36
+ 5 => :back,
37
+ 6 => :j0,
38
+ 7 => :j1,
39
+ 8 => :lb,
40
+ 9 => :rb,
41
+ 10 => :xbox,
42
+ 11 => :a,
43
+ 12 => :b,
44
+ 13 => :x,
45
+ 14 => :y
46
+ },
47
+ :axis_map => {
48
+ :j0_x => 0,
49
+ :j0_y => 1,
50
+ :j1_x => 2,
51
+ :j1_y => 3,
52
+ :lt => 4,
53
+ :rt => 5
54
+ }
55
+ }
56
+ }
@@ -4,40 +4,42 @@ module Artoo
4
4
  module Drivers
5
5
  # The Ps3 controller driver behaviors
6
6
  class Ps3 < Artoo::Drivers::Joystick
7
- BUTTON_MAP = {
8
- 0 => 'square',
9
- 1 => 'x',
10
- 2 => 'circle',
11
- 3 => 'triangle',
12
- 4 => 'l1',
13
- 5 => 'r1',
14
- 6 => 'l2',
15
- 7 => 'r2',
16
- 8 => 'select',
17
- 9 => 'start',
18
- 10 => 'left_joystick',
19
- 11 => 'right_joystick',
20
- 12 => 'home'
21
- }
7
+
8
+ def currently_pressed?(b)
9
+ if button_map.has_value?(b)
10
+ button_values[button_map.key(b)]
11
+ else
12
+ super b
13
+ end
14
+ end
22
15
 
23
16
  def handle_joystick
24
- x0 = connection.axis(0)
25
- y0 = connection.axis(1)
17
+ x0 = connection.axis(axis_map[:j0_x])
18
+ y0 = connection.axis(axis_map[:j0_y])
26
19
  publish_joystick(0, x0, y0)
27
20
 
28
- x1 = connection.axis(2)
29
- y1 = connection.axis(3)
21
+ x1 = connection.axis(axis_map[:j1_x])
22
+ y1 = connection.axis(axis_map[:j1_y])
30
23
  publish_joystick(1, x1, y1)
31
24
  end
32
25
 
33
26
  def publish_button(b)
34
- publish(event_topic_name("button_#{button_letter(b)}"))
27
+ if button_values[b] == 1
28
+ publish(event_topic_name("button_#{button_map[b]}"))
29
+ else
30
+ publish(event_topic_name("button_up_#{button_map[b]}"))
31
+ end
35
32
  super
36
33
  end
37
34
 
38
- def button_letter(b)
39
- BUTTON_MAP[b]
35
+ def button_map
36
+ BINDING_MAP[:ps3][:button_map]
40
37
  end
38
+
39
+ def axis_map
40
+ BINDING_MAP[:ps3][:axis_map]
41
+ end
42
+
41
43
  end
42
44
  end
43
45
  end
@@ -4,35 +4,58 @@ module Artoo
4
4
  module Drivers
5
5
  # The Xbox360 controller driver behaviors
6
6
  class Xbox360 < Artoo::Drivers::Joystick
7
- BUTTON_MAP = {
8
- 0 => 'a',
9
- 1 => 'b',
10
- 2 => 'x',
11
- 3 => 'y',
12
- 4 => 'lb',
13
- 5 => 'rb',
14
- 6 => 'back',
15
- 7 => 'start'
16
- }
7
+
8
+ def currently_pressed?(b)
9
+ if button_map.has_value?(b)
10
+ button_values[button_map.key(b)]
11
+ else
12
+ super b
13
+ end
14
+ end
17
15
 
18
16
  def handle_joystick
19
- x0 = connection.axis(0)
20
- y0 = connection.axis(1)
17
+ x0 = connection.axis(axis_map[:j0_x])
18
+ y0 = connection.axis(axis_map[:j0_y])
21
19
  publish_joystick(0, x0, y0)
22
20
 
23
- x1 = connection.axis(3)
24
- y1 = connection.axis(4)
25
- publish_joystick(1, x1, y1)
21
+ x1 = connection.axis(axis_map[:j1_x])
22
+ y1 = connection.axis(axis_map[:j1_y])
23
+ publish_joystick(1, x1, y1)
24
+
25
+ handle_trigger
26
+ end
27
+
28
+ def handle_trigger
29
+ unless axis_map[:lt].nil?
30
+ publish_trigger(:lt, connection.axis(axis_map[:lt]))
31
+ end
32
+
33
+ unless axis_map[:rt].nil?
34
+ publish_trigger(:rt, connection.axis(axis_map[:rt]))
35
+ end
36
+ end
37
+
38
+ def publish_trigger(t, v)
39
+ publish(event_topic_name("trigger_#{t}"), v)
26
40
  end
27
41
 
28
42
  def publish_button(b)
29
- publish(event_topic_name("button_#{button_letter(b)}"))
43
+ if button_values[b] == 1
44
+ publish(event_topic_name("button_#{button_map[b]}"))
45
+ else
46
+ publish(event_topic_name("button_up_#{button_map[b]}"))
47
+ end
30
48
  super
31
49
  end
32
50
 
33
- def button_letter(b)
34
- BUTTON_MAP[b]
51
+ def button_map
52
+ BINDING_MAP[:xbox360][:button_map]
35
53
  end
54
+
55
+ def axis_map
56
+ BINDING_MAP[:xbox360][:axis_map]
57
+ end
58
+
36
59
  end
37
60
  end
38
61
  end
metadata CHANGED
@@ -1,83 +1,84 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artoo-joystick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ron Evans
8
+ - Andrew Stewart
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-10-18 00:00:00.000000000 Z
12
+ date: 2014-02-07 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: artoo
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - '>='
18
+ - - ">="
18
19
  - !ruby/object:Gem::Version
19
- version: 1.4.0
20
+ version: 1.6.0
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - '>='
25
+ - - ">="
25
26
  - !ruby/object:Gem::Version
26
- version: 1.4.0
27
+ version: 1.6.0
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: hybridgroup-ruby-sdl-ffi
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - '>='
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
34
  version: '0'
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - '>='
39
+ - - ">="
39
40
  - !ruby/object:Gem::Version
40
41
  version: '0'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: minitest
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - '>='
46
+ - - ">="
46
47
  - !ruby/object:Gem::Version
47
48
  version: '5.0'
48
49
  type: :development
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - '>='
53
+ - - ">="
53
54
  - !ruby/object:Gem::Version
54
55
  version: '5.0'
55
56
  - !ruby/object:Gem::Dependency
56
57
  name: minitest-happy
57
58
  requirement: !ruby/object:Gem::Requirement
58
59
  requirements:
59
- - - '>='
60
+ - - ">="
60
61
  - !ruby/object:Gem::Version
61
62
  version: '0'
62
63
  type: :development
63
64
  prerelease: false
64
65
  version_requirements: !ruby/object:Gem::Requirement
65
66
  requirements:
66
- - - '>='
67
+ - - ">="
67
68
  - !ruby/object:Gem::Version
68
69
  version: '0'
69
70
  - !ruby/object:Gem::Dependency
70
71
  name: mocha
71
72
  requirement: !ruby/object:Gem::Requirement
72
73
  requirements:
73
- - - '>='
74
+ - - ">="
74
75
  - !ruby/object:Gem::Version
75
76
  version: 0.14.0
76
77
  type: :development
77
78
  prerelease: false
78
79
  version_requirements: !ruby/object:Gem::Requirement
79
80
  requirements:
80
- - - '>='
81
+ - - ">="
81
82
  - !ruby/object:Gem::Version
82
83
  version: 0.14.0
83
84
  description: Artoo adaptor and driver for SDL joysticks and game controllers
@@ -87,20 +88,27 @@ executables: []
87
88
  extensions: []
88
89
  extra_rdoc_files: []
89
90
  files:
90
- - .travis.yml
91
+ - ".gitignore"
92
+ - ".travis.yml"
91
93
  - Gemfile
92
94
  - Gemfile.lock
93
95
  - LICENSE
94
96
  - README.md
95
97
  - Rakefile
96
98
  - artoo-joystick.gemspec
99
+ - docs/events_joystick.md
100
+ - docs/events_ps3.md
101
+ - docs/events_xbox360.md
97
102
  - examples/controller.rb
98
103
  - examples/ps3_controller.rb
99
104
  - examples/xbox_360_controller.rb
105
+ - examples/xbox_360_osx.rb
100
106
  - lib/artoo-joystick.rb
101
107
  - lib/artoo-joystick/version.rb
102
108
  - lib/artoo/adaptors/joystick.rb
103
109
  - lib/artoo/drivers/joystick.rb
110
+ - lib/artoo/drivers/linux_binding_map.rb
111
+ - lib/artoo/drivers/macosx_binding_map.rb
104
112
  - lib/artoo/drivers/ps3.rb
105
113
  - lib/artoo/drivers/xbox360.rb
106
114
  - test/adaptors/joystick_adaptor_test.rb
@@ -118,17 +126,17 @@ require_paths:
118
126
  - lib
119
127
  required_ruby_version: !ruby/object:Gem::Requirement
120
128
  requirements:
121
- - - '>='
129
+ - - ">="
122
130
  - !ruby/object:Gem::Version
123
131
  version: '0'
124
132
  required_rubygems_version: !ruby/object:Gem::Requirement
125
133
  requirements:
126
- - - '>='
134
+ - - ">="
127
135
  - !ruby/object:Gem::Version
128
136
  version: '0'
129
137
  requirements: []
130
138
  rubyforge_project: artoo-joystick
131
- rubygems_version: 2.0.3
139
+ rubygems_version: 2.2.1
132
140
  signing_key:
133
141
  specification_version: 4
134
142
  summary: Artoo adaptor and driver for SDL joysticks and game controllers