summaryrefslogtreecommitdiffstats
path: root/tradeshow/iot-sensortag/resources
diff options
context:
space:
mode:
authorMaurice Kalinowski <maurice.kalinowski@qt.io>2017-02-15 11:58:01 +0100
committerTitta Heikkala <titta.heikkala@qt.io>2017-02-16 08:05:16 +0000
commitc8ce4940c5be641b753ef943cf336963596705a4 (patch)
treed81cdce08c8daae30bc50951239530dc3d189608 /tradeshow/iot-sensortag/resources
parent90e26ea85564f22458dbec138e91e8078371f8b2 (diff)
Move series updates to C++
Instead of jumping to and from the QML engine for each sensor update, rather stay inside C++ and let QML only do the visual updates. This only updates the items which use Charts, as updates to a series is expensive. Change-Id: Idc7a98d2865e7095264f226c0ac5bbb5a977d18a Reviewed-by: Titta Heikkala <titta.heikkala@qt.io>
Diffstat (limited to 'tradeshow/iot-sensortag/resources')
-rw-r--r--tradeshow/iot-sensortag/resources/base/GyroChart.qml25
-rw-r--r--tradeshow/iot-sensortag/resources/base/MagnetometerChart.qml21
-rw-r--r--tradeshow/iot-sensortag/resources/base/TemperatureChart.qml25
-rw-r--r--tradeshow/iot-sensortag/resources/base/main.qml2
4 files changed, 18 insertions, 55 deletions
diff --git a/tradeshow/iot-sensortag/resources/base/GyroChart.qml b/tradeshow/iot-sensortag/resources/base/GyroChart.qml
index 30aba64..f7d2b71 100644
--- a/tradeshow/iot-sensortag/resources/base/GyroChart.qml
+++ b/tradeshow/iot-sensortag/resources/base/GyroChart.qml
@@ -51,12 +51,12 @@ import QtQuick 2.5
import QtCharts 2.1
import SensorTag.DataProvider 1.0
import QtGraphicalEffects 1.0
+import QtQml 2.2
BaseChart {
id: gyroHolderRect
// Replace with actual gyro properties
- property int gyroSeriesIndex: 0
property int maxGyroReadings: 24
readonly property string xColor: "#15bdff"
@@ -64,12 +64,6 @@ BaseChart {
readonly property string zColor: "red"
readonly property color textColor: "white"
- onSensorChanged: {
- if (sensor) {
- sensor.rotationValuesChanged.connect(contentItem.updateRotation);
- }
- }
-
onClicked: {
if (sensor)
sensor.recalibrate();
@@ -81,19 +75,12 @@ BaseChart {
content: Item {
anchors.fill: parent
- function updateRotation() {
- gyroSeriesX.append(gyroSeriesIndex, sensor.rotationX);
- gyroSeriesY.append(gyroSeriesIndex, sensor.rotationY);
- gyroSeriesZ.append(gyroSeriesIndex, sensor.rotationZ);
-
- if (gyroSeriesIndex >= maxGyroReadings) {
- gyroSeriesX.remove(gyroSeriesX.at(gyroSeriesIndex-maxGyroReadings));
- gyroSeriesY.remove(gyroSeriesY.at(gyroSeriesIndex-maxGyroReadings));
- gyroSeriesZ.remove(gyroSeriesZ.at(gyroSeriesIndex-maxGyroReadings));
- valueAxisX.min++;
- valueAxisX.max++;
+ Connections {
+ target: mainWindow
+ onSeriesStorageChanged: {
+ if (seriesStorage)
+ seriesStorage.setGyroSeries(gyroSeriesX, gyroSeriesY, gyroSeriesZ);
}
- gyroSeriesIndex++;
}
Glow {
diff --git a/tradeshow/iot-sensortag/resources/base/MagnetometerChart.qml b/tradeshow/iot-sensortag/resources/base/MagnetometerChart.qml
index 6c4ba79..3bac8e6 100644
--- a/tradeshow/iot-sensortag/resources/base/MagnetometerChart.qml
+++ b/tradeshow/iot-sensortag/resources/base/MagnetometerChart.qml
@@ -55,7 +55,6 @@ import QtGraphicalEffects 1.0
BaseChart {
id: magnetHolderRect
- property int magneticSeriesIndex: 0
property int maxNumOfMagnReadings: 24
readonly property color chartColor: "#15bdff"
@@ -64,28 +63,18 @@ BaseChart {
readonly property string zColor: "red"
readonly property color textColor: "white"
- onSensorChanged: if (sensor) sensor.magnetometerMicroTChanged.connect(contentItem.updateMagneticGraph)
-
title: qsTr("Magnetometer")
rightSide: true
content: Item {
anchors.fill: parent
- function updateMagneticGraph()
- {
- magnSeriesX.append(magneticSeriesIndex, sensor.magnetometerMicroT_xAxis);
- magnSeriesY.append(magneticSeriesIndex, sensor.magnetometerMicroT_yAxis);
- magnSeriesZ.append(magneticSeriesIndex, sensor.magnetometerMicroT_zAxis);
-
- if (magneticSeriesIndex >= maxNumOfMagnReadings) {
- magnSeriesX.remove(magnSeriesX.at(magneticSeriesIndex-maxNumOfMagnReadings));
- magnSeriesY.remove(magnSeriesY.at(magneticSeriesIndex-maxNumOfMagnReadings));
- magnSeriesZ.remove(magnSeriesY.at(magneticSeriesIndex-maxNumOfMagnReadings));
- valueAxisX.min++;
- valueAxisX.max++;
+ Connections {
+ target: mainWindow
+ onSeriesStorageChanged: {
+ if (seriesStorage)
+ seriesStorage.setMagnetoMeterSeries(magnSeriesX, magnSeriesY, magnSeriesZ);
}
- magneticSeriesIndex++;
}
Image {
diff --git a/tradeshow/iot-sensortag/resources/base/TemperatureChart.qml b/tradeshow/iot-sensortag/resources/base/TemperatureChart.qml
index dab2479..8bb1a25 100644
--- a/tradeshow/iot-sensortag/resources/base/TemperatureChart.qml
+++ b/tradeshow/iot-sensortag/resources/base/TemperatureChart.qml
@@ -55,7 +55,6 @@ import QtGraphicalEffects 1.0
BaseChart {
id: tempHolderRect
- property int temperatureSeriesIndex: 0
property int maxNumOfTempReadings: 30
property real minimum: 10
property real maximum: 40
@@ -77,29 +76,15 @@ BaseChart {
content: Item {
anchors.fill: parent
- Component.onCompleted: {
- // Initialize series
- var i = 0
- while (i < maxNumOfTempReadings) {
- avgTempSeries.append(i, defaultAvgValue)
- i++
+ Connections {
+ target: mainWindow
+ onSeriesStorageChanged: {
+ if (seriesStorage)
+ seriesStorage.setTemperatureSeries(avgTempSeries);
}
- temperatureSeriesIndex = i
}
function updateTemperatureGraph() {
- // Make sure defaultAvgValue is the last valuea in the series
- avgTempSeries.remove(temperatureSeriesIndex - 1, defaultAvgValue);
- avgTempSeries.append(temperatureSeriesIndex - 1, sensor.infraredAmbientTemperature);
- avgTempSeries.append(temperatureSeriesIndex, defaultAvgValue);
-
- if (temperatureSeriesIndex >= maxNumOfTempReadings) {
- avgTempSeries.remove(avgTempSeries.at(temperatureSeriesIndex - maxNumOfTempReadings));
- valueAxisX.min++;
- valueAxisX.max++;
- }
- temperatureSeriesIndex++;
-
var value = sensor.infraredAmbientTemperature;
if (minValue > value)
minValue = value;
diff --git a/tradeshow/iot-sensortag/resources/base/main.qml b/tradeshow/iot-sensortag/resources/base/main.qml
index 679a8dc..c55d8ee 100644
--- a/tradeshow/iot-sensortag/resources/base/main.qml
+++ b/tradeshow/iot-sensortag/resources/base/main.qml
@@ -50,12 +50,14 @@
import QtQuick 2.6
import QtQuick.Window 2.0
import SensorTag.DataProvider 1.0
+import SensorTag.SeriesStorage 1.0
Window {
id: mainWindow
property alias contentFile: contentLoader.source
property DataProviderPool dataProviderPool
+ property SeriesStorage seriesStorage
// Size defaults to the small display
width: 1920