summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2017-04-03 12:17:20 +0200
committerAlex Blasche <alexander.blasche@qt.io>2017-04-04 09:02:31 +0000
commit462954b30267e5b22f35caba0e37fb3d02d2c29c (patch)
treef769e66c21fd0f4f52439736fb2a587b82bd1686
parent283870e39be08e89050377cf2e4584b453cdc4e2 (diff)
downloadqtconnectivity-462954b30267e5b22f35caba0e37fb3d02d2c29c.tar.gz
Add means to enable simulator build with one easy define
Otherwise it is only enabled on Win32 builds Change-Id: I23ce25411294ebe2dae2272c16789da897b43e82 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
-rw-r--r--examples/bluetooth/heartrate-game/connectionhandler.cpp3
-rw-r--r--examples/bluetooth/heartrate-game/devicefinder.cpp8
-rw-r--r--examples/bluetooth/heartrate-game/devicefinder.h3
-rw-r--r--examples/bluetooth/heartrate-game/devicehandler.cpp9
-rw-r--r--examples/bluetooth/heartrate-game/devicehandler.h4
-rw-r--r--examples/bluetooth/heartrate-game/deviceinfo.cpp5
-rw-r--r--examples/bluetooth/heartrate-game/heartrate-game.pro3
-rw-r--r--examples/bluetooth/heartrate-game/heartrate-global.h51
8 files changed, 71 insertions, 15 deletions
diff --git a/examples/bluetooth/heartrate-game/connectionhandler.cpp b/examples/bluetooth/heartrate-game/connectionhandler.cpp
index 6ca3f1d7..d5084179 100644
--- a/examples/bluetooth/heartrate-game/connectionhandler.cpp
+++ b/examples/bluetooth/heartrate-game/connectionhandler.cpp
@@ -38,6 +38,7 @@
**
****************************************************************************/
+#include "heartrate-global.h"
#include "connectionhandler.h"
#include <QtDebug>
@@ -49,7 +50,7 @@ ConnectionHandler::ConnectionHandler(QObject *parent) : QObject(parent)
bool ConnectionHandler::alive() const
{
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
return true;
#else
return m_localDevice.isValid() && m_localDevice.hostMode() != QBluetoothLocalDevice::HostPoweredOff;
diff --git a/examples/bluetooth/heartrate-game/devicefinder.cpp b/examples/bluetooth/heartrate-game/devicefinder.cpp
index 0579ad4a..71c4dcee 100644
--- a/examples/bluetooth/heartrate-game/devicefinder.cpp
+++ b/examples/bluetooth/heartrate-game/devicefinder.cpp
@@ -58,7 +58,7 @@ DeviceFinder::DeviceFinder(DeviceHandler *handler, QObject *parent):
connect(m_deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::canceled, this, &DeviceFinder::scanFinished);
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
m_demoTimer.setSingleShot(true);
m_demoTimer.setInterval(2000);
connect(&m_demoTimer, &QTimer::timeout, this, &DeviceFinder::scanFinished);
@@ -80,7 +80,7 @@ void DeviceFinder::startSearch()
emit devicesChanged();
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
m_demoTimer.start();
#else
m_deviceDiscoveryAgent->start();
@@ -111,7 +111,7 @@ void DeviceFinder::scanError(QBluetoothDeviceDiscoveryAgent::Error error)
void DeviceFinder::scanFinished()
{
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
// Only for testing
for (int i = 0; i < 5; i++)
m_devices.append(new DeviceInfo(QBluetoothDeviceInfo()));
@@ -146,7 +146,7 @@ void DeviceFinder::connectToService(const QString &address)
bool DeviceFinder::scanning() const
{
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
return m_demoTimer.isActive();
#else
return m_deviceDiscoveryAgent->isActive();
diff --git a/examples/bluetooth/heartrate-game/devicefinder.h b/examples/bluetooth/heartrate-game/devicefinder.h
index d9ad66ad..c82c0fe5 100644
--- a/examples/bluetooth/heartrate-game/devicefinder.h
+++ b/examples/bluetooth/heartrate-game/devicefinder.h
@@ -41,6 +41,7 @@
#ifndef DEVICEFINDER_H
#define DEVICEFINDER_H
+#include "heartrate-global.h"
#include "bluetoothbaseclass.h"
#include <QTimer>
@@ -83,7 +84,7 @@ private:
QBluetoothDeviceDiscoveryAgent *m_deviceDiscoveryAgent;
QList<QObject*> m_devices;
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
QTimer m_demoTimer;
#endif
};
diff --git a/examples/bluetooth/heartrate-game/devicehandler.cpp b/examples/bluetooth/heartrate-game/devicehandler.cpp
index da643ff5..d0f06d27 100644
--- a/examples/bluetooth/heartrate-game/devicehandler.cpp
+++ b/examples/bluetooth/heartrate-game/devicehandler.cpp
@@ -38,6 +38,7 @@
**
****************************************************************************/
+#include "heartrate-global.h"
#include "devicehandler.h"
#include "deviceinfo.h"
#include <QtEndian>
@@ -52,7 +53,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
m_currentValue(0),
m_min(0), m_max(0), m_sum(0), m_avg(0), m_calories(0)
{
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
m_demoTimer.setSingleShot(false);
m_demoTimer.setInterval(2000);
connect(&m_demoTimer, &QTimer::timeout, this, &DeviceHandler::updateDemoHR);
@@ -66,7 +67,7 @@ void DeviceHandler::setDevice(DeviceInfo *device)
clearMessages();
m_currentDevice = device;
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
setInfo(tr("Demo device connected."));
return;
#endif
@@ -209,7 +210,7 @@ void DeviceHandler::updateHeartRateValue(const QLowEnergyCharacteristic &c, cons
addMeasurement(hrvalue);
}
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
void DeviceHandler::updateDemoHR()
{
int randomValue = 0;
@@ -258,7 +259,7 @@ bool DeviceHandler::measuring() const
bool DeviceHandler::alive() const
{
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
return true;
#endif
diff --git a/examples/bluetooth/heartrate-game/devicehandler.h b/examples/bluetooth/heartrate-game/devicehandler.h
index d00f0406..08831cb3 100644
--- a/examples/bluetooth/heartrate-game/devicehandler.h
+++ b/examples/bluetooth/heartrate-game/devicehandler.h
@@ -101,7 +101,7 @@ private:
void confirmedDescriptorWrite(const QLowEnergyDescriptor &d,
const QByteArray &value);
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
void updateDemoHR();
#endif
private:
@@ -123,7 +123,7 @@ private:
QVector<int> m_measurements;
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
QTimer m_demoTimer;
#endif
};
diff --git a/examples/bluetooth/heartrate-game/deviceinfo.cpp b/examples/bluetooth/heartrate-game/deviceinfo.cpp
index 4d1a3498..cb2ca97e 100644
--- a/examples/bluetooth/heartrate-game/deviceinfo.cpp
+++ b/examples/bluetooth/heartrate-game/deviceinfo.cpp
@@ -38,6 +38,7 @@
**
****************************************************************************/
+#include "heartrate-global.h"
#include "deviceinfo.h"
#include <QBluetoothAddress>
#include <QBluetoothUuid>
@@ -54,7 +55,7 @@ QBluetoothDeviceInfo DeviceInfo::getDevice() const
QString DeviceInfo::getName() const
{
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
return "Demo device";
#else
return m_device.name();
@@ -63,7 +64,7 @@ QString DeviceInfo::getName() const
QString DeviceInfo::getAddress() const
{
-#ifdef Q_OS_WIN32
+#ifdef SIMULATOR
return "00:11:22:33:44:55";
#elif Q_OS_DARWIN
// workaround for Core Bluetooth:
diff --git a/examples/bluetooth/heartrate-game/heartrate-game.pro b/examples/bluetooth/heartrate-game/heartrate-game.pro
index 5a856b9c..fcec0bd2 100644
--- a/examples/bluetooth/heartrate-game/heartrate-game.pro
+++ b/examples/bluetooth/heartrate-game/heartrate-game.pro
@@ -9,7 +9,8 @@ HEADERS += \
deviceinfo.h \
devicefinder.h \
devicehandler.h \
- bluetoothbaseclass.h
+ bluetoothbaseclass.h \
+ heartrate-global.h
SOURCES += main.cpp \
connectionhandler.cpp \
diff --git a/examples/bluetooth/heartrate-game/heartrate-global.h b/examples/bluetooth/heartrate-game/heartrate-global.h
new file mode 100644
index 00000000..376c7990
--- /dev/null
+++ b/examples/bluetooth/heartrate-game/heartrate-global.h
@@ -0,0 +1,51 @@
+/***************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the examples of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef HEARTRATEGLOBAL_H
+#define HEARTRATEGLOBAL_H
+
+//#define USE_SIMULATOR
+
+#if defined(Q_OS_WIN32) || defined(USE_SIMULATOR)
+#define SIMULATOR
+#endif
+
+
+#endif // HEARTRATEGLOBAL_H