summaryrefslogtreecommitdiffstats
path: root/tradeshow
diff options
context:
space:
mode:
authorOtto Ryynänen <otto.ryynanen@qt.io>2017-01-30 16:30:13 +0200
committerKari Hautamäki <kari.hautamaki@qt.io>2017-01-31 11:15:58 +0000
commit4a7c0e5841b2bb69ddaef2c9620c443934d194ee (patch)
tree0997ae3fdb9de74ace3d140724b96fe1fdde386d /tradeshow
parent632e35db6d6ef6bf15891e486da983aabfb740b3 (diff)
SensorTag changed to broadcasting mode form read-resp mode
Sensortag now sends data according to set intervals and app only listens to signals. Timers removed as they are no longer needed. Both ambient and object temperature read and converted properly. Cloud data updated with dedicated abient and object temperatures. Version is now 1.1 (backwards compatible). Mock data reflects to reality better. Change-Id: I6a0325a513c1a054322f18e68d2b15c474db3ee5 Reviewed-by: Kari Hautamäki <kari.hautamaki@qt.io>
Diffstat (limited to 'tradeshow')
-rw-r--r--tradeshow/iot-sensortag/bluetoothdataprovider.cpp18
-rw-r--r--tradeshow/iot-sensortag/bluetoothdataprovider.h2
-rw-r--r--tradeshow/iot-sensortag/bluetoothdevice.cpp212
-rw-r--r--tradeshow/iot-sensortag/bluetoothdevice.h28
-rw-r--r--tradeshow/iot-sensortag/clouddataprovider.cpp11
-rw-r--r--tradeshow/iot-sensortag/cloudupdate.cpp4
-rw-r--r--tradeshow/iot-sensortag/mockdataprovider.cpp42
-rw-r--r--tradeshow/iot-sensortag/mockdataprovider.h3
-rw-r--r--tradeshow/iot-sensortag/resources/base/ObjectTemperatureChart.qml2
-rw-r--r--tradeshow/iot-sensortag/resources/base/TemperatureChart.qml10
-rw-r--r--tradeshow/iot-sensortag/sensortagdataprovider.cpp38
-rw-r--r--tradeshow/iot-sensortag/sensortagdataprovider.h15
12 files changed, 122 insertions, 263 deletions
diff --git a/tradeshow/iot-sensortag/bluetoothdataprovider.cpp b/tradeshow/iot-sensortag/bluetoothdataprovider.cpp
index 4737987..c76404f 100644
--- a/tradeshow/iot-sensortag/bluetoothdataprovider.cpp
+++ b/tradeshow/iot-sensortag/bluetoothdataprovider.cpp
@@ -95,11 +95,10 @@ void BluetoothDataProvider::startServiceScan()
activeDevice->scanServices();
}
-void BluetoothDataProvider::temperatureReceived(double temperature)
+void BluetoothDataProvider::temperatureReceived(double newAmbientTemperature, double newObjectTemperature)
{
- if (temperature == irTemperature)
- return;
- irTemperature = temperature;
+ irAmbientTemperature = newAmbientTemperature;
+ irObjectTemperature = newObjectTemperature;
emit infraredCelsiusTemperatureChanged();
}
@@ -137,8 +136,6 @@ float BluetoothDataProvider::countRotationDegrees(double degreesPerSecond, quint
void BluetoothDataProvider::motionReceived(MotionSensorData &data)
{
- qCDebug(boot2QtDemos) << Q_FUNC_INFO << ":" << data.gyroScope_x << "," << data.msSincePreviousData
- << "=" << countRotationDegrees(data.gyroScope_x, data.msSincePreviousData);
gyroscopeX_degPerSec = data.gyroScope_x;
gyroscopeY_degPerSec = data.gyroScope_y;
gyroscopeZ_degPerSec = data.gyroScope_z;
@@ -163,10 +160,6 @@ void BluetoothDataProvider::motionReceived(MotionSensorData &data)
emit rotationXChanged();
emit rotationYChanged();
emit rotationZChanged();
- // Signal that all values have changed, for easier
- // value change handling in clients
- emit rotationValuesChanged();
-
accelometer_mG_xAxis = data.accelometer_x;
accelometer_mG_yAxis = data.accelometer_y;
accelometer_mG_zAxis = data.accelometer_z;
@@ -175,6 +168,9 @@ void BluetoothDataProvider::motionReceived(MotionSensorData &data)
magnetometerMicroT_yAxis = data.magnetometer_y;
magnetometerMicroT_zAxis = data.magnetometer_z;
emit magnetometerMicroTChanged();
+ // Signal that all values have changed, for easier
+ // value change handling in clients
+ emit rotationValuesChanged();
}
QString BluetoothDataProvider::sensorType() const
@@ -184,7 +180,7 @@ QString BluetoothDataProvider::sensorType() const
QString BluetoothDataProvider::versionString() const
{
- return QString("1.0");
+ return QString("1.1");
}
void BluetoothDataProvider::updateState()
diff --git a/tradeshow/iot-sensortag/bluetoothdataprovider.h b/tradeshow/iot-sensortag/bluetoothdataprovider.h
index 0c72673..f232aae 100644
--- a/tradeshow/iot-sensortag/bluetoothdataprovider.h
+++ b/tradeshow/iot-sensortag/bluetoothdataprovider.h
@@ -75,7 +75,7 @@ public:
public slots:
void startServiceScan();
- void temperatureReceived(double temperature);
+ void temperatureReceived(double newAmbientTemperature, double newObjectTemperature);
void barometerReceived(double temperature, double barometer);
void humidityReceived(double humidity);
void lightIntensityReceived(double lightIntensity);
diff --git a/tradeshow/iot-sensortag/bluetoothdevice.cpp b/tradeshow/iot-sensortag/bluetoothdevice.cpp
index 66faf5a..a7b8bc4 100644
--- a/tradeshow/iot-sensortag/bluetoothdevice.cpp
+++ b/tradeshow/iot-sensortag/bluetoothdevice.cpp
@@ -58,18 +58,14 @@
#include <QTimer>
#include <QDebug>
#include <QtMath>
+#include <QDateTime>
Q_DECLARE_LOGGING_CATEGORY(boot2QtDemos)
-// The average time from read request to read response is 150ms in optimal conditions.
-// With other sensors being read we have to limit it to even longer periods.
-#define RAPID_TIMER_MS 350
-#define MEDIUM_TIMER_MS (1.5*RAPID_TIMER_MS)
-#define SLOW_TIMER_MS 2000
-
#define START_MEASUREMENT_STR "01" /* 01 start, 00 stop */
#define DISABLE_NOTIF_STR "0000" /* 0100 enable, 0000 disable */
-#define SLOW_TIMER_TIMEOUT_STR "FA" /* 250 -> 2500ms */
+#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 */
@@ -85,6 +81,13 @@ Q_DECLARE_LOGGING_CATEGORY(boot2QtDemos)
//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 / 32.768)
+#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;
@@ -107,10 +110,8 @@ BluetoothDevice::BluetoothDevice()
, motionService(0)
, m_deviceState(DeviceState::Disconnected)
, randomAddress(false)
- , slowTimer(0)
- , mediumTimer(0)
- , rapidTimer(0)
{
+ lastMilliseconds = QDateTime::currentMSecsSinceEpoch();
statusUpdated("Device created");
}
@@ -122,18 +123,6 @@ BluetoothDevice::BluetoothDevice(const QBluetoothDeviceInfo &d)
BluetoothDevice::~BluetoothDevice()
{
- if (slowTimer) {
- slowTimer->stop();
- delete slowTimer;
- }
- if (mediumTimer) {
- mediumTimer->stop();
- delete mediumTimer;
- }
- if (rapidTimer) {
- rapidTimer->stop();
- delete rapidTimer;
- }
delete discoveryAgent;
delete controller;
qDeleteAll(m_services);
@@ -240,7 +229,7 @@ void BluetoothDevice::serviceScanDone()
irTemperatureService = controller->createServiceObject(uuid);
connect(irTemperatureService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::temperatureDetailsDiscovered);
- connect(irTemperatureService, &QLowEnergyService::characteristicRead, this, &BluetoothDevice::characteristicsRead);
+ connect(irTemperatureService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
irTemperatureService->discoverDetails();
}
if (!baroService)
@@ -256,7 +245,7 @@ void BluetoothDevice::serviceScanDone()
baroService = controller->createServiceObject(uuid);
connect(baroService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::barometerDetailsDiscovered);
- connect(baroService, &QLowEnergyService::characteristicRead, this, &BluetoothDevice::characteristicsRead);
+ connect(baroService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
baroService->discoverDetails();
}
if (!humidityService)
@@ -273,7 +262,7 @@ void BluetoothDevice::serviceScanDone()
humidityService = controller->createServiceObject(uuid);
connect(humidityService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::humidityDetailsDiscovered);
- connect(humidityService, &QLowEnergyService::characteristicRead, this, &BluetoothDevice::characteristicsRead);
+ connect(humidityService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
humidityService->discoverDetails();
}
@@ -291,7 +280,7 @@ void BluetoothDevice::serviceScanDone()
lightService = controller->createServiceObject(uuid);
connect(lightService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::lightIntensityDetailsDiscovered);
- connect(lightService, &QLowEnergyService::characteristicRead, this, &BluetoothDevice::characteristicsRead);
+ connect(lightService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
lightService->discoverDetails();
}
if (!motionService)
@@ -306,7 +295,7 @@ void BluetoothDevice::serviceScanDone()
}
motionService = controller->createServiceObject(uuid);
connect(motionService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::motionDetailsDiscovered);
- connect(motionService, &QLowEnergyService::characteristicRead, this, &BluetoothDevice::characteristicsRead);
+ connect(motionService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
motionService->discoverDetails();
}
attitudeChangeInterval.restart();
@@ -331,7 +320,7 @@ void BluetoothDevice::temperatureDetailsDiscovered(QLowEnergyService::ServiceSta
if (id.toString().contains("f000aa01-0451-4000-b000-000000000000")) {
//RN
- irTemperatureService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(DISABLE_NOTIF_STR));
+ irTemperatureService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(ENABLE_NOTIF_STR));
}
if (id.toString().contains("f000aa02-0451-4000-b000-000000000000")) {
//RW
@@ -363,13 +352,13 @@ void BluetoothDevice::barometerDetailsDiscovered(QLowEnergyService::ServiceState
qCDebug(boot2QtDemos)<<"characteristic:"<<id.toString();
if (id.toString().contains("f000aa41-0451-4000-b000-000000000000")) {
- baroService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(DISABLE_NOTIF_STR));
+ baroService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(ENABLE_NOTIF_STR));
}
if (id.toString().contains("f000aa42-0451-4000-b000-000000000000")) {
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(SLOW_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); // Period 1 second
+ baroService->writeCharacteristic(characteristic, QByteArray::fromHex(MEDIUM_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); // Period 1 second
}
}
m_barometerMeasurementStarted = true;
@@ -394,7 +383,7 @@ void BluetoothDevice::humidityDetailsDiscovered(QLowEnergyService::ServiceState
qCDebug(boot2QtDemos)<<"characteristic:"<<id.toString();
if (id.toString().contains("f000aa21-0451-4000-b000-000000000000")) {
- humidityService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(DISABLE_NOTIF_STR));
+ humidityService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(ENABLE_NOTIF_STR));
}
if (id.toString().contains("f000aa22-0451-4000-b000-000000000000")) {
humidityService->writeCharacteristic(characteristic, QByteArray::fromHex(START_MEASUREMENT_STR), QLowEnergyService::WriteWithResponse); // Start
@@ -425,7 +414,7 @@ void BluetoothDevice::lightIntensityDetailsDiscovered(QLowEnergyService::Service
qCDebug(boot2QtDemos)<<"characteristic:"<<id.toString();
if (id.toString().contains("f000aa71-0451-4000-b000-000000000000")) {
- lightService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(DISABLE_NOTIF_STR));
+ lightService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(ENABLE_NOTIF_STR));
}
if (id.toString().contains("f000aa72-0451-4000-b000-000000000000")) {
lightService->writeCharacteristic(characteristic, QByteArray::fromHex(START_MEASUREMENT_STR), QLowEnergyService::WriteWithResponse); // Start
@@ -440,8 +429,13 @@ void BluetoothDevice::lightIntensityDetailsDiscovered(QLowEnergyService::Service
void BluetoothDevice::motionDetailsDiscovered(QLowEnergyService::ServiceState newstate)
{
+ // reset the time once more before we start to receive measurements.
+ lastMilliseconds = QDateTime::currentMSecsSinceEpoch();
+
if (newstate == QLowEnergyService::ServiceDiscovered) {
- connect(motionService, &QLowEnergyService::characteristicWritten, this, &BluetoothDevice::startTimers);
+ connect(motionService, &QLowEnergyService::characteristicWritten, [=]() {
+ qCDebug(boot2QtDemos) << "Wrote Characteristic - gyro";
+ });
connect(motionService, static_cast<void(QLowEnergyService::*)(QLowEnergyService::ServiceError)>(&QLowEnergyService::error),
[=](QLowEnergyService::ServiceError newError) {
@@ -454,65 +448,19 @@ void BluetoothDevice::motionDetailsDiscovered(QLowEnergyService::ServiceState ne
qCDebug(boot2QtDemos)<<"characteristic:"<<id.toString();
if (id.toString().contains("f000aa81-0451-4000-b000-000000000000")) {
- motionService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(DISABLE_NOTIF_STR));
+ motionService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(ENABLE_NOTIF_STR));
}
if (id.toString().contains("f000aa82-0451-4000-b000-000000000000")) {
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("0a"), QLowEnergyService::WriteWithResponse);
+ motionService->writeCharacteristic(characteristic, QByteArray::fromHex(RAPID_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse);
}
}
m_motionMeasurementStarted = true;
}
}
-void BluetoothDevice::startTimers() {
- qCDebug(boot2QtDemos) << "Wrote Characteristic - gyro, starting timers.";
- if (!slowTimer) {
- slowTimer = new QTimer(this);
- connect(slowTimer, SIGNAL(timeout()), this, SLOT(slowTimerExpired()));
- slowTimer->start(SLOW_TIMER_MS);
- }
- if (!mediumTimer) {
- mediumTimer = new QTimer(this);
- connect(mediumTimer, SIGNAL(timeout()), this, SLOT(mediumTimerExpired()));
- mediumTimer->start(MEDIUM_TIMER_MS);
- }
- if (!rapidTimer) {
- rapidTimer = new QTimer(this);
- connect(rapidTimer, SIGNAL(timeout()), this, SLOT(rapidTimerExpired()));
- rapidTimer->start(RAPID_TIMER_MS);
- }
-}
-
-void BluetoothDevice::slowTimerExpired()
-{
- if (irTemperatureService && m_temperatureMeasurementStarted) {
- queueReadRequest(temperatureCharacteristic);
- }
- if (baroService && m_barometerMeasurementStarted) {
- queueReadRequest(barometerCharacteristic);
- }
- if (humidityService && m_humidityMeasurementStarted){
- queueReadRequest(humidityCharacteristic);
- }
-}
-
-void BluetoothDevice::mediumTimerExpired()
-{
- if (lightService && m_lightIntensityMeasurementStarted){
- queueReadRequest(lightCharacteristic);
- }
-}
-
-void BluetoothDevice::rapidTimerExpired()
-{
- if (motionService && m_motionMeasurementStarted) {
- queueReadRequest(motionCharacteristic);
- }
-}
-
void BluetoothDevice::characteristicsRead(const QLowEnergyCharacteristic &info, const QByteArray &value)
{
switch (info.handle())
@@ -536,9 +484,6 @@ void BluetoothDevice::characteristicsRead(const QLowEnergyCharacteristic &info,
qWarning() << "Invalid handle" << info.handle() << "in characteristicsRead!";
break;
}
- delete readRequestQueue.takeFirst();
- // Response got, now we can send new request.
- sendFirstFromQueue();
}
void BluetoothDevice::setState(BluetoothDevice::DeviceState state)
@@ -549,76 +494,22 @@ void BluetoothDevice::setState(BluetoothDevice::DeviceState state)
}
}
-bool BluetoothDevice::isNotInQueue(CharacteristicType characteristic)
-{
- bool characteristicFound = false;
- QVector<QueueData*>::const_iterator i;
- for (i = readRequestQueue.constBegin(); i != readRequestQueue.constEnd(); ++i) {
- if (characteristic == (*i)->typeToSend) {
- characteristicFound = true;
- break;
- }
- }
- return !characteristicFound;
-}
-
-void BluetoothDevice::queueReadRequest(CharacteristicType characteristicToRead)
-{
- if (isNotInQueue(characteristicToRead)) {
- readRequestQueue.append(new QueueData(characteristicToRead));
- // Try to send. If there is a request ongoing, this does nothing.
- sendFirstFromQueue();
- } else {
- qWarning() << "tried to add request of type " << characteristicToRead << " to queue before previous response was received!";
- }
-}
-
-void BluetoothDevice::sendFirstFromQueue()
+double BluetoothDevice::convertIrTemperatureAPIReadingToCelsius(quint16 rawReading)
{
- while (readRequestQueue.length() &&
- (false == readRequestQueue.first()->alreadySent)) {
- readRequestQueue.first()->alreadySent = true;
- switch (readRequestQueue.first()->typeToSend)
- {
- case temperatureCharacteristic:
- if (irTemperatureService)
- irTemperatureService->readCharacteristic(irTemperatureService->characteristic(QUuid(QString("f000aa01-0451-4000-b000-000000000000"))));
- break;
- case humidityCharacteristic:
- if (humidityService)
- humidityService->readCharacteristic(humidityService->characteristic(QUuid(QString("f000aa21-0451-4000-b000-000000000000"))));
- break;
- case barometerCharacteristic:
- if (baroService)
- baroService->readCharacteristic(baroService->characteristic(QUuid(QString("f000aa41-0451-4000-b000-000000000000"))));
- break;
- case motionCharacteristic:
- if (motionService)
- motionService->readCharacteristic(motionService->characteristic(QUuid(QString("f000aa81-0451-4000-b000-000000000000"))));
- break;
- case lightCharacteristic:
- if (lightService)
- lightService->readCharacteristic(lightService->characteristic(QUuid(QString("f000aa71-0451-4000-b000-000000000000"))));
- break;
- default:
- delete readRequestQueue.takeFirst();
- break;
- }
- }
+ // Compute and filter final value according to TI Bluetooth LE API
+ const float SCALE_LSB = 0.03125;
+ int it = (int)((rawReading) >> 2);
+ float t = (float)it;
+ return t * SCALE_LSB;
}
void BluetoothDevice::irTemperatureReceived(const QByteArray &value)
{
- //Merge bytes
- unsigned int temperature_raw = (((quint8)value.at(3)) << 8) + ((quint8)value.at(2));
- double temperature = static_cast<double>(temperature_raw);
-
- //Compute and filter final value
- if (temperature < 32768)
- temperature = temperature/128.0; //Positive temperature values
- else if (temperature > 32768)
- temperature = (temperature - 65536) / 128.0; //Negative temperature values
- emit temperatureChanged(temperature);
+ const unsigned int rawObjectTemperature = (((quint8)value.at(3)) << 8) + ((quint8)value.at(2));
+ const double objectTemperature = convertIrTemperatureAPIReadingToCelsius(rawObjectTemperature);
+ const unsigned int rawAmbientTemperature = (((quint8)value.at(1)) << 8) + ((quint8)value.at(0));
+ const double ambientTemperature = convertIrTemperatureAPIReadingToCelsius(rawAmbientTemperature);
+ emit temperatureChanged(ambientTemperature, objectTemperature);
}
void BluetoothDevice::barometerReceived(const QByteArray &value)
@@ -635,10 +526,10 @@ void BluetoothDevice::barometerReceived(const QByteArray &value)
}
double temperature = static_cast<double>(temperature_raw);
- temperature /= 100;
+ temperature /= BAROMETER_API_READING_DIVIDER;
double barometer = static_cast<double>(barometer_raw);
- barometer /= 100;
+ barometer /= BAROMETER_API_READING_DIVIDER;
emit barometerChanged(temperature, barometer);
}
@@ -647,7 +538,7 @@ void BluetoothDevice::humidityReceived(const QByteArray &value)
//Merge bytes
unsigned int humidity_raw = (((quint8)value.at(3)) << 8) + ((quint8)value.at(2));
double humidity = static_cast<double>(humidity_raw);
- humidity = (humidity / 65536)*100;
+ humidity = humidity * HUMIDITY_API_READING_MULTIPLIER;
emit humidityChanged(humidity);
}
@@ -660,6 +551,7 @@ void BluetoothDevice::lightIntensityReceived(const QByteArray &value)
m = lightIntensity_raw & 0x0FFF;
e = (lightIntensity_raw & 0xF000) >> 12;
+ // Compute and final value according to TI Bluetooth LE API
double lightIntensity = ((double)m) * (0.01 * (double)qPow(2.0,(qreal)e));
emit lightIntensityChanged(lightIntensity);
}
@@ -667,7 +559,9 @@ void BluetoothDevice::lightIntensityReceived(const QByteArray &value)
void BluetoothDevice::motionReceived(const QByteArray &value)
{
static MotionSensorData data;
- data.msSincePreviousData = attitudeChangeInterval.restart();
+ data.msSincePreviousData = lastMilliseconds;
+ lastMilliseconds = QDateTime::currentMSecsSinceEpoch();
+ data.msSincePreviousData = lastMilliseconds - data.msSincePreviousData;
movement_data_t values;
quint8* writePtr = (quint8*)(&values);
@@ -679,13 +573,13 @@ void BluetoothDevice::motionReceived(const QByteArray &value)
// Data is in little endian. Fix here if needed.
//Convert gyroscope and accelometer readings to proper units
- data.gyroScope_x = (double(values.gyrox) * 500) / 65536;
- data.gyroScope_y = (double(values.gyroy) * 500) / 65536;
- data.gyroScope_z = (double(values.gyroz) * 500) / 65536;
+ data.gyroScope_x = double(values.gyrox) * GYROSCOPE_API_READING_MULTIPLIER;
+ data.gyroScope_y = double(values.gyroy) * GYROSCOPE_API_READING_MULTIPLIER;
+ data.gyroScope_z = double(values.gyroz) * GYROSCOPE_API_READING_MULTIPLIER;
// Accelometer at 8G
- data.accelometer_x = (double(values.accelx)*8) / 32.768;
- data.accelometer_y = (double(values.accely)*8) / 32.768;
- data.accelometer_z = (double(values.accelz)*8) / 32.768;
+ data.accelometer_x = double(values.accelx) * ACCELOMETER_API_READING_MULTIPLIER;
+ data.accelometer_y = double(values.accely) * ACCELOMETER_API_READING_MULTIPLIER;
+ data.accelometer_z = double(values.accelz) * ACCELOMETER_API_READING_MULTIPLIER;
data.magnetometer_x = double(values.magnetomx);
data.magnetometer_y = double(values.magnetomy);
data.magnetometer_z = double(values.magnetomz);
diff --git a/tradeshow/iot-sensortag/bluetoothdevice.h b/tradeshow/iot-sensortag/bluetoothdevice.h
index 58f17c3..26ad814 100644
--- a/tradeshow/iot-sensortag/bluetoothdevice.h
+++ b/tradeshow/iot-sensortag/bluetoothdevice.h
@@ -95,19 +95,6 @@ typedef enum CharacteristicType {
lightCharacteristic
} CharacteristicType;
-class QueueData {
-public:
- CharacteristicType typeToSend;
- bool alreadySent;
- QueueData(CharacteristicType characteristic) {
- typeToSend = characteristic;
- alreadySent = false;
- }
-
-private:
- QueueData() {}
-};
-
class SensorTagDataProvider;
class BluetoothDevice: public QObject
@@ -142,7 +129,7 @@ signals:
void updateChanged();
void stateChanged();
void randomAddressChanged();
- void temperatureChanged(double temperature);
+ void temperatureChanged(double ambientTemperature, double objectTemperature);
void barometerChanged(double temperature, double barometer);
void humidityChanged(double humidity);
void lightIntensityChanged(double intensity);
@@ -151,7 +138,6 @@ signals:
public slots:
void scanServices();
- void startTimers();
void connectToService(const QString &uuid);
void disconnectFromDevice();
void temperatureDetailsDiscovered(QLowEnergyService::ServiceState newstate);
@@ -171,9 +157,6 @@ private slots:
// QLowEnergyService related
void serviceDetailsDiscovered(QLowEnergyService::ServiceState newState);
- void slowTimerExpired();
- void mediumTimerExpired();
- void rapidTimerExpired();
void characteristicsRead(const QLowEnergyCharacteristic &info,
const QByteArray &value);
@@ -181,14 +164,12 @@ private:
void setState(DeviceState state);
private:
- bool isNotInQueue(const CharacteristicType characteristic);
- void queueReadRequest(CharacteristicType characteristicToRead);
- void sendFirstFromQueue();
void irTemperatureReceived(const QByteArray &value);
void barometerReceived(const QByteArray &value);
void humidityReceived(const QByteArray &value);
void lightIntensityReceived(const QByteArray &value);
void motionReceived(const QByteArray &value);
+ double convertIrTemperatureAPIReadingToCelsius(quint16 rawReading);
QBluetoothDeviceDiscoveryAgent *discoveryAgent;
QList<QObject*> m_services;
@@ -207,11 +188,8 @@ private:
bool m_lightIntensityMeasurementStarted;
bool m_motionMeasurementStarted;
bool randomAddress;
- QTimer* slowTimer;
- QTimer* mediumTimer;
- QTimer* rapidTimer;
QElapsedTimer attitudeChangeInterval;
- QVector<QueueData*> readRequestQueue;
+ quint64 lastMilliseconds;
QBluetoothDeviceInfo m_deviceInfo;
diff --git a/tradeshow/iot-sensortag/clouddataprovider.cpp b/tradeshow/iot-sensortag/clouddataprovider.cpp
index ef1efa3..f98432d 100644
--- a/tradeshow/iot-sensortag/clouddataprovider.cpp
+++ b/tradeshow/iot-sensortag/clouddataprovider.cpp
@@ -54,7 +54,7 @@
#include <QTimer>
#define MAJOR_VERSION_NUMBER 1
-#define MINOR_VERSION_NUMBER 0
+#define MINOR_VERSION_NUMBER 1
#ifndef QT_NO_SSL
static QString dataFetchUrl = "https://ottoryynanenqt.blob.core.windows.net/btsensortagreadings/sensorTagReadings.txt";
#else
@@ -118,7 +118,14 @@ void CloudDataProvider::parseReceivedText()
humidity = doubleValue;
emit relativeHumidityChanged();
} else if ("Temp(IR):" == headerText) {
- irTemperature = doubleValue;
+ // Old object temperature from version 1.0
+ irObjectTemperature = doubleValue;
+ emit infraredCelsiusTemperatureChanged();
+ } else if ("Temp(Ambient):" == headerText) {
+ irAmbientTemperature = doubleValue;
+ emit infraredCelsiusTemperatureChanged();
+ } else if ("Temp(Object):" == headerText) {
+ irObjectTemperature = doubleValue;
emit infraredCelsiusTemperatureChanged();
} else if ("Light:" == headerText) {
lightIntensityLux = doubleValue;
diff --git a/tradeshow/iot-sensortag/cloudupdate.cpp b/tradeshow/iot-sensortag/cloudupdate.cpp
index 54b0558..6ef373c 100644
--- a/tradeshow/iot-sensortag/cloudupdate.cpp
+++ b/tradeshow/iot-sensortag/cloudupdate.cpp
@@ -164,7 +164,9 @@ QString CloudUpdate::buildString() const
exportString += QString("Type:\n%1\n").arg(m_provider->sensorType());
exportString += QString("Version:\n%1\n").arg(m_provider->versionString());
exportString += QString("Humid:\n%1\n").arg(m_provider->getRelativeHumidity(), 0, 'f', ROUNDING_DECIMALS);
- exportString += QString("Temp(IR):\n%1\n").arg(m_provider->getInfraredCelsiusTemperature(), 0, 'f', ROUNDING_DECIMALS);
+ exportString += QString("Temp(IR):\n%1\n").arg(m_provider->getInfraredObjectTemperature(), 0, 'f', ROUNDING_DECIMALS);
+ exportString += QString("Temp(Ambient):\n%1\n").arg(m_provider->getInfraredAmbientTemperature(), 0, 'f', ROUNDING_DECIMALS);
+ exportString += QString("Temp(Object):\n%1\n").arg(m_provider->getInfraredObjectTemperature(), 0, 'f', ROUNDING_DECIMALS);
exportString += QString("Light:\n%1\n").arg(m_provider->getLightIntensityLux(), 0, 'f', ROUNDING_DECIMALS);
exportString += QString("Temp(Baro):\n%1\n").arg(m_provider->getBarometerCelsiusTemperature(), 0, 'f', ROUNDING_DECIMALS);
exportString += QString("hPa:\n%1\n").arg(m_provider->getBarometer_hPa(), 0, 'f', ROUNDING_DECIMALS);
diff --git a/tradeshow/iot-sensortag/mockdataprovider.cpp b/tradeshow/iot-sensortag/mockdataprovider.cpp
index 8a34790..3bd841a 100644
--- a/tradeshow/iot-sensortag/mockdataprovider.cpp
+++ b/tradeshow/iot-sensortag/mockdataprovider.cpp
@@ -55,10 +55,14 @@ MockDataProvider::MockDataProvider(QString id, QObject* parent)
xAxisG(-10),
zAxisG(0),
luxIncrease(100),
+ rotationDegPerSecXIncrease(5),
+ rotationDegPerSecYIncrease(7),
+ rotationDegPerSecZIncrease(-9),
m_smaSamples(0)
{
humidity = 40;
- irTemperature = 25;
+ irAmbientTemperature = 25;
+ irObjectTemperature = 25;
barometerCelsiusTemperature = 25;
barometerHPa = 1040;
magnetometerMicroT_xAxis = 333;
@@ -93,7 +97,7 @@ QString MockDataProvider::sensorType() const
QString MockDataProvider::versionString() const
{
- return QLatin1String("1.0");
+ return QLatin1String("1.1");
}
void MockDataProvider::setTagType(int tagType)
@@ -113,13 +117,14 @@ void MockDataProvider::oneSecondTimerExpired()
// IR temperature goes randomly up OR down by half of a degree. So does barometer temperature.
if (qrand() % 2)
- irTemperature -= 0.5;
+ irAmbientTemperature -= 0.5;
else
- irTemperature += 0.5;
- if (irTemperature > 38)
- irTemperature = 38;
- if (irTemperature < 15)
- irTemperature = 15;
+ irAmbientTemperature += 0.5;
+ if (irAmbientTemperature > 38)
+ irAmbientTemperature = 38;
+ if (irAmbientTemperature < 15)
+ irAmbientTemperature = 15;
+ irObjectTemperature = irAmbientTemperature + 2;
emit infraredCelsiusTemperatureChanged();
if (qrand() % 2)
barometerCelsiusTemperature -= 0.5;
@@ -209,14 +214,17 @@ void MockDataProvider::twentyMsTimerExpired()
// value change handling in clients
emit rotationValuesChanged();
- gyroscopeX_degPerSec += 1;
- if (gyroscopeX_degPerSec > 360)
- gyroscopeX_degPerSec -= 360;
- gyroscopeY_degPerSec += 4;
- if (gyroscopeY_degPerSec > 360)
- gyroscopeY_degPerSec -= 360;
- gyroscopeZ_degPerSec += 9;
- if (gyroscopeZ_degPerSec > 360)
- gyroscopeZ_degPerSec -= 360;
+ gyroscopeX_degPerSec += rotationDegPerSecXIncrease;
+ if ((gyroscopeX_degPerSec > 240) ||
+ (gyroscopeX_degPerSec < -240))
+ rotationDegPerSecXIncrease *= -1;
+ gyroscopeY_degPerSec += rotationDegPerSecYIncrease;
+ if ((gyroscopeY_degPerSec > 240) ||
+ (gyroscopeY_degPerSec < -240))
+ rotationDegPerSecYIncrease *= -1;
+ gyroscopeZ_degPerSec += rotationDegPerSecZIncrease;
+ if ((gyroscopeZ_degPerSec > 240) ||
+ (gyroscopeZ_degPerSec < -240))
+ rotationDegPerSecZIncrease *= -1;
emit gyroscopeDegPerSecChanged();
}
diff --git a/tradeshow/iot-sensortag/mockdataprovider.h b/tradeshow/iot-sensortag/mockdataprovider.h
index 8383cfd..1381a7d 100644
--- a/tradeshow/iot-sensortag/mockdataprovider.h
+++ b/tradeshow/iot-sensortag/mockdataprovider.h
@@ -78,6 +78,9 @@ private:
int xAxisG;
int zAxisG;
int luxIncrease;
+ int rotationDegPerSecXIncrease;
+ int rotationDegPerSecYIncrease;
+ int rotationDegPerSecZIncrease;
int m_smaSamples;
};
diff --git a/tradeshow/iot-sensortag/resources/base/ObjectTemperatureChart.qml b/tradeshow/iot-sensortag/resources/base/ObjectTemperatureChart.qml
index e0e612e..11da845 100644
--- a/tradeshow/iot-sensortag/resources/base/ObjectTemperatureChart.qml
+++ b/tradeshow/iot-sensortag/resources/base/ObjectTemperatureChart.qml
@@ -58,7 +58,7 @@ BaseChart {
property real value
function updateTemps(){
- value = sensor.infraredCelsiusTemperature.toFixed(1);
+ value = sensor.infraredObjectTemperature.toFixed(1);
if (minValue > value)
minValue = value;
if (maxValue < value)
diff --git a/tradeshow/iot-sensortag/resources/base/TemperatureChart.qml b/tradeshow/iot-sensortag/resources/base/TemperatureChart.qml
index d4878a4..5a98029 100644
--- a/tradeshow/iot-sensortag/resources/base/TemperatureChart.qml
+++ b/tradeshow/iot-sensortag/resources/base/TemperatureChart.qml
@@ -68,16 +68,16 @@ BaseChart {
readonly property color chartColor: "#15bdff"
onSensorChanged: if (sensor) {
- sensor.barometerCelsiusTemperatureChanged.connect(contentItem.updateTemperatureGraph)
+ sensor.infraredCelsiusTemperatureChanged.connect(contentItem.updateTemperatureGraph)
}
- title: qsTr("Temperature")
+ title: qsTr("Ambient Temperature")
content: Item {
anchors.fill: parent
function updateTemperatureGraph() {
- avgTempSeries.append(temperatureSeriesIndex, sensor.barometerCelsiusTemperature);
+ avgTempSeries.append(temperatureSeriesIndex, sensor.infraredAmbientTemperature);
if (temperatureSeriesIndex >= maxNumOfTempReadings) {
avgTempSeries.remove(avgTempSeries.at(temperatureSeriesIndex-maxNumOfTempReadings));
@@ -86,7 +86,7 @@ BaseChart {
}
temperatureSeriesIndex++;
- var value = sensor.barometerCelsiusTemperature;
+ var value = sensor.infraredAmbientTemperature;
if (minValue > value)
minValue = value;
if (maxValue < value)
@@ -122,7 +122,7 @@ BaseChart {
Text {
anchors.centerIn: parent
- text: sensor ? sensor.barometerCelsiusTemperature : ""
+ text: sensor ? sensor.infraredAmbientTemperature : ""
color: "white"
}
}
diff --git a/tradeshow/iot-sensortag/sensortagdataprovider.cpp b/tradeshow/iot-sensortag/sensortagdataprovider.cpp
index e278f94..157673d 100644
--- a/tradeshow/iot-sensortag/sensortagdataprovider.cpp
+++ b/tradeshow/iot-sensortag/sensortagdataprovider.cpp
@@ -63,7 +63,8 @@ SensorTagDataProvider::SensorTagDataProvider(QObject *parent)
SensorTagDataProvider::SensorTagDataProvider(QString id, QObject* parent)
: QObject(parent),
humidity(0),
- irTemperature(0),
+ irAmbientTemperature(0),
+ irObjectTemperature(0),
lightIntensityLux(0),
barometerCelsiusTemperature(0),
barometerHPa(0),
@@ -96,14 +97,14 @@ double SensorTagDataProvider::getRelativeHumidity()
return humidity;
}
-QString SensorTagDataProvider::getInfraredCelsiusTemperatureString()
+double SensorTagDataProvider::getInfraredAmbientTemperature()
{
- return QString::number(irTemperature) + QString("\u00B0C");
+ return irAmbientTemperature;
}
-double SensorTagDataProvider::getInfraredCelsiusTemperature()
+double SensorTagDataProvider::getInfraredObjectTemperature()
{
- return irTemperature;
+ return irObjectTemperature;
}
QString SensorTagDataProvider::getLightIntensityLuxString()
@@ -185,33 +186,6 @@ float SensorTagDataProvider::getMagnetometerMicroT_zAxis()
return magnetometerMicroT_zAxis;
}
-QColor SensorTagDataProvider::getTemperatureColor()
-{
- // Get average and limit it between 15 and 38 degrees celsius.
- double averageTemperature = (irTemperature + barometerCelsiusTemperature) / 2;
- averageTemperature = std::min(averageTemperature, double(38));
- averageTemperature = std::max(averageTemperature, double(15));
- double relativeTemperature = ((averageTemperature-15)*255)/23;
- int red;
- int green = 128;
- int blue;
- if (relativeTemperature < 128) {
- blue = 255;
- red = relativeTemperature*2;
- } else {
- red = 255;
- blue = 255 - ((relativeTemperature-128)*2);
- }
- return QColor(red, green, blue);
-}
-
-QColor SensorTagDataProvider::getLightIntensityColor()
-{
- double relativeLightIntensityLux = std::min(lightIntensityLux, double(1000));
- relativeLightIntensityLux = 10+((relativeLightIntensityLux*40) / 1000);
- return QColor(relativeLightIntensityLux, relativeLightIntensityLux, relativeLightIntensityLux);
-}
-
float SensorTagDataProvider::getRotationX()
{
return rotation_x;
diff --git a/tradeshow/iot-sensortag/sensortagdataprovider.h b/tradeshow/iot-sensortag/sensortagdataprovider.h
index 510fc6f..7ee4a0d 100644
--- a/tradeshow/iot-sensortag/sensortagdataprovider.h
+++ b/tradeshow/iot-sensortag/sensortagdataprovider.h
@@ -64,8 +64,8 @@ class SensorTagDataProvider : public QObject
Q_PROPERTY(QString providerId MEMBER m_id CONSTANT)
Q_PROPERTY(QString relativeHumidityString READ getRelativeHumidityString NOTIFY relativeHumidityChanged)
Q_PROPERTY(double relativeHumidity READ getRelativeHumidity NOTIFY relativeHumidityChanged)
- Q_PROPERTY(QString infraredCelsiusTemperatureString READ getInfraredCelsiusTemperatureString NOTIFY infraredCelsiusTemperatureChanged)
- Q_PROPERTY(double infraredCelsiusTemperature READ getInfraredCelsiusTemperature NOTIFY infraredCelsiusTemperatureChanged)
+ Q_PROPERTY(double infraredAmbientTemperature READ getInfraredAmbientTemperature NOTIFY infraredCelsiusTemperatureChanged)
+ Q_PROPERTY(double infraredObjectTemperature READ getInfraredObjectTemperature NOTIFY infraredCelsiusTemperatureChanged)
Q_PROPERTY(QString lightIntensityLuxString READ getLightIntensityLuxString NOTIFY lightIntensityChanged)
Q_PROPERTY(double lightIntensityLux READ getLightIntensityLux NOTIFY lightIntensityChanged)
Q_PROPERTY(double barometerCelsiusTemperature READ getBarometerCelsiusTemperature NOTIFY barometerCelsiusTemperatureChanged)
@@ -82,8 +82,6 @@ class SensorTagDataProvider : public QObject
Q_PROPERTY(float magnetometerMicroT_xAxis READ getMagnetometerMicroT_xAxis NOTIFY magnetometerMicroTChanged)
Q_PROPERTY(float magnetometerMicroT_yAxis READ getMagnetometerMicroT_yAxis NOTIFY magnetometerMicroTChanged)
Q_PROPERTY(float magnetometerMicroT_zAxis READ getMagnetometerMicroT_zAxis NOTIFY magnetometerMicroTChanged)
- Q_PROPERTY(QColor temperatureColor READ getTemperatureColor NOTIFY infraredCelsiusTemperatureChanged)
- Q_PROPERTY(QColor lightIntensityColor READ getLightIntensityColor NOTIFY lightIntensityChanged)
Q_PROPERTY(float rotationX READ getRotationX NOTIFY rotationXChanged)
Q_PROPERTY(float rotationY READ getRotationY NOTIFY rotationYChanged)
Q_PROPERTY(float rotationZ READ getRotationZ NOTIFY rotationZChanged)
@@ -105,8 +103,8 @@ public:
virtual void endDataFetching() {}
QString getRelativeHumidityString();
double getRelativeHumidity();
- QString getInfraredCelsiusTemperatureString();
- double getInfraredCelsiusTemperature();
+ double getInfraredAmbientTemperature();
+ double getInfraredObjectTemperature();
QString getLightIntensityLuxString();
double getLightIntensityLux();
double getBarometerCelsiusTemperature();
@@ -123,8 +121,6 @@ public:
float getMagnetometerMicroT_xAxis();
float getMagnetometerMicroT_yAxis();
float getMagnetometerMicroT_zAxis();
- QColor getTemperatureColor();
- QColor getLightIntensityColor();
float getRotationX();
float getRotationY();
float getRotationZ();
@@ -157,7 +153,8 @@ signals:
protected:
double humidity;
- double irTemperature;
+ double irAmbientTemperature;
+ double irObjectTemperature;
double lightIntensityLux;
double barometerCelsiusTemperature;
double barometerTemperatureAverage;