summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2013-05-10 19:32:39 -0700
committerMathias Agopian <mathias@google.com>2013-05-16 18:47:21 -0700
commit0319306670b0344da99efa606b6f172dde575a39 (patch)
tree9be3e260132258ad7e02eabe2f1dc065e62bbdf2 /services
parent59eaeed5fabc27942d62327fa460ebb8bd2f3822 (diff)
downloadframeworks_native-0319306670b0344da99efa606b6f172dde575a39.zip
frameworks_native-0319306670b0344da99efa606b6f172dde575a39.tar.gz
frameworks_native-0319306670b0344da99efa606b6f172dde575a39.tar.bz2
various fixes to the sensorservice
1) "google" sensors are now reporting AOSP as the vendor string 2) don't expose the system's sensor fusion if the HAL provides it 3) use uncalibrated gyro if availble for the system's sensor fusion Change-Id: I25140436cdb29d55e39fd6fbbf8c44a410a83d5c
Diffstat (limited to 'services')
-rw-r--r--services/sensorservice/CorrectedGyroSensor.cpp2
-rw-r--r--services/sensorservice/GravitySensor.cpp2
-rw-r--r--services/sensorservice/LinearAccelerationSensor.cpp2
-rw-r--r--services/sensorservice/OrientationSensor.cpp5
-rw-r--r--services/sensorservice/RotationVectorSensor.cpp4
-rw-r--r--services/sensorservice/SensorFusion.cpp20
-rw-r--r--services/sensorservice/SensorService.cpp76
-rw-r--r--services/sensorservice/SensorService.h4
8 files changed, 61 insertions, 54 deletions
diff --git a/services/sensorservice/CorrectedGyroSensor.cpp b/services/sensorservice/CorrectedGyroSensor.cpp
index 1857443..09f60a9 100644
--- a/services/sensorservice/CorrectedGyroSensor.cpp
+++ b/services/sensorservice/CorrectedGyroSensor.cpp
@@ -69,7 +69,7 @@ status_t CorrectedGyroSensor::setDelay(void* ident, int handle, int64_t ns) {
Sensor CorrectedGyroSensor::getSensor() const {
sensor_t hwSensor;
hwSensor.name = "Corrected Gyroscope Sensor";
- hwSensor.vendor = "Google Inc.";
+ hwSensor.vendor = "AOSP";
hwSensor.version = 1;
hwSensor.handle = '_cgy';
hwSensor.type = SENSOR_TYPE_GYROSCOPE;
diff --git a/services/sensorservice/GravitySensor.cpp b/services/sensorservice/GravitySensor.cpp
index c57715f..0bf20db 100644
--- a/services/sensorservice/GravitySensor.cpp
+++ b/services/sensorservice/GravitySensor.cpp
@@ -77,7 +77,7 @@ status_t GravitySensor::setDelay(void* ident, int handle, int64_t ns) {
Sensor GravitySensor::getSensor() const {
sensor_t hwSensor;
hwSensor.name = "Gravity Sensor";
- hwSensor.vendor = "Google Inc.";
+ hwSensor.vendor = "AOSP";
hwSensor.version = 3;
hwSensor.handle = '_grv';
hwSensor.type = SENSOR_TYPE_GRAVITY;
diff --git a/services/sensorservice/LinearAccelerationSensor.cpp b/services/sensorservice/LinearAccelerationSensor.cpp
index f0054f2..25ae473 100644
--- a/services/sensorservice/LinearAccelerationSensor.cpp
+++ b/services/sensorservice/LinearAccelerationSensor.cpp
@@ -62,7 +62,7 @@ Sensor LinearAccelerationSensor::getSensor() const {
Sensor gsensor(mGravitySensor.getSensor());
sensor_t hwSensor;
hwSensor.name = "Linear Acceleration Sensor";
- hwSensor.vendor = "Google Inc.";
+ hwSensor.vendor = "AOSP";
hwSensor.version = gsensor.getVersion();
hwSensor.handle = '_lin';
hwSensor.type = SENSOR_TYPE_LINEAR_ACCELERATION;
diff --git a/services/sensorservice/OrientationSensor.cpp b/services/sensorservice/OrientationSensor.cpp
index 037adaa..b146332 100644
--- a/services/sensorservice/OrientationSensor.cpp
+++ b/services/sensorservice/OrientationSensor.cpp
@@ -33,6 +33,9 @@ OrientationSensor::OrientationSensor()
: mSensorDevice(SensorDevice::getInstance()),
mSensorFusion(SensorFusion::getInstance())
{
+ // FIXME: instead of using the SensorFusion code, we should use
+ // the SENSOR_TYPE_ROTATION_VECTOR instead. This way we could use the
+ // HAL's implementation.
}
bool OrientationSensor::process(sensors_event_t* outEvent,
@@ -73,7 +76,7 @@ status_t OrientationSensor::setDelay(void* ident, int handle, int64_t ns) {
Sensor OrientationSensor::getSensor() const {
sensor_t hwSensor;
hwSensor.name = "Orientation Sensor";
- hwSensor.vendor = "Google Inc.";
+ hwSensor.vendor = "AOSP";
hwSensor.version = 1;
hwSensor.handle = '_ypr';
hwSensor.type = SENSOR_TYPE_ORIENTATION;
diff --git a/services/sensorservice/RotationVectorSensor.cpp b/services/sensorservice/RotationVectorSensor.cpp
index 5ea9568..725deb4 100644
--- a/services/sensorservice/RotationVectorSensor.cpp
+++ b/services/sensorservice/RotationVectorSensor.cpp
@@ -63,7 +63,7 @@ status_t RotationVectorSensor::setDelay(void* ident, int handle, int64_t ns) {
Sensor RotationVectorSensor::getSensor() const {
sensor_t hwSensor;
hwSensor.name = "Rotation Vector Sensor";
- hwSensor.vendor = "Google Inc.";
+ hwSensor.vendor = "AOSP";
hwSensor.version = 3;
hwSensor.handle = '_rov';
hwSensor.type = SENSOR_TYPE_ROTATION_VECTOR;
@@ -112,7 +112,7 @@ status_t GyroDriftSensor::setDelay(void* ident, int handle, int64_t ns) {
Sensor GyroDriftSensor::getSensor() const {
sensor_t hwSensor;
hwSensor.name = "Gyroscope Bias (debug)";
- hwSensor.vendor = "Google Inc.";
+ hwSensor.vendor = "AOSP";
hwSensor.version = 1;
hwSensor.handle = '_gbs';
hwSensor.type = SENSOR_TYPE_ACCELEROMETER;
diff --git a/services/sensorservice/SensorFusion.cpp b/services/sensorservice/SensorFusion.cpp
index d23906d..4837b97 100644
--- a/services/sensorservice/SensorFusion.cpp
+++ b/services/sensorservice/SensorFusion.cpp
@@ -28,6 +28,7 @@ SensorFusion::SensorFusion()
mEnabled(false), mGyroTime(0)
{
sensor_t const* list;
+ Sensor uncalibratedGyro;
ssize_t count = mSensorDevice.getSensorList(&list);
if (count > 0) {
for (size_t i=0 ; i<size_t(count) ; i++) {
@@ -39,18 +40,27 @@ SensorFusion::SensorFusion()
}
if (list[i].type == SENSOR_TYPE_GYROSCOPE) {
mGyro = Sensor(list + i);
- // 200 Hz for gyro events is a good compromise between precision
- // and power/cpu usage.
- mGyroRate = 200;
- mTargetDelayNs = 1000000000LL/mGyroRate;
}
+ if (list[i].type == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED) {
+ uncalibratedGyro = Sensor(list + i);
+ }
+ }
+
+ // Use the uncalibrated gyroscope for sensor fusion when available
+ if (uncalibratedGyro.getType() == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED) {
+ mGyro = uncalibratedGyro;
}
+
+ // 200 Hz for gyro events is a good compromise between precision
+ // and power/cpu usage.
+ mGyroRate = 200;
+ mTargetDelayNs = 1000000000LL/mGyroRate;
mFusion.init();
}
}
void SensorFusion::process(const sensors_event_t& event) {
- if (event.type == SENSOR_TYPE_GYROSCOPE) {
+ if (event.type == mGyro.getType()) {
if (mGyroTime != 0) {
const float dT = (event.timestamp - mGyroTime) / 1000000000.0f;
const float freq = 1 / dT;
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index ebf5cf0..4718447 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -93,6 +93,7 @@ void SensorService::onFirstRef()
orientationIndex = i;
break;
case SENSOR_TYPE_GYROSCOPE:
+ case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
hasGyro = true;
break;
case SENSOR_TYPE_GRAVITY:
@@ -108,54 +109,44 @@ void SensorService::onFirstRef()
// registered)
const SensorFusion& fusion(SensorFusion::getInstance());
+ // build the sensor list returned to users
+ mUserSensorList = mSensorList;
+
if (hasGyro) {
- // Always instantiate Android's virtual sensors. Since they are
- // instantiated behind sensors from the HAL, they won't
- // interfere with applications, unless they looks specifically
- // for them (by name).
+ Sensor aSensor;
- registerVirtualSensor( new RotationVectorSensor() );
- registerVirtualSensor( new GravitySensor(list, count) );
- registerVirtualSensor( new LinearAccelerationSensor(list, count) );
+ // Add Android virtual sensors if they're not already
+ // available in the HAL
- // these are optional
- registerVirtualSensor( new OrientationSensor() );
- registerVirtualSensor( new CorrectedGyroSensor(list, count) );
- }
+ aSensor = registerVirtualSensor( new RotationVectorSensor() );
+ if (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR)) {
+ mUserSensorList.add(aSensor);
+ }
- // build the sensor list returned to users
- mUserSensorList = mSensorList;
+ aSensor = registerVirtualSensor( new GravitySensor(list, count) );
+ if (virtualSensorsNeeds & (1<<SENSOR_TYPE_GRAVITY)) {
+ mUserSensorList.add(aSensor);
+ }
- if (hasGyro) {
- // virtual debugging sensors are not added to mUserSensorList
- registerVirtualSensor( new GyroDriftSensor() );
- }
+ aSensor = registerVirtualSensor( new LinearAccelerationSensor(list, count) );
+ if (virtualSensorsNeeds & (1<<SENSOR_TYPE_LINEAR_ACCELERATION)) {
+ mUserSensorList.add(aSensor);
+ }
- if (hasGyro &&
- (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR))) {
- // if we have the fancy sensor fusion, and it's not provided by the
- // HAL, use our own (fused) orientation sensor by removing the
- // HAL supplied one form the user list.
- if (orientationIndex >= 0) {
- mUserSensorList.removeItemsAt(orientationIndex);
+ aSensor = registerVirtualSensor( new OrientationSensor() );
+ if (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR)) {
+ // if we are doing our own rotation-vector, also add
+ // the orientation sensor and remove the HAL provided one.
+ mUserSensorList.replaceAt(aSensor, orientationIndex);
}
+
+ // virtual debugging sensors are not added to mUserSensorList
+ registerVirtualSensor( new CorrectedGyroSensor(list, count) );
+ registerVirtualSensor( new GyroDriftSensor() );
}
// debugging sensor list
- for (size_t i=0 ; i<mSensorList.size() ; i++) {
- switch (mSensorList[i].getType()) {
- case SENSOR_TYPE_GRAVITY:
- case SENSOR_TYPE_LINEAR_ACCELERATION:
- case SENSOR_TYPE_ROTATION_VECTOR:
- if (strstr(mSensorList[i].getVendor().string(), "Google")) {
- mUserSensorListDebug.add(mSensorList[i]);
- }
- break;
- default:
- mUserSensorListDebug.add(mSensorList[i]);
- break;
- }
- }
+ mUserSensorListDebug = mSensorList;
run("SensorService", PRIORITY_URGENT_DISPLAY);
mInitCheck = NO_ERROR;
@@ -163,7 +154,7 @@ void SensorService::onFirstRef()
}
}
-void SensorService::registerSensor(SensorInterface* s)
+Sensor SensorService::registerSensor(SensorInterface* s)
{
sensors_event_t event;
memset(&event, 0, sizeof(event));
@@ -175,12 +166,15 @@ void SensorService::registerSensor(SensorInterface* s)
mSensorMap.add(sensor.getHandle(), s);
// create an entry in the mLastEventSeen array
mLastEventSeen.add(sensor.getHandle(), event);
+
+ return sensor;
}
-void SensorService::registerVirtualSensor(SensorInterface* s)
+Sensor SensorService::registerVirtualSensor(SensorInterface* s)
{
- registerSensor(s);
+ Sensor sensor = registerSensor(s);
mVirtualSensorList.add( s );
+ return sensor;
}
SensorService::~SensorService()
diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h
index ff3b555..67489cc 100644
--- a/services/sensorservice/SensorService.h
+++ b/services/sensorservice/SensorService.h
@@ -114,8 +114,8 @@ class SensorService :
int getSensorType(int handle) const;
void recordLastValue(sensors_event_t const * buffer, size_t count);
static void sortEventBuffer(sensors_event_t* buffer, size_t count);
- void registerSensor(SensorInterface* sensor);
- void registerVirtualSensor(SensorInterface* sensor);
+ Sensor registerSensor(SensorInterface* sensor);
+ Sensor registerVirtualSensor(SensorInterface* sensor);
status_t cleanupWithoutDisable(const sp<SensorEventConnection>& connection,
int handle);
void cleanupAutoDisabledSensor(const sp<SensorEventConnection>& connection,