Class: BluetoothCommunication
- Inherits:
-
Object
- Object
- BluetoothCommunication
- Defined in:
- lib/communication/bluetooth_communication.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
-
#initialize(device, serial_port_profile = nil) ⇒ BluetoothCommunication
constructor
A new instance of BluetoothCommunication.
- #receive_message ⇒ Object
- #send_message(message, reply_class = nil, &block) ⇒ Object
Constructor Details
#initialize(device, serial_port_profile = nil) ⇒ BluetoothCommunication
Returns a new instance of BluetoothCommunication.
4 5 6 7 8 |
# File 'lib/communication/bluetooth_communication.rb', line 4 def initialize(device, serial_port_profile=nil) raise ArgumentError, "device must be non-nil" if device.nil? @profile = serial_port_profile || SerialPortProfile.new(device) end |
Instance Method Details
#connect ⇒ Object
10 11 12 |
# File 'lib/communication/bluetooth_communication.rb', line 10 def connect @profile.connect end |
#disconnect ⇒ Object
14 15 16 |
# File 'lib/communication/bluetooth_communication.rb', line 14 def disconnect @profile.disconnect end |
#receive_message ⇒ Object
37 38 39 40 41 |
# File 'lib/communication/bluetooth_communication.rb', line 37 def = @profile.receive_data_package = () ([:message]) end |
#send_message(message, reply_class = nil, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/communication/bluetooth_communication.rb', line 18 def (, reply_class=nil, &block) package = create_bluetooth_data_package() @profile.send_data_package(package) if .require_response? response = response = reply_class.new(response) unless reply_class.nil? if block_given? yield response else response end else nil # return nil when no response is required end end |