--- /dev/null
+/*
+ * 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__
+
static int display_cnt = -1;
struct display {
- int max;
+ int normal_max;
+ int dim_max;
} *display_arr;
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;
}
int device_display_get_max_brightness(int display_index, int *max_brightness)
{
+ char *arr[1];
+ char str_val[32];
int ret;
if (!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)
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);
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;
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);
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;
+}