artoo-joystick 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +66 -0
- data/LICENSE +13 -0
- data/README.md +56 -0
- data/Rakefile +10 -0
- data/artoo-joystick.gemspec +28 -0
- data/examples/controller.rb +13 -0
- data/examples/ps3_controller.rb +16 -0
- data/examples/xbox_360_controller.rb +22 -0
- data/lib/artoo/adaptors/joystick.rb +91 -0
- data/lib/artoo/drivers/joystick.rb +78 -0
- data/lib/artoo/drivers/ps3.rb +43 -0
- data/lib/artoo/drivers/xbox360.rb +38 -0
- data/lib/artoo-joystick/version.rb +5 -0
- data/lib/artoo-joystick.rb +5 -0
- data/test/adaptors/joystick_adaptor_test.rb +87 -0
- data/test/drivers/joystick_driver_test.rb +4 -0
- data/test/drivers/ps3_test.rb +4 -0
- data/test/drivers/xbox360_test.rb +4 -0
- data/test/test_helper.rb +10 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0c85eb882b2e9308a8d8f3cdb26205510be784e
|
4
|
+
data.tar.gz: 58c51740b9f39ce8c228871298a02b6ad7550375
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8056e13185651b0d77f120b137146687eada40a9a5af15b70bb3fef25fa1abf9c4e25baf3f85aeb791dcb7d97780ea9b3b6ac64eeac9b994976639d70a416aa
|
7
|
+
data.tar.gz: 275aafc357b7bf5b7159d3622019aee166e5cd025d66bdfd8353424601499b53b600a9deba37a54ab11d18bd5eab032d26d5fcc3a000a6061bd56c235c3594f2
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
artoo-joystick (0.2.0)
|
5
|
+
artoo (>= 1.3.0)
|
6
|
+
hybridgroup-ruby-sdl-ffi
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
artoo (1.3.0)
|
12
|
+
celluloid (~> 0.15.0)
|
13
|
+
celluloid-io (~> 0.15.0)
|
14
|
+
multi_json (~> 1.6)
|
15
|
+
pry (~> 0.9)
|
16
|
+
rake
|
17
|
+
reel (~> 0.4.0)
|
18
|
+
thor (~> 0.18.1)
|
19
|
+
celluloid (0.15.1)
|
20
|
+
timers (~> 1.1.0)
|
21
|
+
celluloid-io (0.15.0)
|
22
|
+
celluloid (>= 0.15.0)
|
23
|
+
nio4r (>= 0.5.0)
|
24
|
+
coderay (1.0.9)
|
25
|
+
ffi (1.9.0)
|
26
|
+
http (0.5.0)
|
27
|
+
http_parser.rb
|
28
|
+
http_parser.rb (0.6.0.beta.2)
|
29
|
+
hybridgroup-ruby-sdl-ffi (0.4.1)
|
30
|
+
nice-ffi (>= 0.2)
|
31
|
+
metaclass (0.0.1)
|
32
|
+
method_source (0.8.2)
|
33
|
+
minitest (5.0.8)
|
34
|
+
minitest-happy (1.0.0)
|
35
|
+
mocha (0.14.0)
|
36
|
+
metaclass (~> 0.0.1)
|
37
|
+
multi_json (1.8.0)
|
38
|
+
nice-ffi (0.4)
|
39
|
+
ffi (>= 0.5.0)
|
40
|
+
nio4r (0.5.0)
|
41
|
+
pry (0.9.12.2)
|
42
|
+
coderay (~> 1.0.5)
|
43
|
+
method_source (~> 0.8)
|
44
|
+
slop (~> 3.4)
|
45
|
+
rake (10.1.0)
|
46
|
+
reel (0.4.0)
|
47
|
+
celluloid (>= 0.15.1)
|
48
|
+
celluloid-io (>= 0.15.0)
|
49
|
+
http (>= 0.5.0)
|
50
|
+
http_parser.rb (>= 0.6.0.beta.2)
|
51
|
+
websocket_parser (>= 0.1.4)
|
52
|
+
slop (3.4.6)
|
53
|
+
thor (0.18.1)
|
54
|
+
timers (1.1.0)
|
55
|
+
websocket_parser (0.1.4)
|
56
|
+
http
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
java
|
60
|
+
ruby
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
artoo-joystick!
|
64
|
+
minitest (>= 5.0)
|
65
|
+
minitest-happy
|
66
|
+
mocha (>= 0.14.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2013 The Hybrid Group
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Artoo Adaptor For Joysticks & Game Controllers
|
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/).
|
4
|
+
|
5
|
+
Artoo is a open source micro-framework for robotics using Ruby.
|
6
|
+
|
7
|
+
For more information about Artoo, check out our repo at https://github.com/hybridgroup/artoo
|
8
|
+
|
9
|
+
The artoo-joystick adaptor uses the rubysdl gem (http://www.kmc.gr.jp/~ohai/rubysdl.en.html).
|
10
|
+
|
11
|
+
[](https://codeclimate.com/github/hybridgroup/artoo-joystick) [](https://travis-ci.org/hybridgroup/artoo-joystick)
|
12
|
+
|
13
|
+
## Installing
|
14
|
+
|
15
|
+
```
|
16
|
+
gem install artoo-joystick
|
17
|
+
```
|
18
|
+
|
19
|
+
## Using
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'artoo'
|
23
|
+
|
24
|
+
connection :joystick, :adaptor => :joystick
|
25
|
+
device :controller, :driver => :xbox360, :connection => :joystick, :interval => 0.1
|
26
|
+
|
27
|
+
work do
|
28
|
+
on controller, :joystick => proc { |*value|
|
29
|
+
puts "joystick #{value[1][:s]} x:#{value[1][:x]} y:#{value[1][:y]}"
|
30
|
+
}
|
31
|
+
on controller, :button_a => proc { |*value|
|
32
|
+
puts "ayyyy!"
|
33
|
+
}
|
34
|
+
on controller, :button_b => proc { |*value|
|
35
|
+
puts "bee!"
|
36
|
+
}
|
37
|
+
on controller, :button_x => proc { |*value|
|
38
|
+
puts "exxx!"
|
39
|
+
}
|
40
|
+
on controller, :button_y => proc { |*value|
|
41
|
+
puts "why!"
|
42
|
+
}
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
## Connecting to USB Joysticks and Game Controllers
|
47
|
+
|
48
|
+
Plus your USB joystick or game controller into your USB port. If your device is supported by SDL, you are now ready.
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
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
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "artoo-joystick/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "artoo-joystick"
|
7
|
+
s.version = Artoo::Joystick::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Ron Evans"]
|
10
|
+
s.email = ["artoo@hybridgroup.com"]
|
11
|
+
s.homepage = "https://github.com/hybridgroup/artoo-joystick"
|
12
|
+
s.summary = %q{Artoo adaptor and driver for SDL joysticks and game controllers}
|
13
|
+
s.description = %q{Artoo adaptor and driver for SDL joysticks and game controllers}
|
14
|
+
s.license = 'Apache 2.0'
|
15
|
+
|
16
|
+
s.rubyforge_project = "artoo-joystick"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_runtime_dependency 'artoo', '>= 1.3.0'
|
24
|
+
s.add_runtime_dependency 'hybridgroup-ruby-sdl-ffi'
|
25
|
+
s.add_development_dependency 'minitest', '>= 5.0'
|
26
|
+
s.add_development_dependency 'minitest-happy'
|
27
|
+
s.add_development_dependency 'mocha', '>= 0.14.0'
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
connection :joystick, :adaptor => :joystick
|
4
|
+
device :controller, :driver => :joystick, :connection => :joystick, :interval => 0.1
|
5
|
+
|
6
|
+
work do
|
7
|
+
on controller, :joystick => proc { |*value|
|
8
|
+
puts "joystick #{value[1][:s]} x:#{value[1][:x]} y:#{value[1][:y]}"
|
9
|
+
}
|
10
|
+
on controller, :button => proc { |*value|
|
11
|
+
puts "button #{value[1]}"
|
12
|
+
}
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
connection :joystick, :adaptor => :joystick
|
4
|
+
device :controller, :driver => :ps3, :connection => :joystick, :interval => 0.1
|
5
|
+
|
6
|
+
work do
|
7
|
+
on controller, :joystick => proc { |*value|
|
8
|
+
puts "joystick #{value[1][:s]} x:#{value[1][:x]} y:#{value[1][:y]}"
|
9
|
+
}
|
10
|
+
on controller, :button => proc { |*value|
|
11
|
+
puts "button #{value[1]}"
|
12
|
+
}
|
13
|
+
on controller, :button_square => proc { |*value|
|
14
|
+
puts "l7 weenie!"
|
15
|
+
}
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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 => proc { |*value|
|
8
|
+
puts "joystick #{value[1][:s]} x:#{value[1][:x]} y:#{value[1][:y]}"
|
9
|
+
}
|
10
|
+
on controller, :button_a => proc { |*value|
|
11
|
+
puts "ayyyy!"
|
12
|
+
}
|
13
|
+
on controller, :button_b => proc { |*value|
|
14
|
+
puts "bee!"
|
15
|
+
}
|
16
|
+
on controller, :button_x => proc { |*value|
|
17
|
+
puts "exxx!"
|
18
|
+
}
|
19
|
+
on controller, :button_y => proc { |*value|
|
20
|
+
puts "why!"
|
21
|
+
}
|
22
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'artoo/adaptors/adaptor'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Adaptors
|
5
|
+
# Connect to a joystick device
|
6
|
+
# @see device documentation for more information
|
7
|
+
class Joystick < Adaptor
|
8
|
+
finalizer :finalize
|
9
|
+
attr_reader :joystick
|
10
|
+
|
11
|
+
# Closes connection with device if connected
|
12
|
+
# @return [Boolean]
|
13
|
+
def finalize
|
14
|
+
disconnect if connected?
|
15
|
+
end
|
16
|
+
|
17
|
+
# Creates a connection with device
|
18
|
+
# @return [Boolean]
|
19
|
+
def connect
|
20
|
+
require 'ruby-sdl-ffi' unless defined?(::SDL)
|
21
|
+
|
22
|
+
::SDL.Init( ::SDL::INIT_JOYSTICK )
|
23
|
+
|
24
|
+
raise "No SDL joystick available" if num_joysticks == 0
|
25
|
+
|
26
|
+
@joystick = ::SDL.JoystickOpen(0) # TODO: allow user to choose which joystick
|
27
|
+
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
# Closes connection with device
|
32
|
+
# @return [Boolean]
|
33
|
+
def disconnect
|
34
|
+
::SDL.JoystickClose(joystick)
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
# Name of device
|
39
|
+
# @return [String]
|
40
|
+
def firmware_name
|
41
|
+
::SDL.JoystickName(0)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Version of device
|
45
|
+
# @return [String]
|
46
|
+
def version
|
47
|
+
Artoo::Joystick::VERSION
|
48
|
+
end
|
49
|
+
|
50
|
+
def poll
|
51
|
+
::SDL.JoystickUpdate
|
52
|
+
end
|
53
|
+
|
54
|
+
def num_joysticks
|
55
|
+
::SDL.NumJoysticks
|
56
|
+
end
|
57
|
+
|
58
|
+
def num_axes
|
59
|
+
::SDL.JoystickNumAxes(joystick)
|
60
|
+
end
|
61
|
+
|
62
|
+
def axis(n)
|
63
|
+
::SDL.JoystickGetAxis(joystick, n)
|
64
|
+
end
|
65
|
+
|
66
|
+
def num_balls
|
67
|
+
::SDL.JoystickNumBalls(joystick)
|
68
|
+
end
|
69
|
+
|
70
|
+
def ball(n)
|
71
|
+
::SDL.JoystickGetBall(joystick, n)
|
72
|
+
end
|
73
|
+
|
74
|
+
def num_hats
|
75
|
+
::SDL.JoystickNumHats(joystick)
|
76
|
+
end
|
77
|
+
|
78
|
+
def hat(n)
|
79
|
+
::SDL.JoystickGetHat(joystick, n)
|
80
|
+
end
|
81
|
+
|
82
|
+
def num_buttons
|
83
|
+
::SDL.JoystickNumButtons(joystick)
|
84
|
+
end
|
85
|
+
|
86
|
+
def button(n)
|
87
|
+
::SDL.JoystickGetButton(joystick, n)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'artoo/drivers/driver'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Drivers
|
5
|
+
# The sdl-joystick driver behaviors
|
6
|
+
class Joystick < Driver
|
7
|
+
attr_reader :button_values
|
8
|
+
|
9
|
+
# Start driver and any required connections
|
10
|
+
def start_driver
|
11
|
+
@button_values = {}
|
12
|
+
|
13
|
+
begin
|
14
|
+
every(interval) do
|
15
|
+
handle_message_events
|
16
|
+
end
|
17
|
+
|
18
|
+
super
|
19
|
+
rescue Exception => e
|
20
|
+
Logger.error "Error starting SdlJoystick driver!"
|
21
|
+
Logger.error e.message
|
22
|
+
Logger.error e.backtrace.inspect
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def handle_message_events
|
27
|
+
connection.poll
|
28
|
+
handle_joystick
|
29
|
+
# TODO: handle_trackball
|
30
|
+
# TODO: handle_hats
|
31
|
+
handle_buttons
|
32
|
+
end
|
33
|
+
|
34
|
+
def handle_joystick
|
35
|
+
number_sticks = connection.num_axes / 2
|
36
|
+
number_sticks.times {|s|
|
37
|
+
x = connection.axis(s * 2)
|
38
|
+
y = connection.axis(s * 2 + 1)
|
39
|
+
|
40
|
+
publish_joystick(s, x, y)
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def handle_trackball
|
45
|
+
if connection.num_balls == 1
|
46
|
+
x, y = connection.ball(0)
|
47
|
+
|
48
|
+
publish(event_topic_name("update"), "trackball", {:x => x, :y => y})
|
49
|
+
publish(event_topic_name("trackball"), {:x => x, :y => y})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def handle_buttons
|
54
|
+
connection.num_buttons.times {|b|
|
55
|
+
currently_pressed = connection.button(b)
|
56
|
+
if button_values[b] != currently_pressed
|
57
|
+
button_values[b] = currently_pressed
|
58
|
+
if currently_pressed == 1
|
59
|
+
publish_button(b)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def publish_joystick(s, x, y)
|
66
|
+
publish(event_topic_name("update"), "joystick", {:x => x, :y => y, :s => s})
|
67
|
+
publish(event_topic_name("joystick"), {:x => x, :y => y, :s => s})
|
68
|
+
publish(event_topic_name("joystick_#{s}"), {:x => x, :y => y})
|
69
|
+
end
|
70
|
+
|
71
|
+
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}"))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'artoo/drivers/joystick'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Drivers
|
5
|
+
# The Ps3 controller driver behaviors
|
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
|
+
}
|
22
|
+
|
23
|
+
def handle_joystick
|
24
|
+
x0 = connection.axis(0)
|
25
|
+
y0 = connection.axis(1)
|
26
|
+
publish_joystick(0, x0, y0)
|
27
|
+
|
28
|
+
x1 = connection.axis(2)
|
29
|
+
y1 = connection.axis(3)
|
30
|
+
publish_joystick(1, x1, y1)
|
31
|
+
end
|
32
|
+
|
33
|
+
def publish_button(b)
|
34
|
+
publish(event_topic_name("button_#{button_letter(b)}"))
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
def button_letter(b)
|
39
|
+
BUTTON_MAP[b]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'artoo/drivers/joystick'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Drivers
|
5
|
+
# The Xbox360 controller driver behaviors
|
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
|
+
}
|
17
|
+
|
18
|
+
def handle_joystick
|
19
|
+
x0 = connection.axis(0)
|
20
|
+
y0 = connection.axis(1)
|
21
|
+
publish_joystick(0, x0, y0)
|
22
|
+
|
23
|
+
x1 = connection.axis(3)
|
24
|
+
y1 = connection.axis(4)
|
25
|
+
publish_joystick(1, x1, y1)
|
26
|
+
end
|
27
|
+
|
28
|
+
def publish_button(b)
|
29
|
+
publish(event_topic_name("button_#{button_letter(b)}"))
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
def button_letter(b)
|
34
|
+
BUTTON_MAP[b]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
require 'artoo/adaptors/joystick'
|
3
|
+
require 'ruby-sdl-ffi'
|
4
|
+
|
5
|
+
describe Artoo::Adaptors::Joystick do
|
6
|
+
before do
|
7
|
+
@adaptor = Artoo::Adaptors::Joystick.new
|
8
|
+
@adaptor.stubs(:joystick).returns("joy")
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'must #connect' do
|
12
|
+
::SDL.expects(:Init).with(::SDL::INIT_JOYSTICK)
|
13
|
+
@adaptor.expects(:num_joysticks).returns(1)
|
14
|
+
::SDL.expects(:JoystickOpen).with(0)
|
15
|
+
|
16
|
+
@adaptor.connect
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'must #disconnect' do
|
20
|
+
::SDL.expects(:JoystickClose).with("joy")
|
21
|
+
|
22
|
+
@adaptor.disconnect
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "device info interface" do
|
26
|
+
it "#firmware_name" do
|
27
|
+
::SDL.expects(:JoystickName).with(0).returns("somuchjoy")
|
28
|
+
@adaptor.firmware_name.must_equal "somuchjoy"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "#version" do
|
32
|
+
@adaptor.version.must_equal Artoo::Joystick::VERSION
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "SDL interface" do
|
37
|
+
it "#poll" do
|
38
|
+
::SDL.expects(:JoystickUpdate)
|
39
|
+
@adaptor.poll
|
40
|
+
end
|
41
|
+
|
42
|
+
it "#num_joysticks" do
|
43
|
+
::SDL.expects(:NumJoysticks).returns(1)
|
44
|
+
@adaptor.num_joysticks.must_equal 1
|
45
|
+
end
|
46
|
+
|
47
|
+
it "#num_axes" do
|
48
|
+
::SDL.expects(:JoystickNumAxes).with("joy").returns(2)
|
49
|
+
@adaptor.num_axes.must_equal 2
|
50
|
+
end
|
51
|
+
|
52
|
+
it "#axis" do
|
53
|
+
::SDL.expects(:JoystickGetAxis).with("joy", 0).returns(101)
|
54
|
+
@adaptor.axis(0).must_equal 101
|
55
|
+
end
|
56
|
+
|
57
|
+
it "#num_balls" do
|
58
|
+
::SDL.expects(:JoystickNumBalls).with("joy").returns(2)
|
59
|
+
@adaptor.num_balls.must_equal 2
|
60
|
+
end
|
61
|
+
|
62
|
+
it "#ball" do
|
63
|
+
::SDL.expects(:JoystickGetBall).with("joy", 0).returns(102)
|
64
|
+
@adaptor.ball(0).must_equal 102
|
65
|
+
end
|
66
|
+
|
67
|
+
it "#num_hats" do
|
68
|
+
::SDL.expects(:JoystickNumHats).with("joy").returns(3)
|
69
|
+
@adaptor.num_hats.must_equal 3
|
70
|
+
end
|
71
|
+
|
72
|
+
it "#hat" do
|
73
|
+
::SDL.expects(:JoystickGetHat).with("joy", 0).returns(103)
|
74
|
+
@adaptor.hat(0).must_equal 103
|
75
|
+
end
|
76
|
+
|
77
|
+
it "#num_buttons" do
|
78
|
+
::SDL.expects(:JoystickNumButtons).with("joy").returns(5)
|
79
|
+
@adaptor.num_buttons.must_equal 5
|
80
|
+
end
|
81
|
+
|
82
|
+
it "#button" do
|
83
|
+
::SDL.expects(:JoystickGetButton).with("joy", 0).returns(true)
|
84
|
+
@adaptor.button(0).must_equal true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: artoo-joystick
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ron Evans
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: artoo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hybridgroup-ruby-sdl-ffi
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-happy
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.14.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.14.0
|
83
|
+
description: Artoo adaptor and driver for SDL joysticks and game controllers
|
84
|
+
email:
|
85
|
+
- artoo@hybridgroup.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- Gemfile
|
91
|
+
- Gemfile.lock
|
92
|
+
- LICENSE
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- artoo-joystick.gemspec
|
96
|
+
- examples/controller.rb
|
97
|
+
- examples/ps3_controller.rb
|
98
|
+
- examples/xbox_360_controller.rb
|
99
|
+
- lib/artoo-joystick.rb
|
100
|
+
- lib/artoo-joystick/version.rb
|
101
|
+
- lib/artoo/adaptors/joystick.rb
|
102
|
+
- lib/artoo/drivers/joystick.rb
|
103
|
+
- lib/artoo/drivers/ps3.rb
|
104
|
+
- lib/artoo/drivers/xbox360.rb
|
105
|
+
- test/adaptors/joystick_adaptor_test.rb
|
106
|
+
- test/drivers/joystick_driver_test.rb
|
107
|
+
- test/drivers/ps3_test.rb
|
108
|
+
- test/drivers/xbox360_test.rb
|
109
|
+
- test/test_helper.rb
|
110
|
+
homepage: https://github.com/hybridgroup/artoo-joystick
|
111
|
+
licenses:
|
112
|
+
- Apache 2.0
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project: artoo-joystick
|
130
|
+
rubygems_version: 2.0.3
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Artoo adaptor and driver for SDL joysticks and game controllers
|
134
|
+
test_files: []
|