diff options
author | Mike Lockwood <lockwood@google.com> | 2010-10-22 15:31:59 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@google.com> | 2010-10-22 15:31:59 -0400 |
commit | a7b1f6b5f7951012bce331946e608c86f40e808a (patch) | |
tree | fe087439fd281904092d08caa520da2323a01ffb /libsensors | |
parent | 399345f89c4a69d80df78564122d757ffdd06c1e (diff) | |
download | device_samsung_crespo-a7b1f6b5f7951012bce331946e608c86f40e808a.tar.gz device_samsung_crespo-a7b1f6b5f7951012bce331946e608c86f40e808a.tar.bz2 device_samsung_crespo-a7b1f6b5f7951012bce331946e608c86f40e808a.zip |
Ignore first four light sensor events after enabling the sensor.
The Crespo light sensor will report 4 bogus events that appear to be based
on the value at the time the sensor was disabled when the sensor is reenabled.
These events cause problems with monotonically increasing algorithm
in the Power Manager ALS support.
Change-Id: I6c53f9c93276921d359107df8ee0279579c50092
Signed-off-by: Mike Lockwood <lockwood@google.com>
Diffstat (limited to 'libsensors')
-rw-r--r-- | libsensors/LightSensor.cpp | 26 | ||||
-rw-r--r-- | libsensors/LightSensor.h | 1 |
2 files changed, 15 insertions, 12 deletions
diff --git a/libsensors/LightSensor.cpp b/libsensors/LightSensor.cpp index 750d8cd..c87bacd 100644 --- a/libsensors/LightSensor.cpp +++ b/libsensors/LightSensor.cpp @@ -27,9 +27,17 @@ /*****************************************************************************/ +/* The Crespo ADC sends 4 somewhat bogus events after enabling the sensor. + This becomes a problem if the phone is turned off in bright light + and turned back on in the dark. + To avoid this we ignore the first 4 events received after enabling the sensor. + */ +#define FIRST_GOOD_EVENT 5 + LightSensor::LightSensor() : SensorBase(NULL, "lightsensor-level"), mEnabled(0), + mEventsSinceEnable(0), mInputReader(4), mHasPendingEvent(false) { @@ -71,6 +79,8 @@ int LightSensor::setDelay(int32_t handle, int64_t ns) int LightSensor::enable(int32_t handle, int en) { int flags = en ? 1 : 0; + mEventsSinceEnable = 0; + mPreviousLight = -1; if (flags != mEnabled) { int fd; strcpy(&input_sysfs_path[input_sysfs_path_len], "enable"); @@ -87,7 +97,6 @@ int LightSensor::enable(int32_t handle, int en) err = write(fd, buf, sizeof(buf)); close(fd); mEnabled = flags; - setInitialState(); return 0; } return -1; @@ -95,16 +104,6 @@ int LightSensor::enable(int32_t handle, int en) return 0; } -int LightSensor::setInitialState() { - struct input_absinfo absinfo; - if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_LIGHT), &absinfo)) { - mPendingEvent.light = indexToValue(absinfo.value); - mPreviousLight = mPendingEvent.light; - mHasPendingEvent = true; - } - return 0; -} - bool LightSensor::hasPendingEvents() const { return mHasPendingEvent; } @@ -133,10 +132,13 @@ int LightSensor::readEvents(sensors_event_t* data, int count) if (type == EV_ABS) { if (event->code == EVENT_TYPE_LIGHT) { mPendingEvent.light = indexToValue(event->value); + if (mEventsSinceEnable < FIRST_GOOD_EVENT) + mEventsSinceEnable++; } } else if (type == EV_SYN) { mPendingEvent.timestamp = timevalToNano(event->time); - if (mEnabled && (mPendingEvent.light != mPreviousLight)) { + if (mEnabled && (mPendingEvent.light != mPreviousLight) && + mEventsSinceEnable >= FIRST_GOOD_EVENT) { *data++ = mPendingEvent; count--; numEventReceived++; diff --git a/libsensors/LightSensor.h b/libsensors/LightSensor.h index 78e781a..b40283f 100644 --- a/libsensors/LightSensor.h +++ b/libsensors/LightSensor.h @@ -32,6 +32,7 @@ struct input_event; class LightSensor : public SensorBase { int mEnabled; + int mEventsSinceEnable; InputEventCircularReader mInputReader; sensors_event_t mPendingEvent; bool mHasPendingEvent; |