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
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 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 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 @@
 
     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 @@
     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 @@
         { "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,
diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml
index eb71bf5..0bfc868 100644
--- a/overlay/frameworks/base/core/res/res/values/config.xml
+++ b/overlay/frameworks/base/core/res/res/values/config.xml
@@ -44,11 +44,11 @@
 
          Must be overridden in platform specific overlays -->
     <integer-array name="config_autoBrightnessLevels">
-        <item>100</item>
-        <item>200</item>
-        <item>400</item>
-        <item>1000</item>
-        <item>3000</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