diff options
22 files changed, 693 insertions, 42 deletions
diff --git a/.qmake.conf b/.qmake.conf index 661ac1ae..2f09a2ba 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1,3 +1,3 @@ load(qt_build_config) -MODULE_VERSION = 5.1.1 +MODULE_VERSION = 5.2.0 diff --git a/src/imports/sensors/qmlpressuresensor.cpp b/src/imports/sensors/qmlpressuresensor.cpp index a21f7c0d..8f32b4e0 100644 --- a/src/imports/sensors/qmlpressuresensor.cpp +++ b/src/imports/sensors/qmlpressuresensor.cpp @@ -99,6 +99,7 @@ QmlPressureReading::QmlPressureReading(QPressureSensor *sensor) : QmlSensorReading(sensor) , m_sensor(sensor) , m_pressure(0) + , m_temperature(0) { } @@ -118,6 +119,19 @@ qreal QmlPressureReading::pressure() const return m_pressure; } +/*! + \qmlproperty qreal PressureReading::temperature + This property holds the pressure sensor's temperature value in degrees Celsius. + + Please see QPressureReading::temperature for information about this property. + \since QtSensors 5.2 +*/ + +qreal QmlPressureReading::temperature() const +{ + return m_temperature; +} + QSensorReading *QmlPressureReading::reading() const { return m_sensor->reading(); @@ -130,4 +144,10 @@ void QmlPressureReading::readingUpdate() m_pressure = pressure; Q_EMIT pressureChanged(); } + + qreal temperature = m_sensor->reading()->temperature(); + if (m_temperature != temperature) { + m_temperature = temperature; + Q_EMIT temperatureChanged(); + } } diff --git a/src/imports/sensors/qmlpressuresensor.h b/src/imports/sensors/qmlpressuresensor.h index 627915a6..c8c19fd2 100644 --- a/src/imports/sensors/qmlpressuresensor.h +++ b/src/imports/sensors/qmlpressuresensor.h @@ -65,14 +65,17 @@ class QmlPressureReading : public QmlSensorReading { Q_OBJECT Q_PROPERTY(qreal pressure READ pressure NOTIFY pressureChanged) + Q_PROPERTY(qreal temperature READ temperature NOTIFY temperatureChanged REVISION 1) public: explicit QmlPressureReading(QPressureSensor *sensor); ~QmlPressureReading(); qreal pressure() const; + qreal temperature() const; Q_SIGNALS: void pressureChanged(); + Q_REVISION(1) void temperatureChanged(); private: QSensorReading *reading() const Q_DECL_OVERRIDE; @@ -80,6 +83,7 @@ private: QPressureSensor *m_sensor; qreal m_pressure; + qreal m_temperature; }; QT_END_NAMESPACE diff --git a/src/imports/sensors/sensors.cpp b/src/imports/sensors/sensors.cpp index 77ad754a..abcb3812 100644 --- a/src/imports/sensors/sensors.cpp +++ b/src/imports/sensors/sensors.cpp @@ -174,6 +174,49 @@ public: qmlRegisterUncreatableType<QmlTiltSensorReading >(package, major, minor, "TiltReading", QLatin1String("Cannot create TiltReading")); qmlRegisterType <QmlSensorGesture >(package, major, minor, "SensorGesture"); + + // Register the 5.2 interfaces + major = 5; + minor = 2; + qmlRegisterSingletonType <QmlSensorGlobal >(package, major, minor, "QmlSensors", global_object_50); + qmlRegisterUncreatableType<QmlSensorRange >(package, major, minor, "Range", QLatin1String("Cannot create Range")); + qmlRegisterUncreatableType<QmlSensorOutputRange >(package, major, minor, "OutputRange", QLatin1String("Cannot create OutputRange")); + qmlRegisterUncreatableType<QmlSensor,1 >(package, major, minor, "Sensor", QLatin1String("Cannot create Sensor")); + qmlRegisterUncreatableType<QmlSensorReading >(package, major, minor, "SensorReading", QLatin1String("Cannot create SensorReading")); + qmlRegisterType <QmlAccelerometer,1 >(package, major, minor, "Accelerometer"); + qmlRegisterUncreatableType<QmlAccelerometerReading >(package, major, minor, "AccelerometerReading", QLatin1String("Cannot create AccelerometerReading")); + qmlRegisterType <QmlAltimeter >(package, major, minor, "Altimeter"); + qmlRegisterUncreatableType<QmlAltimeterReading >(package, major, minor, "AltimeterReading", QLatin1String("Cannot create AltimeterReading")); + qmlRegisterType <QmlAmbientLightSensor >(package, major, minor, "AmbientLightSensor"); + qmlRegisterUncreatableType<QmlAmbientLightSensorReading>(package, major, minor, "AmbientLightReading", QLatin1String("Cannot create AmbientLightReading")); + qmlRegisterType <QmlAmbientTemperatureSensor >(package, major, minor, "AmbientTemperatureSensor"); + qmlRegisterUncreatableType<QmlAmbientTemperatureReading>(package, major, minor, "AmbientTemperatureReading", QLatin1String("Cannot create AmbientTemperatureReading")); + qmlRegisterType <QmlCompass >(package, major, minor, "Compass"); + qmlRegisterUncreatableType<QmlCompassReading >(package, major, minor, "CompassReading", QLatin1String("Cannot create CompassReading")); + qmlRegisterType <QmlGyroscope >(package, major, minor, "Gyroscope"); + qmlRegisterUncreatableType<QmlGyroscopeReading >(package, major, minor, "GyroscopeReading", QLatin1String("Cannot create GyroscopeReading")); + qmlRegisterType <QmlHolsterSensor >(package, major, minor, "HolsterSensor"); + qmlRegisterUncreatableType<QmlHolsterReading >(package, major, minor, "HolsterReading", QLatin1String("Cannot create HolsterReading")); + qmlRegisterType <QmlIRProximitySensor >(package, major, minor, "IRProximitySensor"); + qmlRegisterUncreatableType<QmlIRProximitySensorReading >(package, major, minor, "IRProximityReading", QLatin1String("Cannot create IRProximityReading")); + qmlRegisterType <QmlLightSensor >(package, major, minor, "LightSensor"); + qmlRegisterUncreatableType<QmlLightSensorReading >(package, major, minor, "LightReading", QLatin1String("Cannot create LightReading")); + qmlRegisterType <QmlMagnetometer >(package, major, minor, "Magnetometer"); + qmlRegisterUncreatableType<QmlMagnetometerReading >(package, major, minor, "MagnetometerReading", QLatin1String("Cannot create MagnetometerReading")); + qmlRegisterType <QmlOrientationSensor >(package, major, minor, "OrientationSensor"); + qmlRegisterUncreatableType<QmlOrientationSensorReading >(package, major, minor, "OrientationReading", QLatin1String("Cannot create OrientationReading")); + qmlRegisterType <QmlPressureSensor >(package, major, minor, "PressureSensor"); + qmlRegisterUncreatableType<QmlPressureReading,1 >(package, major, minor, "PressureReading", QLatin1String("Cannot create PressureReading")); + qmlRegisterType <QmlProximitySensor >(package, major, minor, "ProximitySensor"); + qmlRegisterUncreatableType<QmlProximitySensorReading >(package, major, minor, "ProximityReading", QLatin1String("Cannot create ProximityReading")); + qmlRegisterType <QmlRotationSensor >(package, major, minor, "RotationSensor"); + qmlRegisterUncreatableType<QmlRotationSensorReading >(package, major, minor, "RotationReading", QLatin1String("Cannot create RotationReading")); + qmlRegisterType <QmlTapSensor >(package, major, minor, "TapSensor"); + qmlRegisterUncreatableType<QmlTapSensorReading >(package, major, minor, "TapReading", QLatin1String("Cannot create TapReading")); + qmlRegisterType <QmlTiltSensor >(package, major, minor, "TiltSensor"); + qmlRegisterUncreatableType<QmlTiltSensorReading >(package, major, minor, "TiltReading", QLatin1String("Cannot create TiltReading")); + + qmlRegisterType <QmlSensorGesture >(package, major, minor, "SensorGesture"); } }; diff --git a/src/plugins/sensors/blackberry/bbpressuresensor.cpp b/src/plugins/sensors/blackberry/bbpressuresensor.cpp index 8cb9b1ea..edbb3927 100644 --- a/src/plugins/sensors/blackberry/bbpressuresensor.cpp +++ b/src/plugins/sensors/blackberry/bbpressuresensor.cpp @@ -53,8 +53,7 @@ QString BbPressureSensor::devicePath() bool BbPressureSensor::updateReadingFromEvent(const sensor_event_t &event, QPressureReading *reading) { - // TODO: I was unable to test this since the device I was testing this with did not have - // a pressure sensor. Verify that this works and check that the units are correct. reading->setPressure(event.pressure_s.pressure); + reading->setTemperature(event.pressure_s.temperature); return true; } diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.cpp b/src/plugins/sensors/blackberry/bbsensorbackend.cpp index 6b614a8a..7822dd86 100644 --- a/src/plugins/sensors/blackberry/bbsensorbackend.cpp +++ b/src/plugins/sensors/blackberry/bbsensorbackend.cpp @@ -303,6 +303,7 @@ bool BbSensorBackendBase::isFeatureSupported(QSensor::Feature feature) const case QSensor::Buffering: case QSensor::AccelerationMode: case QSensor::SkipDuplicates: + case QSensor::PressureSensorTemperature: return true; case QSensor::GeoValues: #ifndef Q_OS_BLACKBERRY_TABLET diff --git a/src/plugins/sensors/ios/iosaccelerometer.h b/src/plugins/sensors/ios/iosaccelerometer.h index 5fcac19f..1a6560b1 100644 --- a/src/plugins/sensors/ios/iosaccelerometer.h +++ b/src/plugins/sensors/ios/iosaccelerometer.h @@ -42,29 +42,28 @@ #ifndef IOSACCELEROMETER_H #define IOSACCELEROMETER_H -#include <Foundation/Foundation.h> +#include <CoreMotion/CMMotionManager.h> #include <qsensorbackend.h> #include <qaccelerometer.h> QT_BEGIN_NAMESPACE -@class QtIoAccelListener; - class IOSAccelerometer : public QSensorBackend { public: static char const * const id; explicit IOSAccelerometer(QSensor *sensor); - ~IOSAccelerometer(); + void timerEvent(QTimerEvent *); void start(); void stop(); private: - NSOperationQueue *m_updateQueue; + CMMotionManager *m_motionManager; QAccelerometerReading m_reading; + int m_timer; }; QT_END_NAMESPACE diff --git a/src/plugins/sensors/ios/iosaccelerometer.mm b/src/plugins/sensors/ios/iosaccelerometer.mm index b657b507..5f9c0f16 100644 --- a/src/plugins/sensors/ios/iosaccelerometer.mm +++ b/src/plugins/sensors/ios/iosaccelerometer.mm @@ -40,8 +40,6 @@ ****************************************************************************/ #include <UIKit/UIAccelerometer.h> -#include <CoreMotion/CMMotionManager.h> -#include <QPointer> #include "iosaccelerometer.h" #include "iosmotionmanager.h" @@ -52,49 +50,39 @@ QT_BEGIN_NAMESPACE IOSAccelerometer::IOSAccelerometer(QSensor *sensor) : QSensorBackend(sensor) - , m_updateQueue([[NSOperationQueue alloc] init]) + , m_motionManager([QIOSMotionManager sharedManager]) + , m_timer(0) { setReading<QAccelerometerReading>(&m_reading); addDataRate(1, 100); // 100Hz addOutputRange(-22.418, 22.418, 0.17651); // 2G } -IOSAccelerometer::~IOSAccelerometer() -{ - [m_updateQueue release]; -} - void IOSAccelerometer::start() { - CMMotionManager *motionManager = [QIOSMotionManager sharedManager]; - // Convert from Hz to NSTimeInterval: int hz = sensor()->dataRate(); - motionManager.accelerometerUpdateInterval = (hz == 0) ? 0 : 1. / hz; - - QPointer<QObject> self = this; - [motionManager startAccelerometerUpdatesToQueue:m_updateQueue withHandler:^(CMAccelerometerData *data, NSError *error) { - // NSOperationQueue is multi-threaded, so we process the data by queuing a callback to - // the main application queue. By the time the callback executes, IOSAccelerometer might - // have been deleted, so we need an extra QPointer check for that: - dispatch_async(dispatch_get_main_queue(), ^{ - if (self) { - Q_UNUSED(error); - // Convert from NSTimeInterval to microseconds and G to m/s2, and flip axes: - CMAcceleration acc = data.acceleration; - const qreal G = 9.8066; - m_reading.setTimestamp(quint64(data.timestamp * 1000000)); - m_reading.setX(qreal(acc.x) * G * -1); - m_reading.setY(qreal(acc.y) * G * -1); - m_reading.setZ(qreal(acc.z) * G * -1); - newReadingAvailable(); - } - }); - }]; + m_timer = startTimer(1000 / (hz == 0 ? 60 : hz)); + [m_motionManager startAccelerometerUpdates]; } void IOSAccelerometer::stop() { - [[QIOSMotionManager sharedManager] stopAccelerometerUpdates]; + [m_motionManager stopAccelerometerUpdates]; + killTimer(m_timer); + m_timer = 0; +} + +void IOSAccelerometer::timerEvent(QTimerEvent *) +{ + // Convert from NSTimeInterval to microseconds and G to m/s2, and flip axes: + CMAccelerometerData *data = m_motionManager.accelerometerData; + CMAcceleration acc = data.acceleration; + static const qreal G = 9.8066; + m_reading.setTimestamp(quint64(data.timestamp * 1e6)); + m_reading.setX(qreal(acc.x) * G * -1); + m_reading.setY(qreal(acc.y) * G * -1); + m_reading.setZ(qreal(acc.z) * G * -1); + newReadingAvailable(); } QT_END_NAMESPACE diff --git a/src/sensors/qpressuresensor.cpp b/src/sensors/qpressuresensor.cpp index ceb77dff..1aea843a 100644 --- a/src/sensors/qpressuresensor.cpp +++ b/src/sensors/qpressuresensor.cpp @@ -79,6 +79,33 @@ void QPressureReading::setPressure(qreal pressure) d->pressure = pressure; } +/*! + \property QPressureReading::temperature + \brief The pressure sensor's temperature. + \since 5.2 + + The temperature is returned in degree Celsius. + This property, if supported, provides the pressure sensor die temperature. + Note that this temperature may be (and usually is) different than the temperature + reported from QAmbientTemperatureSensor. + Use QSensor::isFeatureSupported() with the QSensor::PressureSensorTemperature + flag to determine its availability. +*/ + +qreal QPressureReading::temperature() const +{ + return d->temperature; +} + +/*! + Sets the pressure sensor's temperature to \a temperature. + \since 5.2 +*/ +void QPressureReading::setTemperature(qreal temperature) +{ + d->temperature = temperature; +} + // ===================================================================== /*! diff --git a/src/sensors/qpressuresensor.h b/src/sensors/qpressuresensor.h index 2a544cb0..8a14d410 100644 --- a/src/sensors/qpressuresensor.h +++ b/src/sensors/qpressuresensor.h @@ -51,10 +51,14 @@ class Q_SENSORS_EXPORT QPressureReading : public QSensorReading { Q_OBJECT Q_PROPERTY(qreal pressure READ pressure) + Q_PROPERTY(qreal temperature READ temperature) DECLARE_READING(QPressureReading) public: qreal pressure() const; void setPressure(qreal pressure); + + qreal temperature() const; + void setTemperature(qreal temperature); }; class Q_SENSORS_EXPORT QPressureFilter : public QSensorFilter diff --git a/src/sensors/qpressuresensor_p.h b/src/sensors/qpressuresensor_p.h index 1c74e7f1..f91b3bad 100644 --- a/src/sensors/qpressuresensor_p.h +++ b/src/sensors/qpressuresensor_p.h @@ -58,11 +58,12 @@ class QPressureReadingPrivate { public: QPressureReadingPrivate() - : pressure(0) + : pressure(0), temperature(0) { } qreal pressure; + qreal temperature; }; QT_END_NAMESPACE diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp index 473c459a..7f05189f 100644 --- a/src/sensors/qsensor.cpp +++ b/src/sensors/qsensor.cpp @@ -245,6 +245,10 @@ void QSensorPrivate::init(const QByteArray &sensorType) \value AccelerationMode The backend supports switching the acceleration mode of the acceleromter with the QAccelerometer::accelerationMode property. + The features of QPressureSensor are: + + \value PressureSensorTemperature The backend provides the pressure sensor's die temperature + The features of all orientable sensors are: \value AxesOrientation The backend supports changing the axes orientation from the default of diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h index 2b602488..b83d736b 100644 --- a/src/sensors/qsensor.h +++ b/src/sensors/qsensor.h @@ -107,6 +107,7 @@ public: AccelerationMode, SkipDuplicates, AxesOrientation, + PressureSensorTemperature, Reserved = 257 // Make sure at least 2 bytes are used for the enum to avoid breaking BC later }; diff --git a/tests/auto/qsensor/test_backends.h b/tests/auto/qsensor/test_backends.h index b76d4128..674abf80 100644 --- a/tests/auto/qsensor/test_backends.h +++ b/tests/auto/qsensor/test_backends.h @@ -135,6 +135,7 @@ PREPARE_SENSORINTERFACE(QOrientationSensor, QOrientationReading, QOrientationFil }) PREPARE_SENSORINTERFACE(QPressureSensor, QPressureReading, QPressureFilter, { reading->setPressure(1.0); + reading->setTemperature(1.0); }) PREPARE_SENSORINTERFACE(QProximitySensor, QProximityReading, QProximityFilter, { reading->setClose(true); diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp index a410f711..ce5f8e36 100644 --- a/tests/auto/qsensor/tst_qsensor.cpp +++ b/tests/auto/qsensor/tst_qsensor.cpp @@ -891,6 +891,7 @@ private slots: TEST_SENSORINTERFACE(QPressureSensor, QPressureReading, { QCOMPARE(reading->pressure(), 1.0); + QCOMPARE(reading->temperature(), 1.0); }) TEST_SENSORINTERFACE(QProximitySensor, QProximityReading, { diff --git a/tests/manual/sensor_explorer/sensor_explorer.pro b/tests/manual/sensor_explorer/sensor_explorer.pro index c8de3f2d..f14709c2 100644 --- a/tests/manual/sensor_explorer/sensor_explorer.pro +++ b/tests/manual/sensor_explorer/sensor_explorer.pro @@ -1,7 +1,7 @@ TEMPLATE=app TARGET=sensor_explorer -QT = core gui sensors +QT = widgets sensors FORMS=\ explorer.ui diff --git a/tests/manual/sensorclerk/collector.cpp b/tests/manual/sensorclerk/collector.cpp new file mode 100644 index 00000000..afe195fc --- /dev/null +++ b/tests/manual/sensorclerk/collector.cpp @@ -0,0 +1,190 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Lorn Potter. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors 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 Digia Plc and its Subsidiary(-ies) 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$ +** +****************************************************************************/ + +#include <QtQml/qqml.h> +#include <QtCore/QFile> +#include <QFileInfo> + +#include <QTextStream> +#include <QtSensors> +#include <QDir> +#include <QtSensors/QAccelerometer> +#include <QtSensors/QIRProximitySensor> +#include <QtSensors/QOrientationSensor> +#include <QtSensors/QProximitySensor> +#include <QDebug> + +#include "collector.h" + +Collector::Collector(QObject *parent) + : QObject(parent), + accel(0), + orientation(0), + proximity(0), + irProx(0), + tapSensor(0), + dataFile(QDir::tempPath()+"/sensordump_0.dat") + , isActive(0), + fileCounter(0) +{ + accel = new QAccelerometer(this); + accel->connectToBackend(); + accel->setDataRate(100); + connect(accel,SIGNAL(readingChanged()),this,SLOT(accelChanged())); + + orientation = new QOrientationSensor(this); + orientation->connectToBackend(); + orientation->setDataRate(100); + connect(orientation,SIGNAL(readingChanged()),this,SLOT(orientationChanged())); + + proximity = new QProximitySensor(this); + proximity->connectToBackend(); + connect(proximity,SIGNAL(readingChanged()),this,SLOT(proximityChanged())); + + irProx = new QIRProximitySensor(this); + irProx->connectToBackend(); + irProx->setDataRate(50); + connect(irProx,SIGNAL(readingChanged()),this,SLOT(irProximityChanged())); + + tapSensor = new QTapSensor(this); + tapSensor->connectToBackend(); + connect(tapSensor,SIGNAL(readingChanged()),this,SLOT(tapChanged())); +} + +Collector::~Collector() +{ +} + +void Collector::accelChanged() +{ + const qreal x = accel->reading()->x(); + const qreal y = accel->reading()->y(); + const qreal z = accel->reading()->z(); + const quint64 ts = accel->reading()->timestamp(); + + QTextStream out(&dataFile); + out << QString("accelerometer: %1,%2,%3,%4").arg(ts).arg(x).arg(y).arg(z) << "\n"; +} + +void Collector::orientationChanged() +{ + const QOrientationReading *orientationReading = orientation->reading(); + QOrientationReading::Orientation o = orientationReading->orientation(); + const quint64 ts = orientationReading->timestamp(); + + QTextStream out(&dataFile); + out << QString("orientation: %1,%2").arg(ts).arg(o) << "\n"; +} + +void Collector::proximityChanged() +{ + const QProximityReading *proximityReading = proximity->reading(); + const quint64 ts = proximityReading->timestamp(); + const bool prox = proximityReading->close(); + + QTextStream out(&dataFile); + out << QString("proximity: %1,%2").arg(ts).arg(prox) << "\n"; +} + +void Collector::irProximityChanged() +{ + const QIRProximityReading *irProximityReading = irProx->reading(); + const quint64 ts = irProximityReading->timestamp(); + const qreal ref = irProximityReading->reflectance(); + + QTextStream out(&dataFile); + out << QString("irProximity: %1,%2").arg(ts).arg(ref) << "\n"; +} + +void Collector::tapChanged() +{ + const QTapReading *tapReading = tapSensor->reading(); + const quint64 ts = tapReading->timestamp(); + const bool dTap = tapReading->isDoubleTap(); + + QTextStream out(&dataFile); + out << QString("tap: %1,%2").arg(ts).arg(dTap) << "\n"; +} + +void Collector::startCollecting() +{ + if (dataFile.exists()) { + fileCounter++; + for (int i = 0; i < fileCounter; i++) { + if (!QFileInfo(QString(QDir::tempPath()+"/sensordump_%1.dat").arg(fileCounter)).exists()) + dataFile.setFileName(QString(QDir::tempPath()+"/sensordump_%1.dat").arg(fileCounter)); + break; + fileCounter++; + } + } + if (!dataFile.exists()) { + if (dataFile.open(QIODevice::WriteOnly | QIODevice::Text)) { + accel->start(); + orientation->start(); + proximity->start(); + irProx->start(); + tapSensor->start(); + + isActive = true; + } else { + qDebug() << "dump file not opened"; + } + } else { + startCollecting(); + } +} + +void Collector::stopCollecting() +{ + if (isActive) { + accel->stop(); + orientation->stop(); + proximity->stop(); + irProx->stop(); + tapSensor->stop(); + isActive = !isActive; + } + if (dataFile.isOpen()) + dataFile.close(); +} + + +QML_DECLARE_TYPE(Collector) + diff --git a/tests/manual/sensorclerk/collector.h b/tests/manual/sensorclerk/collector.h new file mode 100644 index 00000000..15854bf0 --- /dev/null +++ b/tests/manual/sensorclerk/collector.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Lorn Potter. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors 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 Digia Plc and its Subsidiary(-ies) 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 COLLECTOR_H +#define COLLECTOR_H + +#include <QtCore/QObject> +#include <QtCore/QString> +#include <QFile> + +class QAccelerometer; +class QOrientationSensor; +class QProximitySensor; +class QIRProximitySensor; +class QTapSensor; + +class Collector : public QObject +{ + Q_OBJECT + +public: + explicit Collector(QObject *parent = 0); + ~Collector(); + +public slots: + void startCollecting(); + void stopCollecting(); + +private Q_SLOTS: + void accelChanged(); + void orientationChanged(); + void proximityChanged(); + void irProximityChanged(); + void tapChanged(); + +private: + + QAccelerometer *accel; + QOrientationSensor *orientation; + QProximitySensor *proximity; + QIRProximitySensor *irProx; + QTapSensor *tapSensor; + QFile dataFile; + + bool isActive; + int fileCounter; + + Q_DISABLE_COPY(Collector) +}; + +#endif // COLLECTOR_H + diff --git a/tests/manual/sensorclerk/main.cpp b/tests/manual/sensorclerk/main.cpp new file mode 100644 index 00000000..d56c1f73 --- /dev/null +++ b/tests/manual/sensorclerk/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Lorn Potter. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors 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 Digia Plc and its Subsidiary(-ies) 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$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QtQuick/QQuickView> +#include <QtQml/qqml.h> +#include <QDebug> + + +#include "collector.h" + +int main( int argc, char** argv ) +{ + QGuiApplication app( argc, argv ); + qmlRegisterType<Collector>("Collector", 1, 0, "Collector"); + QQuickView view; + view.setResizeMode(QQuickView::SizeRootObjectToView); +#if defined(Q_OS_QNX) + view.setSource( QUrl( "app/native/qml/main.qml" ) ); +#else + view.setSource( QUrl( "qml/main.qml" ) ); +#endif + view.show(); + return app.exec(); +} + diff --git a/tests/manual/sensorclerk/qml/Button.qml b/tests/manual/sensorclerk/qml/Button.qml new file mode 100644 index 00000000..3565a5b9 --- /dev/null +++ b/tests/manual/sensorclerk/qml/Button.qml @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors 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 Digia Plc and its Subsidiary(-ies) 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$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +//Implementation of the Button control. +Item { + id: button + width: 250 + height: 150 + property alias text: innerText.text; + property color color: "white" + property color hoverColor: "#aaaaaa" + property color pressColor: "slategray" + property int fontSize: 10 + property int borderWidth: 1 + property int borderRadius: 2 + scale: state === "Pressed" ? 0.96 : 1.0 + onEnabledChanged: state = "" + signal clicked + + //define a scale animation + Behavior on scale { + NumberAnimation { + duration: 100 + easing.type: Easing.InOutQuad + } + } + + //Rectangle to draw the button + Rectangle { + id: rectangleButton + anchors.fill: parent + radius: borderRadius + color: button.enabled ? button.color : "grey" + border.width: borderWidth + border.color: "black" + + Text { + id: innerText + font.pointSize: fontSize + anchors.centerIn: parent + } + } + + //change the color of the button in differen button states + states: [ + State { + name: "Hovering" + PropertyChanges { + target: rectangleButton + color: hoverColor + } + }, + State { + name: "Pressed" + PropertyChanges { + target: rectangleButton + color: pressColor + } + } + ] + + //define transmission for the states + transitions: [ + Transition { + from: ""; to: "Hovering" + ColorAnimation { duration: 200 } + }, + Transition { + from: "*"; to: "Pressed" + ColorAnimation { duration: 10 } + } + ] + + //Mouse area to react on click events + MouseArea { + hoverEnabled: true + anchors.fill: button + onEntered: { button.state='Hovering'} + onExited: { button.state=''} + onClicked: { button.clicked();} + onPressed: { button.state="Pressed" } + onReleased: { + if (containsMouse) + button.state="Hovering"; + else + button.state=""; + } + } +} diff --git a/tests/manual/sensorclerk/qml/main.qml b/tests/manual/sensorclerk/qml/main.qml new file mode 100644 index 00000000..a49f21ae --- /dev/null +++ b/tests/manual/sensorclerk/qml/main.qml @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Lorn Potter. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors 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 Digia Plc and its Subsidiary(-ies) 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import Collector 1.0 +import QtSensors 5.0 + +Rectangle { + Collector { + id: writer + } + + Text { + id: label + text: "Sensor Clerk<br> push to start and stop<br> sensor dump"; + anchors.horizontalCenter: parent.horizontalCenter + } + + Button { + id: startCollectingButton + text: depressed ? "Stop" : "Start" + property bool depressed: false + anchors.top: label.bottom + enabled: true; + anchors.horizontalCenter: parent + onClicked: { + if (!depressed) { + writer.startCollecting() + depressed = true + } else { + writer.stopCollecting() + depressed = false + } + } + } + +} + + diff --git a/tests/manual/sensorclerk/sensorclerk.pro b/tests/manual/sensorclerk/sensorclerk.pro new file mode 100644 index 00000000..61eeef15 --- /dev/null +++ b/tests/manual/sensorclerk/sensorclerk.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +QT += quick sensors + +SOURCES += main.cpp \ + collector.cpp + +HEADERS += collector.h + +OTHER_FILES += qml/main.qml \ + qml/Button.qml |