2017-06-06 02:41:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef BTDISCOVERY_H
|
|
|
|
#define BTDISCOVERY_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QLoggingCategory>
|
2017-07-17 04:45:21 +00:00
|
|
|
#include <QAbstractListModel>
|
2017-06-06 02:41:57 +00:00
|
|
|
#include <QBluetoothLocalDevice>
|
|
|
|
#include <QBluetoothDeviceDiscoveryAgent>
|
|
|
|
#include <QBluetoothUuid>
|
2017-06-10 12:22:28 +00:00
|
|
|
#include "core/libdivecomputer.h"
|
2017-06-06 02:41:57 +00:00
|
|
|
|
|
|
|
#if defined(Q_OS_ANDROID)
|
|
|
|
#include <QAndroidJniObject>
|
2017-06-11 22:45:46 +00:00
|
|
|
#include <QAndroidJniEnvironment>
|
2017-06-06 02:41:57 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-24 23:17:33 +00:00
|
|
|
void saveBtDeviceInfo(const QString &devaddr, QBluetoothDeviceInfo deviceInfo);
|
2018-09-25 00:39:33 +00:00
|
|
|
bool isBluetoothAddress(const QString &address);
|
2019-02-12 15:35:35 +00:00
|
|
|
bool matchesKnownDiveComputerNames(QString btName);
|
2018-09-27 13:21:04 +00:00
|
|
|
QString extractBluetoothAddress(const QString &address);
|
|
|
|
QString extractBluetoothNameAddress(const QString &address, QString &name);
|
2018-02-24 23:17:33 +00:00
|
|
|
QBluetoothDeviceInfo getBtDeviceInfo(const QString &devaddr);
|
2017-09-17 03:19:41 +00:00
|
|
|
|
2019-09-27 23:26:54 +00:00
|
|
|
class BTDiscovery : public QObject {
|
2017-06-06 02:41:57 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
BTDiscovery(QObject *parent = NULL);
|
|
|
|
~BTDiscovery();
|
2019-09-27 23:26:54 +00:00
|
|
|
static BTDiscovery *instance();
|
2017-06-06 02:41:57 +00:00
|
|
|
|
|
|
|
struct btPairedDevice {
|
2017-06-30 02:47:51 +00:00
|
|
|
QString address;
|
2017-06-06 02:41:57 +00:00
|
|
|
QString name;
|
|
|
|
};
|
Mobile: wrap up fixes for BT download on Android
Major functional change in this commit is the addition of found static BT devices
to the internal administration (on Android), in a way that is equivalent to
mobile-on-desktop. So, in both cases, the list of devices in the app are
as in the list of devices on the host OS (Linux or Android). To minimize code
duplication, the btDeviceDiscovered slot is split in two parts, the part to
act as slot for the Qt BT discovery agent (Linux, so mobile-on-desktop), and
the part only needed for Android.
Remaining to be fixed: the correct handling of the QML UI selection of
vendor/product. The first default dive computer is correctly detected,
all paired devices from the virtual vendow can be selected, but clicking
through vendors results in non logical selections. It is obvious why
this is, but a fix is not straigforward at this point.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-12 08:38:24 +00:00
|
|
|
|
|
|
|
struct btVendorProduct {
|
|
|
|
btPairedDevice btpdi;
|
|
|
|
dc_descriptor_t *dcDescriptor;
|
|
|
|
int vendorIdx;
|
|
|
|
int productIdx;
|
|
|
|
};
|
|
|
|
|
2017-06-06 02:41:57 +00:00
|
|
|
void btDeviceDiscovered(const QBluetoothDeviceInfo &device);
|
Mobile: wrap up fixes for BT download on Android
Major functional change in this commit is the addition of found static BT devices
to the internal administration (on Android), in a way that is equivalent to
mobile-on-desktop. So, in both cases, the list of devices in the app are
as in the list of devices on the host OS (Linux or Android). To minimize code
duplication, the btDeviceDiscovered slot is split in two parts, the part to
act as slot for the Qt BT discovery agent (Linux, so mobile-on-desktop), and
the part only needed for Android.
Remaining to be fixed: the correct handling of the QML UI selection of
vendor/product. The first default dive computer is correctly detected,
all paired devices from the virtual vendow can be selected, but clicking
through vendors results in non logical selections. It is obvious why
this is, but a fix is not straigforward at this point.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-12 08:38:24 +00:00
|
|
|
void btDeviceDiscoveredMain(const btPairedDevice &device);
|
2017-07-12 11:13:25 +00:00
|
|
|
bool btAvailable() const;
|
2019-02-14 06:48:50 +00:00
|
|
|
void showNonDiveComputers(bool show);
|
|
|
|
|
2017-06-06 02:41:57 +00:00
|
|
|
#if defined(Q_OS_ANDROID)
|
|
|
|
void getBluetoothDevices();
|
|
|
|
#endif
|
Mobile: wrap up fixes for BT download on Android
Major functional change in this commit is the addition of found static BT devices
to the internal administration (on Android), in a way that is equivalent to
mobile-on-desktop. So, in both cases, the list of devices in the app are
as in the list of devices on the host OS (Linux or Android). To minimize code
duplication, the btDeviceDiscovered slot is split in two parts, the part to
act as slot for the Qt BT discovery agent (Linux, so mobile-on-desktop), and
the part only needed for Android.
Remaining to be fixed: the correct handling of the QML UI selection of
vendor/product. The first default dive computer is correctly detected,
all paired devices from the virtual vendow can be selected, but clicking
through vendors results in non logical selections. It is obvious why
this is, but a fix is not straigforward at this point.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-12 08:38:24 +00:00
|
|
|
QList<btVendorProduct> getBtDcs();
|
2017-10-12 07:43:40 +00:00
|
|
|
QBluetoothLocalDevice localBtDevice;
|
|
|
|
void BTDiscoveryReDiscover();
|
2018-09-26 03:04:02 +00:00
|
|
|
void discoverAddress(QString address);
|
2017-10-06 14:52:17 +00:00
|
|
|
|
2017-06-06 02:41:57 +00:00
|
|
|
private:
|
2019-09-27 23:26:54 +00:00
|
|
|
static BTDiscovery *m_instance;
|
2017-07-12 11:13:25 +00:00
|
|
|
bool m_btValid;
|
2019-02-14 06:48:50 +00:00
|
|
|
bool m_showNonDiveComputers;
|
2017-10-06 14:52:17 +00:00
|
|
|
|
2017-06-10 08:09:56 +00:00
|
|
|
QList<struct btVendorProduct> btDCs; // recognized DCs
|
|
|
|
QList<struct btVendorProduct> btAllDevices; // all paired BT stuff
|
2017-10-06 14:52:17 +00:00
|
|
|
|
2017-06-06 02:41:57 +00:00
|
|
|
#if defined(Q_OS_ANDROID)
|
|
|
|
bool checkException(const char* method, const QAndroidJniObject* obj);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QList<struct btPairedDevice> btPairedDevices;
|
|
|
|
QBluetoothDeviceDiscoveryAgent *discoveryAgent;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void dcVendorChanged();
|
|
|
|
void dcProductChanged();
|
|
|
|
void dcBtChanged();
|
|
|
|
};
|
|
|
|
#endif // BTDISCOVERY_H
|