summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2010-07-29 16:51:38 -0700
committerMathias Agopian <mathias@google.com>2010-07-29 18:18:00 -0700
commita48bcf62b6a26f24a0bdd2b44bb39fadce499e92 (patch)
tree573eab127b2e6fe0544669f8c2309c44e8593989
parent27065359e3db4f2a256839107cbe4f64b457ed41 (diff)
downloadframeworks_native-a48bcf62b6a26f24a0bdd2b44bb39fadce499e92.zip
frameworks_native-a48bcf62b6a26f24a0bdd2b44bb39fadce499e92.tar.gz
frameworks_native-a48bcf62b6a26f24a0bdd2b44bb39fadce499e92.tar.bz2
Added SensorManager.getMinDelay()
Exposed the new "min delay" sensor property through native and java sensor apis. This allows the caller to know what is the maximum rate at which a sensor can return events, or, if a sensor works in "update" mode (events returned only when the value changes). Also augmented SensorManager.regusterSensorEvent() so that it can accept a value in microsecond in addition to the 4 constants already defined. Change-Id: If425e9979892666df8c989d7de3c362230fa19e0
-rw-r--r--include/gui/Sensor.h2
-rw-r--r--include/gui/SensorEventQueue.h2
-rw-r--r--libs/gui/Sensor.cpp12
-rw-r--r--libs/gui/SensorEventQueue.cpp4
4 files changed, 15 insertions, 5 deletions
diff --git a/include/gui/Sensor.h b/include/gui/Sensor.h
index e696d63..2de07b1 100644
--- a/include/gui/Sensor.h
+++ b/include/gui/Sensor.h
@@ -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;
};
// ----------------------------------------------------------------------------
diff --git a/include/gui/SensorEventQueue.h b/include/gui/SensorEventQueue.h
index ad36dac..6581ae3 100644
--- a/include/gui/SensorEventQueue.h
+++ b/include/gui/SensorEventQueue.h
@@ -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:
diff --git a/libs/gui/Sensor.cpp b/libs/gui/Sensor.cpp
index cb85df9..b1f37ff 100644
--- a/libs/gui/Sensor.cpp
+++ b/libs/gui/Sensor.cpp
@@ -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;
}
diff --git a/libs/gui/SensorEventQueue.cpp b/libs/gui/SensorEventQueue.cpp
index 4b46842..3396f25 100644
--- a/libs/gui/SensorEventQueue.cpp
+++ b/libs/gui/SensorEventQueue.cpp
@@ -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;
}