subsurface/core/btdiscovery.h
Dirk Hohndel 345e063eb5 Rewrite the matching code for BT devices
This should be much more robust in getting us the correct Bluetooth address
and the correct vendor / product for our selection.

When we pick a paired device, we extract the address right from its name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-03 21:58:26 -07:00

70 lines
1.5 KiB
C++

// SPDX-License-Identifier: GPL-2.0
#ifndef BTDISCOVERY_H
#define BTDISCOVERY_H
#include <QObject>
#include <QString>
#include <QLoggingCategory>
#if defined(BT_SUPPORT)
#include <QBluetoothLocalDevice>
#include <QBluetoothDeviceDiscoveryAgent>
#include <QBluetoothUuid>
#include "core/libdivecomputer.h"
#endif
#if defined(Q_OS_ANDROID)
#include <QAndroidJniObject>
#include <QAndroidJniEnvironment>
#endif
class BTDiscovery : public QObject {
Q_OBJECT
public:
BTDiscovery(QObject *parent = NULL);
~BTDiscovery();
static BTDiscovery *instance();
#if defined(BT_SUPPORT)
struct btPairedDevice {
QString address;
QString name;
};
struct btVendorProduct {
btPairedDevice btpdi;
dc_descriptor_t *dcDescriptor;
int vendorIdx;
int productIdx;
};
void btDeviceDiscovered(const QBluetoothDeviceInfo &device);
void btDeviceDiscoveredMain(const btPairedDevice &device);
#if defined(Q_OS_ANDROID)
void getBluetoothDevices();
#endif
QList<btVendorProduct> getBtDcs();
#endif
private:
static BTDiscovery *m_instance;
#if defined(BT_SUPPORT)
QList<struct btVendorProduct> btDCs; // recognized DCs
QList<struct btVendorProduct> btAllDevices; // all paired BT stuff
#endif
#if defined(Q_OS_ANDROID)
bool checkException(const char* method, const QAndroidJniObject* obj);
#endif
#if defined(BT_SUPPORT)
QList<struct btPairedDevice> btPairedDevices;
QBluetoothLocalDevice localBtDevice;
QBluetoothDeviceDiscoveryAgent *discoveryAgent;
#endif
signals:
void dcVendorChanged();
void dcProductChanged();
void dcBtChanged();
};
#endif // BTDISCOVERY_H