Add internal APIs for DIM control 03/177003/6 accepted/tizen/unified/20180502.071147 submit/tizen/20180426.071254 submit/tizen/20180430.025008 submit/tizen/20180430.025608 submit/tizen/20180502.014710
authorlokilee73 <changjoo.lee@samsung.com>
Tue, 24 Apr 2018 11:29:51 +0000 (20:29 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Thu, 26 Apr 2018 07:39:35 +0000 (16:39 +0900)
Change-Id: Iab1e71c6cca32fa04e8bd3f762e01e4ea5d05a11
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
include/display-internal.h [new file with mode: 0755]
src/display.c [changed mode: 0644->0755]

diff --git a/include/display-internal.h b/include/display-internal.h
new file mode 100755 (executable)
index 0000000..a1c4ba6
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __TIZEN_SYSTEM_DISPLAY_INTERNAL_H__
+#define __TIZEN_SYSTEM_LED_INTERNAL_H__
+
+
+#include "device-error.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @brief Gets the display brightness value.
+ * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/display
+ * @param[in] display_index The index of the display \n
+ *                          It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_numbers(). \n
+ *                          The index zero is always assigned to the main display
+ * @param[out] brightness The current brightness value of the display
+ * @param[in] state The enum value of the display state \n
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #DEVICE_ERROR_NONE Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
+ * @see device_display_get_numbers()
+ * @see device_display_set_brightness_state()
+ * @see device_display_get_max_brightness_state()
+ */
+int device_display_get_brightness_state(int display_index, display_state_e state, int *brightness);
+
+
+/**
+ * @brief Gets the maximum brightness value that can be set.
+ * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/display
+ * @param[in] display_index The index of the display \n
+ *                          It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_numbers(). \n
+ *                          The index zero is always assigned to the main display
+ * @param[out] max_brightness The maximum brightness value of the display
+ * @param[in] state The enum value of the display state \n
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #DEVICE_ERROR_NONE Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
+ * @see device_display_get_numbers()
+ * @see device_display_get_brightness_state()
+ * @see device_display_set_brightness_state()
+ */
+int device_display_get_max_brightness_state(int display_index, display_state_e state, int *brightness);
+
+
+/**
+ * @brief Sets the display brightness value.
+ * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/display
+ * @param[in] display_index The index of the display \n
+ *                          It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_numbers(). \n
+ *                          The index zero is always assigned to the main display
+ * @param[in] brightness The new brightness value to set \n
+ *                       The maximum value can be represented by device_display_get_max_brightness_state()
+ * @param[in] state The enum value of the display state \n
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #DEVICE_ERROR_NONE Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
+ * @see device_display_get_numbers()
+ * @see device_display_get_max_brightness()
+ * @see device_display_set_brightness_state()
+ */
+int device_display_set_brightness_state(int display_index, display_state_e state, int brightness);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif  // __TIZEN_SYSTEM_DISPLAY_INTERNAL_H__
+
old mode 100644 (file)
new mode 100755 (executable)
index e633d8c..40817b0
@@ -35,7 +35,8 @@
 
 static int display_cnt = -1;
 struct display {
-       int max;
+       int normal_max;
+       int dim_max;
 } *display_arr;
 
 static int alloc_display(void)
@@ -49,8 +50,10 @@ static int alloc_display(void)
        if (!display_arr)
                return -ENOMEM;
 
-       for (i = 0; i < display_cnt; ++i)
-               display_arr[i].max = -1;
+       for (i = 0; i < display_cnt; ++i) {
+               display_arr[i].normal_max = -1;
+               display_arr[i].dim_max = -1;
+       }
 
        return 0;
 }
@@ -80,6 +83,8 @@ int device_display_get_numbers(int *device_number)
 
 int device_display_get_max_brightness(int display_index, int *max_brightness)
 {
+       char *arr[1];
+       char str_val[32];
        int ret;
 
        if (!max_brightness)
@@ -97,21 +102,25 @@ int device_display_get_max_brightness(int display_index, int *max_brightness)
        if (!display_arr && alloc_display() < 0)
                return DEVICE_ERROR_OPERATION_FAILED;
 
-       if (display_arr[display_index].max < 0) {
+       snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_NORMAL);
+       arr[0] = str_val;
+       if (display_arr[display_index].normal_max < 0) {
                ret = dbus_method_sync(DEVICED_BUS_NAME,
                                DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                               METHOD_GET_MAX_BRIGHTNESS, NULL, NULL);
+                               METHOD_GET_MAX_BRIGHTNESS, "i", arr);
                if (ret < 0)
                        return errno_to_device_error(ret);
-               display_arr[display_index].max = ret;
+               display_arr[display_index].normal_max = ret;
        }
 
-       *max_brightness = display_arr[display_index].max;
+       *max_brightness = display_arr[display_index].normal_max;
        return DEVICE_ERROR_NONE;
 }
 
 int device_display_get_brightness(int display_index, int *brightness)
 {
+       char *arr[1];
+       char str_val[32];
        int ret;
 
        if (!brightness)
@@ -126,9 +135,12 @@ int device_display_get_brightness(int display_index, int *brightness)
        if (display_index < 0 || display_index >= display_cnt)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
+       snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_NORMAL);
+       arr[0] = str_val;
+
        ret = dbus_method_sync(DEVICED_BUS_NAME,
                        DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                       METHOD_GET_BRIGHTNESS, NULL, NULL);
+                       METHOD_GET_BRIGHTNESS, "i", arr);
        if (ret < 0)
                return errno_to_device_error(ret);
 
@@ -138,7 +150,8 @@ int device_display_get_brightness(int display_index, int *brightness)
 
 int device_display_set_brightness(int display_index, int brightness)
 {
-       char *arr[1];
+       char *arr[2];
+       char str_state[32];
        char str_val[32];
        int ret, max;
 
@@ -151,18 +164,21 @@ int device_display_set_brightness(int display_index, int brightness)
        if (display_index < 0 || display_index >= display_cnt)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       if (display_arr[display_index].max < 0)
+       if (display_arr[display_index].normal_max < 0)
                device_display_get_max_brightness(display_index, &max);
 
-       if (brightness < 0 || brightness > display_arr[display_index].max)
+       if (brightness < 0 || brightness > display_arr[display_index].normal_max)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
+       snprintf(str_state, sizeof(str_state), "%d", DISPLAY_STATE_NORMAL);
+       arr[0] = str_state;
+
        snprintf(str_val, sizeof(str_val), "%d", brightness);
-       arr[0] = str_val;
+       arr[1] = str_val;
 
        ret = dbus_method_sync(DEVICED_BUS_NAME,
                        DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                       METHOD_SET_BRIGHTNESS, "i", arr);
+                       METHOD_SET_BRIGHTNESS, "ii", arr);
        if (ret < 0)
                return errno_to_device_error(ret);
 
@@ -230,3 +246,141 @@ int device_display_change_state(display_state_e state)
 
        return DEVICE_ERROR_NONE;
 }
+
+int device_display_get_max_brightness_state(int display_index, display_state_e state, int *brightness)
+{
+       char *arr[1];
+       char str_val[32];
+       int ret;
+
+       if (!brightness)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       if (state > DISPLAY_STATE_SCREEN_DIM)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       if (display_cnt < 0) {
+               ret = device_display_get_numbers(&display_cnt);
+               if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error
+                       return ret;
+       }
+
+       if (display_index < 0 || display_index >= display_cnt)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       if (!display_arr && alloc_display() < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       if (state == DISPLAY_STATE_NORMAL)
+               snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_NORMAL);
+       else if (state == DISPLAY_STATE_SCREEN_DIM)
+               snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_SCREEN_DIM);
+       arr[0] = str_val;
+
+       ret = dbus_method_sync(DEVICED_BUS_NAME,
+                               DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
+                               METHOD_GET_MAX_BRIGHTNESS, "i", arr);
+       if (ret < 0)
+               return errno_to_device_error(ret);
+
+       if (state == DISPLAY_STATE_NORMAL) {
+               display_arr[display_index].normal_max = ret;
+               *brightness = display_arr[display_index].normal_max;
+       } else {
+               display_arr[display_index].dim_max = ret;
+               *brightness = display_arr[display_index].dim_max;
+       }
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_display_get_brightness_state(int display_index, display_state_e state, int *brightness)
+{
+       char *arr[1];
+       char str_val[32];
+       int ret;
+
+       if (!brightness)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       if (state > DISPLAY_STATE_SCREEN_DIM)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       if (display_cnt < 0) {
+               ret = device_display_get_numbers(&display_cnt);
+               if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error
+                       return ret;
+       }
+
+       if (display_index < 0 || display_index >= display_cnt)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       if (state == DISPLAY_STATE_NORMAL)
+               snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_NORMAL);
+       else if (state == DISPLAY_STATE_SCREEN_DIM)
+               snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_SCREEN_DIM);
+       arr[0] = str_val;
+
+       ret = dbus_method_sync(DEVICED_BUS_NAME,
+                       DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
+                       METHOD_GET_BRIGHTNESS, "i", arr);
+       if (ret < 0)
+               return errno_to_device_error(ret);
+
+       *brightness = ret;
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_display_set_brightness_state(int display_index, display_state_e state, int brightness)
+{
+       char *arr[2];
+       char str_state[32];
+       char str_val[32];
+       int ret, max;
+
+       if (display_cnt < 0) {
+               ret = device_display_get_numbers(&display_cnt);
+               if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error
+                       return ret;
+       }
+
+       if (state > DISPLAY_STATE_SCREEN_DIM)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       if (display_index < 0 || display_index >= display_cnt)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       switch (state) {
+       case DISPLAY_STATE_NORMAL:
+               if (display_arr[display_index].normal_max < 0)
+                       device_display_get_max_brightness_state(display_index, DISPLAY_STATE_NORMAL, &max);
+               if (brightness < 0 || brightness > display_arr[display_index].normal_max)
+                       return DEVICE_ERROR_INVALID_PARAMETER;
+
+               snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_NORMAL);
+               arr[0] = str_val;
+               snprintf(str_val, sizeof(str_val), "%d", brightness);
+               arr[1] = str_val;
+               break;
+       case DISPLAY_STATE_SCREEN_DIM:
+               if (display_arr[display_index].dim_max < 0)
+                       device_display_get_max_brightness_state(display_index, DISPLAY_STATE_SCREEN_DIM, &max);
+               if (brightness < 0 || brightness > display_arr[display_index].dim_max)
+                       return DEVICE_ERROR_INVALID_PARAMETER;
+
+               snprintf(str_state, sizeof(str_state), "%d", DISPLAY_STATE_SCREEN_DIM);
+               arr[0] = str_state;
+               snprintf(str_val, sizeof(str_val), "%d", brightness);
+               arr[1] = str_val;
+               break;
+       }
+
+       ret = dbus_method_sync(DEVICED_BUS_NAME,
+                       DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
+                       METHOD_SET_BRIGHTNESS, "ii", arr);
+       if (ret < 0)
+               return errno_to_device_error(ret);
+
+       return DEVICE_ERROR_NONE;
+}