Class: Bluetooth::Device

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

Overview

A bluetooth device

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address, name = nil) ⇒ Device

Creates a new Device with an address and an optional name



19
20
21
22
23
24
25
# File 'lib/bluetooth/device.rb', line 19

def initialize address, name = nil
  @address = address
  @name = name

  @pair_error = nil
  @pair_confirmation_callback = nil
end

Instance Attribute Details

#addressObject

The address of this device in XX-XX-XX-XX-XX-XX format



9
10
11
# File 'lib/bluetooth/device.rb', line 9

def address
  @address
end

#nameObject

The name of this Device. It will be automatically looked up if not already known.



47
48
49
50
51
52
53
54
55
# File 'lib/bluetooth/device.rb', line 47

def name
  return @name if @name

  @name = request_name

  return '(unknown)' unless @name

  @name
end

Instance Method Details

#address_bytesObject

The bytes of this address



30
31
32
# File 'lib/bluetooth/device.rb', line 30

def address_bytes
  @address.split('-').map { |c| c.to_i(16) }.pack 'C*'
end

Returns the link quality for the device.



37
38
39
40
41
# File 'lib/bluetooth/device.rb', line 37

def link_quality
  connect do
    _link_quality
  end
end

#pair_confirmation(&block) ⇒ Object

Called during pairing if user confirmation is required with a number to match with the device. Return true if the number matches.



61
62
63
# File 'lib/bluetooth/device.rb', line 61

def pair_confirmation &block
  @pair_confirmation_callback = block
end

#rssiObject

Returns the RSSI for the device



68
69
70
71
72
# File 'lib/bluetooth/device.rb', line 68

def rssi
  connect do
    _rssi
  end
end

#to_sObject

:nodoc:



74
75
76
# File 'lib/bluetooth/device.rb', line 74

def to_s # :nodoc:
  "#{name} at #{address}"
end