From: lokilee73 Date: Fri, 2 Feb 2018 05:06:31 +0000 (+0900) Subject: Add new APIs that control multiple LEDs X-Git-Tag: accepted/tizen/unified/20180502.071147~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5269069f438415824047b2c27021191263ffaf97;p=platform%2Fcore%2Fapi%2Fdevice.git Add new APIs that control multiple LEDs Change-Id: I6c1e0bc0b54a910ddb7ec371a24765552b07d6ff Signed-off-by: lokilee73 Signed-off-by: Hyotaek Shim --- diff --git a/include/battery.h b/include/battery.h old mode 100755 new mode 100644 diff --git a/include/device.h b/include/device.h old mode 100755 new mode 100644 index d2e31da..38d5326 --- a/include/device.h +++ b/include/device.h @@ -11,7 +11,7 @@ * 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. + * limitations under the License. */ @@ -70,14 +70,14 @@ int device_get_display_numbers(int* device_number); int device_get_brightness(int display_index, int *brightness); /** - * @brief Sets the display brightness value. + * @brief Sets the display brightness value. * * @param[in] display_index The index of the display, it be greater than or equal to 0 and less than \n * the number of displays returned by device_get_display_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_get_max_brightness() - * + * * @return 0 on success, otherwise a negative error value. * @retval #DEVICE_ERROR_NONE Successful * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter @@ -92,7 +92,7 @@ int device_get_brightness(int display_index, int *brightness); int device_set_brightness(int display_index, int brightness); /** - * @brief Gets the maximum brightness value that can be set. + * @brief Gets the maximum brightness value that can be set. * * @param[in] display_index The index of the display, it be greater than or equal to 0 and less than \n * the number of displays returned by device_get_display_numbers().\n diff --git a/include/display.h b/include/display.h old mode 100755 new mode 100644 diff --git a/include/led-internal.h b/include/led-internal.h new file mode 100644 index 0000000..7d2e016 --- /dev/null +++ b/include/led-internal.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2014 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_LED_INTERNAL_H__ +#define __TIZEN_SYSTEM_LED_INTERNAL_H__ + + +#include "device-error.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @brief Gets the total number of LEDs in the device. + * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * @remarks This API is related to the following feature: %http://tizen.org/feature/led + * @param[out] Number of LEDs + * @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 + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_multi_led_get_number(int *num_of_leds); + +/** + * @brief Plays multiple LEDs at the same time. + * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * @remarks This API is related to the following feature: %http://tizen.org/feature/led + * @remarks The array size must be the same as the number of LEDs, which is obtained by device_multi_led_get_number(). + * @param[in] led[] Indicate LEDs to be controlled + * @param[in] color[] The Color values \n + * The first byte means opaque, and the other 3 bytes mean RGB values + * @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 + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_multi_led_play_custom(bool led[], unsigned int color[]); + +/** + * @brief Stops multiple LEDs at the same time. + * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * @remarks This API is related to the following feature: %http://tizen.org/feature/led + * @remarks The array size must be the same as the number of LEDs, which is obtained by device_multi_led_get_number(). + * @param[in] led[] Indicate LEDs to be controlled + * @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 + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_multi_led_stop_custom(bool led[]); + + +#ifdef __cplusplus +} +#endif + + +#endif // __TIZEN_SYSTEM_LED_INTERNAL_H__ diff --git a/include/power.h b/include/power.h old mode 100755 new mode 100644 diff --git a/src/common.c b/src/common.c index 63481dc..c6fd0a1 100644 --- a/src/common.c +++ b/src/common.c @@ -160,4 +160,4 @@ tizen_profile_t _get_tizen_profile() free(profileName); return profile; -} \ No newline at end of file +} diff --git a/src/dbus.c b/src/dbus.c index e49e71b..4f84fcc 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -294,6 +294,63 @@ int dbus_method_sync(const char *dest, const char *path, return result; } +int dbus_method_sync_var(const char *dest, const char *path, + const char *interface, const char *method, GVariant *var) +{ + GDBusProxy *proxy; + GError *err = NULL; + GVariant *output; + int result; + +#if !GLIB_CHECK_VERSION(2, 35, 0) + g_type_init(); +#endif + + pthread_mutex_lock(&dmutex); + proxy = get_proxy_from_proxy_pool(dest, path, interface, &err); + if (!proxy) { +//LCOV_EXCL_START System Error + pthread_mutex_unlock(&dmutex); + _E("fail to get proxy from proxy pool : %s-%s (%d-%s)", + interface, method, err->code, err->message); + result = g_dbus_error_to_errno(err->code); + g_clear_error(&err); + return result; +//LCOV_EXCL_STOP + } + + output = g_dbus_proxy_call_sync(proxy, + method, /* method name */ + var, /* parameters */ + G_DBUS_CALL_FLAGS_NONE, + DBUS_REPLY_TIMEOUT, /* timeout */ + NULL, /* GCancellable */ + &err); + pthread_mutex_unlock(&dmutex); + + if (!output) { +//LCOV_EXCL_START System Error + if (!err) { + _E("g_dbus_proxy_call_sync error : %s-%s", + interface, method); + return -EPERM; + } + _E("g_dbus_proxy_call_sync error : %s-%s (%d-%s)", + interface, method, err->code, err->message); + result = g_dbus_error_to_errno(err->code); + g_clear_error(&err); + return result; +//LCOV_EXCL_STOP + } + + /* get output value */ + g_variant_get(output, "(i)", &result); + + g_variant_unref(output); + + return result; +} + int dbus_method_sync_with_reply(const char *dest, const char *path, const char *interface, const char *method, const char *sig, diff --git a/src/dbus.h b/src/dbus.h index 11d13ce..c502284 100644 --- a/src/dbus.h +++ b/src/dbus.h @@ -70,6 +70,8 @@ int dbus_method_sync_with_reply(const char *dest, const char *path, const char *interface, const char *method, const char *sig, char *param[], GVariant **info); +int dbus_method_sync_var(const char *dest, const char *path, + const char *iface, const char *method, GVariant *var); /** * If result is NULL, err is set. diff --git a/src/led.c b/src/led.c old mode 100644 new mode 100755 index bb388e7..43d8e07 --- a/src/led.c +++ b/src/led.c @@ -21,20 +21,25 @@ #include #include "led.h" +#include "led-internal.h" #include "common.h" #include "dbus.h" #define METHOD_GET_MAX_BRIGHTNESS "GetMaxBrightness" #define METHOD_GET_BRIGHTNESS "GetBrightness" #define METHOD_SET_BRIGHTNESS "SetBrightness" -#define METHOD_PLAY_CUSTOM "playcustom" -#define METHOD_STOP_CUSTOM "stopcustom" +#define METHOD_PLAY_CUSTOM "playcustom" +#define METHOD_GET_LED_NUMBER "GetNumOfLeds" +#define METHOD_MULTI_PLAY_CUSTOM "multi_playcustom" +#define METHOD_MULTI_STOP_CUSTOM "multi_stopcustom" +#define METHOD_STOP_CUSTOM "stopcustom" #define FRONT_LED_FEATURE "tizen.org/feature/led" #define CAMERA_LED_FEATURE "tizen.org/feature/camera.back.flash" static bool support_front_led; static bool support_camera_led; +static int number_of_devices; static void __CONSTRUCTOR__ init(void) { @@ -170,3 +175,75 @@ int device_led_stop_custom(void) return DEVICE_ERROR_NONE; } + +int device_multi_led_get_number(int *num_of_leds) +{ + int ret; + + if (!support_front_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (!num_of_leds) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_GET_LED_NUMBER, NULL, NULL); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + *num_of_leds = ret; + number_of_devices = ret; + return DEVICE_ERROR_NONE; +} + +int device_multi_led_play_custom(bool led[], unsigned int color[]) +{ + GVariantBuilder *builder = NULL; + GVariant *var = NULL; + int i; + + if (!support_front_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (led == NULL || color == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a(bu)")); + for (i = 0; i < number_of_devices; i++) + g_variant_builder_add(builder, "(bu)", led[i], color[i]); + + var = g_variant_new("(a(bu))", builder); + g_variant_builder_unref(builder); + + return dbus_method_sync_var(DEVICED_BUS_NAME, DEVICED_PATH_LED, + DEVICED_INTERFACE_LED, METHOD_MULTI_PLAY_CUSTOM, var); + +} + +int device_multi_led_stop_custom(bool led[]) +{ + GVariantBuilder *builder = NULL; + GVariant *var = NULL; + int ret, i; + + if (!support_front_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + builder = g_variant_builder_new(G_VARIANT_TYPE("ab")); + for (i = 0 ; i < number_of_devices; i++) + g_variant_builder_add(builder, "b", led[i]); + + var = g_variant_new("(ab)", builder); + g_variant_builder_unref(builder); + + ret = dbus_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_MULTI_STOP_CUSTOM, var); + //LCOV_EXCL_START System Error + if (ret < 0) + return errno_to_device_error(ret); + //LCOV_EXCL_STOP + + return DEVICE_ERROR_NONE; +}