haptic: add haptic hal api 81/251181/4
authorYunmi Ha <yunmi.ha@samsung.com>
Mon, 11 Jan 2021 05:16:21 +0000 (14:16 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Wed, 13 Jan 2021 01:55:25 +0000 (10:55 +0900)
Change-Id: Icdc4afa8b3fd282ce8e8c27f85262cd16e005a78
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
include/backend/hal-haptic-interface.h [new file with mode: 0644]
include/hal-haptic.h
src/haptic.c [new file with mode: 0644]

diff --git a/include/backend/hal-haptic-interface.h b/include/backend/hal-haptic-interface.h
new file mode 100644 (file)
index 0000000..d0b8d4a
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2021 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 __HAL_HAPTIC_INTERFACE_H__
+#define __HAL_HAPTIC_INTERFACE_H__
+
+#include <hal/hal-common-interface.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumerations of unlimited duration for the Haptic Module API.
+ */
+typedef enum {
+    HAPTIC_MODULE_DURATION_UNLIMITED = 0x7FFFFFFF,
+} haptic_module_duration;
+
+typedef struct _hal_backend_haptic_funcs {
+       int (*get_device_count)(int *count);
+       int (*open_device)(int *dev_handle);
+       int (*close_device)(int dev_handle);
+       bool (*is_valid)(void);
+       int (*vibrate_monotone)(int device_handle, int duration, int frequency, int overdrive, int level, int intensity, int priority);
+       int (*stop_device)(int dev_handle);
+} hal_backend_haptic_funcs;
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_HAPTIC_INTERFACE_H__ */
index 08800fb..dfbeb54 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2021 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.
  */
 
 
-#ifndef __TIZEN_SYSTEM_HAPTIC_H__
-#define __TIZEN_SYSTEM_HAPTIC_H__
-
-
-#include "device-error.h"
+#ifndef __HAL_HAPTIC_H__
+#define __HAL_HAPTIC_H__
 
+#include <stdbool.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+int hal_device_haptic_get_backend(void);
+int hal_device_haptic_put_backend(void);
 
-/**
- * @addtogroup CAPI_SYSTEM_DEVICE_HAPTIC_MODULE
- * @{
- */
-
-
-/**
- * @brief The haptic device handle.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-typedef void* haptic_device_h;
-
-
-/**
- * @brief The haptic effect handle.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- */
-typedef void* haptic_effect_h;
-
-
-/**
- * @brief Gets the number of vibrators.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @privlevel public
- * @privilege %http://tizen.org/privilege/haptic
- * @param[in] device_number The number of vibrators
- * @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_haptic_get_count(int *device_number);
-
-
-/**
- * @brief Opens a haptic-vibration device.
- * @details Internally, it makes a connection to the vibrator.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @privlevel public
- * @privilege %http://tizen.org/privilege/haptic
- * @remarks You must close the Haptic API using device_haptic_close().
- * @param[in] device_index The index of device what you want to vibrate \n
- *                         The index starts from @c 0
- * @param[out] device_handle The handle of vibrator
- * @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
- * @see device_haptic_close()
- */
-int device_haptic_open(int device_index, haptic_device_h *device_handle);
-
-
-/**
- * @brief Closes a haptic-vibration device.
- * @details Internally, it disconnects the connection to the vibrator.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @privlevel public
- * @privilege %http://tizen.org/privilege/haptic
- * @param[in] device_handle The device handle from device_haptic_open()
- * @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
- * @see device_haptic_open()
- */
-int device_haptic_close(haptic_device_h device_handle);
-
-
-/**
- * @brief Vibrates during the specified time with a constant intensity.
- * @details This function can be used to start monotonous vibration for the specified time.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @privlevel public
- * @privilege %http://tizen.org/privilege/haptic
- * @remarks @a feedback level is reserved for auto changing to save variable in the settings.
- * @remarks @a effect_handle effect_handle value can be @c 0(zero).
- * @remarks To prevent unexpected sleep (suspend) during vibration, please use @ref CAPI_SYSTEM_DEVICE_POWER_MODULE.
- * @param[in] device_handle The device handle from device_haptic_open()
- * @param[in] duration The play duration in milliseconds
- * @param[in] feedback The amount of the intensity variation (@c 0 ~ @c 100)
- * @param[out] effect_handle The pointer to the variable that will receive a handle to the playing effect
- * @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
- * @see device_haptic_stop()
- */
-int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedback, haptic_effect_h *effect_handle);
-
-
-/**
- * @brief Stops all vibration effects which are being played.
- * @details This function can be used to stop all effects started by device_haptic_vibrate().
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @privlevel public
- * @privilege %http://tizen.org/privilege/haptic
- * @param[in] device_handle The device handle from device_haptic_open()
- * @param[in] effect_handle The effect handle from device_haptic_vibrate()
- * @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
- * @see device_haptic_vibrate()
- */
-int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_handle);
-
-
-/**
- * @}
- */
-
+int hal_device_haptic_get_device_count(int *count);
+int hal_device_haptic_open_device(int *handle);
+int hal_device_haptic_close_device(int handle);
+bool hal_device_haptic_is_valid(void);
+int hal_device_haptic_vibrate(int handle, int duration, int frequency, int overdrive, int level, int intensity, int priority);
+int hal_device_haptic_stop_device(int handle);
 
 #ifdef __cplusplus
 }
 #endif
 
-
-#endif  // __TIZEN_SYSTEM_HAPTIC_H__
+#endif  // __HAL_HAPTIC_H__
diff --git a/src/haptic.c b/src/haptic.c
new file mode 100644 (file)
index 0000000..72ffbbf
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#include <stdio.h>
+#include <hal/hal-common.h>
+
+#include "hal-haptic.h"
+#include "hal-haptic-interface.h"
+
+#include "common.h"
+
+static hal_backend_haptic_funcs *g_haptic_funcs = NULL;
+
+int hal_device_haptic_get_backend(void)
+{
+       int ret;
+
+       if (g_haptic_funcs)
+               return 0;
+
+       ret = hal_common_get_backend(HAL_MODULE_DEVICE_HAPTIC, (void **)&g_haptic_funcs);
+       if (ret < 0) {
+                _E("Failed to get haptic backend");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+int hal_device_haptic_put_backend(void)
+{
+       if (!g_haptic_funcs)
+               return 0;
+
+       hal_common_put_backend(HAL_MODULE_DEVICE_HAPTIC, (void *)g_haptic_funcs);
+       g_haptic_funcs = NULL;
+
+       return 0;
+}
+
+int hal_device_haptic_get_device_count(int *count)
+{
+       if (!g_haptic_funcs || !g_haptic_funcs->get_device_count)
+               return -ENODEV;
+
+       if(!count)
+               return -EINVAL;
+
+       return g_haptic_funcs->get_device_count(count);
+}
+
+int hal_device_haptic_open_device(int *handle)
+{
+       if (!g_haptic_funcs || !g_haptic_funcs->open_device)
+               return -ENODEV;
+
+       if (!handle)
+               return -EINVAL;
+
+       return g_haptic_funcs->open_device(handle);
+}
+
+int hal_device_haptic_close_device(int handle)
+{
+       if (!g_haptic_funcs || !g_haptic_funcs->close_device)
+               return -ENODEV;
+
+       return g_haptic_funcs->close_device(handle);
+}
+
+bool hal_device_haptic_is_valid(void)
+{
+       if (!g_haptic_funcs || !g_haptic_funcs->is_valid)
+               return -ENODEV;
+
+       return g_haptic_funcs->is_valid();
+}
+
+int hal_device_haptic_vibrate(int handle, int duration, int frequency, int overdrive, int level, int intensity, int priority)
+{
+       if (!g_haptic_funcs || !g_haptic_funcs->vibrate_monotone)
+               return -ENODEV;
+
+       return g_haptic_funcs->vibrate_monotone(handle, duration, frequency, overdrive,
+                                                                                       level, intensity, priority);
+}
+
+int hal_device_haptic_stop_device(int handle)
+{
+       if (!g_haptic_funcs || !g_haptic_funcs->stop_device)
+               return -ENODEV;
+
+       return g_haptic_funcs->stop_device(handle);
+}