2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <system_info.h>
27 #define METHOD_GET_MAX_BRIGHTNESS "GetMaxBrightness"
28 #define METHOD_GET_BRIGHTNESS "GetBrightness"
29 #define METHOD_SET_BRIGHTNESS "SetBrightness"
30 #define METHOD_PLAY_CUSTOM "playcustom"
31 #define METHOD_STOP_CUSTOM "stopcustom"
33 #define FRONT_LED_FEATURE "tizen.org/feature/led"
34 #define CAMERA_LED_FEATURE "tizen.org/feature/camera.back.flash"
36 static bool support_front_led;
37 static bool support_camera_led;
39 static void __CONSTRUCTOR__ init(void)
44 ret = system_info_get_platform_bool(FRONT_LED_FEATURE, &val);
45 if (ret == SYSTEM_INFO_ERROR_NONE && val)
46 support_front_led = true;
48 ret = system_info_get_platform_bool(CAMERA_LED_FEATURE, &val);
49 if (ret == SYSTEM_INFO_ERROR_NONE && val)
50 support_camera_led = true;
53 int device_flash_get_max_brightness(int *max_brightness)
57 if (!support_camera_led)
58 return DEVICE_ERROR_NOT_SUPPORTED;
61 return DEVICE_ERROR_INVALID_PARAMETER;
63 ret = dbus_method_sync(DEVICED_BUS_NAME,
64 DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
65 METHOD_GET_MAX_BRIGHTNESS, NULL, NULL);
67 return errno_to_device_error(ret);
69 *max_brightness = ret;
70 return DEVICE_ERROR_NONE;
73 int device_flash_get_brightness(int *brightness)
77 if (!support_camera_led)
78 return DEVICE_ERROR_NOT_SUPPORTED;
81 return DEVICE_ERROR_INVALID_PARAMETER;
83 ret = dbus_method_sync(DEVICED_BUS_NAME,
84 DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
85 METHOD_GET_BRIGHTNESS, NULL, NULL);
87 return errno_to_device_error(ret);
90 return DEVICE_ERROR_NONE;
93 int device_flash_set_brightness(int brightness)
100 if (!support_camera_led)
101 return DEVICE_ERROR_NOT_SUPPORTED;
103 ret = device_flash_get_max_brightness(&max);
107 if (brightness < 0 || brightness > max)
108 return DEVICE_ERROR_INVALID_PARAMETER;
110 snprintf(buf_val, sizeof(buf_val), "%d", brightness);
112 snprintf(buf_noti, sizeof(buf_noti), "%d", 0);
115 /* if camera API preempt a flash device, it will return -EBUSY error. */
116 ret = dbus_method_sync(DEVICED_BUS_NAME,
117 DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
118 METHOD_SET_BRIGHTNESS, "ii", arr);
120 return errno_to_device_error(ret);
122 return DEVICE_ERROR_NONE;
125 int device_led_play_custom(int on, int off, unsigned int color, unsigned int flags)
128 char str_on[32], str_off[32];
129 char str_color[32], str_flags[32];
132 if (!support_front_led)
133 return DEVICE_ERROR_NOT_SUPPORTED;
135 if (on < 0 || off < 0)
136 return DEVICE_ERROR_INVALID_PARAMETER;
138 snprintf(str_on, sizeof(str_on), "%d", on);
140 snprintf(str_off, sizeof(str_off), "%d", off);
142 snprintf(str_color, sizeof(str_color), "%lu", (long unsigned int)color);
144 snprintf(str_flags, sizeof(str_flags), "%lu", (long unsigned int)flags);
147 ret = dbus_method_sync(DEVICED_BUS_NAME,
148 DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
149 METHOD_PLAY_CUSTOM, "iiuu", arr);
151 return errno_to_device_error(ret);
153 return DEVICE_ERROR_NONE;
156 int device_led_stop_custom(void)
160 if (!support_front_led)
161 return DEVICE_ERROR_NOT_SUPPORTED;
163 ret = dbus_method_sync(DEVICED_BUS_NAME,
164 DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
165 METHOD_STOP_CUSTOM, NULL, NULL);
167 return errno_to_device_error(ret);
169 return DEVICE_ERROR_NONE;