summaryrefslogtreecommitdiff
path: root/src/plugins/sensors/ios/iosgyroscope.mm
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-09-21 08:34:05 +0200
committerLiang Qi <liang.qi@qt.io>2016-09-21 08:34:05 +0200
commit53a414e33ce45f28b89217678597416b681128d4 (patch)
tree51ab26cf4a14662e525c4a648d84dae81090f0c7 /src/plugins/sensors/ios/iosgyroscope.mm
parent3523afa703792fabc8bac3febe5541766bc1ccd4 (diff)
parentdf3374bd4bb8af1494f6a35b1102f15cfe9633e0 (diff)
downloadqtsensors-53a414e33ce45f28b89217678597416b681128d4.tar.gz
Merge remote-tracking branch 'origin/5.8' into dev
Change-Id: Iaeb7c9f62b50d68e0cedb95c523aebcceb9128c0
Diffstat (limited to 'src/plugins/sensors/ios/iosgyroscope.mm')
-rw-r--r--src/plugins/sensors/ios/iosgyroscope.mm14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/plugins/sensors/ios/iosgyroscope.mm b/src/plugins/sensors/ios/iosgyroscope.mm
index fc9b616..19e65e5 100644
--- a/src/plugins/sensors/ios/iosgyroscope.mm
+++ b/src/plugins/sensors/ios/iosgyroscope.mm
@@ -44,6 +44,8 @@ char const * const IOSGyroscope::id("ios.gyroscope");
QT_BEGIN_NAMESPACE
+int IOSGyroscope::s_startCount = 0;
+
IOSGyroscope::IOSGyroscope(QSensor *sensor)
: QSensorBackend(sensor)
, m_motionManager([QIOSMotionManager sharedManager])
@@ -56,16 +58,24 @@ IOSGyroscope::IOSGyroscope(QSensor *sensor)
void IOSGyroscope::start()
{
+ if (m_timer != 0)
+ return;
+
int hz = sensor()->dataRate();
m_timer = startTimer(1000 / (hz == 0 ? 60 : hz));
- [m_motionManager startGyroUpdates];
+ if (++s_startCount == 1)
+ [m_motionManager startGyroUpdates];
}
void IOSGyroscope::stop()
{
- [m_motionManager stopGyroUpdates];
+ if (m_timer == 0)
+ return;
+
killTimer(m_timer);
m_timer = 0;
+ if (--s_startCount == 0)
+ [m_motionManager stopGyroUpdates];
}
void IOSGyroscope::timerEvent(QTimerEvent *)