diff options
author | Pawit Pornkitprasan <p.pawit@gmail.com> | 2012-12-05 12:40:45 +0700 |
---|---|---|
committer | Pawit Pornkitprasan <p.pawit@gmail.com> | 2012-12-05 12:42:18 +0700 |
commit | a1aa229340e805da8cbd1edaaf2e6fcb380a1070 (patch) | |
tree | 4ef1db05ab5991346091f7f8a26e09ca10e3581e /services/sensorservice/SensorService.cpp | |
parent | 9cdde0d0b41e4d0d1187e7b664f97b00a9a3e4af (diff) | |
download | frameworks_native-a1aa229340e805da8cbd1edaaf2e6fcb380a1070.zip frameworks_native-a1aa229340e805da8cbd1edaaf2e6fcb380a1070.tar.gz frameworks_native-a1aa229340e805da8cbd1edaaf2e6fcb380a1070.tar.bz2 |
Sensor: Add RotationVectorSensor2
(ported from 4.1)
Some ICS apps (namely, Google Maps) expects a rotation vector to be
available. Newer devices, this is provided by either Android's
sensor fusion (requires Gyro) or by hardware sensor fusion (MPL).
Older devices will lack this virtual sensor and compass in Google
Maps will not work. To fix this, we can provide our own rotation
vector sensor by converting the values from the orientation sensor.
(They are basically the same information in different formats.)
Thanks to Unhelpful for the help with related math.
Change-Id: I39489b3a5ce7c7d890768614357f32cc491bd6d9
Diffstat (limited to 'services/sensorservice/SensorService.cpp')
-rw-r--r-- | services/sensorservice/SensorService.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp index e3dcd02..8ff0872 100644 --- a/services/sensorservice/SensorService.cpp +++ b/services/sensorservice/SensorService.cpp @@ -45,6 +45,7 @@ #include "LinearAccelerationSensor.h" #include "OrientationSensor.h" #include "RotationVectorSensor.h" +#include "RotationVectorSensor2.h" #include "SensorFusion.h" #include "SensorService.h" @@ -136,6 +137,12 @@ void SensorService::onFirstRef() if (orientationIndex >= 0) { mUserSensorList.removeItemsAt(orientationIndex); } + } else if (orientationIndex != -1) { + // If we don't have a gyro but have a orientation sensor from + // elsewhere, we can compute rotation vector from that. + // (Google Maps expects rotation vector sensor to exist.) + + registerVirtualSensor( &RotationVectorSensor2::getInstance() ); } // debugging sensor list @@ -272,6 +279,12 @@ bool SensorService::threadLoop() fusion.process(event[i]); } } + RotationVectorSensor2& rv2(RotationVectorSensor2::getInstance()); + if (rv2.isEnabled()) { + for (size_t i=0 ; i<size_t(count) ; i++) { + rv2.process(event[i]); + } + } for (size_t i=0 ; i<size_t(count) && k<minBufferSize ; i++) { for (size_t j=0 ; j<activeVirtualSensorCount ; j++) { if (count + k >= minBufferSize) { |