summaryrefslogtreecommitdiffstats
path: root/libsensors/AkmSensor.cpp
diff options
context:
space:
mode:
authorEd Heyl <edheyl@google.com>2010-11-16 14:37:12 -0800
committerEd Heyl <edheyl@google.com>2010-11-16 14:37:12 -0800
commitbf277c0565892e783e4bb93164a83e8620ce113f (patch)
treeda3c7324d2fe080e00a17816e65e24b935f800dd /libsensors/AkmSensor.cpp
parent339031d332706f21cbce560ca379e7624cad8316 (diff)
downloaddevice_samsung_crespo-bf277c0565892e783e4bb93164a83e8620ce113f.zip
device_samsung_crespo-bf277c0565892e783e4bb93164a83e8620ce113f.tar.gz
device_samsung_crespo-bf277c0565892e783e4bb93164a83e8620ce113f.tar.bz2
Revert "Revert "Revert "S5PC11X: libsensor: Changes to match libakm change"""
This reverts commit 339031d332706f21cbce560ca379e7624cad8316.
Diffstat (limited to 'libsensors/AkmSensor.cpp')
-rw-r--r--libsensors/AkmSensor.cpp43
1 files changed, 31 insertions, 12 deletions
diff --git a/libsensors/AkmSensor.cpp b/libsensors/AkmSensor.cpp
index 32bdd6d..68d2fc2 100644
--- a/libsensors/AkmSensor.cpp
+++ b/libsensors/AkmSensor.cpp
@@ -34,7 +34,7 @@
int (*akm_is_sensor_enabled)(uint32_t sensor_type);
int (*akm_enable_sensor)(uint32_t sensor_type);
int (*akm_disable_sensor)(uint32_t sensor_type);
-int (*akm_set_delay)(uint32_t sensor_type, uint64_t delay);
+int (*akm_set_delay)(uint64_t delay);
int stub_is_sensor_enabled(uint32_t sensor_type) {
return 0;
@@ -44,7 +44,7 @@ int stub_enable_disable_sensor(uint32_t sensor_type) {
return -ENODEV;
}
-int stub_set_delay(uint32_t sensor_type, uint64_t delay) {
+int stub_set_delay(uint64_t delay) {
return -ENODEV;
}
@@ -79,6 +79,9 @@ AkmSensor::AkmSensor()
mPendingEvents[Orientation ].type = SENSOR_TYPE_ORIENTATION;
mPendingEvents[Orientation ].orientation.status = SENSOR_STATUS_ACCURACY_HIGH;
+ for (int i=0 ; i<numSensors ; i++)
+ mDelays[i] = 200000000; // 200 ms by default
+
// read the actual value of all sensors if they're enabled already
struct input_absinfo absinfo;
short flags = 0;
@@ -167,6 +170,7 @@ int AkmSensor::enable(int32_t handle, int en)
if (!err) {
mEnabled &= ~(1<<what);
mEnabled |= (uint32_t(flags)<<what);
+ update_delay();
}
}
return err;
@@ -174,21 +178,36 @@ int AkmSensor::enable(int32_t handle, int en)
int AkmSensor::setDelay(int32_t handle, int64_t ns)
{
- uint32_t sensor_type = 0;
-
- if (ns < 0)
- return -EINVAL;
-
+ int what = -1;
switch (handle) {
- case ID_A: sensor_type = SENSOR_TYPE_ACCELEROMETER; break;
- case ID_M: sensor_type = SENSOR_TYPE_MAGNETIC_FIELD; break;
- case ID_O: sensor_type = SENSOR_TYPE_ORIENTATION; break;
+ case ID_A: what = Accelerometer; break;
+ case ID_M: what = MagneticField; break;
+ case ID_O: what = Orientation; break;
}
- if (sensor_type == 0)
+ if (uint32_t(what) >= numSensors)
+ return -EINVAL;
+
+ if (ns < 0)
return -EINVAL;
- return akm_set_delay(sensor_type, ns);
+ mDelays[what] = ns;
+ return update_delay();
+}
+
+int AkmSensor::update_delay()
+{
+ if (mEnabled) {
+ uint64_t wanted = -1LLU;
+ for (int i=0 ; i<numSensors ; i++) {
+ if (mEnabled & (1<<i)) {
+ uint64_t ns = mDelays[i];
+ wanted = wanted < ns ? wanted : ns;
+ }
+ }
+ return akm_set_delay(int64_t(wanted));
+ }
+ return 0;
}
int AkmSensor::loadAKMLibrary()