Index: sources/bluetooth/BluetoothInterface.cpp =================================================================== diff -u -raa8f2c87c14c68d1fda6da2540d47144990a596c -rb252cd2777aadbce2d04aa32cc275f193de0cf52 --- sources/bluetooth/BluetoothInterface.cpp (.../BluetoothInterface.cpp) (revision aa8f2c87c14c68d1fda6da2540d47144990a596c) +++ sources/bluetooth/BluetoothInterface.cpp (.../BluetoothInterface.cpp) (revision b252cd2777aadbce2d04aa32cc275f193de0cf52) @@ -113,6 +113,9 @@ this , &BluetoothInterface ::onAgentDiscoverCancel ); connect(_agent , static_cast(&QBluetoothDeviceDiscoveryAgent::error), this , &BluetoothInterface ::onAgentDiscoverError ); + + connect(this , SIGNAL(didDeviceSelect(BluetoothDeviceData)), + this , SLOT( onDeviceSelect(BluetoothDeviceData))); } /*! @@ -177,12 +180,12 @@ vInfo.isValid() , \ vInfo.deviceUuid().toString() )); #define NOTIFY_SCAN_FOUND notifyStateChange(MBluetooth(MBluetooth::eIS_Scan_Found , \ - _temp.address().toString() , \ - _temp.name(), "" , \ - _local->pairingStatus(_temp.address()) , \ + vInfo.address().toString() , \ + vInfo.name(), "" , \ + _local->pairingStatus(vInfo.address()) , \ 0 , \ - _temp.isValid() , \ - _temp.deviceUuid().toString() )); + vInfo.isValid() , \ + vInfo.deviceUuid().toString() )); #define NOTIFY_SCAN_START notifyStateChange(MBluetooth(MBluetooth::eIS_Scan_Start )); #define NOTIFY_SCAN_REJECT notifyStateChange(MBluetooth(MBluetooth::eIS_Scan_Reject )); #define NOTIFY_SCAN_NOTFOUND notifyStateChange(MBluetooth(MBluetooth::eIS_Scan_NotFound ,"", "" )); @@ -336,15 +339,7 @@ */ void BluetoothInterface::ondoScan() { - if ( ! isValid() ) return; // POST failed. - - if (_agent && _agent->isActive()) { - NOTIFY_SCAN_REJECT - return; - } - - NOTIFY_SCAN_START - _agent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod); + startScan(); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -395,10 +390,12 @@ NOTIFY_SCAN_DISCOVER if (vInfo.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) { if ( isDeviceSupported( vInfo.name() ) ) { - _temp = QBluetoothDeviceInfo(vInfo.address(), vInfo.name(), QBluetoothDeviceInfo::HealthBloodPressureMonitor); + BluetoothDeviceData data; + data.addr = vInfo.address().toString(); + data.name = vInfo.name(); + data.pair = _local->pairingStatus(vInfo.address()); + emit didDeviceChange(data); NOTIFY_SCAN_FOUND - if (_agent->isActive()) - _agent->stop(); } } } @@ -429,7 +426,6 @@ void BluetoothInterface::onAgentDiscoverFinish() { NOTIFY_SCAN_DONE - connectToDevice(); } /*! @@ -441,7 +437,6 @@ void BluetoothInterface::onAgentDiscoverCancel() { NOTIFY_SCAN_STOP - connectToDevice(); } /*! @@ -742,7 +737,50 @@ } } + /*! + * \brief BluetoothInterface::onDeviceSelect + * \details the signal which will be called from a View created in the QML namespace to safely set the current selected device. + * \param vDevice + */ +void BluetoothInterface::onDeviceSelect(const BluetoothDeviceData &vDevice) { + _temp = QBluetoothDeviceInfo(QBluetoothAddress(vDevice.addr), vDevice.name, QBluetoothDeviceInfo::HealthBloodPressureMonitor); + connectToDevice(); +} + +/*! + * \brief BluetoothInterface::startScan + * \details Stars the agent device scan + * \return true if the agent can successfully start the scan. + */ +bool BluetoothInterface::startScan() +{ + if ( ! isValid() ) return false; // POST failed. + + if (_agent && _agent->isActive()) { + NOTIFY_SCAN_REJECT + return false; + } + + NOTIFY_SCAN_START + _agent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod); + return true; +} + +/*! + * \brief BluetoothInterface::stopScan + * \details Stops the agent device scan + * \return true if the agent is currently active and is stopped or false if it was not active. + */ +bool BluetoothInterface::stopScan() +{ + if (! _agent->isActive()) return false; + _agent->stop(); + // No NOTIFICATION here. will be send in the corresponding slot of the finish/cancel agent scan. + return true; +} + +/*! * \brief BluetoothInterface::initDevice * \return Initializes the device by making a new device and initializes its connections */