dozen 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +63 -0
- data/bin/dozen +56 -0
- data/lib/dozen.rb +93 -0
- metadata +93 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Rob Fletcher
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# dozen
|
2
|
+
A tool to pair your Sixaxis controller with an arbitrary Bluetooth device. A more readable and more usable Ruby port of [`sixpair.c`](http://www.pabr.org/sixlinux/sixpair.c)
|
3
|
+
|
4
|
+
This was written by Rob Fletcher, but I looked at sixpair to figure out the USB stuff.
|
5
|
+
|
6
|
+
## What does it do?
|
7
|
+
|
8
|
+
All this tool will do is tell your Sixaxis controller who it's Bluetooth master is. This is often called *pairing*. This should work with stock Ruby that comes with all OS X installations.
|
9
|
+
|
10
|
+
### I'm confused if this is what I need!
|
11
|
+
|
12
|
+
With USB devices, you can just plug it in, and it will send data. It knows where to go, just follow the wire. With Bluetooth, you need to jump through a few hoops in order for the device to know where to send data. Most devices make this easy... you can scan for Bluetooth devices, find the one you want, and you're good. The PS3 didn't really have to, since the Sixaxis controller came with a Mini-USB port, so you could just plug it into your PS3, it would pair itself silently, and when you unplugged it would remember where to send the data.
|
13
|
+
|
14
|
+
If you want a PS3 controller to send data to something ELSE (like a phone or a tablet) it can be bit more awkward. If you have a device without a USB port, it's entirely awkward.
|
15
|
+
|
16
|
+
That's what this will do. I have a Nexus 4 and it has a very useless USB port, but I wanted to pair my Sixaxis with it. The tools for Linux and OS X linked to from [Dancing Pixel Studios](http://www.dancingpixelstudios.com/sixaxiscontroller/tool.html) weren't the greatest. I can't even remember why I gave up trying to build the tool, but I think it was the super-old version of libusb that was required.
|
17
|
+
|
18
|
+
But if you just plug your PS3 controller into your computer (I've only tested this on OS X) and run this, you can tell it to pair with any Bluetooth device address you want. I put in my phone's Bluetooth address (helpfully listed right from the [Sixaxis](https://play.google.com/store/apps/details?id=com.dancingpixelstudios.sixaxiscontroller&hl=en) app or if you dig into your settings. I suspect that's what most people will use this for.
|
19
|
+
|
20
|
+
### What doesn't this do
|
21
|
+
|
22
|
+
All this does is pair the controller with something. It's not a driver. The thing you're pairing your controller with has to know what to do with the device. So if you're using this for an Android device, that probably means you need to root your phone and buy the super handy [Sixaxis](https://play.google.com/store/apps/details?id=com.dancingpixelstudios.sixaxiscontroller&hl=en).
|
23
|
+
|
24
|
+
I don't know what it takes to get a Sixaxis controller paired via Bluetooth to be recognized by whatever OS you've got, but this won't do it.
|
25
|
+
|
26
|
+
## Getting started
|
27
|
+
|
28
|
+
**TODO: Install the gem... that should do it once that's done**
|
29
|
+
|
30
|
+
## Basic Usage
|
31
|
+
So, you know your phone's Bluetooth address. Let's say that it is `aa:bb:cc:dd:ee:ff`.
|
32
|
+
This will be your usecase 99% of the time.
|
33
|
+
|
34
|
+
1. Plug in your Sixaxis controller via USB
|
35
|
+
2. `ruby -Ilib bin/dozen pair aa:bb:cc:dd:ee:ff` (lol I didn't set it up as a gem yet)
|
36
|
+
3. Done! That controller is now paired with your phone. Fire up sixaxis and you're all done
|
37
|
+
|
38
|
+
## Advanced Features
|
39
|
+
|
40
|
+
### Pair multiple controllers at once!
|
41
|
+
So now you have 3 sixaxis controllers and want to use them all on your phone at once. Hopefully you also have an HDMI dongle, but that is beyond the scope of this document.
|
42
|
+
|
43
|
+
You could do the usage step 3 times, but ol' flubby was thoughtful enough to add an `--all` flag!
|
44
|
+
|
45
|
+
1. Plug in ALL THREE of your Sixaxis controllers at once
|
46
|
+
2. `ruby -Ilib bin/dozen pair --all aa:bb:cc:dd:ee:ff`
|
47
|
+
3. Go play Snood or something!
|
48
|
+
|
49
|
+
### Sniper usage
|
50
|
+
|
51
|
+
All right then fancy pants. Now you have ... 18 Sixaxis controllers and you only want to pair one them with your phone.
|
52
|
+
|
53
|
+
1. Buy a quality series of USB hubs
|
54
|
+
2. Plug in all 18 Sixaxis controllers
|
55
|
+
3. `ruby -Ilib bin/dozen list`
|
56
|
+
4. Work out which of the 18 nearly-identical entires is the controller you want (it's #4)
|
57
|
+
5. `ruby -Ilib bin/dozen pair aa:bb:cc:dd:ee:ff --index 4` (yeah yeah, gemspec something...)
|
58
|
+
|
59
|
+
|
60
|
+
# TO DO
|
61
|
+
|
62
|
+
* Test coverage
|
63
|
+
* Make it a proper gem
|
data/bin/dozen
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'commander/import'
|
5
|
+
require 'dozen'
|
6
|
+
|
7
|
+
program :name, 'dozen'
|
8
|
+
program :version, Dozen.VERSION
|
9
|
+
program :description, 'Tool to pair your Sixaxis PS3 controller to an abritary ' +
|
10
|
+
'Bluetooth master. Based on sixpair\'s source.'
|
11
|
+
program :help_formatter, Commander::HelpFormatter::Terminal
|
12
|
+
|
13
|
+
command :list do |c|
|
14
|
+
c.syntax = 'dozen list'
|
15
|
+
c.description = 'Lists all Sixaxis controllers connected via USB and their masters.'
|
16
|
+
c.action do |args, options|
|
17
|
+
Dozen.show_header
|
18
|
+
dozen = Dozen.new
|
19
|
+
dozen.list_controllers
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
command :pair do |c|
|
24
|
+
c.syntax = 'dozen pair ADDRESS '
|
25
|
+
c.description = 'Pairs the first controller on the `dozen list` with the Bluetooth address.'
|
26
|
+
c.option '--index NUMBER', Integer, 'Specify which controller on `dozen list` to pair.'
|
27
|
+
c.option '--all', 'Pair every connected Sixaxis controller with the specified address.'
|
28
|
+
|
29
|
+
c.action do |args, options|
|
30
|
+
Dozen.show_header
|
31
|
+
|
32
|
+
options.default :index => 0
|
33
|
+
|
34
|
+
if args.empty?
|
35
|
+
puts "You must specify a Bluetooth device address."
|
36
|
+
next
|
37
|
+
end
|
38
|
+
|
39
|
+
desiredMaster = Dozen.parse_bluetooth_address(args[0])
|
40
|
+
|
41
|
+
if desiredMaster == false
|
42
|
+
puts "Invalid input for Bluetooth device address. Please use six, colon-delimited hexadecimal pairs (00:10:60:AA:36:F8)."
|
43
|
+
next
|
44
|
+
end
|
45
|
+
|
46
|
+
dozen = Dozen.new
|
47
|
+
|
48
|
+
if options.all
|
49
|
+
dozen.assign_address_to_all(desiredMaster)
|
50
|
+
else
|
51
|
+
dozen.assign_address_to_controller(desiredMaster, options.index)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
default_command :list
|
data/lib/dozen.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'libusb'
|
2
|
+
|
3
|
+
class Dozen
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@usb = LIBUSB::Context.new
|
7
|
+
@devices = query_usb_for_sixaxis_devices
|
8
|
+
if @devices.length == 0
|
9
|
+
puts "No Sixaxis controllers connected via USB."
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def list_controllers
|
14
|
+
@devices.each_with_index do |device, index|
|
15
|
+
device.open do |handle|
|
16
|
+
master = get_device_master_from_handle(handle)
|
17
|
+
puts "Controller ##{index} is paired with #{master.each_byte.map { |b| b.to_s(16) }.join(':')}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def assign_address_to_controller(address, controller_index)
|
23
|
+
if @devices[controller_index].nil?
|
24
|
+
puts "No device available at index #{controller_index}"
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
@devices[controller_index].open do |handle|
|
29
|
+
puts "Assigning address #{formatAddress(address)} to controller ##{controller_index}"
|
30
|
+
assign_master_to_handle(address, handle)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def assign_address_to_all(address)
|
35
|
+
@devices.each_with_index do |device, index|
|
36
|
+
device.open do |handle|
|
37
|
+
puts "Assigning address #{formatAddress(address)} to controller ##{index}"
|
38
|
+
assign_master_to_handle(address, handle)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.parse_bluetooth_address(raw_address)
|
44
|
+
begin
|
45
|
+
preparedAddress = raw_address.split(':').map{ |x| Integer("0x" + x)}
|
46
|
+
rescue
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
return false if preparedAddress.length != 6
|
50
|
+
return false if preparedAddress.any? {|x| x < 0 || x > 0xFF}
|
51
|
+
preparedAddress
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.show_header
|
55
|
+
puts "Dozen v#{Dozen.VERSION}"
|
56
|
+
puts
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.VERSION
|
60
|
+
'1.1.0'
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def formatAddress(address)
|
66
|
+
address.map{|x| x.to_s(16)}.join(':')
|
67
|
+
end
|
68
|
+
|
69
|
+
def query_usb_for_sixaxis_devices
|
70
|
+
@usb.devices(:idVendor => 0x054c, :idProduct => 0x0268)
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_device_master_from_handle(handle)
|
74
|
+
handle.control_transfer(
|
75
|
+
:bmRequestType => LIBUSB::REQUEST_TYPE_CLASS | LIBUSB::ENDPOINT_IN | LIBUSB::RECIPIENT_INTERFACE,
|
76
|
+
:bRequest => 0x01,
|
77
|
+
:wValue => 0x03f5,
|
78
|
+
:wIndex => 0x0000,
|
79
|
+
:dataIn => 8,
|
80
|
+
:timeout => 5000)[2,6]
|
81
|
+
end
|
82
|
+
|
83
|
+
def assign_master_to_handle(address, handle)
|
84
|
+
msg = ([0x01, 0x00] + address).pack('c*')
|
85
|
+
handle.control_transfer(
|
86
|
+
:bmRequestType => LIBUSB::REQUEST_TYPE_CLASS | LIBUSB::ENDPOINT_OUT | LIBUSB::RECIPIENT_INTERFACE,
|
87
|
+
:bRequest => 0x09,
|
88
|
+
:wValue => 0x03f5,
|
89
|
+
:wIndex => 0x0000,
|
90
|
+
:dataOut => msg,
|
91
|
+
:timeout => 5000)
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dozen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 1.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Rob Fletcher
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2013-09-13 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: commander
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 4
|
29
|
+
- 1
|
30
|
+
- 3
|
31
|
+
version: 4.1.3
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: libusb
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 3
|
44
|
+
- 4
|
45
|
+
version: 0.3.4
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
description: A simple tool to pair your Sixaxis controller with any Bluetooth device. Derived from the sixpair.c source.
|
49
|
+
email:
|
50
|
+
- rob@terraflubb.com
|
51
|
+
executables:
|
52
|
+
- dozen
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- lib/dozen.rb
|
59
|
+
- bin/dozen
|
60
|
+
- LICENSE
|
61
|
+
- README.md
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: https://github.com/terraflubb/dozen
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.6
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: A simple tool to pair your Sixaxis controller with any Bluetooth device
|
92
|
+
test_files: []
|
93
|
+
|