display: fix auto-brightness change operation 66/93266/8
authortaeyoung <ty317.kim@samsung.com>
Mon, 24 Oct 2016 03:04:07 +0000 (12:04 +0900)
committertaeyoung <ty317.kim@samsung.com>
Mon, 24 Oct 2016 07:31:41 +0000 (16:31 +0900)
- Previously, auto-brightness change did not work
  since sensor apis were little bit changed, and
  there was no HAL to convert the sensing value
  to the brightness value.

- Now, auto-brightness change works well. The codes
  related with sensor are fixed to deliver the handle
  of the sensor object, not the pointer of the handle.
  And brightness converting HAL is newly added, and
  thus the HAL provides the correct brightness according
  to the light sensing value.

Change-Id: If35a056f5c75ac91a76491a2021859507dec716e
Signed-off-by: taeyoung <ty317.kim@samsung.com>
src/display/auto-brightness.c
src/display/device-interface.c
src/display/device-interface.h
src/display/display-ivi.conf

index c7923af..13ab754 100644 (file)
@@ -46,7 +46,6 @@
 #define MAX_SAMPLING_COUNT     3
 #define MAX_FAULT              5
 #define DEFAULT_AUTOMATIC_BRT  5
-#define MAX_AUTOMATIC_COUNT    11
 #define AUTOMATIC_DEVIDE_VAL   10
 #define AUTOMATIC_DELAY_TIME   0.5     /* 0.5 sec */
 
@@ -55,7 +54,6 @@
 #define WORKING_ANGLE_MIN      0
 #define WORKING_ANGLE_MAX      20
 
-#define ISVALID_AUTOMATIC_INDEX(index) (index >= 0 && index < MAX_AUTOMATIC_COUNT)
 #define BOARD_CONF_FILE "/etc/deviced/display.conf"
 
 #define ON_LUX         -1
@@ -72,7 +70,9 @@ static int fault_count;
 static int automatic_brt = DEFAULT_AUTOMATIC_BRT;
 static int min_brightness = PM_MIN_BRIGHTNESS;
 static char *min_brightness_name = 0;
-static int value_table[MAX_AUTOMATIC_COUNT];
+
+/* light sensor */
+static float lmax, lmin;
 
 static bool update_working_position(void)
 {
@@ -174,25 +174,23 @@ static bool alc_update_brt(bool setting)
 {
        int value = 0;
        int ret = -1;
-       int cmd;
        sensor_event_s light_data;
 
        ret = sensor_listener_read_data(light_listener, &light_data);
        if (ret != SENSOR_ERROR_NONE || (int)light_data.values[0] < 0) {
                fault_count++;
        } else {
-               int force = (setting ? 1 : 0);
-               cmd = DISP_FORCE_CMD(PROP_DISPLAY_BRIGHTNESS_BY_LUX, force);
-               cmd = DISP_CMD(cmd, (int)light_data.values[0]);
-               ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, value_table);
-
-               value = (ISVALID_AUTOMATIC_INDEX(automatic_brt) ?
-                   value_table[automatic_brt] : value_table[DEFAULT_AUTOMATIC_BRT]);
+               ret = backlight_ops.get_brightness_by_light_sensor(
+                               lmax, lmin, light_data.values[0], &value);
+               if (ret == -ENOTSUP) {
+                       _E("Not supported to handle the light data");
+                       return EINA_FALSE;
+               }
 
                if (ret < 0 || value < PM_MIN_BRIGHTNESS ||
                    value > PM_MAX_BRIGHTNESS) {
-                       _E("fail to load light data : %d lux, %d",
-                               (int)light_data.values[0], value);
+                       _E("fail to load light data : light(%d), value(%d), ret(%d)",
+                               (int)light_data.values[0], value, ret);
                        fault_count++;
                } else {
                        fault_count = 0;
@@ -266,7 +264,19 @@ static int connect_sensor(void)
                _E("Failed to get default light sensor!");
                goto error;
        }
-       ret = sensor_create_listener(&sensor, &light_listener);
+       ret = sensor_get_min_range(sensor, &lmin);
+       if (ret != SENSOR_ERROR_NONE) {
+               _E("Failed to get light sensor min range (%d)", ret);
+               goto error;
+       }
+       ret = sensor_get_max_range(sensor, &lmax);
+       if (ret != SENSOR_ERROR_NONE) {
+               _E("Failed to get light sensor max range (%d)", ret);
+               goto error;
+       }
+       _I("Light sensor min(%f), max(%f)", lmin, lmax);
+
+       ret = sensor_create_listener(sensor, &light_listener);
        if (ret != SENSOR_ERROR_NONE) {
                _E("Failed to create listener(light)!");
                goto error;
@@ -601,8 +611,6 @@ static void exit_lsensor(void)
 
 static void auto_brightness_init(void *data)
 {
-       int ret;
-
        display_info.update_auto_brightness = update_auto_brightness;
        display_info.set_autobrightness_min = set_autobrightness_min;
        display_info.reset_autobrightness_min = reset_autobrightness_min;
index bf60ef0..d8c9c57 100644 (file)
@@ -538,15 +538,10 @@ static int set_brightness(int val)
        return display_dev->set_brightness(val);
 }
 
-static int get_brightness(int *val)
+static int get_brt_normalized(int brt_raw)
 {
-       int max, brt, ret;
        int quotient, remainder;
-
-       if (!display_dev || !display_dev->get_brightness) {
-               _E("there is no display device");
-               return -ENOENT;
-       }
+       int max;
 
        max = get_max_brightness();
        if (max < 0) {
@@ -554,12 +549,6 @@ static int get_brightness(int *val)
                return max;
        }
 
-       ret = display_dev->get_brightness(&brt);
-       if (ret < 0) {
-               _E("Failed to get brightness (%d)", ret);
-               return ret;
-       }
-
        /* Maximum Brightness to users is 100.
         * Thus the brightness value need to be calculated using real brightness.
         *    ex) Let's suppose that the maximum brightness of driver is 255.
@@ -571,12 +560,48 @@ static int get_brightness(int *val)
         *              Thus the brightness to users is
         *                 104 * 100 / 255 = 40.7843.... = 41 (rounded up)
         */
-       quotient = brt * 100 / max;
-       remainder = brt * 100 % max;
+       quotient = brt_raw * 100 / max;
+       remainder = brt_raw * 100 % max;
        if (remainder > 0)
                quotient++;
 
-       *val = quotient;
+       return quotient;
+}
+
+static int get_brightness(int *val)
+{
+       int brt, ret;
+
+       if (!display_dev || !display_dev->get_brightness) {
+               _E("there is no display device");
+               return -ENOENT;
+       }
+
+       ret = display_dev->get_brightness(&brt);
+       if (ret < 0) {
+               _E("failed to get brightness (%d)", ret);
+               return ret;
+       }
+
+       *val = get_brt_normalized(brt);
+       return 0;
+}
+
+static int get_brightness_by_light_sensor(float lmax, float lmin, float light, int *brt)
+{
+       int brt_raw;
+       int ret;
+
+       if (!display_dev || !display_dev->get_auto_brightness)
+               return -ENOTSUP;
+
+       ret = display_dev->get_auto_brightness(lmax, lmin, light, &brt_raw);
+       if (ret < 0) {
+               _E("failed to get brightness by light sensor(%d)", ret);
+               return ret;
+       }
+
+       *brt = get_brt_normalized(brt_raw);
        return 0;
 }
 
@@ -596,6 +621,7 @@ static void _init_ops(void)
        backlight_ops.set_force_brightness = set_force_brightness;
        backlight_ops.set_brightness = set_brightness;
        backlight_ops.get_brightness = get_brightness;
+       backlight_ops.get_brightness_by_light_sensor = get_brightness_by_light_sensor;
 
        power_ops.suspend = system_suspend;
        power_ops.enable_autosleep = system_enable_autosleep;
index 07153ac..3381c70 100644 (file)
@@ -74,6 +74,7 @@ struct _backlight_ops {
        int (*set_force_brightness)(int level);
        int (*set_brightness)(int val);
        int (*get_brightness)(int *val);
+       int (*get_brightness_by_light_sensor)(float lmax, float lmin, float light, int *brt);
 };
 
 struct _power_ops {
index 20d092c..b10488c 100644 (file)
@@ -12,3 +12,6 @@ TimeoutEnable=no              # yes or no
 # and/or HW key inputs are supported.
 # Default value is yes.
 InputSupport=no                        # yes or no
+
+# Use Accelator sensor when autobrightness is on.
+AccelSensorOn=no        # yes or no