summaryrefslogtreecommitdiffstats
path: root/src/plugins/sensors/blackberry/bbsensorbackend.cpp
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>2013-01-10 13:38:43 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-23 18:33:17 +0100
commit78ad1fabee403ac910d29bb212cf0e3b9a670708 (patch)
tree9dbfdfdab19de9666eaf2923e79d2b9141cc4eaa /src/plugins/sensors/blackberry/bbsensorbackend.cpp
parent5700ab09b06617d73b0495d2db0696512913ba51 (diff)
Add a axes remapping feature
This allows orientable sensors like accelerometer or compass to change to adapt the reading values based on the current screen orientation. Add support for the BlackBerry backend. Change-Id: If7cfde8f20da4f677fdd13c38f7e11f2ed96bedd Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
Diffstat (limited to 'src/plugins/sensors/blackberry/bbsensorbackend.cpp')
-rw-r--r--src/plugins/sensors/blackberry/bbsensorbackend.cpp35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.cpp b/src/plugins/sensors/blackberry/bbsensorbackend.cpp
index 9850d4dd..de6661e2 100644
--- a/src/plugins/sensors/blackberry/bbsensorbackend.cpp
+++ b/src/plugins/sensors/blackberry/bbsensorbackend.cpp
@@ -86,6 +86,7 @@ BbSensorBackendBase::BbSensorBackendBase(const QString &devicePath, sensor_type_
m_mappingMatrix[0] = m_mappingMatrix[3] = 1;
m_mappingMatrix[1] = m_mappingMatrix[2] = 0;
connect(sensor, SIGNAL(alwaysOnChanged()), this, SLOT(applyAlwaysOnProperty()));
+ connect(sensor, SIGNAL(userOrientationChanged(int)), this, SLOT(updateOrientation()));
// Set some sensible default values
sensor->setProperty("efficientBufferSize", defaultBufferSize);
@@ -183,12 +184,13 @@ qreal BbSensorBackendBase::convertValue(float bbValue)
bool BbSensorBackendBase::isAutoAxisRemappingEnabled() const
{
- return sensor()->property("automaticAxisRemapping").toBool();
+ return sensor()->isFeatureSupported(QSensor::AxesOrientation) &&
+ sensor()->axesOrientationMode() != QSensor::FixedOrientation;
}
void BbSensorBackendBase::remapMatrix(const float inputMatrix[], float outputMatrix[])
{
- if (!isAutoAxisRemappingEnabled() || m_guiHelper->currentOrientation() == 0) {
+ if (!isAutoAxisRemappingEnabled() || orientationForRemapping() == 0) {
memcpy(outputMatrix, inputMatrix, sizeof(float) * 9);
return;
}
@@ -199,10 +201,10 @@ void BbSensorBackendBase::remapMatrix(const float inputMatrix[], float outputMat
void BbSensorBackendBase::remapAxes(float *x, float *y, float *z)
{
Q_ASSERT(x && y && z);
- if (!isAutoAxisRemappingEnabled() || m_guiHelper->currentOrientation() == 0)
+ if (!isAutoAxisRemappingEnabled() || orientationForRemapping() == 0)
return;
- const int angle = m_guiHelper->currentOrientation();
+ const int angle = orientationForRemapping();
const float oldX = *x;
const float oldY = *y;
@@ -306,6 +308,11 @@ void BbSensorBackendBase::stop()
bool BbSensorBackendBase::isFeatureSupported(QSensor::Feature feature) const
{
switch (feature) {
+ case QSensor::AxesOrientation:
+ return (sensorType() == SENSOR_TYPE_ACCELEROMETER || sensorType() == SENSOR_TYPE_MAGNETOMETER ||
+ sensorType() == SENSOR_TYPE_GYROSCOPE || sensorType() == SENSOR_TYPE_GRAVITY ||
+ sensorType() == SENSOR_TYPE_LINEAR_ACCEL || sensorType() == SENSOR_TYPE_ROTATION_VECTOR ||
+ sensorType() == SENSOR_TYPE_ROTATION_MATRIX || sensorType() == SENSOR_TYPE_AZIMUTH_PITCH_ROLL);
case QSensor::AlwaysOn:
case QSensor::Buffering:
case QSensor::AccelerationMode:
@@ -387,12 +394,26 @@ void BbSensorBackendBase::updatePauseState()
void BbSensorBackendBase::updateOrientation()
{
- // ### I can't really test this, the rotation matrix has too many glitches and drifts over time,
- // making any measurement quite hard
- const int rotationAngle = guiHelper()->currentOrientation();
+ const int rotationAngle = orientationForRemapping();
m_mappingMatrix[0] = cos(rotationAngle*M_PI/180);
m_mappingMatrix[1] = sin(rotationAngle*M_PI/180);
m_mappingMatrix[2] = -sin(rotationAngle*M_PI/180);
m_mappingMatrix[3] = cos(rotationAngle*M_PI/180);
+
+ if (sensor()->isFeatureSupported(QSensor::AxesOrientation))
+ sensor()->setCurrentOrientation(rotationAngle);
+}
+
+int BbSensorBackendBase::orientationForRemapping() const
+{
+ if (!sensor()->isFeatureSupported(QSensor::AxesOrientation))
+ return 0;
+
+ switch (sensor()->axesOrientationMode()) {
+ default:
+ case QSensor::FixedOrientation: return 0;
+ case QSensor::AutomaticOrientation: return guiHelper()->currentOrientation();
+ case QSensor::UserOrientation: return sensor()->userOrientation();
+ }
}