Class: Bluetooth::Device
- Inherits:
-
Object
- Object
- Bluetooth::Device
- Defined in:
- lib/bluetooth/device.rb
Overview
A bluetooth device
Instance Attribute Summary collapse
-
#address ⇒ Object
The address of this device in XX-XX-XX-XX-XX-XX format.
-
#name ⇒ Object
The name of this Device.
Instance Method Summary collapse
-
#address_bytes ⇒ Object
The bytes of this address.
-
#initialize(address, name = nil) ⇒ Device
constructor
Creates a new Device with an
address
and an optionalname
. -
#link_quality ⇒ Object
Returns the link quality for the device.
-
#pair_confirmation(&block) ⇒ Object
Called during pairing if user confirmation is required with a number to match with the device.
-
#rssi ⇒ Object
Returns the RSSI for the device.
-
#to_s ⇒ Object
:nodoc:.
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
#address ⇒ Object
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 |
#name ⇒ Object
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_bytes ⇒ Object
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 |
#link_quality ⇒ Object
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 |
#rssi ⇒ Object
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_s ⇒ Object
:nodoc:
74 75 76 |
# File 'lib/bluetooth/device.rb', line 74 def to_s # :nodoc: "#{name} at #{address}" end |