Index: sources/bluetooth/BLEScanner.cpp =================================================================== diff -u -r5696b8db4628ee3143d93952c5dbdf511fa985b1 -r5220c64dd3a0fc9c322a68884e73503bb7893d12 --- sources/bluetooth/BLEScanner.cpp (.../BLEScanner.cpp) (revision 5696b8db4628ee3143d93952c5dbdf511fa985b1) +++ sources/bluetooth/BLEScanner.cpp (.../BLEScanner.cpp) (revision 5220c64dd3a0fc9c322a68884e73503bb7893d12) @@ -114,7 +114,7 @@ for (const QString &prefix : omronDeviceNamesPrefixes) { if (deviceInfo.name().toLower().contains(prefix.toLower())) { - devices.append(deviceInfo); + devices.insert(0, deviceInfo); emit didDiscoverDevice(deviceInfo); } } @@ -200,10 +200,7 @@ ); if (!c.isValid()) { qDebug() << "Cannot read device information."; - disconnect(timer, SIGNAL(timeout()), - this, SLOT(onRequestDeviceInformation())); - connect(timer, SIGNAL(timeout()), - this, SLOT(onRetryConnectToDevice())); + updateBLECuffCheckinType(true); return; } omronDeviceInformationService->readCharacteristic(c); @@ -216,7 +213,7 @@ void BLEScanner::onRequestDeviceInformation() { qDebug() << __FUNCTION__; -// onRequestDeviceInformation(); + onRequestDeviceSerialNumber(); } @@ -436,11 +433,34 @@ */ void BLEScanner::onControllerError(const QLowEnergyController::Error &error) { - qDebug() << __FUNCTION__ << "LE controller error: " << error; emit didReceiveControllerError(error); } /*! + * \brief BLEScanner::updateBLECuffCheckinType + * Toggles the type of check we do with the BLE cuff. + * If already connected, just query it repeatedly ever 1Hz. + * Otherwise, start trying to reconnect to it. + * \param retryConnection - if true, retry connection, normal checkin otherwise. + */ +void BLEScanner::updateBLECuffCheckinType(bool retryConnection) +{ + timer->stop(); + if (retryConnection) { + disconnect(timer, SIGNAL(timeout()), + this, SLOT(onRequestDeviceInformation())); + connect(timer, SIGNAL(timeout()), + this, SLOT(onRetryConnectToDevice())); + } else{ + disconnect(timer, SIGNAL(timeout()), + this, SLOT(onRetryConnectToDevice())); + connect(timer, SIGNAL(timeout()), + this, SLOT(onRequestDeviceInformation())); + } + timer->start(); +} + +/*! * \brief BLEScanner::onDeviceConnected * Called when we successfully connect to a device. * Starts the scan for services on the device @@ -451,10 +471,7 @@ lowEnergyController->discoverServices(); - disconnect(timer, SIGNAL(timeout()), - this, SLOT(onRetryConnectToDevice())); - connect(timer, SIGNAL(timeout()), - this, SLOT(onRequestDeviceInformation())); + updateBLECuffCheckinType(false); if (!timer->isActive()) timer->start(); @@ -471,29 +488,6 @@ } /*! - * \brief BLEScanner::onControllerStateChanged - * Slot called when the low energy controller state changes - * \param state - the new state of the low energy controller - */ -void BLEScanner::onControllerStateChanged(const QLowEnergyController::ControllerState &state) -{ - qDebug() << __FUNCTION__ << state; - switch (state) { - case (QLowEnergyController::ClosingState): - emit didDisconnectFromDevice(selectedDeviceInfo); - break; - case (QLowEnergyController::UnconnectedState): - case (QLowEnergyController::ConnectingState): - case (QLowEnergyController::ConnectedState): - case (QLowEnergyController::DiscoveringState): - case (QLowEnergyController::DiscoveredState): - case (QLowEnergyController::AdvertisingState): - default: - break; - } -} - -/*! * \brief BLEScanner::connectToDevice * Creates the low energy controller object * Configures the low energy controller signals @@ -521,9 +515,6 @@ connect(lowEnergyController, SIGNAL(disconnected()), this, SLOT(onDeviceDisconnected())); - connect(lowEnergyController, SIGNAL(stateChanged(QLowEnergyController::ControllerState)), - this, SLOT(onControllerStateChanged(QLowEnergyController::ControllerState))); - emit didStartConnectingToDevice(); lowEnergyController->connectToDevice(); }