Index: sources/bluetooth/BluetoothInterface.cpp =================================================================== diff -u -r93cb2e56782aa64aafb2b69ec526a5e49ffdf1c7 -r068426e216f9ae5bc4879e4f75bf0f346e33a1ae --- sources/bluetooth/BluetoothInterface.cpp (.../BluetoothInterface.cpp) (revision 93cb2e56782aa64aafb2b69ec526a5e49ffdf1c7) +++ sources/bluetooth/BluetoothInterface.cpp (.../BluetoothInterface.cpp) (revision 068426e216f9ae5bc4879e4f75bf0f346e33a1ae) @@ -163,12 +163,6 @@ #define NOTIFY_LOCAL_ERROR_OFF notifyStateChange(MBluetooth(MBluetooth::eIS_Local_Error_Off )); #define NOTIFY_LOCAL_ERROR_INVALID notifyStateChange(MBluetooth(MBluetooth::eIS_Local_Error_Invalid )); #define NOTIFY_LOCAL_DISCONNECT notifyStateChange(MBluetooth(MBluetooth::eIS_Local_Disconnect , vAddress.toString()) ); -// ~~~~~~~~~~~ Pair -#define NOTIFY_PAIR_START notifyStateChange(MBluetooth(MBluetooth::eIS_Pair_Start , _device->remoteAddress().toString())); -#define NOTIFY_PAIR_DONE notifyStateChange(MBluetooth(MBluetooth::eIS_Pair_Done , vAddress.toString(), "", "", vPairing)); -#define NOTIFY_PAIR_CONFIRM notifyStateChange(MBluetooth(MBluetooth::eIS_Pair_Confirm , vAddress.toString(), "", vPin ) ); -#define NOTIFY_PAIR_PINCODE notifyStateChange(MBluetooth(MBluetooth::eIS_Pair_PinCode , vAddress.toString(), "", vPin ) ); -#define NOTIFY_PAIR_ERROR notifyStateChange(MBluetooth(MBluetooth::eIS_Pair_Error )); // ~~~~~~~~~~~ Scan #define NOTIFY_SCAN_DISCOVER notifyStateChange(MBluetooth(MBluetooth::eIS_Scan_Discover , \ vInfo.address().toString() , \ @@ -273,6 +267,7 @@ */ void BluetoothInterface::ondoScan() { + onstart(); // TODO: it may require in case the application needs to reset the Bluetooth Adapter. Or can be moved to Adapter Reset function(no implemented yet) if (_agent && _agent->isActive()) { NOTIFY_SCAN_REJECT return; @@ -350,7 +345,7 @@ case QBluetoothDeviceDiscoveryAgent::InputOutputError : NOTIFY_LOCAL_ERROR_IO break; default : NOTIFY_LOCAL_ERROR break; } - if ( _device ) _device->disconnectFromDevice(); + quitDevice(); } /*! @@ -396,6 +391,14 @@ return true; } +bool BluetoothInterface::reconnectToDevice() +{ + if ( ! isLocalValid() ) return false; + NOTIFY_DEVICE_START + _device->connectToDevice(); + return true; +} + /*! * \brief BluetoothInterface::discoverServices * \details The function to be called to start retrieving the remote Bluetooth device _device's services, and @@ -470,7 +473,11 @@ */ void BluetoothInterface::onDeviceError(QLowEnergyController::Error vError) { - NOTIFY_DEVICE_ERROR + // if reconnect is active it should display "Device Connecting ..." and shouldn't display the "Connection Error", + // because we know we will always get the error since we are trying to connected to a device which is probably off. + if ( ! _reconnectionActive ) + NOTIFY_DEVICE_ERROR + } void BluetoothInterface::onServiceCharacteristicChanged(const QLowEnergyCharacteristic &vCharacteristic, const QByteArray &vValue) { @@ -592,7 +599,7 @@ return; } service->readCharacteristic(detailBPFeat); - _connectionActive = true; + _reconnectionActive = true; } break; @@ -650,9 +657,8 @@ */ void BluetoothInterface::timerEvent(QTimerEvent *) { - if ( _connectionActive ) { - if ( _device ) - _device->connectToDevice(); + if ( _reconnectionActive ) { + reconnectToDevice(); } } @@ -677,6 +683,7 @@ bool BluetoothInterface::isLocalValid() { if (! _local->isValid() ) { NOTIFY_LOCAL_ERROR_INVALID + quitDevice(); return false; } return true; @@ -735,7 +742,7 @@ * \details quits and deletes the old remote device _device and the device info _temp. */ void BluetoothInterface::quitDevice() { - _connectionActive = false; + _reconnectionActive = false; if ( _device ) { NOTIFY_DEVICE_DONE quitServices(); // it seems safe to delete all the services when the device is deleted because the current discovered service may not apply to the next device.