From a1b4c4ad291ff531b6efe8fabe409dfaae3cc854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otto=20Ryyn=C3=A4nen?= Date: Fri, 3 Feb 2017 12:55:13 +0200 Subject: RotationPage added Added a page that has three rotating disks. Current pictures are placeholders for final graphics. SensorTag can be recalibrated. Change-Id: I0666ab06e665d8c40861e170f36b09013b722973 Reviewed-by: Titta Heikkala --- tradeshow/iot-sensortag/SensorTagDemo.pro | 3 +- tradeshow/iot-sensortag/base.qrc | 1 + tradeshow/iot-sensortag/bluetoothapiconstants.h | 91 ++++++++++ tradeshow/iot-sensortag/bluetoothdataprovider.cpp | 31 +++- tradeshow/iot-sensortag/bluetoothdataprovider.h | 7 + tradeshow/iot-sensortag/bluetoothdevice.cpp | 37 +--- tradeshow/iot-sensortag/clouddataprovider.cpp | 4 +- tradeshow/iot-sensortag/clouddataprovider.h | 3 +- tradeshow/iot-sensortag/mockdataprovider.cpp | 22 ++- tradeshow/iot-sensortag/mockdataprovider.h | 10 +- .../iot-sensortag/resources/base/RotationPage.qml | 188 +++++++++++++++++++++ .../iot-sensortag/resources/small/MainSmall.qml | 3 +- .../resources/small/images/Gyro/particle.png | Bin 0 -> 870 bytes .../resources/small/images/Gyro/ring_large.png | Bin 0 -> 387182 bytes .../resources/small/images/Gyro/ring_medium.png | Bin 0 -> 263861 bytes .../resources/small/images/Gyro/ring_outer.png | Bin 0 -> 253803 bytes .../resources/small/images/Gyro/ring_small.png | Bin 0 -> 225215 bytes tradeshow/iot-sensortag/sensortagdataprovider.cpp | 19 ++- tradeshow/iot-sensortag/sensortagdataprovider.h | 8 +- tradeshow/iot-sensortag/uismall.qrc | 5 + 20 files changed, 376 insertions(+), 56 deletions(-) create mode 100644 tradeshow/iot-sensortag/bluetoothapiconstants.h create mode 100644 tradeshow/iot-sensortag/resources/base/RotationPage.qml create mode 100644 tradeshow/iot-sensortag/resources/small/images/Gyro/particle.png create mode 100644 tradeshow/iot-sensortag/resources/small/images/Gyro/ring_large.png create mode 100644 tradeshow/iot-sensortag/resources/small/images/Gyro/ring_medium.png create mode 100644 tradeshow/iot-sensortag/resources/small/images/Gyro/ring_outer.png create mode 100644 tradeshow/iot-sensortag/resources/small/images/Gyro/ring_small.png (limited to 'tradeshow') diff --git a/tradeshow/iot-sensortag/SensorTagDemo.pro b/tradeshow/iot-sensortag/SensorTagDemo.pro index f1df6d6..752ea9b 100644 --- a/tradeshow/iot-sensortag/SensorTagDemo.pro +++ b/tradeshow/iot-sensortag/SensorTagDemo.pro @@ -49,7 +49,8 @@ HEADERS += \ cloudservice.h \ dataproviderpool.h \ clouddataproviderpool.h \ - demodataproviderpool.h + demodataproviderpool.h \ + bluetoothapiconstants.h BLUETOOTH_LINUX_HOST { !winrt:CONFIG += UPDATE_TO_CLOUD diff --git a/tradeshow/iot-sensortag/base.qrc b/tradeshow/iot-sensortag/base.qrc index 65b86eb..798fb43 100644 --- a/tradeshow/iot-sensortag/base.qrc +++ b/tradeshow/iot-sensortag/base.qrc @@ -21,5 +21,6 @@ resources/base/fonts/titilliumweb/TitilliumWeb-Regular.ttf resources/base/fonts/titilliumweb/TitilliumWeb-SemiBold.ttf resources/base/images/bg_blue.jpg + resources/base/RotationPage.qml diff --git a/tradeshow/iot-sensortag/bluetoothapiconstants.h b/tradeshow/iot-sensortag/bluetoothapiconstants.h new file mode 100644 index 0000000..b29d73b --- /dev/null +++ b/tradeshow/iot-sensortag/bluetoothapiconstants.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of Qt for Device Creation. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 BLUETOOTHAPICONSTANTS_H +#define BLUETOOTHAPICONSTANTS_H + +// NOTE! This file should only contain defines, no implementation + +/* Timeouts (values between 100ms and 2500ms allowed by API specification. + * API values are passed in hex as strings and multiplied by 10 in SensorTag. + * These values can be modifed as needed by performance. + * Keep defines and strings in sync! + */ +#define SENSORTAG_SLOW_TIMER_TIMEOUT_MS 1000 /* 1 second */ +#define SENSORTAG_SLOW_TIMER_TIMEOUT_STR "64" /* 64hex -> 100 -> 1000ms */ +#define SENSORTAG_MEDIUM_TIMER_TIMEOUT_MS 500 /* 500ms */ +#define SENSORTAG_MEDIUM_TIMER_TIMEOUT_STR "32" /* 32hex -> 50 -> 500ms */ +#define SENSORTAG_RAPID_TIMER_TIMEOUT_MS 100 /* 100ms */ +#define SENSORTAG_RAPID_TIMER_TIMEOUT_STR "0A" /* A(hex) -> 10 -> 100ms */ + +// These modifiers come from the Texas Intruments SensorTag Bluetooth LE API specification +#define GYROSCOPE_API_READING_MULTIPLIER (500.0 / 65536.0) +#define ACCELOMETER_API_READING_MULTIPLIER (8.0 / 32768.0) +#define HUMIDITY_API_READING_MULTIPLIER (100.0 / 65536.0) +#define IR_TEMPERATURE_API_READING_DIVIDER 128.0 +#define BAROMETER_API_READING_DIVIDER 100 + +// These are parameters from the Texas Intruments SensorTag Bluetooth LE API specification +#define START_MEASUREMENT_STR "01" /* 01 start, 00 stop */ +#define DISABLE_NOTIF_STR "0000" /* 0100 enable, 0000 disable */ +#define ENABLE_NOTIF_STR "0100" /* 0100 enable, 0000 disable */ +#define MOVEMENT_ENABLE_SENSORS_BITMASK_VALUE "7F02" /* see below */ +//Enable motion axis: 0b0000_0010_0111_1111 = 0x7F 0x02 (all sensors, 8G, no wake on motion) +//bits of first byte: +//MPU9250_GYROSCOPE = 0b0000_0111 all 3 xyz axes, 1 bit per axis +//MPU9250_ACCELEROMETER = 0b0011_1000 all 3 xyz axes, 1 bit per axis +//MPU9250_MAGNETOMETER = 0b0100_0000 all 3 xyz axes with one bit +//MPU9250_WAKEONMOTION = 0b1000_0000 enables wake on motion +//bits of second byte (only 2 bits used) Accelerometer range in G +//MPU9250_ACCELEROMETER_RANGE_0 =0b0000_0000 = 2 G +//MPU9250_ACCELEROMETER_RANGE_1 =0b0000_0001 = 4 G +//MPU9250_ACCELEROMETER_RANGE_2 =0b0000_0010 = 8 G (default) +//MPU9250_ACCELEROMETER_RANGE_3 =0b0000_0011 = 16 G + +#endif // BLUETOOTHAPICONSTANTS_H diff --git a/tradeshow/iot-sensortag/bluetoothdataprovider.cpp b/tradeshow/iot-sensortag/bluetoothdataprovider.cpp index 1f0cbf5..8745552 100644 --- a/tradeshow/iot-sensortag/bluetoothdataprovider.cpp +++ b/tradeshow/iot-sensortag/bluetoothdataprovider.cpp @@ -49,6 +49,7 @@ ****************************************************************************/ #include "bluetoothdataprovider.h" #include +#include "bluetoothapiconstants.h" Q_DECLARE_LOGGING_CATEGORY(boot2QtDemos) @@ -56,7 +57,11 @@ BluetoothDataProvider::BluetoothDataProvider(QString id, QObject *parent) : SensorTagDataProvider(id, parent) , activeDevice(Q_NULLPTR) , m_smaSamples(0) + , gyroscopeX_calibration(0) + , gyroscopeY_calibration(0) + , gyroscopeZ_calibration(0) { + intervalRotation = SENSORTAG_RAPID_TIMER_TIMEOUT_MS; } BluetoothDataProvider::~BluetoothDataProvider() @@ -152,14 +157,15 @@ void BluetoothDataProvider::motionReceived(MotionSensorData &data) /* NOTE: We emit the signals even if value is unchanged. * Otherwise the scrolling graphs in UI will not scroll. */ - gyroscopeX_degPerSec = data.gyroScope_x; - gyroscopeY_degPerSec = data.gyroScope_y; - gyroscopeZ_degPerSec = data.gyroScope_z; + latestData = data; + gyroscopeX_degPerSec = data.gyroScope_x - gyroscopeX_calibration; + gyroscopeY_degPerSec = data.gyroScope_y - gyroscopeY_calibration; + gyroscopeZ_degPerSec = data.gyroScope_z - gyroscopeZ_calibration; emit gyroscopeDegPerSecChanged(); - rotation_x += countRotationDegrees(data.gyroScope_x, data.msSincePreviousData); - rotation_y += countRotationDegrees(data.gyroScope_y, data.msSincePreviousData); - rotation_z += countRotationDegrees(data.gyroScope_z, data.msSincePreviousData); + rotation_x += countRotationDegrees(gyroscopeX_degPerSec, data.msSincePreviousData); + rotation_y += countRotationDegrees(gyroscopeY_degPerSec, data.msSincePreviousData); + rotation_z += countRotationDegrees(gyroscopeZ_degPerSec, data.msSincePreviousData); if (rotation_x > 360) rotation_x -= 360; @@ -216,6 +222,19 @@ void BluetoothDataProvider::updateState() } } +void BluetoothDataProvider::reset() +{ + rotation_x = 0; + rotation_y = 0; + rotation_z = 0; + gyroscopeX_calibration = latestData.gyroScope_x; + gyroscopeY_calibration = latestData.gyroScope_y; + gyroscopeZ_calibration = latestData.gyroScope_z; + emit rotationXChanged(); + emit rotationYChanged(); + emit rotationZChanged(); +} + void BluetoothDataProvider::bindToDevice(BluetoothDevice *device) { activeDevice = device; diff --git a/tradeshow/iot-sensortag/bluetoothdataprovider.h b/tradeshow/iot-sensortag/bluetoothdataprovider.h index 21db2c6..ac7c417 100644 --- a/tradeshow/iot-sensortag/bluetoothdataprovider.h +++ b/tradeshow/iot-sensortag/bluetoothdataprovider.h @@ -81,12 +81,19 @@ public slots: void lightIntensityReceived(double lightIntensity); void motionReceived(MotionSensorData &data); +protected: + void reset(); + private: void updateState(); float countRotationDegrees(double degreesPerSecond, quint64 milliseconds); BluetoothDevice* activeDevice; QTimer timer; int m_smaSamples; + float gyroscopeX_calibration; + float gyroscopeY_calibration; + float gyroscopeZ_calibration; + MotionSensorData latestData; }; #endif // BLUETOOTHDATAPROVIDER_H diff --git a/tradeshow/iot-sensortag/bluetoothdevice.cpp b/tradeshow/iot-sensortag/bluetoothdevice.cpp index 459e879..0ef6bc8 100644 --- a/tradeshow/iot-sensortag/bluetoothdevice.cpp +++ b/tradeshow/iot-sensortag/bluetoothdevice.cpp @@ -59,35 +59,10 @@ #include #include #include +#include "bluetoothapiconstants.h" Q_DECLARE_LOGGING_CATEGORY(boot2QtDemos) -#define START_MEASUREMENT_STR "01" /* 01 start, 00 stop */ -#define DISABLE_NOTIF_STR "0000" /* 0100 enable, 0000 disable */ -#define ENABLE_NOTIF_STR "0100" /* 0100 enable, 0000 disable */ -#define SLOW_TIMER_TIMEOUT_STR "64" /* 100 -> 1000ms */ -#define MEDIUM_TIMER_TIMEOUT_STR "32" /* 50 -> 500ms */ -#define RAPID_TIMER_TIMEOUT_STR "0A" /* 10 -> 100ms */ -#define MOVEMENT_ENABLE_SENSORS_BITMASK_VALUE "7F02" /* see below */ -//Enable motion axis: 0b0000_0010_0111_1111 = 0x7F 0x02 (all sensors, 8G, no wake on motion) -//bits of first byte: -//MPU9250_GYROSCOPE = 0b0000_0111 all 3 xyz axes, 1 bit per axis -//MPU9250_ACCELEROMETER = 0b0011_1000 all 3 xyz axes, 1 bit per axis -//MPU9250_MAGNETOMETER = 0b0100_0000 all 3 xyz axes with one bit -//MPU9250_WAKEONMOTION = 0b1000_0000 enables wake on motion -//bits of second byte (only 2 bits used) Accelerometer range in G -//MPU9250_ACCELEROMETER_RANGE_0 =0b0000_0000 = 2 G -//MPU9250_ACCELEROMETER_RANGE_1 =0b0000_0001 = 4 G -//MPU9250_ACCELEROMETER_RANGE_2 =0b0000_0010 = 8 G (default) -//MPU9250_ACCELEROMETER_RANGE_3 =0b0000_0011 = 16 G - -// These modifiers come from the Texas Intruments SensorTag Bluetooth LE API specification -#define GYROSCOPE_API_READING_MULTIPLIER (500.0 / 65536.0) -#define ACCELOMETER_API_READING_MULTIPLIER (8.0 / 32768.0) -#define HUMIDITY_API_READING_MULTIPLIER (100.0 / 65536.0) -#define IR_TEMPERATURE_API_READING_DIVIDER 128.0 -#define BAROMETER_API_READING_DIVIDER 100 - typedef struct { qint16 gyrox; qint16 gyroy; @@ -328,7 +303,7 @@ void BluetoothDevice::temperatureDetailsDiscovered(QLowEnergyService::ServiceSta } if (id.toString().contains("f000aa03-0451-4000-b000-000000000000")) { //RW - irTemperatureService->writeCharacteristic(characteristic, QByteArray::fromHex(SLOW_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); // Period 1 second + irTemperatureService->writeCharacteristic(characteristic, QByteArray::fromHex(SENSORTAG_SLOW_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); // Period 1 second } } m_temperatureMeasurementStarted = true; @@ -358,7 +333,7 @@ void BluetoothDevice::barometerDetailsDiscovered(QLowEnergyService::ServiceState baroService->writeCharacteristic(characteristic, QByteArray::fromHex(START_MEASUREMENT_STR), QLowEnergyService::WriteWithResponse); // Start } if (id.toString().contains("f000aa44-0451-4000-b000-000000000000")) { - baroService->writeCharacteristic(characteristic, QByteArray::fromHex(MEDIUM_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); // Period 1 second + baroService->writeCharacteristic(characteristic, QByteArray::fromHex(SENSORTAG_MEDIUM_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); // Period 1 second } } m_barometerMeasurementStarted = true; @@ -389,7 +364,7 @@ void BluetoothDevice::humidityDetailsDiscovered(QLowEnergyService::ServiceState humidityService->writeCharacteristic(characteristic, QByteArray::fromHex(START_MEASUREMENT_STR), QLowEnergyService::WriteWithResponse); // Start } if (id.toString().contains("f000aa23-0451-4000-b000-000000000000")) { - humidityService->writeCharacteristic(characteristic, QByteArray::fromHex(SLOW_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); // Period 1 second + humidityService->writeCharacteristic(characteristic, QByteArray::fromHex(SENSORTAG_SLOW_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); // Period 1 second } } m_humidityMeasurementStarted = true; @@ -420,7 +395,7 @@ void BluetoothDevice::lightIntensityDetailsDiscovered(QLowEnergyService::Service lightService->writeCharacteristic(characteristic, QByteArray::fromHex(START_MEASUREMENT_STR), QLowEnergyService::WriteWithResponse); // Start } if (id.toString().contains("f000aa73-0451-4000-b000-000000000000")) { - lightService->writeCharacteristic(characteristic, QByteArray::fromHex(MEDIUM_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); // Period 1 second + lightService->writeCharacteristic(characteristic, QByteArray::fromHex(SENSORTAG_MEDIUM_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); // Period 1 second } } m_lightIntensityMeasurementStarted = true; @@ -454,7 +429,7 @@ void BluetoothDevice::motionDetailsDiscovered(QLowEnergyService::ServiceState ne motionService->writeCharacteristic(characteristic, QByteArray::fromHex(MOVEMENT_ENABLE_SENSORS_BITMASK_VALUE), QLowEnergyService::WriteWithResponse); } if (id.toString().contains("f000aa83-0451-4000-b000-000000000000")) { - motionService->writeCharacteristic(characteristic, QByteArray::fromHex(RAPID_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); + motionService->writeCharacteristic(characteristic, QByteArray::fromHex(SENSORTAG_RAPID_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); } } m_motionMeasurementStarted = true; diff --git a/tradeshow/iot-sensortag/clouddataprovider.cpp b/tradeshow/iot-sensortag/clouddataprovider.cpp index d45d79f..46891fb 100644 --- a/tradeshow/iot-sensortag/clouddataprovider.cpp +++ b/tradeshow/iot-sensortag/clouddataprovider.cpp @@ -55,6 +55,7 @@ #define MAJOR_VERSION_NUMBER 1 #define MINOR_VERSION_NUMBER 1 +#define CLOUD_DATA_POLL_INTERVAL_MS 1000 /* 1 second update interval */ #ifndef QT_NO_SSL static QString dataFetchUrl = "https://ottoryynanenqt.blob.core.windows.net/btsensortagreadings/sensorTagReadings.txt"; #else @@ -67,6 +68,7 @@ CloudDataProvider::CloudDataProvider(QString id, QObject* parent) : SensorTagDataProvider(id, parent) , reply(Q_NULLPTR) { + intervalRotation = CLOUD_DATA_POLL_INTERVAL_MS; connect(&qnam, &QNetworkAccessManager::authenticationRequired, this, &CloudDataProvider::slotAuthenticationRequired); #ifndef QT_NO_SSL @@ -79,7 +81,7 @@ bool CloudDataProvider::startDataFetching() { pollTimer = new QTimer(this); connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollTimerExpired())); - pollTimer->start(1000); // 1 second update interval + pollTimer->start(CLOUD_DATA_POLL_INTERVAL_MS); return true; } diff --git a/tradeshow/iot-sensortag/clouddataprovider.h b/tradeshow/iot-sensortag/clouddataprovider.h index 904431d..ccfbeed 100644 --- a/tradeshow/iot-sensortag/clouddataprovider.h +++ b/tradeshow/iot-sensortag/clouddataprovider.h @@ -78,7 +78,8 @@ private slots: #ifndef QT_NO_SSL void sslErrors(QNetworkReply *, const QList &errors); #endif - +protected: + void reset() {} private: void parseReceivedText(); diff --git a/tradeshow/iot-sensortag/mockdataprovider.cpp b/tradeshow/iot-sensortag/mockdataprovider.cpp index f081c30..d6f0ab8 100644 --- a/tradeshow/iot-sensortag/mockdataprovider.cpp +++ b/tradeshow/iot-sensortag/mockdataprovider.cpp @@ -50,6 +50,9 @@ #include "mockdataprovider.h" #include +#define MOCK_DATA_SLOW_REFRESH_INTERVAL_MS 1000 +#define MOCK_DATA_RAPID_REFRESH_INTERVAL_MS 200 + MockDataProvider::MockDataProvider(QString id, QObject* parent) : SensorTagDataProvider(id, parent), xAxisG(-0.02), @@ -60,6 +63,7 @@ MockDataProvider::MockDataProvider(QString id, QObject* parent) rotationDegPerSecZIncrease(-9), m_smaSamples(0) { + intervalRotation = MOCK_DATA_RAPID_REFRESH_INTERVAL_MS; humidity = 40; irAmbientTemperature = 25; irObjectTemperature = 25; @@ -78,18 +82,18 @@ bool MockDataProvider::startDataFetching() m_state = Connected; qsrand(QDateTime::currentMSecsSinceEpoch() / 1000); - oneSecondTimer = new QTimer(this); - connect(oneSecondTimer, SIGNAL(timeout()), this, SLOT(oneSecondTimerExpired())); - oneSecondTimer->start(1000); - twentyMillisecondTimer = new QTimer(this); - connect(twentyMillisecondTimer, SIGNAL(timeout()), this, SLOT(twentyMsTimerExpired())); - twentyMillisecondTimer->start(200); + slowUpdateTimer = new QTimer(this); + connect(slowUpdateTimer, SIGNAL(timeout()), this, SLOT(slowTimerExpired())); + slowUpdateTimer->start(MOCK_DATA_SLOW_REFRESH_INTERVAL_MS); + rapidUpdateTimer = new QTimer(this); + connect(rapidUpdateTimer, SIGNAL(timeout()), this, SLOT(rapidTimerExpired())); + rapidUpdateTimer->start(MOCK_DATA_RAPID_REFRESH_INTERVAL_MS); return true; } void MockDataProvider::endDataFetching() { - oneSecondTimer->stop(); + slowUpdateTimer->stop(); } QString MockDataProvider::sensorType() const @@ -107,7 +111,7 @@ void MockDataProvider::setTagType(int tagType) m_tagType = tagType; } -void MockDataProvider::oneSecondTimerExpired() +void MockDataProvider::slowTimerExpired() { /* Emit the signals even if values are unchanged. * Otherwise the scrolling graphs in UI will not scroll. */ @@ -169,7 +173,7 @@ void MockDataProvider::oneSecondTimerExpired() } -void MockDataProvider::twentyMsTimerExpired() +void MockDataProvider::rapidTimerExpired() { //Rotate counter-clockwise around Z axis accelometerX += xAxisG; diff --git a/tradeshow/iot-sensortag/mockdataprovider.h b/tradeshow/iot-sensortag/mockdataprovider.h index 18b238a..5b70b16 100644 --- a/tradeshow/iot-sensortag/mockdataprovider.h +++ b/tradeshow/iot-sensortag/mockdataprovider.h @@ -69,12 +69,14 @@ public: void setTagType(int tagType); public slots: - void oneSecondTimerExpired(); - void twentyMsTimerExpired(); + void slowTimerExpired(); + void rapidTimerExpired(); +protected: + void reset() {} private: - QTimer *oneSecondTimer; - QTimer *twentyMillisecondTimer; + QTimer *slowUpdateTimer; + QTimer *rapidUpdateTimer; float xAxisG; float yAxisG; float zAxisG; diff --git a/tradeshow/iot-sensortag/resources/base/RotationPage.qml b/tradeshow/iot-sensortag/resources/base/RotationPage.qml new file mode 100644 index 0000000..60b2d09 --- /dev/null +++ b/tradeshow/iot-sensortag/resources/base/RotationPage.qml @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of Qt for Device Creation. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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$ +** +****************************************************************************/ +import QtQuick 2.6 +import SensorTag.DataProvider 1.0 +import QtQuick.Particles 2.0 + +Item { + id: dialerRoot + property var sensor: null + anchors.fill: parent + focus: true + + Image { + id: outerRing + anchors.fill: parent + fillMode: Image.PreserveAspectFit + source: pathPrefix + "Gyro/ring_outer.png" + z: parent.z + 1 + } + Image { + id: largeRing + anchors.centerIn: parent + width: outerRing.width * 0.8 + fillMode: Image.PreserveAspectFit + source: pathPrefix + "Gyro/ring_large.png" + rotation: sensor.rotationX + z: parent.z + 2 + Behavior on rotation { + RotationAnimation { + easing.type: Easing.Linear + duration: sensor.rotationUpdateInterval + direction: RotationAnimation.Shortest + } + } + } + Image { + id: mediumRing + anchors.centerIn: parent + width: outerRing.width * 0.6 + fillMode: Image.PreserveAspectFit + source: pathPrefix + "Gyro/ring_medium.png" + rotation: sensor.rotationY + z: parent.z + 3 + Behavior on rotation { + RotationAnimation { + easing.type: Easing.Linear + duration: sensor.rotationUpdateInterval + direction: RotationAnimation.Shortest + } + } + } + Image { + id: centerRing + anchors.centerIn: parent + width: outerRing.width * 0.4 + fillMode: Image.PreserveAspectFit + source: pathPrefix + "Gyro/ring_small.png" + rotation: sensor.rotationZ + z: parent.z + 4 + Behavior on rotation { + RotationAnimation { + easing.type: Easing.Linear + duration: sensor.rotationUpdateInterval + direction: RotationAnimation.Shortest + } + } + } + ParticleSystem { + id: particles + anchors.fill: parent + z: parent.z + 5 + ImageParticle { + source: pathPrefix + "Gyro/particle.png" + alpha: 0 + colorVariation: 0.2 + } + Emitter { + property int rateToEmit: Math.abs(sensor.gyroscopeZ_degPerSec) * 4 + id: centerEmitter + x: centerRing.x + y: centerRing.y + width: centerRing.width + height: centerRing.height + emitRate: rateToEmit > 400 ? rateToEmit : 0 + lifeSpan: 1000 + enabled: true + shape: EllipseShape { + fill: false + } + velocity: AngleDirection{ + magnitude: 100 + angleVariation: 0 + angle: 90 + } + size: particles.width / 200 + sizeVariation: 3 + } + Emitter { + property int rateToEmit: Math.abs(sensor.gyroscopeY_degPerSec) * 4 + id: midEmitter + x: mediumRing.x + y: mediumRing.y + width: mediumRing.width + height: mediumRing.height + emitRate: rateToEmit > 400 ? rateToEmit : 0 + lifeSpan: 1000 + enabled: true + shape: EllipseShape { + fill: false + } + velocity: AngleDirection{ + magnitude: 100 + angleVariation: 0 + angle: 90 + } + size: particles.width / 200 + sizeVariation: 3 + } + Emitter { + property int rateToEmit: Math.abs(sensor.gyroscopeX_degPerSec) * 4 + id: largeEmitter + x: largeRing.x + y: largeRing.y + width: largeRing.width + height: largeRing.height + emitRate: rateToEmit > 400 ? rateToEmit : 0 + lifeSpan: 1000 + enabled: true + shape: EllipseShape { + fill: false + } + velocity: AngleDirection{ + magnitude: 100 + angleVariation: 0 + angle: 90 + } + size: particles.width / 200 + sizeVariation: 3 + } + } +} diff --git a/tradeshow/iot-sensortag/resources/small/MainSmall.qml b/tradeshow/iot-sensortag/resources/small/MainSmall.qml index 7cdc7fe..6d87009 100644 --- a/tradeshow/iot-sensortag/resources/small/MainSmall.qml +++ b/tradeshow/iot-sensortag/resources/small/MainSmall.qml @@ -145,8 +145,9 @@ Item { width: rightPane.width height: rightPane.height * 0.3 - 60 onClicked: { - //mainContainer.source = "../base/GyroPage.qml"; + mainContainer.source = "../base/RotationPage.qml"; gyroConnection.enabled = true; + sensor.recalibrate(); } Connections { diff --git a/tradeshow/iot-sensortag/resources/small/images/Gyro/particle.png b/tradeshow/iot-sensortag/resources/small/images/Gyro/particle.png new file mode 100644 index 0000000..d86fc96 Binary files /dev/null and b/tradeshow/iot-sensortag/resources/small/images/Gyro/particle.png differ diff --git a/tradeshow/iot-sensortag/resources/small/images/Gyro/ring_large.png b/tradeshow/iot-sensortag/resources/small/images/Gyro/ring_large.png new file mode 100644 index 0000000..fcd1cdc Binary files /dev/null and b/tradeshow/iot-sensortag/resources/small/images/Gyro/ring_large.png differ diff --git a/tradeshow/iot-sensortag/resources/small/images/Gyro/ring_medium.png b/tradeshow/iot-sensortag/resources/small/images/Gyro/ring_medium.png new file mode 100644 index 0000000..14924cc Binary files /dev/null and b/tradeshow/iot-sensortag/resources/small/images/Gyro/ring_medium.png differ diff --git a/tradeshow/iot-sensortag/resources/small/images/Gyro/ring_outer.png b/tradeshow/iot-sensortag/resources/small/images/Gyro/ring_outer.png new file mode 100644 index 0000000..4d4d803 Binary files /dev/null and b/tradeshow/iot-sensortag/resources/small/images/Gyro/ring_outer.png differ diff --git a/tradeshow/iot-sensortag/resources/small/images/Gyro/ring_small.png b/tradeshow/iot-sensortag/resources/small/images/Gyro/ring_small.png new file mode 100644 index 0000000..d281f93 Binary files /dev/null and b/tradeshow/iot-sensortag/resources/small/images/Gyro/ring_small.png differ diff --git a/tradeshow/iot-sensortag/sensortagdataprovider.cpp b/tradeshow/iot-sensortag/sensortagdataprovider.cpp index 4d1abcd..456b42d 100644 --- a/tradeshow/iot-sensortag/sensortagdataprovider.cpp +++ b/tradeshow/iot-sensortag/sensortagdataprovider.cpp @@ -53,6 +53,7 @@ #include Q_DECLARE_LOGGING_CATEGORY(boot2QtDemos) +#define DEFAULT_REFRESH_INTERVAL_MS 1000 SensorTagDataProvider::SensorTagDataProvider(QObject *parent) : QObject(parent) @@ -75,12 +76,13 @@ SensorTagDataProvider::SensorTagDataProvider(QString id, QObject* parent) accelometerY(0), accelometerZ(0), /* Object is not "walking in the air" so have one axis at 1G */ - magnetometerMicroT_xAxis(-1000), + magnetometerMicroT_xAxis(-1), magnetometerMicroT_yAxis(0), magnetometerMicroT_zAxis(0), rotation_x(0), rotation_y(0), rotation_z(0), + intervalRotation(DEFAULT_REFRESH_INTERVAL_MS), m_tagType(AmbientTemperature | ObjectTemperature | Humidity | AirPressure | Light | Magnetometer | Rotation | Accelometer), m_id(id), m_state(Disconnected) @@ -201,6 +203,11 @@ float SensorTagDataProvider::getRotationZ() return rotation_z; } +int SensorTagDataProvider::getRotationUpdateInterval() +{ + return intervalRotation; +} + int SensorTagDataProvider::tagType() const { return m_tagType; @@ -223,3 +230,13 @@ void SensorTagDataProvider::setState(SensorTagDataProvider::ProviderState state) emit stateChanged(); } } + +void SensorTagDataProvider::reset() +{ + qCDebug(boot2QtDemos) << "Attempt to reset sensortag that doesn't have reset functionality implemented!"; +} + +void SensorTagDataProvider::recalibrate() +{ + reset(); +} diff --git a/tradeshow/iot-sensortag/sensortagdataprovider.h b/tradeshow/iot-sensortag/sensortagdataprovider.h index 43dda8e..a3cebd0 100644 --- a/tradeshow/iot-sensortag/sensortagdataprovider.h +++ b/tradeshow/iot-sensortag/sensortagdataprovider.h @@ -85,6 +85,7 @@ class SensorTagDataProvider : public QObject Q_PROPERTY(float rotationX READ getRotationX NOTIFY rotationXChanged) Q_PROPERTY(float rotationY READ getRotationY NOTIFY rotationYChanged) Q_PROPERTY(float rotationZ READ getRotationZ NOTIFY rotationZChanged) + Q_PROPERTY(int rotationUpdateInterval READ getRotationUpdateInterval NOTIFY rotationUpdateIntervalChanged) public: enum TagType {AmbientTemperature = 1 << 0, @@ -125,6 +126,7 @@ public: float getRotationX(); float getRotationY(); float getRotationZ(); + int getRotationUpdateInterval(); Q_INVOKABLE int tagType() const; QString id() const; @@ -135,6 +137,8 @@ public: virtual QString sensorType() const { return QString();} virtual QString versionString() const{ return QString();} +public slots: + void recalibrate(); signals: void stateChanged(); @@ -152,8 +156,10 @@ signals: void rotationYChanged(); void rotationZChanged(); void rotationValuesChanged(); + void rotationUpdateIntervalChanged(); protected: + virtual void reset(); double humidity; double irAmbientTemperature; double irObjectTemperature; @@ -174,7 +180,7 @@ protected: float rotation_x; float rotation_y; float rotation_z; - + int intervalRotation; int m_tagType; QString m_id; QString m_name; diff --git a/tradeshow/iot-sensortag/uismall.qrc b/tradeshow/iot-sensortag/uismall.qrc index 2384261..64784e0 100644 --- a/tradeshow/iot-sensortag/uismall.qrc +++ b/tradeshow/iot-sensortag/uismall.qrc @@ -18,5 +18,10 @@ resources/small/images/Toolbar/icon_topbar_cloud.png resources/small/images/Accelometer/inner_ring.png resources/small/images/Accelometer/outer_ring.png + resources/small/images/Gyro/ring_large.png + resources/small/images/Gyro/ring_medium.png + resources/small/images/Gyro/ring_outer.png + resources/small/images/Gyro/ring_small.png + resources/small/images/Gyro/particle.png -- cgit v1.2.3