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>
24 #include "led-internal.h"
28 #define METHOD_GET_MAX_BRIGHTNESS "GetMaxBrightness"
29 #define METHOD_GET_BRIGHTNESS "GetBrightness"
30 #define METHOD_SET_BRIGHTNESS "SetBrightness"
31 #define METHOD_PLAY_CUSTOM "playcustom"
32 #define METHOD_GET_LED_NUMBER "GetNumOfLeds"
33 #define METHOD_MULTI_LED_CONTROL "multi_led_control"
34 #define METHOD_STOP_CUSTOM "stopcustom"
36 #define FRONT_LED_FEATURE "tizen.org/feature/led"
37 #define CAMERA_LED_FEATURE "tizen.org/feature/camera.back.flash"
39 static bool support_front_led;
40 static bool support_camera_led;
41 static int number_of_devices = -1;
43 static void __CONSTRUCTOR__ init(void)
48 ret = system_info_get_platform_bool(FRONT_LED_FEATURE, &val);
49 if (ret == SYSTEM_INFO_ERROR_NONE && val)
50 support_front_led = true;
52 ret = system_info_get_platform_bool(CAMERA_LED_FEATURE, &val);
53 if (ret == SYSTEM_INFO_ERROR_NONE && val)
54 support_camera_led = true;
57 int device_flash_get_max_brightness(int *max_brightness)
61 if (!support_camera_led)
62 return DEVICE_ERROR_NOT_SUPPORTED;
65 return DEVICE_ERROR_INVALID_PARAMETER;
67 ret = dbus_method_sync_var(DEVICED_BUS_NAME,
68 DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
69 METHOD_GET_MAX_BRIGHTNESS, NULL);
71 return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
73 *max_brightness = ret;
74 return DEVICE_ERROR_NONE;
77 int device_flash_get_brightness(int *brightness)
81 if (!support_camera_led)
82 return DEVICE_ERROR_NOT_SUPPORTED;
85 return DEVICE_ERROR_INVALID_PARAMETER;
87 ret = dbus_method_sync_var(DEVICED_BUS_NAME,
88 DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
89 METHOD_GET_BRIGHTNESS, NULL);
91 return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
94 return DEVICE_ERROR_NONE;
97 int device_flash_set_brightness(int brightness)
101 if (!support_camera_led)
102 return DEVICE_ERROR_NOT_SUPPORTED;
104 ret = device_flash_get_max_brightness(&max);
108 if (brightness < 0 || brightness > max)
109 return DEVICE_ERROR_INVALID_PARAMETER;
111 /* if camera API preempt a flash device, it will return -EBUSY error. */
112 ret = dbus_method_sync_var(DEVICED_BUS_NAME,
113 DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
114 METHOD_SET_BRIGHTNESS, g_variant_new("(ii)", brightness, 0));
116 return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
118 return DEVICE_ERROR_NONE;
121 int device_led_play_custom(int on, int off, unsigned int color, unsigned int flags)
125 if (!support_front_led)
126 return DEVICE_ERROR_NOT_SUPPORTED;
128 if (on < 0 || off < 0)
129 return DEVICE_ERROR_INVALID_PARAMETER;
131 ret = dbus_method_sync_var(DEVICED_BUS_NAME,
132 DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
133 METHOD_PLAY_CUSTOM, g_variant_new("(iiuu)", on, off, (unsigned int)color, (unsigned int)flags));
134 //LCOV_EXCL_START System Error
136 return errno_to_device_error(ret);
138 return DEVICE_ERROR_NONE;
141 int device_led_stop_custom(void)
145 if (!support_front_led)
146 return DEVICE_ERROR_NOT_SUPPORTED;
148 ret = dbus_method_sync_var(DEVICED_BUS_NAME,
149 DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
150 METHOD_STOP_CUSTOM, NULL);
151 //LCOV_EXCL_START System Error
153 return errno_to_device_error(ret);
156 return DEVICE_ERROR_NONE;
159 //LCOV_EXCL_START Not used function
160 int device_multi_led_get_number(int *num_of_leds)
164 if (!support_front_led)
165 return DEVICE_ERROR_NOT_SUPPORTED;
168 return DEVICE_ERROR_INVALID_PARAMETER;
170 if (number_of_devices < 0) {
171 ret = dbus_method_sync_var(DEVICED_BUS_NAME,
172 DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
173 METHOD_GET_LED_NUMBER, NULL);
175 return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
176 number_of_devices = ret;
179 *num_of_leds = number_of_devices;
181 return DEVICE_ERROR_NONE;
184 int device_multi_led_control(unsigned int color[])
186 GVariantBuilder *builder = NULL;
187 GVariant *var = NULL;
190 if (!support_front_led)
191 return DEVICE_ERROR_NOT_SUPPORTED;
194 return DEVICE_ERROR_INVALID_PARAMETER;
196 if (number_of_devices < 0) {
197 ret = device_multi_led_get_number(&number_of_devices);
198 if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error
202 builder = g_variant_builder_new(G_VARIANT_TYPE("au"));
203 for (i = 0; i < number_of_devices; i++)
204 g_variant_builder_add(builder, "u", color[i]);
206 var = g_variant_new("(au)", builder);
207 g_variant_builder_unref(builder);
209 return dbus_method_sync_var(DEVICED_BUS_NAME, DEVICED_PATH_LED,
210 DEVICED_INTERFACE_LED, METHOD_MULTI_LED_CONTROL, var);