QML UI: move BT handling into core code

This shouldn't be part of the UI (qmlmanager), but part of our
overall handling of dive computers and BT devices.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2017-06-05 19:41:57 -07:00
parent 3b993fbaad
commit b14a522f4f
8 changed files with 305 additions and 199 deletions

View file

@ -99,8 +99,15 @@ void fill_computer_list()
#endif
}
DCDeviceData *DCDeviceData::m_instance = NULL;
DCDeviceData::DCDeviceData(QObject *parent) : QObject(parent)
{
if (m_instance) {
qDebug() << "already have an instance of DCDevieData";
return;
}
m_instance = this;
memset(&data, 0, sizeof(data));
data.trip = nullptr;
data.download_table = nullptr;
@ -108,6 +115,18 @@ DCDeviceData::DCDeviceData(QObject *parent) : QObject(parent)
data.deviceid = 0;
}
DCDeviceData *DCDeviceData::instance()
{
if (!m_instance)
m_instance = new DCDeviceData();
return m_instance;
}
QStringList DCDeviceData::getProductListFromVendor(const QString &vendor)
{
return productList[vendor];
}
DCDeviceData * DownloadThread::data()
{
return m_data;
@ -222,3 +241,40 @@ device_data_t* DCDeviceData::internalData()
{
return &data;
}
int DCDeviceData::getDetectedVendorIndex()
{
#if defined(BT_SUPPORT)
QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
if (!btDCs.isEmpty()) {
qDebug() << "getVendorIdx" << btDCs.first().vendorIdx;
return btDCs.first().vendorIdx;
}
#endif
return -1;
}
int DCDeviceData::getDetectedProductIndex()
{
#if defined(BT_SUPPORT)
QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
if (!btDCs.isEmpty()) {
qDebug() << "getProductIdx" << btDCs.first().productIdx;
return btDCs.first().productIdx;
}
#endif
return -1;
}
QString DCDeviceData::getDetectedDeviceAddress()
{
#if BT_SUPPORT
QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
if (!btDCs.isEmpty()) {
QString btAddr = btDCs.first().btdi.address().toString();
qDebug() << "getBtAddress" << btAddr;
return btAddr;
}
return QString();
#endif
}