summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/bluetooth/heartrate-game/devicefinder.cpp9
-rw-r--r--examples/bluetooth/heartrate-game/devicehandler.cpp12
2 files changed, 21 insertions, 0 deletions
diff --git a/examples/bluetooth/heartrate-game/devicefinder.cpp b/examples/bluetooth/heartrate-game/devicefinder.cpp
index 4ff967eb..aed47b6c 100644
--- a/examples/bluetooth/heartrate-game/devicefinder.cpp
+++ b/examples/bluetooth/heartrate-game/devicefinder.cpp
@@ -46,6 +46,7 @@ DeviceFinder::DeviceFinder(DeviceHandler *handler, QObject *parent):
BluetoothBaseClass(parent),
m_deviceHandler(handler)
{
+ //! [devicediscovery-1]
m_deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
m_deviceDiscoveryAgent->setLowEnergyDiscoveryTimeout(5000);
@@ -55,6 +56,7 @@ DeviceFinder::DeviceFinder(DeviceHandler *handler, QObject *parent):
connect(m_deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &DeviceFinder::scanFinished);
connect(m_deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::canceled, this, &DeviceFinder::scanFinished);
+ //! [devicediscovery-1]
#ifdef SIMULATOR
@@ -82,21 +84,28 @@ void DeviceFinder::startSearch()
#ifdef SIMULATOR
m_demoTimer.start();
#else
+ //! [devicediscovery-2]
m_deviceDiscoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
+ //! [devicediscovery-2]
#endif
emit scanningChanged();
setInfo(tr("Scanning for devices..."));
}
+//! [devicediscovery-3]
void DeviceFinder::addDevice(const QBluetoothDeviceInfo &device)
{
// If device is LowEnergy-device, add it to the list
if (device.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) {
m_devices.append(new DeviceInfo(device));
setInfo(tr("Low Energy device found. Scanning more..."));
+//! [devicediscovery-3]
emit devicesChanged();
+//! [devicediscovery-4]
}
+ //...
}
+//! [devicediscovery-4]
void DeviceFinder::scanError(QBluetoothDeviceDiscoveryAgent::Error error)
{
diff --git a/examples/bluetooth/heartrate-game/devicehandler.cpp b/examples/bluetooth/heartrate-game/devicehandler.cpp
index 153a99fb..dfc514b5 100644
--- a/examples/bluetooth/heartrate-game/devicehandler.cpp
+++ b/examples/bluetooth/heartrate-game/devicehandler.cpp
@@ -103,8 +103,11 @@ void DeviceHandler::setDevice(DeviceInfo *device)
if (m_currentDevice) {
// Make connections
+ //! [Connect-Signals-1]
m_control = new QLowEnergyController(m_currentDevice->getDevice(), this);
+ //! [Connect-Signals-1]
m_control->setRemoteAddressType(m_addressType);
+ //! [Connect-Signals-2]
connect(m_control, &QLowEnergyController::serviceDiscovered,
this, &DeviceHandler::serviceDiscovered);
connect(m_control, &QLowEnergyController::discoveryFinished,
@@ -125,6 +128,7 @@ void DeviceHandler::setDevice(DeviceInfo *device)
// Connect
m_control->connectToDevice();
+ //! [Connect-Signals-2]
}
}
@@ -149,6 +153,7 @@ void DeviceHandler::stopMeasurement()
emit measuringChanged();
}
+//! [Filter HeartRate service 1]
void DeviceHandler::serviceDiscovered(const QBluetoothUuid &gatt)
{
if (gatt == QBluetoothUuid(QBluetoothUuid::HeartRate)) {
@@ -156,6 +161,7 @@ void DeviceHandler::serviceDiscovered(const QBluetoothUuid &gatt)
m_foundHeartRateService = true;
}
}
+//! [Filter HeartRate service 1]
void DeviceHandler::serviceScanDone()
{
@@ -167,6 +173,7 @@ void DeviceHandler::serviceScanDone()
m_service = 0;
}
+//! [Filter HeartRate service 2]
// If heartRateService found, create new service
if (m_foundHeartRateService)
m_service = m_control->createServiceObject(QBluetoothUuid(QBluetoothUuid::HeartRate), this);
@@ -179,9 +186,11 @@ void DeviceHandler::serviceScanDone()
} else {
setError("Heart Rate Service not found.");
}
+//! [Filter HeartRate service 2]
}
// Service functions
+//! [Find HRM characteristic]
void DeviceHandler::serviceStateChanged(QLowEnergyService::ServiceState s)
{
switch (s) {
@@ -211,7 +220,9 @@ void DeviceHandler::serviceStateChanged(QLowEnergyService::ServiceState s)
emit aliveChanged();
}
+//! [Find HRM characteristic]
+//! [Reading value]
void DeviceHandler::updateHeartRateValue(const QLowEnergyCharacteristic &c, const QByteArray &value)
{
// ignore any other characteristic change -> shouldn't really happen though
@@ -230,6 +241,7 @@ void DeviceHandler::updateHeartRateValue(const QLowEnergyCharacteristic &c, cons
addMeasurement(hrvalue);
}
+//! [Reading value]
#ifdef SIMULATOR
void DeviceHandler::updateDemoHR()