summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Heyl <edheyl@google.com>2010-11-16 15:26:05 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2010-11-16 15:26:05 -0800
commitf4f5b0dc57c7c8325fe5cd1adc189ff49af011fd (patch)
treec9f118c0bf0404c988ebad414619c85ea3034586
parent430f923ca033da50ee9cf94fbfaec53a12a55e0a (diff)
parent164dfdc053c6bf070d660bbfd54ca585acee62f6 (diff)
downloaddevice_samsung_crespo-f4f5b0dc57c7c8325fe5cd1adc189ff49af011fd.zip
device_samsung_crespo-f4f5b0dc57c7c8325fe5cd1adc189ff49af011fd.tar.gz
device_samsung_crespo-f4f5b0dc57c7c8325fe5cd1adc189ff49af011fd.tar.bz2
am 164dfdc0: am bf277c05: Revert "Revert "Revert "S5PC11X: libsensor: Changes to match libakm change"""
* commit '164dfdc053c6bf070d660bbfd54ca585acee62f6': Revert "Revert "Revert "S5PC11X: libsensor: Changes to match libakm change"""
-rw-r--r--libsensors/AkmSensor.cpp43
-rw-r--r--libsensors/AkmSensor.h2
-rw-r--r--libsensors/sensors.cpp6
-rw-r--r--libsensors/sensors.h13
4 files changed, 43 insertions, 21 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()
diff --git a/libsensors/AkmSensor.h b/libsensors/AkmSensor.h
index 44214e0..f637284 100644
--- a/libsensors/AkmSensor.h
+++ b/libsensors/AkmSensor.h
@@ -49,12 +49,14 @@ public:
void processEvent(int code, int value);
private:
+ int update_delay();
int loadAKMLibrary();
void *mLibAKM;
uint32_t mEnabled;
uint32_t mPendingMask;
InputEventCircularReader mInputReader;
sensors_event_t mPendingEvents[numSensors];
+ uint64_t mDelays[numSensors];
};
/*****************************************************************************/
diff --git a/libsensors/sensors.cpp b/libsensors/sensors.cpp
index 4ba1265..2f85225 100644
--- a/libsensors/sensors.cpp
+++ b/libsensors/sensors.cpp
@@ -70,15 +70,15 @@ static const struct sensor_t sSensorList[] = {
{ "KR3DM 3-axis Accelerometer",
"STMicroelectronics",
1, SENSORS_ACCELERATION_HANDLE,
- SENSOR_TYPE_ACCELEROMETER, RANGE_A, CONVERT_A, 0.23f, 20000, { } },
+ SENSOR_TYPE_ACCELEROMETER, RANGE_A, RESOLUTION_A, 0.23f, 20000, { } },
{ "AK8973 3-axis Magnetic field sensor",
"Asahi Kasei Microdevices",
1, SENSORS_MAGNETIC_FIELD_HANDLE,
- SENSOR_TYPE_MAGNETIC_FIELD, 2000.0f, CONVERT_M, 6.8f, 16667, { } },
+ SENSOR_TYPE_MAGNETIC_FIELD, 2000.0f, CONVERT_M, 6.8f, 30000, { } },
{ "AK8973 Orientation sensor",
"Asahi Kasei Microdevices",
1, SENSORS_ORIENTATION_HANDLE,
- SENSOR_TYPE_ORIENTATION, 360.0f, CONVERT_O, 7.8f, 16667, { } },
+ SENSOR_TYPE_ORIENTATION, 360.0f, CONVERT_O, 7.8f, 30000, { } },
{ "GP2A Light sensor",
"Sharp",
1, SENSORS_LIGHT_HANDLE,
diff --git a/libsensors/sensors.h b/libsensors/sensors.h
index 4b12606..20884b6 100644
--- a/libsensors/sensors.h
+++ b/libsensors/sensors.h
@@ -76,16 +76,17 @@ __BEGIN_DECLS
#define EVENT_TYPE_GYRO_Z REL_RZ
-// 64 LSB = 1G for KR3DM
-#define LSB (64.0f)
-#define NUMOFACCDATA (8.0f)
+// 720 LSG = 1G
+#define LSG (720.0f)
+#define NUMOFACCDATA 8
// conversion of acceleration data to SI units (m/s^2)
#define RANGE_A (2*GRAVITY_EARTH)
-#define CONVERT_A (GRAVITY_EARTH / LSB / NUMOFACCDATA)
+#define RESOLUTION_A (RANGE_A/(256*NUMOFACCDATA))
+#define CONVERT_A (GRAVITY_EARTH / LSG / NUMOFACCDATA)
#define CONVERT_A_X (CONVERT_A)
-#define CONVERT_A_Y (CONVERT_A)
-#define CONVERT_A_Z (CONVERT_A)
+#define CONVERT_A_Y (-CONVERT_A)
+#define CONVERT_A_Z (-CONVERT_A)
// conversion of magnetic data to uT units
#define CONVERT_M (1.0f/16.0f)