diff options
author | Liang Qi <liang.qi@qt.io> | 2016-09-19 14:33:39 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-09-19 14:33:44 +0200 |
commit | df3374bd4bb8af1494f6a35b1102f15cfe9633e0 (patch) | |
tree | 5c76f62e0e0be4bb7a79f3441717c6b8c4d302af /src/plugins/sensors/ios/iosgyroscope.mm | |
parent | 0032fd615097baeff2414e352e095bc412000941 (diff) | |
parent | ecd018fe2ee4508e094f631d882ecc1360abec01 (diff) | |
download | qtsensors-df3374bd4bb8af1494f6a35b1102f15cfe9633e0.tar.gz |
Merge remote-tracking branch 'origin/5.7' into 5.8
Change-Id: I35021aba57d8acc6b6e27e9800c6a244cb0e99da
Diffstat (limited to 'src/plugins/sensors/ios/iosgyroscope.mm')
-rw-r--r-- | src/plugins/sensors/ios/iosgyroscope.mm | 14 |
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 *) |