From 09b22dd66a2652201a626b72f24246596767d03b Mon Sep 17 00:00:00 2001 From: dogmaphobic Date: Wed, 9 Dec 2015 16:05:44 -0500 Subject: [PATCH] Bluetooth Cleanup --- QGCCommon.pri | 1 + qgroundcontrol.pro | 18 ++- src/QGCApplication.cc | 14 ++ src/QGCApplication.h | 85 ++++++----- src/comm/BluetoothLink.cc | 178 ++++++++++++++--------- src/comm/BluetoothLink.h | 38 ++++- src/comm/LinkConfiguration.cc | 12 +- src/comm/LinkConfiguration.h | 2 +- src/comm/LinkManager.cc | 16 +- src/comm/LinkManager.h | 14 +- src/main.cc | 4 +- src/ui/preferences/BluetoothSettings.qml | 7 + 12 files changed, 250 insertions(+), 139 deletions(-) diff --git a/QGCCommon.pri b/QGCCommon.pri index 52d71ef09..5cc86be83 100644 --- a/QGCCommon.pri +++ b/QGCCommon.pri @@ -36,6 +36,7 @@ linux { CONFIG += AndroidBuild MobileBuild DEFINES += __android__ DEFINES += __STDC_LIMIT_MACROS + DEFINES += QGC_ENABLE_BLUETOOTH target.path = $$DESTDIR } else { error("Unsuported Linux toolchain, only GCC 32- or 64-bit is supported") diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index e29b81351..da5e40132 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -44,6 +44,18 @@ exists(user_config.pri):infile(user_config.pri, CONFIG) { message($$sprintf("Using user-supplied additional config: '%1' specified in user_config.pri", $$fromfile(user_config.pri, CONFIG))) } +# Bluetooth +contains (DEFINES, QGC_DISABLE_BLUETOOTH) { + message("Skipping support for Bluetooth (manual override from command line)") + DEFINES -= QGC_ENABLE_BLUETOOTH +} else:exists(user_config.pri):infile(user_config.pri, DEFINES, QGC_DISABLE_BLUETOOTH) { + message("Skipping support for Bluetooth (manual override from user_config.pri)") + DEFINES -= QGC_ENABLE_BLUETOOTH +} else:exists(user_config.pri):infile(user_config.pri, DEFINES, QGC_ENABLE_BLUETOOTH) { + message("Including support for Bluetooth (manual override from user_config.pri)") + DEFINES += QGC_ENABLE_BLUETOOTH +} + LinuxBuild { CONFIG += link_pkgconfig } @@ -74,7 +86,7 @@ QT += \ serialport \ } -MobileBuild { +contains(DEFINES, QGC_ENABLE_BLUETOOTH) { QT += \ bluetooth \ } @@ -284,7 +296,7 @@ WindowsBuild { HEADERS += src/stable_headers.h } -MobileBuild { +contains(DEFINES, QGC_ENABLE_BLUETOOTH) { HEADERS += \ src/comm/BluetoothLink.h \ } @@ -402,7 +414,7 @@ SOURCES += \ src/ui/SerialConfigurationWindow.cc \ } -MobileBuild { +contains(DEFINES, QGC_ENABLE_BLUETOOTH) { SOURCES += \ src/comm/BluetoothLink.cc \ } diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index a0462f68f..e75d1c306 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -37,6 +37,10 @@ #include #include +#ifdef QGC_ENABLE_BLUETOOTH +#include +#endif + #include #include "VideoStreaming.h" @@ -170,6 +174,7 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) , _testHighDPI(false) #endif , _toolbox(NULL) + , _bluetoothAvailable(false) { Q_ASSERT(_app == NULL); _app = this; @@ -319,6 +324,15 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) settings.setValue(_settingsVersionKey, QGC_SETTINGS_VERSION); } + // Initialize Bluetooth +#ifdef QGC_ENABLE_BLUETOOTH + QBluetoothLocalDevice localDevice; + if (localDevice.isValid()) + { + _bluetoothAvailable = true; + } +#endif + // Initialize Video Streaming initializeVideoStreaming(argc, argv); diff --git a/src/QGCApplication.h b/src/QGCApplication.h index 492803950..ca4f98a21 100644 --- a/src/QGCApplication.h +++ b/src/QGCApplication.h @@ -1,24 +1,24 @@ /*===================================================================== - + QGroundControl Open Source Ground Control Station - + (c) 2009 - 2015 QGROUNDCONTROL PROJECT - + This file is part of the QGROUNDCONTROL project - + QGROUNDCONTROL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + QGROUNDCONTROL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with QGROUNDCONTROL. If not, see . - + ======================================================================*/ /** @@ -72,35 +72,35 @@ class QGCApplication : public #endif { Q_OBJECT - + public: QGCApplication(int &argc, char* argv[], bool unitTesting); ~QGCApplication(); - + /// @brief Sets the persistent flag to delete all settings the next time QGroundControl is started. void deleteAllSettingsNextBoot(void); - + /// @brief Clears the persistent flag to delete all settings the next time QGroundControl is started. void clearDeleteAllSettingsNextBoot(void); - + /// @brief Returns the location of user visible saved file associated with QGroundControl QString savedFilesLocation(void); - + /// @brief Sets the location of user visible saved file associated with QGroundControl void setSavedFilesLocation(QString& location); - + /// @brief Location to save and load parameter files from. QString savedParameterFilesLocation(void); - + /// @brief Location to save and load mavlink log files from QString mavlinkLogFilesLocation(void); - + /// @brief Validates that the specified location will work for the saved files location. bool validatePossibleSavedFilesLocation(QString& location); - + /// @return true: Prompt to save log file when vehicle goes away bool promptFlightDataSave(void); - + /// @return true: Prompt to save log file even if vehicle was not armed bool promptFlightDataSaveNotArmed(void); @@ -109,13 +109,13 @@ public: /// @brief Returns truee if unit test are being run bool runningUnitTests(void) { return _runningUnitTests; } - + /// @return true: dark ui style, false: light ui style bool styleIsDark(void) { return _styleIsDark; } - + /// Set the current UI style void setStyle(bool styleIsDark); - + /// Used to report a missing Parameter. Warning will be displayed to user. Method may be called /// multiple times. void reportMissingParameter(int componentId, const QString& name); @@ -123,26 +123,29 @@ public: /// Show a non-modal message to the user void showMessage(const QString& message); - /// @return true: Fake ui into showing mobile interface - bool fakeMobile(void) { return _fakeMobile; } - + /// @return true: Fake ui into showing mobile interface + bool fakeMobile(void) { return _fakeMobile; } + #ifdef QT_DEBUG bool testHighDPI(void) { return _testHighDPI; } #endif // Still working on getting rid of this and using dependency injection instead for everything QGCToolbox* toolbox(void) { return _toolbox; } - + + /// Do we have Bluetooth Support? + bool isBluetoothAvailable() { return _bluetoothAvailable; } + public slots: /// You can connect to this slot to show an information message box from a different thread. void informationMessageBoxOnMainThread(const QString& title, const QString& msg); - + /// You can connect to this slot to show a warning message box from a different thread. void warningMessageBoxOnMainThread(const QString& title, const QString& msg); - + /// You can connect to this slot to show a critical message box from a different thread. void criticalMessageBoxOnMainThread(const QString& title, const QString& msg); - + void showFlyView(void); void showPlanView(void); void showSetupView(void); @@ -158,14 +161,14 @@ signals: /// Signals that the style has changed /// @param darkStyle true: dark style, false: light style void styleChanged(bool darkStyle); - + /// This is connected to MAVLinkProtocol::checkForLostLogFiles. We signal this to ourselves to call the slot /// on the MAVLinkProtocol thread; void checkForLostLogFiles(void); - + public: // Although public, these methods are internal and should only be called by UnitTest code - + /// @brief Perform initialize which is common to both normal application running and unit tests. /// Although public should only be called by main. void _initCommon(void); @@ -173,7 +176,7 @@ public: /// @brief Intialize the application for normal application boot. Or in other words we are not going to run /// unit tests. Although public should only be called by main. bool _initForNormalAppBoot(void); - + /// @brief Intialize the application for normal application boot. Or in other words we are not going to run /// unit tests. Although public should only be called by main. bool _initForUnitTests(void); @@ -182,12 +185,12 @@ public: void _showSetupParameters(void); void _showSetupSummary(void); void _showSetupVehicleComponent(VehicleComponent* vehicleComponent); - + static QGCApplication* _app; ///< Our own singleton. Should be reference directly by qgcApp - + private slots: void _missingParamsDisplay(void); - + private: void _loadCurrentStyle(void); QObject* _rootQmlObject(void); @@ -195,36 +198,38 @@ private: #ifdef __mobile__ QQmlApplicationEngine* _qmlAppEngine; #endif - + static const char* _settingsVersionKey; ///< Settings key which hold settings version static const char* _deleteAllSettingsKey; ///< If this settings key is set on boot, all settings will be deleted static const char* _savedFilesLocationKey; ///< Settings key for user visible saved files location static const char* _promptFlightDataSave; ///< Settings key for promptFlightDataSave static const char* _promptFlightDataSaveNotArmed; ///< Settings key for promptFlightDataSaveNotArmed static const char* _styleKey; ///< Settings key for UI style - + static const char* _defaultSavedFileDirectoryName; ///< Default name for user visible save file directory static const char* _savedFileMavlinkLogDirectoryName; ///< Name of mavlink log subdirectory static const char* _savedFileParameterDirectoryName; ///< Name of parameter subdirectory bool _runningUnitTests; ///< true: running unit tests, false: normal app - + static const char* _darkStyleFile; static const char* _lightStyleFile; bool _styleIsDark; ///< true: dark style, false: light style - + static const int _missingParamsDelayedDisplayTimerTimeout = 1000; ///< Timeout to wait for next missing fact to come in before display QTimer _missingParamsDelayedDisplayTimer; ///< Timer use to delay missing fact display QStringList _missingParams; ///< List of missing facts to be displayed - bool _fakeMobile; ///< true: Fake ui into displaying mobile interface - + bool _fakeMobile; ///< true: Fake ui into displaying mobile interface + #ifdef QT_DEBUG bool _testHighDPI; ///< true: double fonts sizes for simulating high dpi devices #endif QGCToolbox* _toolbox; + bool _bluetoothAvailable; + /// Unit Test have access to creating and destroying singletons friend class UnitTest; }; diff --git a/src/comm/BluetoothLink.cc b/src/comm/BluetoothLink.cc index 69895e54f..85df7528b 100644 --- a/src/comm/BluetoothLink.cc +++ b/src/comm/BluetoothLink.cc @@ -34,42 +34,26 @@ This file is part of the QGROUNDCONTROL project #include #include -#include #include #include #include +#include #include "BluetoothLink.h" #include "QGC.h" -/* -static void print_device_info(QBluetoothDeviceInfo info) -{ - qDebug() << "Bluetooth: " << info.name(); - qDebug() << " Services:" << info.serviceClasses(); - qDebug() << " Major Classs:" << info.majorDeviceClass(); - qDebug() << " Minor Classs:" << info.minorDeviceClass(); - qDebug() << " RSSI:" << info.rssi(); - qDebug() << " UUID:" << info.deviceUuid(); - qDebug() << " Service UUID:" << info.serviceUuids(); - qDebug() << " Core Config:" << info.coreConfigurations(); - qDebug() << " Valid:" << info.isValid(); - qDebug() << " Address:" << info.address().toString(); -} -*/ - BluetoothLink::BluetoothLink(BluetoothConfiguration* config) : _connectState(false) , _targetSocket(NULL) - , _targetDevice(NULL) - , _running(false) +#ifdef __ios__ + , _discoveryAgent(NULL) +#endif + , _shutDown(false) { Q_ASSERT(config != NULL); _config = config; _config->setLink(this); - // We're doing it wrong - because the Qt folks got the API wrong: - // http://blog.qt.digia.com/blog/2010/06/17/youre-doing-it-wrong/ - moveToThread(this); + //moveToThread(this); } BluetoothLink::~BluetoothLink() @@ -77,19 +61,18 @@ BluetoothLink::~BluetoothLink() // Disconnect link from configuration _config->setLink(NULL); _disconnect(); - // Tell the thread to exit - _running = false; - quit(); - // Wait for it to exit - wait(); - this->deleteLater(); +#ifdef __ios__ + if(_discoveryAgent) { + _shutDown = true; + _discoveryAgent->stop(); + _discoveryAgent->deleteLater(); + _discoveryAgent = NULL; + } +#endif } void BluetoothLink::run() { - if(_running && _hardwareConnect()) { - exec(); - } } void BluetoothLink::_restartConnection() @@ -142,17 +125,17 @@ void BluetoothLink::readBytes() void BluetoothLink::_disconnect(void) { - _running = false; - quit(); - wait(); - if(_targetDevice) - { - delete _targetDevice; - _targetDevice = NULL; +#ifdef __ios__ + if(_discoveryAgent) { + _shutDown = true; + _discoveryAgent->stop(); + _discoveryAgent->deleteLater(); + _discoveryAgent = NULL; } +#endif if(_targetSocket) { - _targetSocket->deleteLater(); + delete _targetSocket; _targetSocket = NULL; emit disconnected(); } @@ -161,43 +144,86 @@ void BluetoothLink::_disconnect(void) bool BluetoothLink::_connect(void) { - if(this->isRunning() || _running) - { - _running = false; - quit(); - wait(); - } - if(_targetDevice) - { - delete _targetDevice; - _targetDevice = NULL; - } - //-- Start Thread - _running = true; - start(NormalPriority); + _hardwareConnect(); return true; } bool BluetoothLink::_hardwareConnect() +{ +#ifdef __ios__ + if(_discoveryAgent) { + _shutDown = true; + _discoveryAgent->stop(); + _discoveryAgent->deleteLater(); + _discoveryAgent = NULL; + } + _discoveryAgent = new QBluetoothServiceDiscoveryAgent(this); + QObject::connect(_discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), this, SLOT(serviceDiscovered(QBluetoothServiceInfo))); + QObject::connect(_discoveryAgent, SIGNAL(finished()), this, SLOT(discoveryFinished())); + QObject::connect(_discoveryAgent, SIGNAL(canceled()), this, SLOT(discoveryFinished())); + QObject::connect(_discoveryAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)),this, SLOT(discoveryError(QBluetoothServiceDiscoveryAgent::Error))); + _shutDown = false; + _discoveryAgent->start(); +#else + _createSocket(); + _targetSocket->connectToService(QBluetoothAddress(_config->device().address), QBluetoothUuid(QBluetoothUuid::Rfcomm)); +#endif + return true; +} + +void BluetoothLink::_createSocket() { if(_targetSocket) { delete _targetSocket; _targetSocket = NULL; } - _targetDevice = new QBluetoothDeviceInfo(QBluetoothAddress(_config->device().address), _config->device().name, _config->device().bits); - _targetDevice->setCoreConfigurations(QBluetoothDeviceInfo::BaseRateCoreConfiguration); _targetSocket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol, this); - _targetSocket->moveToThread(this); - //print_device_info(*_targetDevice); QObject::connect(_targetSocket, SIGNAL(connected()), this, SLOT(deviceConnected())); QObject::connect(_targetSocket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(deviceError(QBluetoothSocket::SocketError))); QObject::connect(_targetSocket, SIGNAL(readyRead()), this, SLOT(readBytes())); QObject::connect(_targetSocket, SIGNAL(disconnected()), this, SLOT(deviceDisconnected())); - _targetSocket->connectToService(_targetDevice->address(), QBluetoothUuid(QBluetoothUuid::Rfcomm)); - return true; } +#ifdef __ios__ +void BluetoothLink::discoveryError(QBluetoothServiceDiscoveryAgent::Error error) +{ + qDebug() << "Discovery error:" << error; + qDebug() << _discoveryAgent->errorString(); +} +#endif + +#ifdef __ios__ +void BluetoothLink::serviceDiscovered(const QBluetoothServiceInfo& info) +{ + if(!info.device().name().isEmpty() && !_targetSocket) + { + if(_config->device().uuid == info.device().deviceUuid() && _config->device().name == info.device().name()) + { + _createSocket(); + _targetSocket->connectToService(info); + } + } +} +#endif + +#ifdef __ios__ +void BluetoothLink::discoveryFinished() +{ + if(_discoveryAgent && !_shutDown) + { + _shutDown = true; + _discoveryAgent->deleteLater(); + _discoveryAgent = NULL; + if(!_targetSocket) + { + _connectState = false; + emit communicationError("Could not locate Bluetooth device:", _config->device().name); + } + } +} +#endif + void BluetoothLink::deviceConnected() { _connectState = true; @@ -274,18 +300,25 @@ void BluetoothConfiguration::copyFrom(LinkConfiguration *source) void BluetoothConfiguration::saveSettings(QSettings& settings, const QString& root) { settings.beginGroup(root); - settings.setValue("name", _device.name); - settings.setValue("address", _device.address); - settings.setValue("bits", _device.bits); + settings.setValue("deviceName", _device.name); +#ifdef __ios__ + settings.setValue("uuid", _device.uuid.toString()); +#else + settings.setValue("address",_device.address); +#endif settings.endGroup(); } void BluetoothConfiguration::loadSettings(QSettings& settings, const QString& root) { settings.beginGroup(root); - _device.name = settings.value("name", _device.name).toString(); + _device.name = settings.value("deviceName", _device.name).toString(); +#ifdef __ios__ + QString suuid = settings.value("uuid", _device.uuid.toString()).toString(); + _device.uuid = QUuid(suuid); +#else _device.address = settings.value("address", _device.address).toString(); - _device.bits = settings.value("bits", _device.bits).toUInt(); +#endif settings.endGroup(); } @@ -337,10 +370,11 @@ void BluetoothConfiguration::deviceDiscovered(QBluetoothDeviceInfo info) { BluetoothData data; data.name = info.name(); +#ifdef __ios__ + data.uuid = info.deviceUuid(); +#else data.address = info.address().toString(); - data.bits |= ((qint32)info.serviceClasses() << 13); // Service Class - data.bits |= ((qint32)info.majorDeviceClass() << 8); // CLASS MAJOR - data.bits |= ((qint32)info.minorDeviceClass() << 2); // CLASS MINOR +#endif if(!_deviceList.contains(data)) { _deviceList += data; @@ -369,9 +403,19 @@ void BluetoothConfiguration::setDevName(const QString &name) { _device = data; emit devNameChanged(); +#ifndef __ios__ emit addressChanged(); +#endif return; } } } +QString BluetoothConfiguration::address() +{ +#ifdef __ios__ + return QString(""); +#else + return _device.address; +#endif +} diff --git a/src/comm/BluetoothLink.h b/src/comm/BluetoothLink.h index 8311c630c..1767cc1a4 100644 --- a/src/comm/BluetoothLink.h +++ b/src/comm/BluetoothLink.h @@ -39,18 +39,20 @@ This file is part of the QGROUNDCONTROL project #include #include #include +#include +#include #include "QGCConfig.h" #include "LinkManager.h" class QBluetoothDeviceDiscoveryAgent; +class QBluetoothServiceDiscoveryAgent; class BluetoothData { public: BluetoothData() { - bits = 0; } BluetoothData(const BluetoothData& other) { @@ -58,18 +60,28 @@ public: } bool operator==(const BluetoothData& other) { - return bits == other.bits && name == other.name && address == other.address; +#ifdef __ios__ + return uuid == other.uuid && name == other.name; +#else + return name == other.name && address == other.address; +#endif } BluetoothData& operator=(const BluetoothData& other) { - bits = other.bits; name = other.name; +#ifdef __ios__ + uuid = other.uuid; +#else address = other.address; +#endif return *this; } - quint32 bits; QString name; +#ifdef __ios__ + QBluetoothUuid uuid; +#else QString address; +#endif }; class BluetoothConfiguration : public LinkConfiguration @@ -91,7 +103,7 @@ public: Q_INVOKABLE void stopScan (); QString devName () { return _device.name; } - QString address () { return _device.address; } + QString address (); QStringList nameList () { return _nameList; } bool scanning () { return _deviceDiscover != NULL; } @@ -159,6 +171,11 @@ public slots: void deviceConnected (); void deviceDisconnected (); void deviceError (QBluetoothSocket::SocketError error); +#ifdef __ios__ + void serviceDiscovered (const QBluetoothServiceInfo &info); + void discoveryFinished (); + void discoveryError (QBluetoothServiceDiscoveryAgent::Error error); +#endif protected: @@ -177,12 +194,17 @@ private: bool _hardwareConnect (); void _restartConnection (); void _sendBytes (const char* data, qint64 size); + void _createSocket (); private: - QBluetoothSocket* _targetSocket; - QBluetoothDeviceInfo* _targetDevice; - bool _running; + QBluetoothSocket* _targetSocket; +#ifdef __ios__ + QBluetoothServiceDiscoveryAgent* _discoveryAgent; +#endif + + bool _shutDown; + }; #endif // BTLINK_H diff --git a/src/comm/LinkConfiguration.cc b/src/comm/LinkConfiguration.cc index 0779af060..9e84bc3b9 100644 --- a/src/comm/LinkConfiguration.cc +++ b/src/comm/LinkConfiguration.cc @@ -36,7 +36,7 @@ This file is part of the QGROUNDCONTROL project #ifndef __mobile__ #include "LogReplayLink.h" #endif -#ifdef __mobile__ +#ifdef QGC_ENABLE_BLUETOOTH #include "BluetoothLink.h" #endif #ifdef QT_DEBUG @@ -103,7 +103,7 @@ LinkConfiguration* LinkConfiguration::createSettings(int type, const QString& na case LinkConfiguration::TypeTcp: config = new TCPConfiguration(name); break; -#ifdef __mobile__ +#ifdef QGC_ENABLE_BLUETOOTH case LinkConfiguration::TypeBluetooth: config = new BluetoothConfiguration(name); break; @@ -141,10 +141,10 @@ LinkConfiguration* LinkConfiguration::duplicateSettings(LinkConfiguration* sourc case TypeTcp: dupe = new TCPConfiguration(dynamic_cast(source)); break; -#ifdef __mobile__ - case TypeBluetooth: - dupe = new BluetoothConfiguration(dynamic_cast(source)); - break; +#ifdef QGC_ENABLE_BLUETOOTH + case TypeBluetooth: + dupe = new BluetoothConfiguration(dynamic_cast(source)); + break; #endif #ifndef __mobile__ case TypeLogReplay: diff --git a/src/comm/LinkConfiguration.h b/src/comm/LinkConfiguration.h index a874329a8..26249b0ec 100644 --- a/src/comm/LinkConfiguration.h +++ b/src/comm/LinkConfiguration.h @@ -64,7 +64,7 @@ public: #endif TypeUdp, ///< UDP Link TypeTcp, ///< TCP Link -#ifdef __mobile__ +#ifdef QGC_ENABLE_BLUETOOTH TypeBluetooth, ///< Bluetooth Link #endif #if 0 diff --git a/src/comm/LinkManager.cc b/src/comm/LinkManager.cc index a023ad559..5f8bc4a29 100644 --- a/src/comm/LinkManager.cc +++ b/src/comm/LinkManager.cc @@ -39,10 +39,9 @@ This file is part of the QGROUNDCONTROL project #include "LinkManager.h" #include "QGCApplication.h" -#include "QGCApplication.h" #include "UDPLink.h" #include "TCPLink.h" -#ifdef __mobile__ +#ifdef QGC_ENABLE_BLUETOOTH #include "BluetoothLink.h" #endif @@ -125,7 +124,7 @@ LinkInterface* LinkManager::createConnectedLink(LinkConfiguration* config) case LinkConfiguration::TypeTcp: pLink = new TCPLink(dynamic_cast(config)); break; -#ifdef __mobile__ +#ifdef QGC_ENABLE_BLUETOOTH case LinkConfiguration::TypeBluetooth: pLink = new BluetoothLink(dynamic_cast(config)); break; @@ -361,7 +360,7 @@ void LinkManager::loadLinkConfigurationList() case LinkConfiguration::TypeTcp: pLink = (LinkConfiguration*)new TCPConfiguration(name); break; -#ifdef __mobile__ +#ifdef QGC_ENABLE_BLUETOOTH case LinkConfiguration::TypeBluetooth: pLink = (LinkConfiguration*)new BluetoothConfiguration(name); break; @@ -708,7 +707,7 @@ QStringList LinkManager::linkTypeStrings(void) const #endif list += "UDP"; list += "TCP"; -#ifdef __mobile__ +#ifdef QGC_ENABLE_BLUETOOTH list += "Bluetooth"; #endif #ifdef QT_DEBUG @@ -839,7 +838,7 @@ void LinkManager::_fixUnnamed(LinkConfiguration* config) } } break; -#ifdef __mobile__ +#ifdef QGC_ENABLE_BLUETOOTH case LinkConfiguration::TypeBluetooth: { BluetoothConfiguration* tconfig = dynamic_cast(config); if(tconfig) { @@ -888,3 +887,8 @@ bool LinkManager::isAutoconnectLink(LinkInterface* link) { return _autoconnectConfigurations.contains(link->getLinkConfiguration()); } + +bool LinkManager::isBluetoothAvailable(void) +{ + return qgcApp()->isBluetoothAvailable(); +} diff --git a/src/comm/LinkManager.h b/src/comm/LinkManager.h index 473a20679..71e96ba2c 100644 --- a/src/comm/LinkManager.h +++ b/src/comm/LinkManager.h @@ -80,6 +80,7 @@ public: Q_PROPERTY(bool autoconnectPixhawk READ autoconnectPixhawk WRITE setAutoconnectPixhawk NOTIFY autoconnectPixhawkChanged) Q_PROPERTY(bool autoconnect3DRRadio READ autoconnect3DRRadio WRITE setAutoconnect3DRRadio NOTIFY autoconnect3DRRadioChanged) Q_PROPERTY(bool autoconnectPX4Flow READ autoconnectPX4Flow WRITE setAutoconnectPX4Flow NOTIFY autoconnectPX4FlowChanged) + Q_PROPERTY(bool isBluetoothAvailable READ isBluetoothAvailable CONSTANT) /// LinkInterface Accessor Q_PROPERTY(QmlObjectListModel* links READ links CONSTANT) @@ -104,12 +105,13 @@ public: // Property accessors - bool anyConnectedLinks(void); - bool anyActiveLinks(void); - bool autoconnectUDP(void) { return _autoconnectUDP; } - bool autoconnectPixhawk(void) { return _autoconnectPixhawk; } - bool autoconnect3DRRadio(void) { return _autoconnect3DRRadio; } - bool autoconnectPX4Flow(void) { return _autoconnectPX4Flow; } + bool anyConnectedLinks (void); + bool anyActiveLinks (void); + bool autoconnectUDP (void) { return _autoconnectUDP; } + bool autoconnectPixhawk (void) { return _autoconnectPixhawk; } + bool autoconnect3DRRadio (void) { return _autoconnect3DRRadio; } + bool autoconnectPX4Flow (void) { return _autoconnectPX4Flow; } + bool isBluetoothAvailable (void); QmlObjectListModel* links (void) { return &_links; } QmlObjectListModel* linkConfigurations (void) { return &_linkConfigurations; } diff --git a/src/main.cc b/src/main.cc index d377c9d76..c71f48359 100644 --- a/src/main.cc +++ b/src/main.cc @@ -49,7 +49,7 @@ This file is part of the QGROUNDCONTROL project #endif #endif -#ifdef __mobile__ +#ifdef QGC_ENABLE_BLUETOOTH #include #endif @@ -139,7 +139,7 @@ int main(int argc, char *argv[]) #ifndef __ios__ qRegisterMetaType(); #endif -#ifdef __mobile__ +#ifdef QGC_ENABLE_BLUETOOTH qRegisterMetaType(); qRegisterMetaType(); #endif diff --git a/src/ui/preferences/BluetoothSettings.qml b/src/ui/preferences/BluetoothSettings.qml index e6d7e18cc..512b5d04e 100644 --- a/src/ui/preferences/BluetoothSettings.qml +++ b/src/ui/preferences/BluetoothSettings.qml @@ -39,9 +39,16 @@ Item { // No need } + QGCLabel { + text: "Bluetooth Not Available" + visible: !QGroundControl.linkManager.isBluetoothAvailable + anchors.centerIn: parent + } + Column { id: btColumn spacing: ScreenTools.defaultFontPixelHeight / 2 + visible: QGroundControl.linkManager.isBluetoothAvailable ExclusiveGroup { id: linkGroup } -- 2.22.0