Merge "various fixes to the sensorservice"
This commit is contained in:
commit
a6fee1904f
|
@ -69,7 +69,7 @@ status_t CorrectedGyroSensor::setDelay(void* ident, int handle, int64_t ns) {
|
||||||
Sensor CorrectedGyroSensor::getSensor() const {
|
Sensor CorrectedGyroSensor::getSensor() const {
|
||||||
sensor_t hwSensor;
|
sensor_t hwSensor;
|
||||||
hwSensor.name = "Corrected Gyroscope Sensor";
|
hwSensor.name = "Corrected Gyroscope Sensor";
|
||||||
hwSensor.vendor = "Google Inc.";
|
hwSensor.vendor = "AOSP";
|
||||||
hwSensor.version = 1;
|
hwSensor.version = 1;
|
||||||
hwSensor.handle = '_cgy';
|
hwSensor.handle = '_cgy';
|
||||||
hwSensor.type = SENSOR_TYPE_GYROSCOPE;
|
hwSensor.type = SENSOR_TYPE_GYROSCOPE;
|
||||||
|
|
|
@ -77,7 +77,7 @@ status_t GravitySensor::setDelay(void* ident, int handle, int64_t ns) {
|
||||||
Sensor GravitySensor::getSensor() const {
|
Sensor GravitySensor::getSensor() const {
|
||||||
sensor_t hwSensor;
|
sensor_t hwSensor;
|
||||||
hwSensor.name = "Gravity Sensor";
|
hwSensor.name = "Gravity Sensor";
|
||||||
hwSensor.vendor = "Google Inc.";
|
hwSensor.vendor = "AOSP";
|
||||||
hwSensor.version = 3;
|
hwSensor.version = 3;
|
||||||
hwSensor.handle = '_grv';
|
hwSensor.handle = '_grv';
|
||||||
hwSensor.type = SENSOR_TYPE_GRAVITY;
|
hwSensor.type = SENSOR_TYPE_GRAVITY;
|
||||||
|
|
|
@ -62,7 +62,7 @@ Sensor LinearAccelerationSensor::getSensor() const {
|
||||||
Sensor gsensor(mGravitySensor.getSensor());
|
Sensor gsensor(mGravitySensor.getSensor());
|
||||||
sensor_t hwSensor;
|
sensor_t hwSensor;
|
||||||
hwSensor.name = "Linear Acceleration Sensor";
|
hwSensor.name = "Linear Acceleration Sensor";
|
||||||
hwSensor.vendor = "Google Inc.";
|
hwSensor.vendor = "AOSP";
|
||||||
hwSensor.version = gsensor.getVersion();
|
hwSensor.version = gsensor.getVersion();
|
||||||
hwSensor.handle = '_lin';
|
hwSensor.handle = '_lin';
|
||||||
hwSensor.type = SENSOR_TYPE_LINEAR_ACCELERATION;
|
hwSensor.type = SENSOR_TYPE_LINEAR_ACCELERATION;
|
||||||
|
|
|
@ -33,6 +33,9 @@ OrientationSensor::OrientationSensor()
|
||||||
: mSensorDevice(SensorDevice::getInstance()),
|
: mSensorDevice(SensorDevice::getInstance()),
|
||||||
mSensorFusion(SensorFusion::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,
|
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 OrientationSensor::getSensor() const {
|
||||||
sensor_t hwSensor;
|
sensor_t hwSensor;
|
||||||
hwSensor.name = "Orientation Sensor";
|
hwSensor.name = "Orientation Sensor";
|
||||||
hwSensor.vendor = "Google Inc.";
|
hwSensor.vendor = "AOSP";
|
||||||
hwSensor.version = 1;
|
hwSensor.version = 1;
|
||||||
hwSensor.handle = '_ypr';
|
hwSensor.handle = '_ypr';
|
||||||
hwSensor.type = SENSOR_TYPE_ORIENTATION;
|
hwSensor.type = SENSOR_TYPE_ORIENTATION;
|
||||||
|
|
|
@ -63,7 +63,7 @@ status_t RotationVectorSensor::setDelay(void* ident, int handle, int64_t ns) {
|
||||||
Sensor RotationVectorSensor::getSensor() const {
|
Sensor RotationVectorSensor::getSensor() const {
|
||||||
sensor_t hwSensor;
|
sensor_t hwSensor;
|
||||||
hwSensor.name = "Rotation Vector Sensor";
|
hwSensor.name = "Rotation Vector Sensor";
|
||||||
hwSensor.vendor = "Google Inc.";
|
hwSensor.vendor = "AOSP";
|
||||||
hwSensor.version = 3;
|
hwSensor.version = 3;
|
||||||
hwSensor.handle = '_rov';
|
hwSensor.handle = '_rov';
|
||||||
hwSensor.type = SENSOR_TYPE_ROTATION_VECTOR;
|
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 GyroDriftSensor::getSensor() const {
|
||||||
sensor_t hwSensor;
|
sensor_t hwSensor;
|
||||||
hwSensor.name = "Gyroscope Bias (debug)";
|
hwSensor.name = "Gyroscope Bias (debug)";
|
||||||
hwSensor.vendor = "Google Inc.";
|
hwSensor.vendor = "AOSP";
|
||||||
hwSensor.version = 1;
|
hwSensor.version = 1;
|
||||||
hwSensor.handle = '_gbs';
|
hwSensor.handle = '_gbs';
|
||||||
hwSensor.type = SENSOR_TYPE_ACCELEROMETER;
|
hwSensor.type = SENSOR_TYPE_ACCELEROMETER;
|
||||||
|
|
|
@ -28,6 +28,7 @@ SensorFusion::SensorFusion()
|
||||||
mEnabled(false), mGyroTime(0)
|
mEnabled(false), mGyroTime(0)
|
||||||
{
|
{
|
||||||
sensor_t const* list;
|
sensor_t const* list;
|
||||||
|
Sensor uncalibratedGyro;
|
||||||
ssize_t count = mSensorDevice.getSensorList(&list);
|
ssize_t count = mSensorDevice.getSensorList(&list);
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
for (size_t i=0 ; i<size_t(count) ; i++) {
|
for (size_t i=0 ; i<size_t(count) ; i++) {
|
||||||
|
@ -39,18 +40,27 @@ SensorFusion::SensorFusion()
|
||||||
}
|
}
|
||||||
if (list[i].type == SENSOR_TYPE_GYROSCOPE) {
|
if (list[i].type == SENSOR_TYPE_GYROSCOPE) {
|
||||||
mGyro = Sensor(list + i);
|
mGyro = Sensor(list + i);
|
||||||
// 200 Hz for gyro events is a good compromise between precision
|
}
|
||||||
// and power/cpu usage.
|
if (list[i].type == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED) {
|
||||||
mGyroRate = 200;
|
uncalibratedGyro = Sensor(list + i);
|
||||||
mTargetDelayNs = 1000000000LL/mGyroRate;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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();
|
mFusion.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorFusion::process(const sensors_event_t& event) {
|
void SensorFusion::process(const sensors_event_t& event) {
|
||||||
if (event.type == SENSOR_TYPE_GYROSCOPE) {
|
if (event.type == mGyro.getType()) {
|
||||||
if (mGyroTime != 0) {
|
if (mGyroTime != 0) {
|
||||||
const float dT = (event.timestamp - mGyroTime) / 1000000000.0f;
|
const float dT = (event.timestamp - mGyroTime) / 1000000000.0f;
|
||||||
const float freq = 1 / dT;
|
const float freq = 1 / dT;
|
||||||
|
|
|
@ -93,6 +93,7 @@ void SensorService::onFirstRef()
|
||||||
orientationIndex = i;
|
orientationIndex = i;
|
||||||
break;
|
break;
|
||||||
case SENSOR_TYPE_GYROSCOPE:
|
case SENSOR_TYPE_GYROSCOPE:
|
||||||
|
case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
|
||||||
hasGyro = true;
|
hasGyro = true;
|
||||||
break;
|
break;
|
||||||
case SENSOR_TYPE_GRAVITY:
|
case SENSOR_TYPE_GRAVITY:
|
||||||
|
@ -108,54 +109,44 @@ void SensorService::onFirstRef()
|
||||||
// registered)
|
// registered)
|
||||||
const SensorFusion& fusion(SensorFusion::getInstance());
|
const SensorFusion& fusion(SensorFusion::getInstance());
|
||||||
|
|
||||||
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).
|
|
||||||
|
|
||||||
registerVirtualSensor( new RotationVectorSensor() );
|
|
||||||
registerVirtualSensor( new GravitySensor(list, count) );
|
|
||||||
registerVirtualSensor( new LinearAccelerationSensor(list, count) );
|
|
||||||
|
|
||||||
// these are optional
|
|
||||||
registerVirtualSensor( new OrientationSensor() );
|
|
||||||
registerVirtualSensor( new CorrectedGyroSensor(list, count) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// build the sensor list returned to users
|
// build the sensor list returned to users
|
||||||
mUserSensorList = mSensorList;
|
mUserSensorList = mSensorList;
|
||||||
|
|
||||||
if (hasGyro) {
|
if (hasGyro) {
|
||||||
|
Sensor aSensor;
|
||||||
|
|
||||||
|
// Add Android virtual sensors if they're not already
|
||||||
|
// available in the HAL
|
||||||
|
|
||||||
|
aSensor = registerVirtualSensor( new RotationVectorSensor() );
|
||||||
|
if (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR)) {
|
||||||
|
mUserSensorList.add(aSensor);
|
||||||
|
}
|
||||||
|
|
||||||
|
aSensor = registerVirtualSensor( new GravitySensor(list, count) );
|
||||||
|
if (virtualSensorsNeeds & (1<<SENSOR_TYPE_GRAVITY)) {
|
||||||
|
mUserSensorList.add(aSensor);
|
||||||
|
}
|
||||||
|
|
||||||
|
aSensor = registerVirtualSensor( new LinearAccelerationSensor(list, count) );
|
||||||
|
if (virtualSensorsNeeds & (1<<SENSOR_TYPE_LINEAR_ACCELERATION)) {
|
||||||
|
mUserSensorList.add(aSensor);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
// virtual debugging sensors are not added to mUserSensorList
|
||||||
|
registerVirtualSensor( new CorrectedGyroSensor(list, count) );
|
||||||
registerVirtualSensor( new GyroDriftSensor() );
|
registerVirtualSensor( new GyroDriftSensor() );
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// debugging sensor list
|
// debugging sensor list
|
||||||
for (size_t i=0 ; i<mSensorList.size() ; i++) {
|
mUserSensorListDebug = mSensorList;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run("SensorService", PRIORITY_URGENT_DISPLAY);
|
run("SensorService", PRIORITY_URGENT_DISPLAY);
|
||||||
mInitCheck = NO_ERROR;
|
mInitCheck = NO_ERROR;
|
||||||
|
@ -163,7 +154,7 @@ void SensorService::onFirstRef()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorService::registerSensor(SensorInterface* s)
|
Sensor SensorService::registerSensor(SensorInterface* s)
|
||||||
{
|
{
|
||||||
sensors_event_t event;
|
sensors_event_t event;
|
||||||
memset(&event, 0, sizeof(event));
|
memset(&event, 0, sizeof(event));
|
||||||
|
@ -175,12 +166,15 @@ void SensorService::registerSensor(SensorInterface* s)
|
||||||
mSensorMap.add(sensor.getHandle(), s);
|
mSensorMap.add(sensor.getHandle(), s);
|
||||||
// create an entry in the mLastEventSeen array
|
// create an entry in the mLastEventSeen array
|
||||||
mLastEventSeen.add(sensor.getHandle(), event);
|
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 );
|
mVirtualSensorList.add( s );
|
||||||
|
return sensor;
|
||||||
}
|
}
|
||||||
|
|
||||||
SensorService::~SensorService()
|
SensorService::~SensorService()
|
||||||
|
|
|
@ -114,8 +114,8 @@ class SensorService :
|
||||||
int getSensorType(int handle) const;
|
int getSensorType(int handle) const;
|
||||||
void recordLastValue(sensors_event_t const * buffer, size_t count);
|
void recordLastValue(sensors_event_t const * buffer, size_t count);
|
||||||
static void sortEventBuffer(sensors_event_t* buffer, size_t count);
|
static void sortEventBuffer(sensors_event_t* buffer, size_t count);
|
||||||
void registerSensor(SensorInterface* sensor);
|
Sensor registerSensor(SensorInterface* sensor);
|
||||||
void registerVirtualSensor(SensorInterface* sensor);
|
Sensor registerVirtualSensor(SensorInterface* sensor);
|
||||||
status_t cleanupWithoutDisable(const sp<SensorEventConnection>& connection,
|
status_t cleanupWithoutDisable(const sp<SensorEventConnection>& connection,
|
||||||
int handle);
|
int handle);
|
||||||
void cleanupAutoDisabledSensor(const sp<SensorEventConnection>& connection,
|
void cleanupAutoDisabledSensor(const sp<SensorEventConnection>& connection,
|
||||||
|
|
Loading…
Reference in New Issue