summaryrefslogtreecommitdiffstats
path: root/core/qt-ble.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-06 07:21:04 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-06 09:35:04 -0700
commit4834f51a73cab52ff31c59b21b36744eb751687e (patch)
treec26242707f9cdae39df18034d82b2e427f6fdaaf /core/qt-ble.cpp
parentc9c9a8390a9a4187e2b7155539fb5cd1968c10c8 (diff)
downloadsubsurface-4834f51a73cab52ff31c59b21b36744eb751687e.tar.gz
BLE: reduce the noise of debug output
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/qt-ble.cpp')
-rw-r--r--core/qt-ble.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp
index 71ac9bcbf..ff4bc3eda 100644
--- a/core/qt-ble.cpp
+++ b/core/qt-ble.cpp
@@ -10,6 +10,7 @@
#include <QThread>
#include <QTimer>
#include <QDebug>
+#include <QLoggingCategory>
#include <libdivecomputer/version.h>
@@ -21,6 +22,8 @@
#include <libdivecomputer/custom_io.h>
#define BLE_TIMEOUT 12000 // 12 seconds seems like a very long time to wait
+#define DEBUG_THRESHOLD 20
+static int debugCounter;
#define IS_HW(_d) same_string((_d)->vendor, "Heinrichs Weikamp")
#define IS_SHEARWATER(_d) same_string((_d)->vendor, "Shearwater")
@@ -79,7 +82,8 @@ void BLEObject::characteristicWritten(const QLowEnergyCharacteristic &c, const Q
isCharacteristicWritten = true;
}
} else {
- qDebug() << "BLEObject::characteristicWritten";
+ if (debugCounter < DEBUG_THRESHOLD)
+ qDebug() << "BLEObject::characteristicWritten";
}
}
@@ -124,6 +128,7 @@ BLEObject::BLEObject(QLowEnergyController *c, dc_user_device_t *d)
{
controller = c;
device = d;
+ debugCounter = 0;
}
BLEObject::~BLEObject()
@@ -271,6 +276,9 @@ dc_status_t BLEObject::setupHwTerminalIo(QList<QLowEnergyCharacteristic> allC)
dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *devaddr)
{
Q_UNUSED(context)
+ debugCounter = 0;
+ QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));
+
/*
* LE-only devices get the "LE:" prepended by the scanning
* code, so that the rfcomm code can see they only do LE.
@@ -398,15 +406,24 @@ dc_status_t qt_ble_close(dc_custom_io_t *io)
return DC_STATUS_SUCCESS;
}
+static void checkThreshold()
+{
+ if (++debugCounter == DEBUG_THRESHOLD) {
+ QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = false"));
+ qDebug() << "turning off further BT debug output";
+ }
+}
dc_status_t qt_ble_read(dc_custom_io_t *io, void* data, size_t size, size_t *actual)
{
+ checkThreshold();
BLEObject *ble = (BLEObject *) io->userdata;
return ble->read(data, size, actual);
}
dc_status_t qt_ble_write(dc_custom_io_t *io, const void* data, size_t size, size_t *actual)
{
+ checkThreshold();
BLEObject *ble = (BLEObject *) io->userdata;
return ble->write(data, size, actual);
}