Class: Dozen

Inherits:
Object
  • Object
show all
Defined in:
lib/dozen.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDozen

Returns a new instance of Dozen.



5
6
7
8
9
10
11
# File 'lib/dozen.rb', line 5

def initialize
  @usb = LIBUSB::Context.new
  @devices = query_usb_for_sixaxis_devices
  if @devices.length == 0
    puts "No Sixaxis controllers connected via USB."
  end
end

Class Method Details

.parse_bluetooth_address(raw_address) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/dozen.rb', line 43

def self.parse_bluetooth_address(raw_address)
  begin
    preparedAddress = raw_address.split(':').map{ |x| Integer("0x" + x)}
  rescue
    return false
  end
  return false if preparedAddress.length != 6
  return false if preparedAddress.any? {|x| x < 0 || x > 0xFF}
  preparedAddress
end

.show_headerObject



54
55
56
57
# File 'lib/dozen.rb', line 54

def self.show_header
  puts "Dozen v#{Dozen.VERSION}"
  puts
end

.VERSIONObject



59
60
61
# File 'lib/dozen.rb', line 59

def self.VERSION
  '1.1.0'
end

Instance Method Details

#assign_address_to_all(address) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/dozen.rb', line 34

def assign_address_to_all(address)
  @devices.each_with_index do |device, index|
    device.open do |handle|
      puts "Assigning address #{formatAddress(address)} to controller ##{index}"
      assign_master_to_handle(address, handle)
    end
  end
end

#assign_address_to_controller(address, controller_index) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dozen.rb', line 22

def assign_address_to_controller(address, controller_index)
  if @devices[controller_index].nil?
    puts "No device available at index #{controller_index}"
    return
  end

  @devices[controller_index].open do |handle|
    puts "Assigning address #{formatAddress(address)} to controller ##{controller_index}"
    assign_master_to_handle(address, handle)
  end
end

#list_controllersObject



13
14
15
16
17
18
19
20
# File 'lib/dozen.rb', line 13

def list_controllers
  @devices.each_with_index do |device, index|
    device.open do |handle|
      master = get_device_master_from_handle(handle)
      puts "Controller ##{index} is paired with #{master.each_byte.map { |b| b.to_s(16) }.join(':')}"
    end
  end
end