diff options
author | Arve Hjønnevåg <arve@android.com> | 2011-11-01 19:59:11 -0700 |
---|---|---|
committer | Arve Hjønnevåg <arve@android.com> | 2011-11-01 19:59:11 -0700 |
commit | 2e0ab7265e3039fee787c2216e0c98d92ea0b49e (patch) | |
tree | 3728597fe0e21d5624eef9d209aa24f89958f76b /libsensors | |
parent | 7e88d42adb9310bf560f00d2250f7c4c528f03d4 (diff) | |
download | device_samsung_crespo-2e0ab7265e3039fee787c2216e0c98d92ea0b49e.tar.gz device_samsung_crespo-2e0ab7265e3039fee787c2216e0c98d92ea0b49e.tar.bz2 device_samsung_crespo-2e0ab7265e3039fee787c2216e0c98d92ea0b49e.zip |
sensors: Return a calculated lux value instead using the current 8 entry table
The light sensor now uses the lux to current formula in the datasheet,
I = 10 * log(Ev) uA, and multiplies the result by 4 as an attempt
to correct for the glass in front of the sensor.
Also update the config_autoBrightnessLevels table so the auto brightness
change occurs at the same adc values as before (or close for 7.26 and
94.5 lux).
Change-Id: I5a54fda8eca26006671064b7db1e39ba0a5d7889
Diffstat (limited to 'libsensors')
-rw-r--r-- | libsensors/LightSensor.cpp | 37 | ||||
-rw-r--r-- | libsensors/LightSensor.h | 2 | ||||
-rw-r--r-- | libsensors/sensors.cpp | 2 |
3 files changed, 8 insertions, 33 deletions
diff --git a/libsensors/LightSensor.cpp b/libsensors/LightSensor.cpp index c87bacd..a12c218 100644 --- a/libsensors/LightSensor.cpp +++ b/libsensors/LightSensor.cpp @@ -80,7 +80,6 @@ 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 +130,21 @@ 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); + // 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; if (mEventsSinceEnable < FIRST_GOOD_EVENT) mEventsSinceEnable++; } } else if (type == EV_SYN) { mPendingEvent.timestamp = timevalToNano(event->time); - if (mEnabled && (mPendingEvent.light != mPreviousLight) && - mEventsSinceEnable >= FIRST_GOOD_EVENT) { + if (mEnabled && mEventsSinceEnable >= FIRST_GOOD_EVENT) { *data++ = mPendingEvent; count--; numEventReceived++; - mPreviousLight = mPendingEvent.light; } } else { LOGE("LightSensor: unknown event (type=%d, code=%d)", @@ -153,28 +155,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..2d5ed50 100644 --- a/libsensors/LightSensor.h +++ b/libsensors/LightSensor.h @@ -40,8 +40,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/sensors.cpp b/libsensors/sensors.cpp index ec2d754..1dc128a 100644 --- a/libsensors/sensors.cpp +++ b/libsensors/sensors.cpp @@ -82,7 +82,7 @@ static const struct sensor_t sSensorList[] = { { "GP2A Light sensor", "Sharp", 1, SENSORS_LIGHT_HANDLE, - SENSOR_TYPE_LIGHT, 3000.0f, 1.0f, 0.75f, 0, { } }, + SENSOR_TYPE_LIGHT, powf(10, (280.0f / 47.0f)) * 4, 1.0f, 0.75f, 0, { } }, { "GP2A Proximity sensor", "Sharp", 1, SENSORS_PROXIMITY_HANDLE, |