diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rwxr-xr-x | CMakeLists.txt | 90 | ||||
-rwxr-xr-x | LICENSE | 206 | ||||
-rw-r--r-- | capi-system-haptic.pc.in | 15 | ||||
-rw-r--r-- | debian/README | 0 | ||||
-rw-r--r-- | debian/capi-system-haptic-dev.install | 4 | ||||
-rw-r--r-- | debian/capi-system-haptic-dev.postinst | 1 | ||||
-rw-r--r-- | debian/capi-system-haptic.install | 1 | ||||
-rw-r--r-- | debian/capi-system-haptic.postinst | 1 | ||||
-rw-r--r-- | debian/changelog | 21 | ||||
-rw-r--r-- | debian/compat | 1 | ||||
-rw-r--r-- | debian/control | 22 | ||||
-rwxr-xr-x | debian/rules | 65 | ||||
-rw-r--r-- | include/haptic.h | 284 | ||||
-rwxr-xr-x | include/haptic_private.h | 35 | ||||
-rw-r--r-- | packaging/capi-system-haptic.spec | 54 | ||||
-rwxr-xr-x | src/haptic.c | 442 | ||||
-rw-r--r-- | src/haptic_private.c | 147 |
18 files changed, 1390 insertions, 0 deletions
@@ -0,0 +1 @@ +Pius Lee <pius.lee@samsung.com> diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..963b95e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,90 @@ + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "capi-system-haptic") + +PROJECT(${fw_name}) + +SET(CMAKE_INSTALL_PREFIX /usr) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +SET(INC_DIR include) +INCLUDE_DIRECTORIES(${INC_DIR}) + +SET(dependents "devman glib-2.0 dlog") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_name} REQUIRED ${dependents}) +FOREACH(flag ${${fw_name}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DTIZEN_DEBUG") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") + +aux_source_directory(src SOURCES) +ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) + +TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) + +INSTALL(TARGETS ${fw_name} DESTINATION lib) +INSTALL( + DIRECTORY ${INC_DIR}/ DESTINATION include/system + FILES_MATCHING + PATTERN "*_private.h" EXCLUDE + PATTERN "${INC_DIR}/*.h" + ) + +SET(PC_NAME ${fw_name}) +SET(PC_REQUIRED ${dependents}) +SET(PC_LDFLAGS -l${fw_name}) +SET(PC_CFLAGS -I\${includedir}/system) + +CONFIGURE_FILE( + ${fw_name}.pc.in + ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc + @ONLY +) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) + +#ADD_SUBDIRECTORY(test) + +IF(UNIX) + +ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution) +ADD_CUSTOM_COMMAND( + DEPENDS clean + COMMENT "distribution clean" + COMMAND find + ARGS . + -not -name config.cmake -and \( + -name tester.c -or + -name Testing -or + -name CMakeFiles -or + -name cmake.depends -or + -name cmake.check_depends -or + -name CMakeCache.txt -or + -name cmake.check_cache -or + -name *.cmake -or + -name Makefile -or + -name core -or + -name core.* -or + -name gmon.out -or + -name install_manifest.txt -or + -name *.pc -or + -name *~ \) + | grep -v TC | xargs rm -rf + TARGET distclean + VERBATIM +) + +ENDIF(UNIX) + @@ -0,0 +1,206 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
+
+
diff --git a/capi-system-haptic.pc.in b/capi-system-haptic.pc.in new file mode 100644 index 0000000..f758dbd --- /dev/null +++ b/capi-system-haptic.pc.in @@ -0,0 +1,15 @@ + +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=/usr/lib +includedir=/usr/include/system + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} @PC_CFLAGS@ + diff --git a/debian/README b/debian/README new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/debian/README diff --git a/debian/capi-system-haptic-dev.install b/debian/capi-system-haptic-dev.install new file mode 100644 index 0000000..761a28b --- /dev/null +++ b/debian/capi-system-haptic-dev.install @@ -0,0 +1,4 @@ +/usr/include/* +/usr/include/*/* +/usr/lib/pkgconfig/*.pc + diff --git a/debian/capi-system-haptic-dev.postinst b/debian/capi-system-haptic-dev.postinst new file mode 100644 index 0000000..1a24852 --- /dev/null +++ b/debian/capi-system-haptic-dev.postinst @@ -0,0 +1 @@ +#!/bin/sh diff --git a/debian/capi-system-haptic.install b/debian/capi-system-haptic.install new file mode 100644 index 0000000..4a755a4 --- /dev/null +++ b/debian/capi-system-haptic.install @@ -0,0 +1 @@ +/usr/lib/lib*.so* diff --git a/debian/capi-system-haptic.postinst b/debian/capi-system-haptic.postinst new file mode 100644 index 0000000..1a24852 --- /dev/null +++ b/debian/capi-system-haptic.postinst @@ -0,0 +1 @@ +#!/bin/sh diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..076a445 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,21 @@ +capi-system-haptic (0.1.0-9) unstable; urgency=low + + * patch for lower framework functions + * Git: api/haptic + * Tag: capi-system-haptic_0.1.0-9 + + -- Pius Lee <pius.lee@samsung.com> Wed, 04 Jan 2012 16:41:58 +0900 + +capi-system-haptic (0.1.0-8) unstable; urgency=low + + * update version + * Git: api/haptic + * Tag: capi-system-haptic_0.1.0-8 + + -- Pius Lee <pius.lee@samsung.com> Thu, 15 Dec 2011 13:51:19 +0900 + +capi-system-haptic (0.0.1-1) unstable; urgency=low + + * Initial release. + + -- Pius Lee <pius.lee@samsung.com> Wed, 07 Dec 2011 12:47:27 +0900 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..006f3cd --- /dev/null +++ b/debian/control @@ -0,0 +1,22 @@ + +Source: capi-system-haptic +Section: libs +Priority: extra +Maintainer: pius lee <pius.lee@samsung.com> +Build-Depends: debhelper (>= 5), dlog-dev, libdevman-dev, libdevman-haptic-dev, libsvi-dev, libglib2.0-dev, capi-base-common-dev + +Package: capi-system-haptic +Architecture: any +Depends: ${shilbs:Depends}, ${misc:Depends} +Description: A Haptic library in Tizen Native API + +Package: capi-system-haptic-dev +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, capi-system-haptic (= ${Source-Version}), libdevman-dev, libdevman-haptic-dev, libsvi-dev, capi-base-common-dev, dlog-dev +Description: A Haptic library in Tizen Native API (DEV) + +Package: capi-system-haptic-dbg +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, capi-system-haptic (= ${Source-Version}) +Description: A Haptic library in Tizen Native API (DBG) + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..92090e4 --- /dev/null +++ b/debian/rules @@ -0,0 +1,65 @@ +#!/usr/bin/make -f + +CFLAGS = -Wall -g + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif +CMAKE_ROOT_DIR ?= $(CURDIR) +CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp + +configure: configure-stamp +configure-stamp: + dh_testdir + mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake .. + touch configure-stamp + + +build: build-stamp +build-stamp: configure-stamp + dh_testdir + cd $(CMAKE_BUILD_DIR) && $(MAKE) + touch $@ + +clean: + cd $(CMAKE_ROOT_DIR) + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + rm -f `find . -name *.pc` + rm -rf $(CMAKE_BUILD_DIR) + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + +binary-indep: build install + +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples + dh_install --sourcedir=debian/tmp + dh_installman + dh_link + dh_strip --dbg-package=capi-system-haptic-dbg + dh_fixperms + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure + diff --git a/include/haptic.h b/include/haptic.h new file mode 100644 index 0000000..11183e6 --- /dev/null +++ b/include/haptic.h @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2011 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_HAPTIC_H__ +#define __TIZEN_SYSTEM_HAPTIC_H__ + +#include <tizen_error.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup CAPI_SYSTEM_HAPTIC_MODULE + * @{ + * @brief + * This is a Haptic API of the System Service. + * @} + */ + +/** + * @addtogroup CAPI_SYSTEM_HAPTIC_MODULE + * @{ + */ + +/** + * @brief Enumerations of feedback level for haptic. + * @details Haptic level means vibration power (intensity). + */ +typedef enum +{ + HAPTIC_LEVEL_AUTO, /**< vibration level from settings */ + HAPTIC_LEVEL_0, /**< vibration level 0 (silence) */ + HAPTIC_LEVEL_1, /**< vibration level 1 (the lowest) */ + HAPTIC_LEVEL_2, /**< vibration level 2 (low)*/ + HAPTIC_LEVEL_3, /**< vibration level 3 (middle) */ + HAPTIC_LEVEL_4, /**< vibration level 4 (high) */ + HAPTIC_LEVEL_5, /**< vibration level 5 (the highest) */ +} haptic_level_e; + +/** + * @brief Enumerations of error codes for the Haptic API. + */ +typedef enum +{ + HAPTIC_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + HAPTIC_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + HAPTIC_ERROR_NO_SUCH_FILE = TIZEN_ERROR_NO_SUCH_FILE, /**< No such file */ + HAPTIC_ERROR_NOT_SUPPORTED_FORMAT = TIZEN_ERROR_SYSTEM_CLASS | 0x23, /**< Not supported file format */ + HAPTIC_ERROR_NOT_INITIALIZED = TIZEN_ERROR_SYSTEM_CLASS | 0x26, /**< Not initialized */ + HAPTIC_ERROR_OPERATION_FAILED = TIZEN_ERROR_SYSTEM_CLASS | 0x28, /**< Operation failed */ +} haptic_error_e; + + +/** + * @brief The structure type to contain the set of vibration data + * that used for generate a iteration of vibration. + * + * @see haptic_play_pattern() + */ +typedef struct +{ + int vibrator_index; /**< Index of the vibrator */ + haptic_level_e level; /**< Intensity of the vibration in a iteration */ + int time; /**< Duration of the vibration in a iteration */ +} haptic_vibration_iter_s; + +/** + * @brief Gets the number of the vibrators. + * + * @remarks The index zero is reserved meaning for all vibrators at a time. + * + * @param[out] vibrator_number A number of vibrators + * + * @return 0 on success, otherwise a negative error value. + * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed + */ +int haptic_get_count(int* vibrator_number); + +/** + * @brief Initializes haptic API. + * + * @details Internally, it makes a connection to the vibrator. + * + * @remarks If this function is not called in advance, other functions will return #HAPTIC_ERROR_NOT_INITIALIZED. + * @remarks Haptic API must be deinitialized by haptic_deinitialize(). + * + * @return 0 on success, otherwise a negative error value. + * @retval #HAPTIC_ERROR_NONE Successful + * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed + * + * @see haptic_deinitialize() + */ +int haptic_initialize(void); + +/** + * @brief Deinitializes haptic API. + * + * @details Internally, it disconnects the connection to vibrator. + * + * @return 0 on success, otherwise a negative error value. + * @retval #HAPTIC_ERROR_NONE Successful + * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed + * + * @see haptic_initialize() + */ +int haptic_deinitialize(void); + +/** + * @brief Plays a stored rhythmic haptic vibration pattern from a file. + * + * @remarks Both the actual behavior of the vibration pattern and the intensity depend on devices. + * + * @param[in] vibrator_index The index of the vibrator.\n + * The index of the first vibrator is 1.\n + * 0 is reserved for every vibrators at once. + * @param[in] file_path The path of a rhythmic vibration pattern file. + * Only .ivt (Immersion VibeTonz) file is supported. + * @param[in] count The number of iterations to be vibrated. Must be less than the maximum\n + * Iteration range allowed for the device. (currently it's 255) + * @param[in] level The feedback intensity level (it is dependent on target's hardware).\n + * This level is already predefined by enumeration type value from\n + * #HAPTIC_LEVEL_1 to #HAPTIC_LEVEL_5.\n + * If you want to use the value selected by the user in the Setting application menu,\n + * #HAPTIC_LEVEL_AUTO has to be set. It is required that application\n + * must have a main loop to use the #HAPTIC_LEVEL_AUTO. + * + * @return 0 on success, otherwise a negative error value. + * @retval #HAPTIC_ERROR_NONE Success + * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed + * @retval #HAPTIC_ERROR_NO_SUCH_FILE No such file + * @retval #HAPTIC_ERROR_NOT_SUPPORTED_FORMAT Not supported file format + * + * @see haptic_stop_device() + * @see haptic_get_count() + */ +int haptic_vibrate_file(int vibrator_index, const char *file_path, int count, haptic_level_e level); + +/** + * @brief Gets the duration of a rhythmic vibration pattern saved in a given file. + * + * @param[in] vibrator_index The index of the vibrator.\n + * The index of the first vibrator is 1.\n + * 0 is reserved for every vibrators at once. + * @param[in] file_path The path of a rhythmic vibration pattern file. + * Only .ivt (Immersion VibeTonz) file is supported. + * @param[out] duration_ms The duration in milliseconds. + * + * @return 0 on success, otherwise a negative error value. + * @retval #HAPTIC_ERROR_NONE Successful + * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed + * @retval #HAPTIC_ERROR_NO_SUCH_FILE No such file + * @retval #HAPTIC_ERROR_NOT_SUPPORTED_FORMAT Not supported file format + * + * @see haptic_get_count() + */ +int haptic_get_file_duration(int vibrator_index, const char *file_path, int *duration_ms); + +/** + * @brief Vibrates during the specified time with a constant intensity. + * @details + * This function can be used to start monotonous vibration for specified time.\n + * Default value of intensity is used.\n + * + * @param[in] vibrator_index The index of the vibrator.\n + * The index of the first vibrator is 1.\n + * 0 is reserved for every vibrators at once. + * @param[in] duration_ms The play duration in milliseconds + * + * @return 0 on success, otherwise a negative error value. + * @retval #HAPTIC_ERROR_NONE Successful + * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed + * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized + * + * @see haptic_stop_device() + * @see haptic_vibrate_file() + * @see haptic_get_count() + */ +int haptic_vibrate_monotone(int vibrator_index, int duration_ms); + +/** + * @brief Stops the current vibration which is being played. + * @details This function can be used to stop vibration started by haptic_vibrate_file(), or haptic_vibrate_monotone(). + * + * @remarks You must use haptic_stop_pattern() to stop the vibration pattern from haptic_play_pattern(); + * + * @param[in] vibrator_index The index of the vibrator.\n + * The index of the first vibrator is 1.\n + * 0 is reserved for every vibrators at once. + * + * @return 0 on success, otherwise a negative error value. + * @retval #HAPTIC_ERROR_NONE Successful + * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed + * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized + * + * @see haptic_vibrate_file() + * @see haptic_vibrate_monotone() + * @see haptic_get_count() + */ +int haptic_stop_device(int vibrator_index); + +/** + * @brief Starts playing the pattern of continuous vibration data. + * @details + * Each vibration data has index of vibrator, intensity level and duration time. \n + * Vibration data plays continuously in order of specific array. \n + * This function returns the ID of playing session if it succeeds. + * This ID can be used to stop playing iterations. + * + * When played intensity in each vibration data can be changed with level_change parameter. \n + * level_change parameter is quantity of intensity variation, it can be minus or plus integer number. \n + * But if vibration intensity level is under #HAPTIC_LEVEL_0, it does not change. \n + * And level can't be under #HAPTIC_LEVEL_0 or over #HAPTIC_LEVEL_5. + * + * For example, \n + * Level(#HAPTIC_LEVEL_1) + level_change(2) = #HAPTIC_LEVEL_3 \n + * Level(#HAPTIC_LEVEL_2) + level_change(-2) = #HAPTIC_LEVEL_0 \n + * Level(#HAPTIC_LEVEL_5) + level_change(-10) = #HAPTIC_LEVEL_0 \n + * Level(#HAPTIC_LEVEL_0) + level_change(3) = #HAPTIC_LEVEL_0 (It does not change) \n + * Level(#HAPTIC_LEVEL_2) + level_change(-3) = #HAPTIC_LEVEL_0 (It can't be under zero) \n + * Level(#HAPTIC_LEVEL_3) + level_change(10) = #HAPTIC_LEVEL_5 (It can't be over five) \n + * + * + * @param[in] pattern The array of the vibration data + * @param[in] pattern_size The number of the vibration data + * @param[in] count The number of the Iteration that include playing every vibrations + * @param[in] level_change The amount of the intensity variation in each vibrations + * @param[out] id The ID of the vibration pattern + * + * @return 0 on success, otherwise a negative error value. + * @retval #HAPTIC_ERROR_NONE Successful + * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed + * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized + * + * @see haptic_stop_pattern() + */ +int haptic_play_pattern(haptic_vibration_iter_s* pattern, int pattern_size, int count, int level_change, int* id); + +/** + * @brief Stops playing the pattern which is being played. + * + * @remarks haptic_stop_device() can not stop pattern, + * because playing process calls the vibration procedure in each vibration data. + * + * @param[in] id The ID of playing session from haptic_play_pattern() + * + * @return 0 on success, otherwise a negative error value. + * @retval #HAPTIC_ERROR_NONE Successful + * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see haptic_play_pattern() + */ +int haptic_stop_pattern(int id); +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SYSTEM_HAPTIC_H__ + diff --git a/include/haptic_private.h b/include/haptic_private.h new file mode 100755 index 0000000..cbe4059 --- /dev/null +++ b/include/haptic_private.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2011 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_HAPTIC_PRIVATE_H__ +#define __TIZEN_SYSTEM_HAPTIC_PRIVATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void _haptic_init(); +void _haptic_deinit(); +int _haptic_play_monotone(int dev, int duration, haptic_level_e level); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/packaging/capi-system-haptic.spec b/packaging/capi-system-haptic.spec new file mode 100644 index 0000000..fe7f8ca --- /dev/null +++ b/packaging/capi-system-haptic.spec @@ -0,0 +1,54 @@ +Name: capi-system-haptic +Summary: A Haptic library in Tizen Native API +Version: 0.0.1 +Release: 1 +Group: TO_BE/FILLED_IN +License: TO BE FILLED IN +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(devman) +BuildRequires: pkgconfig(devman_haptic) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(capi-base-common) +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description + + +%package devel +Summary: A Haptic library in Tizen Native API (Development) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description devel + + + +%prep +%setup -q + + +%build +cmake . -DCMAKE_INSTALL_PREFIX=/usr + + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files +%{_libdir}/libcapi-system-haptic.so + +%files devel +%{_includedir}/system/*.h +%{_libdir}/pkgconfig/*.pc + + diff --git a/src/haptic.c b/src/haptic.c new file mode 100755 index 0000000..d9d94cb --- /dev/null +++ b/src/haptic.c @@ -0,0 +1,442 @@ +/* + * Copyright (c) 2011 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 <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <stdbool.h> +#include <haptic.h> +#include <devman_haptic.h> +#include <glib.h> +#include <dlog.h> + +#include "haptic_private.h" + +#undef LOG_TAG +#define LOG_TAG "TIZEN_SYSTEM_HAPTIC" + +#define NOT_ASSIGNED -1 +#define VIBE_SILENCE -128 + +#define _MSG_HAPTIC_ERROR_INVALID_PARAMETER "Invalid parameter" +#define _MSG_HAPTIC_ERROR_NO_SUCH_FILE "No such file" +#define _MSG_HAPTIC_ERROR_NOT_SUPPORTED_FORMAT "Not supported format" +#define _MSG_HAPTIC_ERROR_NOT_INITIALIZED "Not initialize" +#define _MSG_HAPTIC_ERROR_OPERATION_FAILED "Operation failed" + +#define RETURN_ERR_MSG(err_code, msg) \ + do { \ + LOGE("[%s] "_MSG_##err_code"(0x%08x) : %s", __FUNCTION__, err_code, msg); \ + return err_code; \ + }while(0) + +#define RETURN_ERR(err_code) \ + do { \ + LOGE("[%s] "_MSG_##err_code"(0x%08x)", __FUNCTION__, err_code); \ + return err_code; \ + }while(0) + +static int _DEV[] = { + DEV_IDX_ALL, + DEV_IDX_0, + DEV_IDX_1, +}; + +static int _LEVEL[] = +{ + HAPTIC_FEEDBACK_LEVEL_AUTO, + VIBE_SILENCE, + HAPTIC_FEEDBACK_LEVEL_1, + HAPTIC_FEEDBACK_LEVEL_2, + HAPTIC_FEEDBACK_LEVEL_3, + HAPTIC_FEEDBACK_LEVEL_4, + HAPTIC_FEEDBACK_LEVEL_5, +}; + +struct _vibe_pattern { + haptic_vibration_iter_s *iters; + int current; + int size; + int level_change; + int iter_count; + int stop; + int pattern_index; + int error; +}; + +GArray *pattern_table = NULL; + +static int initialize = 0; +static int max_device = 0; + +static int* haptic_ids = NULL; + +static void _free_pattern_from_table(int index); + +static bool invalid_ivt(const char* file_name) +{ + if( 0 != access(file_name, R_OK) ) + { + return false; + } + + char* ext = strrchr(file_name, '.'); + if (ext == NULL || 0 != strcasecmp(ext, ".ivt")){ + return false; + } + + return true; +} + +int haptic_get_count(int* vibrator_number) +{ + int count; + if(vibrator_number == NULL) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + count = device_haptic_get_device_count(); + if(count < 0) + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + + *vibrator_number = count; + + return HAPTIC_ERROR_NONE; +} + +int haptic_initialize() +{ + int i, j; + int id; + + if( haptic_get_count(&max_device) < 0) + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + + haptic_ids = (int*)malloc(sizeof(int)*max_device+1); // max + zero + + if(haptic_ids == NULL){ + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + } + + for(i=0; i<=max_device; i++){ + id = device_haptic_open(_DEV[i], 0); + if(id < 0) { + for (j=i; i>=0; i--){ + device_haptic_close(_DEV[i]); + } + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + } + + haptic_ids[i] = id; + } + + initialize = 1; + + pattern_table = g_array_new(FALSE, TRUE, sizeof(struct _vibe_pattern*)); + + _haptic_init(); + + return HAPTIC_ERROR_NONE; +} + +int haptic_deinitialize() +{ + int err, i; + + if(!initialize) + RETURN_ERR(HAPTIC_ERROR_NOT_INITIALIZED); + + for(i=0; i<=max_device; i++){ + err = device_haptic_close(_DEV[i]); + } + initialize = 0; + + if(haptic_ids != NULL) + free(haptic_ids); + + for(i=0; i< pattern_table->len; i++){ + _free_pattern_from_table(i); + } + g_array_free(pattern_table, TRUE); + + _haptic_deinit(); + + return HAPTIC_ERROR_NONE; +} + + +int haptic_get_file_duration(int device_index, const char *file_name , int* duration) +{ + int ret; + + if(!initialize) + RETURN_ERR(HAPTIC_ERROR_NOT_INITIALIZED); + + if(device_index < 0 || device_index > max_device) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + device_index = ((device_index < 3) ? _DEV[device_index] : DEV_IDX_ALL); // xxx + + if(!invalid_ivt(file_name)) + RETURN_ERR(HAPTIC_ERROR_NOT_SUPPORTED_FORMAT); + + ret = device_haptic_get_file_duration(haptic_ids[device_index], file_name, duration); + + if(ret < 0){ + if(ret == -2) + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + else + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + } + + return HAPTIC_ERROR_NONE; +} + +int haptic_vibrate_file(int device_index, const char *file_name , int count , haptic_level_e level) +{ + int ret; + + if(device_index < 0 || device_index > max_device) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + device_index = ((device_index < 3) ? _DEV[device_index] : DEV_IDX_ALL); // xxx + + if(!initialize) + RETURN_ERR(HAPTIC_ERROR_NOT_INITIALIZED); + + if(level == VIBE_SILENCE) + return HAPTIC_ERROR_NONE; + + if(level > HAPTIC_LEVEL_5 || level < 0) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + if(count < 0 || count >= HAPTIC_INFINITE_ITERATION) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + if(count == 0) + count = HAPTIC_INFINITE_ITERATION; + + if(!invalid_ivt(file_name)) + RETURN_ERR(HAPTIC_ERROR_NOT_SUPPORTED_FORMAT); + + ret = device_haptic_play_file(haptic_ids[device_index], file_name, count, _LEVEL[level]); + + if(ret < 0){ + if(ret == -2) + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + else + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + } + + return HAPTIC_ERROR_NONE; +} + +int haptic_vibrate_monotone(int device_index , int duration) +{ + int ret; + + if(device_index < 0 || device_index > max_device) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + device_index = ((device_index < 3) ? _DEV[device_index] : DEV_IDX_ALL); // xxx + + if(!initialize) + RETURN_ERR(HAPTIC_ERROR_NOT_INITIALIZED); + + ret = device_haptic_play_monotone(haptic_ids[device_index], duration); + + if(ret < 0){ + if(ret == -2) + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + else + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + } + + return HAPTIC_ERROR_NONE; +} + +int haptic_stop_device(int device_index) +{ + int ret; + + if(device_index < 0 || device_index > max_device) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + device_index = ((device_index < 3) ? _DEV[device_index] : DEV_IDX_ALL); // xxx + + if(!initialize) + RETURN_ERR(HAPTIC_ERROR_NOT_INITIALIZED); + + ret = device_haptic_stop_play(haptic_ids[device_index]); + + if(ret < 0){ + if(ret == -2) + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + else + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + } + + return HAPTIC_ERROR_NONE; +} + +static void _free_pattern_from_table(int index) +{ + struct _vibe_pattern* p = g_array_index(pattern_table, struct _vibe_pattern *, index); + if(p == NULL) + return; + free(p->iters); + free(p); + g_array_index(pattern_table, struct _vibe_pattern *, index) = NULL; +} + +static gboolean _haptic_play_iter(gpointer data) +{ + int err; + struct _vibe_pattern* pattern = (struct _vibe_pattern*)data; + + if(pattern->stop){ + _free_pattern_from_table(pattern->pattern_index); + return false; + } + int current = pattern->current; + + int device = pattern->iters[current].vibrator_index; + int level = pattern->iters[current].level; + long time = pattern->iters[current].time; + int level_change = pattern->level_change; + int iter_count = pattern->iter_count; + + // set default device, if can't find given device. + if(device >= max_device || device < 0) + device = 0; + + if(level + level_change < HAPTIC_LEVEL_0) + level = HAPTIC_LEVEL_0; + if(level + level_change > HAPTIC_LEVEL_5) + level = HAPTIC_LEVEL_5; + + if(level != HAPTIC_LEVEL_0 || time != 0){ +// err = _haptic_play_monotone(device, time, level); + err = haptic_vibrate_monotone(device, time); + if(err<0){ + pattern->error = err; + return false; + } + } + + pattern->current++; + + // pattern play finish + if(pattern->current >= pattern->size){ + if(iter_count <= 0){ + _free_pattern_from_table(pattern->pattern_index); + return false; + }else{ + pattern->current = 0; + pattern->iter_count--; + } + } + + + g_timeout_add(time, _haptic_play_iter, data); + + return false; +} + +int haptic_play_pattern(haptic_vibration_iter_s* pattern, int pattern_size, int count, int level_change, int* id) +{ + int i, key = -1; + + if(id == NULL) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + if(pattern == NULL) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + if(!initialize) + RETURN_ERR(HAPTIC_ERROR_NOT_INITIALIZED); + + haptic_vibration_iter_s* tmp_ptn = (haptic_vibration_iter_s*) + malloc(sizeof(haptic_vibration_iter_s) * pattern_size); + if(tmp_ptn == NULL){ + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + } + memcpy(tmp_ptn, pattern, sizeof(haptic_vibration_iter_s) * pattern_size); + + struct _vibe_pattern* vibe_p = (struct _vibe_pattern*)malloc(sizeof(struct _vibe_pattern)); + if(vibe_p == NULL){ + free(tmp_ptn); + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + } + vibe_p->iters = tmp_ptn; + vibe_p->size = pattern_size; + vibe_p->level_change = level_change; + vibe_p->iter_count = count; + vibe_p->current = 0; + vibe_p->stop = 0; + vibe_p->error= 0; + + for(i=0; i< pattern_table->len; i++){ + if(g_array_index(pattern_table, struct _vibe_pattern *, i) == NULL){ + key = i; + break; + } + } + if(key == -1){ + g_array_append_val(pattern_table, vibe_p); + key = pattern_table->len -1; + }else{ + g_array_index(pattern_table, struct _vibe_pattern *, key) = vibe_p; + } + + vibe_p->pattern_index = key; + + _haptic_play_iter((gpointer)vibe_p); + + if(vibe_p->error < 0){ + _free_pattern_from_table(key); + if(vibe_p->error == -2) + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + else + RETURN_ERR(HAPTIC_ERROR_NOT_INITIALIZED); + } + + *id = key; + + return HAPTIC_ERROR_NONE; +} + +int haptic_stop_pattern(int id) +{ + if(id < 0) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + if(!initialize || pattern_table == NULL) + RETURN_ERR(HAPTIC_ERROR_NOT_INITIALIZED); + + if(id >= pattern_table->len) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + struct _vibe_pattern* pattern = g_array_index(pattern_table, struct _vibe_pattern *, id); + if(pattern != NULL) + pattern->stop = 1; + else + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + return HAPTIC_ERROR_NONE; +} diff --git a/src/haptic_private.c b/src/haptic_private.c new file mode 100644 index 0000000..46e597b --- /dev/null +++ b/src/haptic_private.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2011 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> // xxx +#include <unistd.h> +#include <devman.h> +#include <devman_haptic.h> +#include "haptic.h" + +#define IMMERSION_DRV_NODE "/dev/tspdrv" +#define INPUT_PARM_MAX 0xFFFFFF +#define COMP_CMD(idx, value) (value<<4)|(idx&0x0F) + +enum { + HAPTIC_PROP_ENABLE, + HAPTIC_PROP_LEVEL, + HAPTIC_PROP_LEVEL_MAX, + HAPTIC_PROP_VALUE, + HAPTIC_PROP_ONESHOT, +}; + +enum { + CMD_GET_INITIALIZE, + CMD_SET_OPEN_DEVICE, + CMD_GET_CURRENT_DEVICE_HANDLE, + CMD_GET_CURRENT_EFFECT_HANDLE, + CMD_SET_EFFECT_TYPE, + CMD_SET_EFFECT_FILE, + CMD_GET_EFFECT_DURATION, + CMD_SET_EFFECT_PLAY, + CMD_SET_EFFECT_PLAY_REPEAT, + CMD_SET_NORMAL_PLAY, + CMD_SET_EFFECT_ALL_STOP, + CMD_PROPERTY_SET_LICENSE_KEY, + CMD_PROPERTY_GET_PRIORITY, + CMD_PROPERTY_SET_PRIORITY, + CMD_PROPERTY_GET_STRENGTH, + CMD_PROPERTY_SET_STRENGTH, + CMD_PROPERTY_GET_MASTER_STRENGTH, + CMD_PROPERTY_SET_MASTER_STRENGTH, + CMD_SET_CLOSE_DEVICE, + CMD_GET_TERMINATE, + CMD_GET_DEVICE_COUNT, +}; + +static int immersion; + +static int IMM_LEVEL[] = { + 0, 0, 2000, 4000, 6000, 8000, 10000 +}; + +static int ETC_LEVEL[] = { + 0,0, 55, 60, 65, 70, 80 +}; + +void _haptic_init() +{ + immersion = access(IMMERSION_DRV_NODE, F_OK) == 0; +} + +void _haptic_deinit() +{ +} + +int _haptic_play_monotone(int dev, int duration, haptic_level_e level) +{ + int status; + int input = 0; + unsigned int cmd; + + if(duration < 1 || duration > INPUT_PARM_MAX) + return HAPTIC_ERROR_INVALID_PARAMETER; + + dev = DEV_IDX_ALL; // xxx + + if(dev != DEV_IDX_ALL && dev != DEV_IDX_0 && dev != DEV_IDX_1) + return HAPTIC_ERROR_INVALID_PARAMETER; + + if(level == HAPTIC_LEVEL_0) + return HAPTIC_ERROR_NONE; + + if(level < HAPTIC_LEVEL_1 || level > HAPTIC_LEVEL_5) + return HAPTIC_ERROR_INVALID_PARAMETER; + + input = immersion ? IMM_LEVEL[level] : ETC_LEVEL[level]; + if(input == 0) + return HAPTIC_ERROR_NONE; + + if (immersion) { + cmd = COMP_CMD(dev, input); + status = device_set_property(DEVTYPE_EFFECT_HAPTIC, + CMD_PROPERTY_SET_STRENGTH, (int)cmd); +// printf("capi [%d - %d - %d] [%d %d]\n", DEVTYPE_EFFECT_HAPTIC, CMD_PROPERTY_SET_STRENGTH, cmd, dev, input); + if (status < 0) { + return HAPTIC_ERROR_OPERATION_FAILED; + } + + cmd = COMP_CMD(dev, 0x05); + status = + device_set_property(DEVTYPE_EFFECT_HAPTIC, + CMD_PROPERTY_SET_PRIORITY, (int)cmd); + if (status < 0) { + return HAPTIC_ERROR_OPERATION_FAILED; + } + } + + if (immersion) { + cmd = COMP_CMD(dev, duration); + status = + device_set_property(DEVTYPE_EFFECT_HAPTIC, + CMD_SET_NORMAL_PLAY, (int)cmd); + if (status < 0) { + return HAPTIC_ERROR_OPERATION_FAILED; + } + } else { + status = + device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_LEVEL, + input); + if (status < 0) { + return HAPTIC_ERROR_OPERATION_FAILED; + } + + status = + device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ONESHOT, + duration); + if (status < 0) { + return HAPTIC_ERROR_OPERATION_FAILED; + } + } + return HAPTIC_ERROR_NONE; +} |