diff options
author | Thomas McGuire <thomas.mcguire.qnx@kdab.com> | 2012-07-20 11:07:18 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-24 11:23:39 +0200 |
commit | 99a01d69ac607f310b4ea64e1547cdbaea7bbf00 (patch) | |
tree | c16539067168741e28472d131619a1e312378b83 /src/plugins/sensors/blackberry/bbrotationsensor.cpp | |
parent | 1760d541f35c851b6c08bc617a89cb16a1d8f975 (diff) |
Blackberry: Implement axes remapping for all axes-based sensors
The remapping code was moved to BbSensorBackend.
Change-Id: I6ede875594a2aaa3745b7deb4aa0ed64c2d9b855
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/plugins/sensors/blackberry/bbrotationsensor.cpp')
-rw-r--r-- | src/plugins/sensors/blackberry/bbrotationsensor.cpp | 58 |
1 files changed, 3 insertions, 55 deletions
diff --git a/src/plugins/sensors/blackberry/bbrotationsensor.cpp b/src/plugins/sensors/blackberry/bbrotationsensor.cpp index f64844ae..5701c279 100644 --- a/src/plugins/sensors/blackberry/bbrotationsensor.cpp +++ b/src/plugins/sensors/blackberry/bbrotationsensor.cpp @@ -42,7 +42,6 @@ #include "bbguihelper.h" #include "bbutil.h" -#include <QtCore/qmath.h> using namespace BbUtil; @@ -50,8 +49,6 @@ BbRotationSensor::BbRotationSensor(QSensor *sensor) : BbSensorBackend<QRotationReading>(devicePath(), SENSOR_TYPE_ROTATION_MATRIX, sensor) { setDescription(QLatin1String("Device rotation in degrees")); - m_mappingMatrix[0] = m_mappingMatrix[2] = 1; - m_mappingMatrix[1] = m_mappingMatrix[3] = 0; } QString BbRotationSensor::devicePath() @@ -59,13 +56,6 @@ QString BbRotationSensor::devicePath() return QLatin1String("/dev/sensor/rotMatrix"); } -void BbRotationSensor::setGuiHelper(BbGuiHelper *guiHelper) -{ - BbSensorBackend<QRotationReading>::setGuiHelper(guiHelper); - connect(guiHelper, SIGNAL(orientationChanged()), this, SLOT(updateOrientation())); - updateOrientation(); -} - void BbRotationSensor::additionalDeviceInit() { addOutputRange(-180, 180, 0 /* ? */); @@ -78,40 +68,15 @@ bool BbRotationSensor::addDefaultRange() return false; } -static void remapMatrix(const float inputMatrix[3*3], - const float mappingMatrix[4], - float outputMatrix[3*3]) -{ - int i,j,k; - - for (i = 0; i < 3; i++) { - for (j = 0; j < 2; j++) { //only goto 2 because last column stays unchanged - - outputMatrix[i*3+j] = 0; - - for (k = 0; k < 2; k++) { //only goto 2 because we know rotation matrix is zero in bottom row - outputMatrix[i*3+j] += inputMatrix[i*3+k] * mappingMatrix[k*2+j]; - } - } - - outputMatrix[i*3+2] = inputMatrix[i*3+2]; - } -} - bool BbRotationSensor::updateReadingFromEvent(const sensor_event_t &event, QRotationReading *reading) { // sensor_event_t has euler angles for a Z-Y'-X'' system, but the QtMobility API // uses Z-X'-Y''. // So extract the euler angles using the Z-X'-Y'' system from the matrix. float xRad, yRad, zRad; - - if (isAutoAxisRemappingEnabled() && guiHelper()->currentOrientation() != 0) { - float mappedRotationMatrix[3*3]; - remapMatrix(event.rotation_matrix, m_mappingMatrix, mappedRotationMatrix); - matrixToEulerZXY(mappedRotationMatrix, xRad, yRad, zRad); - } else { - matrixToEulerZXY(event.rotation_matrix, xRad, yRad, zRad); - } + float mappedRotationMatrix[3*3]; + remapMatrix(event.rotation_matrix, mappedRotationMatrix); + matrixToEulerZXY(mappedRotationMatrix, xRad, yRad, zRad); reading->setFromEuler(radiansToDegrees(xRad), radiansToDegrees(yRad), @@ -124,20 +89,3 @@ qreal BbRotationSensor::convertValue(float bbValueInRad) { return radiansToDegrees(bbValueInRad); } - -bool BbRotationSensor::isAutoAxisRemappingEnabled() const -{ - return sensor()->property("automaticAxisRemapping").toBool(); -} - -void BbRotationSensor::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(); - - 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); -} |