diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-04-29 14:19:38 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-04-29 14:19:38 +0200 |
commit | 623a50a536ab0586faa8ae6f9ea2700069ceda00 (patch) | |
tree | 58772be9a081e72ea00814c16270acf85e7339bd /src/plugins | |
parent | b11d8d673ba36ab22c0d7a40ea53d57f284cca13 (diff) | |
parent | 47198045f8df3135498f061ae3da5a852a0a150c (diff) | |
download | qtsensors-623a50a536ab0586faa8ae6f9ea2700069ceda00.tar.gz |
Merge remote-tracking branch 'origin/stable' into dev
Change-Id: I4cfd0e2a2f108f5ecf79c56418c02928b041856e
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/sensors/generic/generic.pro | 1 | ||||
-rw-r--r-- | src/plugins/sensors/ios/ios.pro | 10 | ||||
-rw-r--r-- | src/plugins/sensors/ios/ioscompass.h | 72 | ||||
-rw-r--r-- | src/plugins/sensors/ios/ioscompass.mm | 128 | ||||
-rw-r--r-- | src/plugins/sensors/ios/iosproximitysensor.h | 73 | ||||
-rw-r--r-- | src/plugins/sensors/ios/iosproximitysensor.mm | 133 | ||||
-rw-r--r-- | src/plugins/sensors/ios/main.mm | 10 | ||||
-rw-r--r-- | src/plugins/sensors/sensors.pro | 4 |
8 files changed, 428 insertions, 3 deletions
diff --git a/src/plugins/sensors/generic/generic.pro b/src/plugins/sensors/generic/generic.pro index fcc1bfc..9226cab 100644 --- a/src/plugins/sensors/generic/generic.pro +++ b/src/plugins/sensors/generic/generic.pro @@ -2,6 +2,7 @@ TARGET = qtsensors_generic QT = core sensors PLUGIN_TYPE = sensors +PLUGIN_CLASS_NAME = genericSensorPlugin load(qt_plugin) HEADERS += generictiltsensor.h diff --git a/src/plugins/sensors/ios/ios.pro b/src/plugins/sensors/ios/ios.pro index 0776d8c..4197b14 100644 --- a/src/plugins/sensors/ios/ios.pro +++ b/src/plugins/sensors/ios/ios.pro @@ -10,12 +10,16 @@ OTHER_FILES = plugin.json HEADERS += iosaccelerometer.h \ iosmotionmanager.h \ iosgyroscope.h \ - iosmagnetometer.h + iosmagnetometer.h \ + ioscompass.h \ + iosproximitysensor.h OBJECTIVE_SOURCES += main.mm \ iosaccelerometer.mm \ iosmotionmanager.mm \ iosgyroscope.mm \ - iosmagnetometer.mm + iosmagnetometer.mm \ + ioscompass.mm \ + iosproximitysensor.mm -LIBS += -framework UIKit -framework CoreMotion +LIBS += -framework UIKit -framework CoreMotion -framework CoreLocation diff --git a/src/plugins/sensors/ios/ioscompass.h b/src/plugins/sensors/ios/ioscompass.h new file mode 100644 index 0000000..c33cf1f --- /dev/null +++ b/src/plugins/sensors/ios/ioscompass.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IOSCompass_H +#define IOSCompass_H + +#import <CoreLocation/CLLocationManager.h> + +#include <qsensorbackend.h> +#include <qcompass.h> + +QT_BEGIN_NAMESPACE + +class IOSCompass : public QSensorBackend +{ +public: + static char const * const id; + + explicit IOSCompass(QSensor *sensor); + ~IOSCompass(); + + void start(); + void stop(); + + void headingChanged(qreal heading, quint64 timestamp, qreal calibrationLevel); + +private: + CLLocationManager *m_locationManager; + QCompassReading m_reading; +}; +QT_END_NAMESPACE + +#endif // IOSCompass_H + diff --git a/src/plugins/sensors/ios/ioscompass.mm b/src/plugins/sensors/ios/ioscompass.mm new file mode 100644 index 0000000..ded26e3 --- /dev/null +++ b/src/plugins/sensors/ios/ioscompass.mm @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#import <CoreLocation/CLHeading.h> +#import <CoreLocation/CLLocationManagerDelegate.h> +#include <QtCore/qglobal.h> + +#include "ioscompass.h" + +char const * const IOSCompass::id("ios.compass"); + +QT_BEGIN_NAMESPACE + +@interface locationDelegate : NSObject <CLLocationManagerDelegate> +{ + IOSCompass *m_iosCompass; +} +@end + +@implementation locationDelegate + +- (id)initWithQIOSCompass:(IOSCompass*)iosCompass +{ + self = [super init]; + if (self) { + m_iosCompass = iosCompass; + } + return self; +} + +- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading +{ + Q_UNUSED(manager); + // Convert NSDate to microseconds: + quint64 timestamp = quint64(newHeading.timestamp.timeIntervalSinceReferenceDate * 1e6); + double accuracy = newHeading.headingAccuracy; + // Accuracy is the maximum number of degrees the reading can be off. The QtSensors scale + // goes from 1 to 0, with 1 being the best (0 degrees off), and 0 worst (365 degrees off): + qreal calibrationLevel = (accuracy < 0) ? 0 : qMax(0., 1 - (accuracy / 365)); + qreal heading = qreal(newHeading.magneticHeading); + m_iosCompass->headingChanged(heading, timestamp, calibrationLevel); +} + +- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager +{ + Q_UNUSED(manager); + return YES; +} + +@end + +IOSCompass::IOSCompass(QSensor *sensor) + : QSensorBackend(sensor) + , m_locationManager(0) +{ + setReading<QCompassReading>(&m_reading); + addDataRate(1, 70); + addOutputRange(0, 359, 1); +} + +IOSCompass::~IOSCompass() +{ + [m_locationManager release]; +} + +void IOSCompass::start() +{ + if (!m_locationManager) { + m_locationManager = [[CLLocationManager alloc] init]; + m_locationManager.desiredAccuracy = kCLLocationAccuracyBest; + m_locationManager.headingFilter = kCLHeadingFilterNone; + m_locationManager.delegate = [[locationDelegate alloc] initWithQIOSCompass:this]; + } + [m_locationManager startUpdatingHeading]; +} + +void IOSCompass::headingChanged(qreal heading, quint64 timestamp, qreal calibrationLevel) +{ + m_reading.setAzimuth(heading); + m_reading.setTimestamp(timestamp); + m_reading.setCalibrationLevel(calibrationLevel); + newReadingAvailable(); +} + +void IOSCompass::stop() +{ + [m_locationManager stopUpdatingHeading]; +} + +QT_END_NAMESPACE diff --git a/src/plugins/sensors/ios/iosproximitysensor.h b/src/plugins/sensors/ios/iosproximitysensor.h new file mode 100644 index 0000000..6788512 --- /dev/null +++ b/src/plugins/sensors/ios/iosproximitysensor.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IOSPROXIMITYSENSOR_H +#define IOSPROXIMITYSENSOR_H + +#include <qsensorbackend.h> +#include <qproximitysensor.h> + +QT_BEGIN_NAMESPACE + +@class ProximitySensorCallback; + +class IOSProximitySensor : public QSensorBackend +{ +public: + static char const * const id; + + explicit IOSProximitySensor(QSensor *sensor); + ~IOSProximitySensor(); + + void start(); + void stop(); + + void proximityChanged(bool close); + static bool available(); + +private: + ProximitySensorCallback *m_proximitySensorCallback; + QProximityReading m_reading; +}; +QT_END_NAMESPACE + +#endif // IOSPROXIMITYSENSOR_H + diff --git a/src/plugins/sensors/ios/iosproximitysensor.mm b/src/plugins/sensors/ios/iosproximitysensor.mm new file mode 100644 index 0000000..5ba832e --- /dev/null +++ b/src/plugins/sensors/ios/iosproximitysensor.mm @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#import <UIKit/UIDevice.h> + +#include "iosproximitysensor.h" + +char const * const IOSProximitySensor::id("ios.proximitysensor"); + +QT_BEGIN_NAMESPACE + +@interface ProximitySensorCallback : NSObject +{ + IOSProximitySensor *m_iosProximitySensor; +} +@end + +@implementation ProximitySensorCallback + +- (id)initWithQIOSProximitySensor:(IOSProximitySensor *)iosProximitySensor +{ + self = [super init]; + if (self) { + m_iosProximitySensor = iosProximitySensor; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(proximityChanged:) + name:@"UIDeviceProximityStateDidChangeNotification" object:nil]; + } + return self; +} + +-(void) dealloc +{ + [[NSNotificationCenter defaultCenter] + removeObserver:self + name:@"UIDeviceProximityStateDidChangeNotification" object:nil]; + [super dealloc]; +} + +- (void)proximityChanged:(NSNotificationCenter *)notification +{ + Q_UNUSED(notification); + bool close = [[UIDevice currentDevice] proximityState] == YES; + m_iosProximitySensor->proximityChanged(close); +} + +@end + +bool IOSProximitySensor::available() +{ + UIDevice *device = [UIDevice currentDevice]; + if (device.proximityMonitoringEnabled) + return true; + // According to the docs, you need to switch it on and + // re-read the property to check if it is available: + device.proximityMonitoringEnabled = YES; + bool available = device.proximityMonitoringEnabled; + device.proximityMonitoringEnabled = NO; + return available; +} + +IOSProximitySensor::IOSProximitySensor(QSensor *sensor) + : QSensorBackend(sensor) + , m_proximitySensorCallback(0) +{ + setReading<QProximityReading>(&m_reading); +} + +IOSProximitySensor::~IOSProximitySensor() +{ + [m_proximitySensorCallback release]; +} + +void IOSProximitySensor::start() +{ + m_proximitySensorCallback = [[ProximitySensorCallback alloc] initWithQIOSProximitySensor:this]; + [UIDevice currentDevice].proximityMonitoringEnabled = YES; +} + +void IOSProximitySensor::proximityChanged(bool close) +{ + m_reading.setClose(close); + m_reading.setTimestamp(quint64([[NSDate date] timeIntervalSinceReferenceDate] * 1e6)); + newReadingAvailable(); +} + +void IOSProximitySensor::stop() +{ + [UIDevice currentDevice].proximityMonitoringEnabled = NO; + [m_proximitySensorCallback release]; + m_proximitySensorCallback = 0; +} + +QT_END_NAMESPACE diff --git a/src/plugins/sensors/ios/main.mm b/src/plugins/sensors/ios/main.mm index 25b41b6..e4a0364 100644 --- a/src/plugins/sensors/ios/main.mm +++ b/src/plugins/sensors/ios/main.mm @@ -47,6 +47,8 @@ #include "iosaccelerometer.h" #include "iosgyroscope.h" #include "iosmagnetometer.h" +#include "ioscompass.h" +#include "iosproximitysensor.h" class IOSSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory { @@ -61,6 +63,10 @@ public: QSensorManager::registerBackend(QGyroscope::type, IOSGyroscope::id, this); if ([QIOSMotionManager sharedManager].magnetometerAvailable) QSensorManager::registerBackend(QMagnetometer::type, IOSMagnetometer::id, this); + if ([CLLocationManager headingAvailable]) + QSensorManager::registerBackend(QCompass::type, IOSCompass::id, this); + if (IOSProximitySensor::available()) + QSensorManager::registerBackend(QProximitySensor::type, IOSProximitySensor::id, this); } QSensorBackend *createBackend(QSensor *sensor) @@ -71,6 +77,10 @@ public: return new IOSGyroscope(sensor); if (sensor->identifier() == IOSMagnetometer::id) return new IOSMagnetometer(sensor); + if (sensor->identifier() == IOSCompass::id) + return new IOSCompass(sensor); + if (sensor->identifier() == IOSProximitySensor::id) + return new IOSProximitySensor(sensor); return 0; } diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro index 73f4267..66f9f5a 100644 --- a/src/plugins/sensors/sensors.pro +++ b/src/plugins/sensors/sensors.pro @@ -14,6 +14,10 @@ sensorfw { isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = sensorfw generic } +ios { + isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = ios generic +} + isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, dummy):SUBDIRS += dummy isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, generic):SUBDIRS += generic isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, simulator):simulator:SUBDIRS += simulator |