am 050b5624: Added SensorManager.getMinDelay()

Merge commit '050b56244ff46d43e4886018d7cd20f0b1dc02b9' into gingerbread-plus-aosp

* commit '050b56244ff46d43e4886018d7cd20f0b1dc02b9':
  Added SensorManager.getMinDelay()
This commit is contained in:
Mathias Agopian
2010-07-29 18:20:51 -07:00
committed by Android Git Automerger
10 changed files with 61 additions and 11 deletions

View File

@ -77561,6 +77561,17 @@
visibility="public"
>
</method>
<method name="getMinDelay"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getName"
return="java.lang.String"
abstract="false"

View File

@ -92,6 +92,7 @@ public class Sensor {
private float mMaxRange;
private float mResolution;
private float mPower;
private int mMinDelay;
private int mLegacyType;
@ -147,6 +148,15 @@ public class Sensor {
return mPower;
}
/**
* @return the minimum delay allowed between two events in microsecond
* or zero if this sensor only returns a value when the data it's measuring
* changes.
*/
public int getMinDelay() {
return mMinDelay;
}
int getHandle() {
return mHandle;
}

View File

@ -935,7 +935,8 @@ public class SensorManager
* received faster or slower than the specified rate. Usually events
* are received faster. The value must be one of
* {@link #SENSOR_DELAY_NORMAL}, {@link #SENSOR_DELAY_UI},
* {@link #SENSOR_DELAY_GAME}, or {@link #SENSOR_DELAY_FASTEST}.
* {@link #SENSOR_DELAY_GAME}, or {@link #SENSOR_DELAY_FASTEST}
* or, the desired delay between events in microsecond.
*
* @return <code>true</code> if the sensor is supported and successfully
* enabled.
@ -967,6 +968,7 @@ public class SensorManager
* are received faster. The value must be one of
* {@link #SENSOR_DELAY_NORMAL}, {@link #SENSOR_DELAY_UI},
* {@link #SENSOR_DELAY_GAME}, or {@link #SENSOR_DELAY_FASTEST}.
* or, the desired delay between events in microsecond.
*
* @param handler
* The {@link android.os.Handler Handler} the
@ -992,16 +994,17 @@ public class SensorManager
delay = 0;
break;
case SENSOR_DELAY_GAME:
delay = 20;
delay = 20000;
break;
case SENSOR_DELAY_UI:
delay = 60;
delay = 60000;
break;
case SENSOR_DELAY_NORMAL:
delay = 200;
delay = 200000;
break;
default:
return false;
delay = rate;
break;
}
synchronized (sListeners) {

View File

@ -38,6 +38,7 @@ struct SensorOffsets
jfieldID range;
jfieldID resolution;
jfieldID power;
jfieldID minDelay;
} gSensorOffsets;
/*
@ -74,6 +75,7 @@ sensors_module_get_next_sensor(JNIEnv *env, jobject clazz, jobject sensor, jint
env->SetFloatField(sensor, sensorOffsets.range, list->getMaxValue());
env->SetFloatField(sensor, sensorOffsets.resolution, list->getResolution());
env->SetFloatField(sensor, sensorOffsets.power, list->getPowerUsage());
env->SetIntField(sensor, sensorOffsets.minDelay, list->getMinDelay());
next++;
return next<count ? next : 0;
@ -154,6 +156,7 @@ nativeClassInit (JNIEnv *_env, jclass _this)
sensorOffsets.range = _env->GetFieldID(sensorClass, "mMaxRange", "F");
sensorOffsets.resolution = _env->GetFieldID(sensorClass, "mResolution","F");
sensorOffsets.power = _env->GetFieldID(sensorClass, "mPower", "F");
sensorOffsets.minDelay = _env->GetFieldID(sensorClass, "mMinDelay", "I");
}
static JNINativeMethod gMethods[] = {

View File

@ -63,6 +63,7 @@ public:
float getMaxValue() const;
float getResolution() const;
float getPowerUsage() const;
int32_t getMinDelay() const;
// Flattenable interface
virtual size_t getFlattenedSize() const;
@ -81,6 +82,7 @@ private:
float mMaxValue;
float mResolution;
float mPower;
int32_t mMinDelay;
};
// ----------------------------------------------------------------------------

View File

@ -65,7 +65,7 @@ public:
status_t setEventRate(Sensor const* sensor, nsecs_t ns) const;
// these are here only to support SensorManager.java
status_t enableSensor(int32_t handle, int32_t ms) const;
status_t enableSensor(int32_t handle, int32_t us) const;
status_t disableSensor(int32_t handle) const;
private:

View File

@ -32,7 +32,7 @@ namespace android {
Sensor::Sensor()
: mHandle(0), mType(0),
mMinValue(0), mMaxValue(0), mResolution(0),
mPower(0)
mPower(0), mMinDelay(0)
{
}
@ -46,6 +46,7 @@ Sensor::Sensor(struct sensor_t const* hwSensor)
mMaxValue = hwSensor->maxRange; // FIXME: maxValue
mResolution = hwSensor->resolution;
mPower = hwSensor->power;
mMinDelay = hwSensor->minDelay;
}
Sensor::~Sensor()
@ -84,12 +85,17 @@ float Sensor::getPowerUsage() const {
return mPower;
}
int32_t Sensor::getMinDelay() const {
return mMinDelay;
}
size_t Sensor::getFlattenedSize() const
{
return sizeof(int32_t) + ((mName.length() + 3) & ~3) +
sizeof(int32_t) + ((mVendor.length() + 3) & ~3) +
sizeof(int32_t) * 2 +
sizeof(float) * 4;
sizeof(float) * 4 +
sizeof(int32_t);
}
size_t Sensor::getFdCount() const
@ -132,6 +138,7 @@ status_t Sensor::flatten(void* buffer, size_t size,
offset += write(buffer, offset, mMaxValue);
offset += write(buffer, offset, mResolution);
offset += write(buffer, offset, mPower);
offset += write(buffer, offset, mMinDelay);
return NO_ERROR;
}
@ -169,6 +176,7 @@ status_t Sensor::unflatten(void const* buffer, size_t size,
offset += read(buffer, offset, &mMaxValue);
offset += read(buffer, offset, &mResolution);
offset += read(buffer, offset, &mPower);
offset += read(buffer, offset, &mMinDelay);
return NO_ERROR;
}

View File

@ -114,10 +114,10 @@ status_t SensorEventQueue::disableSensor(Sensor const* sensor) const {
return mSensorEventConnection->enableDisable(sensor->getHandle(), false);
}
status_t SensorEventQueue::enableSensor(int32_t handle, int32_t ms) const {
status_t SensorEventQueue::enableSensor(int32_t handle, int32_t us) const {
status_t err = mSensorEventConnection->enableDisable(handle, true);
if (err == NO_ERROR) {
mSensorEventConnection->setEventRate(handle, ms2ns(ms));
mSensorEventConnection->setEventRate(handle, us2ns(us));
}
return err;
}

View File

@ -149,3 +149,7 @@ float ASensor_getResolution(ASensor const* sensor)
return static_cast<Sensor const*>(sensor)->getResolution();
}
int ASensor_getMinDelay(ASensor const* sensor)
{
return static_cast<Sensor const*>(sensor)->getMinDelay();
}

View File

@ -121,6 +121,7 @@ typedef struct ASensorEvent {
float temperature;
float distance;
float light;
float pressure;
};
int32_t reserved1[4];
} ASensorEvent;
@ -188,7 +189,8 @@ int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sen
/*
* Sets the delivery rate of events in microseconds for the given sensor.
* Note that this is a hint only, generally event will arrive at a higher
* rate.
* rate. It is an error to set a rate inferior to the value returned by
* ASensor_getMinDelay().
* Returns a negative error code on failure.
*/
int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec);
@ -239,6 +241,13 @@ int ASensor_getType(ASensor const* sensor);
*/
float ASensor_getResolution(ASensor const* sensor);
/*
* Returns the minimum delay allowed between events in microseconds.
* A value of zero means that this sensor doesn't report events at a
* constant rate, but rather only when a new data is available.
*/
int ASensor_getMinDelay(ASensor const* sensor);
#ifdef __cplusplus
};