summaryrefslogtreecommitdiffstats
path: root/libsensors
diff options
context:
space:
mode:
authorPawit Pornkitprasan <p.pawit@gmail.com>2011-12-23 19:33:01 +0700
committerPawit Pornkitprasan <p.pawit@gmail.com>2011-12-23 19:34:39 +0700
commita2f814e52514989f5f8bd795ff603b81095598c2 (patch)
tree8896899aa442498f32252c8f95e39dbe84941eb8 /libsensors
parent91c2ee3f53227cecf4c720171d9379955c9a4463 (diff)
downloaddevice_samsung_aries-common-a2f814e52514989f5f8bd795ff603b81095598c2.zip
device_samsung_aries-common-a2f814e52514989f5f8bd795ff603b81095598c2.tar.gz
device_samsung_aries-common-a2f814e52514989f5f8bd795ff603b81095598c2.tar.bz2
libsensors: Update from crespo
Light sensor now uses calculation instead of pre-determined values Requires updated kernel
Diffstat (limited to 'libsensors')
-rw-r--r--libsensors/LightSensor.cpp50
-rw-r--r--libsensors/LightSensor.h3
-rw-r--r--libsensors/ProximitySensor.cpp2
-rw-r--r--libsensors/sensors.cpp2
4 files changed, 11 insertions, 46 deletions
diff --git a/libsensors/LightSensor.cpp b/libsensors/LightSensor.cpp
index 9025029..5df7cd5 100644
--- a/libsensors/LightSensor.cpp
+++ b/libsensors/LightSensor.cpp
@@ -27,17 +27,9 @@
/*****************************************************************************/
-/* 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, "light_sensor"),
+ : SensorBase(NULL, "lightsensor-level"),
mEnabled(0),
- mEventsSinceEnable(0),
mInputReader(4),
mHasPendingEvent(false)
{
@@ -79,8 +71,6 @@ 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");
@@ -131,18 +121,19 @@ int LightSensor::readEvents(sensors_event_t* data, int count)
int type = event->type;
if (type == EV_ABS) {
if (event->code == EVENT_TYPE_LIGHT) {
- mPendingEvent.light = indexToValue(event->value);
- if (mEventsSinceEnable < FIRST_GOOD_EVENT)
- mEventsSinceEnable++;
+ // Convert adc value to lux assuming:
+ // I = 10 * log(Ev) uA
+ // R = 47kOhm
+ // Max adc value 4095 = 3.3V
+ // 1/4 of light reaches sensor
+ mPendingEvent.light = powf(10, event->value * (330.0f / 4095.0f / 47.0f)) * 4;
}
} else if (type == EV_SYN) {
mPendingEvent.timestamp = timevalToNano(event->time);
- if (mEnabled && (mPendingEvent.light != mPreviousLight) &&
- mEventsSinceEnable >= FIRST_GOOD_EVENT) {
+ if (mEnabled) {
*data++ = mPendingEvent;
count--;
numEventReceived++;
- mPreviousLight = mPendingEvent.light;
}
} else {
LOGE("LightSensor: unknown event (type=%d, code=%d)",
@@ -153,28 +144,3 @@ int LightSensor::readEvents(sensors_event_t* data, int count)
return numEventReceived;
}
-
-float LightSensor::indexToValue(size_t index) const
-{
- /* Driver gives a rolling average adc value. We convert it lux levels. */
- static const struct adcToLux {
- size_t adc_value;
- float lux_value;
- } adcToLux[] = {
- { 150, 10.0 }, /* from 0 - 150 adc, we map to 10.0 lux */
- { 800, 160.0 }, /* from 151 - 800 adc, we map to 160.0 lux */
- { 900, 225.0 }, /* from 801 - 900 adc, we map to 225.0 lux */
- { 1000, 320.0 }, /* from 901 - 1000 adc, we map to 320.0 lux */
- { 1200, 640.0 }, /* from 1001 - 1200 adc, we map to 640.0 lux */
- { 1400, 1280.0 }, /* from 1201 - 1400 adc, we map to 1280.0 lux */
- { 1600, 2600.0 }, /* from 1401 - 1600 adc, we map to 2600.0 lux */
- { 4095, 10240.0 }, /* from 1601 - 4095 adc, we map to 10240.0 lux */
- };
- size_t i;
- for (i = 0; i < ARRAY_SIZE(adcToLux); i++) {
- if (index < adcToLux[i].adc_value) {
- return adcToLux[i].lux_value;
- }
- }
- return adcToLux[ARRAY_SIZE(adcToLux)-1].lux_value;
-}
diff --git a/libsensors/LightSensor.h b/libsensors/LightSensor.h
index b40283f..79e0ccf 100644
--- a/libsensors/LightSensor.h
+++ b/libsensors/LightSensor.h
@@ -32,7 +32,6 @@ struct input_event;
class LightSensor : public SensorBase {
int mEnabled;
- int mEventsSinceEnable;
InputEventCircularReader mInputReader;
sensors_event_t mPendingEvent;
bool mHasPendingEvent;
@@ -40,8 +39,6 @@ class LightSensor : public SensorBase {
int input_sysfs_path_len;
int setInitialState();
- float mPreviousLight;
- float indexToValue(size_t index) const;
public:
LightSensor();
diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp
index 16917fc..794a586 100644
--- a/libsensors/ProximitySensor.cpp
+++ b/libsensors/ProximitySensor.cpp
@@ -29,7 +29,7 @@
/*****************************************************************************/
ProximitySensor::ProximitySensor()
- : SensorBase(NULL, "proximity_sensor"),
+ : SensorBase(NULL, "proximity"),
mEnabled(0),
mInputReader(4),
mHasPendingEvent(false)
diff --git a/libsensors/sensors.cpp b/libsensors/sensors.cpp
index ca0a382..2459389 100644
--- a/libsensors/sensors.cpp
+++ b/libsensors/sensors.cpp
@@ -300,7 +300,9 @@ int sensors_poll_context_t::pollEvents(sensors_event_t* data, int count)
// we still have some room, so try to see if we can get
// some events immediately or just wait if we don't have
// anything to return
+ do {
n = poll(mPollFds, numFds, nbEvents ? 0 : -1);
+ } while (n < 0 && errno == EINTR);
if (n<0) {
LOGE("poll() failed (%s)", strerror(errno));
return -errno;