diff options
author | Pawit Pornkitprasan <p.pawit@gmail.com> | 2011-12-23 19:33:01 +0700 |
---|---|---|
committer | Pawit Pornkitprasan <p.pawit@gmail.com> | 2011-12-23 19:34:39 +0700 |
commit | a2f814e52514989f5f8bd795ff603b81095598c2 (patch) | |
tree | 8896899aa442498f32252c8f95e39dbe84941eb8 | |
parent | 91c2ee3f53227cecf4c720171d9379955c9a4463 (diff) | |
download | device_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
-rw-r--r-- | libsensors/LightSensor.cpp | 50 | ||||
-rw-r--r-- | libsensors/LightSensor.h | 3 | ||||
-rw-r--r-- | libsensors/ProximitySensor.cpp | 2 | ||||
-rw-r--r-- | libsensors/sensors.cpp | 2 | ||||
-rw-r--r-- | overlay/frameworks/base/core/res/res/values/config.xml | 37 |
5 files changed, 25 insertions, 69 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; diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index 0f6e905..389af20 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -44,14 +44,11 @@ Must be overridden in platform specific overlays --> <integer-array name="config_autoBrightnessLevels"> - <item>10</item> - <item>160</item> - <item>225</item> - <item>320</item> - <item>640</item> - <item>1280</item> - <item>2600</item> - <item>10240</item> + <item>7</item> + <item>94</item> + <item>208</item> + <item>458</item> + <item>2223</item> </integer-array> <!-- Array of output values for LCD backlight corresponding to the LUX values @@ -59,15 +56,12 @@ than the size of the config_autoBrightnessLevels array. --> <integer-array name="config_autoBrightnessLcdBacklightValues"> - <item>20</item> - <item>20</item> - <item>20</item> - <item>20</item> + <item>10</item> <item>35</item> - <item>50</item> - <item>50</item> - <item>100</item> - <item>255</item> + <item>55</item> + <item>70</item> + <item>70</item> + <item>250</item> </integer-array> <!-- Array of output values for button backlight corresponding to the LUX values @@ -77,10 +71,7 @@ <integer-array name="config_autoBrightnessButtonBacklightValues"> <item>255</item> <item>255</item> - <item>0</item> - <item>0</item> - <item>0</item> - <item>0</item> + <item>255</item> <item>0</item> <item>0</item> <item>0</item> @@ -98,9 +89,6 @@ <item>0</item> <item>0</item> <item>0</item> - <item>0</item> - <item>0</item> - <item>0</item> </integer-array> <integer name="config_deskDockKeepsScreenOn">0</integer> @@ -181,6 +169,9 @@ <item>7</item> </integer-array> + <!-- Minimum screen brightness allowed by the power manager. --> + <integer name="config_screenBrightnessDim">10</integer> + <!-- Boolean indicating whether the wifi chipset has p2p support --> <bool translatable="false" name="config_wifi_p2p_support">true</bool> |