diff options
author | Fawzi Mohamed <fawzi.mohamed@digia.com> | 2014-04-11 14:35:14 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-17 13:44:57 +0200 |
commit | 8a0da79f058b7ee7cdf4a198fdf088e8a43565fb (patch) | |
tree | 3d0e2649fcc452baf782eab2d9b6c1c7ec6880d9 /src/plugins | |
parent | da27dc09c45a236744c482107a7d9f709069381c (diff) | |
download | qtsensors-8a0da79f058b7ee7cdf4a198fdf088e8a43565fb.tar.gz |
ios: skip accelerometer, gyroscope and magnetomenter updates if NaN
Change-Id: I7becfab81d56fc45ec7dc76333383503b8abccfe
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/sensors/ios/iosaccelerometer.mm | 3 | ||||
-rw-r--r-- | src/plugins/sensors/ios/iosgyroscope.mm | 3 | ||||
-rw-r--r-- | src/plugins/sensors/ios/iosmagnetometer.mm | 6 |
3 files changed, 12 insertions, 0 deletions
diff --git a/src/plugins/sensors/ios/iosaccelerometer.mm b/src/plugins/sensors/ios/iosaccelerometer.mm index 5f9c0f1..ef21546 100644 --- a/src/plugins/sensors/ios/iosaccelerometer.mm +++ b/src/plugins/sensors/ios/iosaccelerometer.mm @@ -77,6 +77,9 @@ 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; + // skip update if NaN + if (acc.x != acc.x || acc.y != acc.y || acc.z != acc.z) + return; static const qreal G = 9.8066; m_reading.setTimestamp(quint64(data.timestamp * 1e6)); m_reading.setX(qreal(acc.x) * G * -1); diff --git a/src/plugins/sensors/ios/iosgyroscope.mm b/src/plugins/sensors/ios/iosgyroscope.mm index 8dfa3a4..751786e 100644 --- a/src/plugins/sensors/ios/iosgyroscope.mm +++ b/src/plugins/sensors/ios/iosgyroscope.mm @@ -75,6 +75,9 @@ void IOSGyroscope::timerEvent(QTimerEvent *) // Convert NSTimeInterval to microseconds and radians to degrees: CMGyroData *data = m_motionManager.gyroData; CMRotationRate rate = data.rotationRate; + // skip update if NaN + if (rate.x != rate.x || rate.y != rate.y || rate.z != rate.z) + return; m_reading.setTimestamp(quint64(data.timestamp * 1e6)); m_reading.setX((qreal(rate.x) / M_PI) * 180); m_reading.setY((qreal(rate.y) / M_PI) * 180); diff --git a/src/plugins/sensors/ios/iosmagnetometer.mm b/src/plugins/sensors/ios/iosmagnetometer.mm index 95f85ae..3cd8b10 100644 --- a/src/plugins/sensors/ios/iosmagnetometer.mm +++ b/src/plugins/sensors/ios/iosmagnetometer.mm @@ -91,6 +91,9 @@ void IOSMagnetometer::timerEvent(QTimerEvent *) CMDeviceMotion *deviceMotion = m_motionManager.deviceMotion; CMCalibratedMagneticField calibratedField = deviceMotion.magneticField; field = calibratedField.field; + // skip update if NaN + if (field.x != field.x || field.y != field.y || field.z != field.z) + return; m_reading.setTimestamp(quint64(deviceMotion.timestamp * 1e6)); switch (calibratedField.accuracy) { @@ -110,6 +113,9 @@ void IOSMagnetometer::timerEvent(QTimerEvent *) } else { CMMagnetometerData *data = m_motionManager.magnetometerData; field = data.magneticField; + // skip update if NaN + if (field.x != field.x || field.y != field.y || field.z != field.z) + return; m_reading.setTimestamp(quint64(data.timestamp * 1e6)); m_reading.setCalibrationLevel(1.0); } |