diff options
author | Sehong Na <sehong.na@samsung.com> | 2014-05-31 12:34:04 +0900 |
---|---|---|
committer | Sehong Na <sehong.na@samsung.com> | 2014-05-31 12:34:04 +0900 |
commit | fce9e6b40bf879143db049cfeddb2fb5b870ff5e (patch) | |
tree | 14a0e901b79ef09620d12d70d747d9516b6d4874 | |
download | haptic-tizen_2.3.tar.gz haptic-tizen_2.3.tar.bz2 haptic-tizen_2.3.zip |
Initialize Tizen 2.3submit/tizen_2.3/20140531.0631522.3a_releasetizen_2.3
39 files changed, 2574 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..b1b6fd6 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,97 @@ + +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") +SET(pc_dependents "capi-base-common") + +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") +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=${LIB_INSTALL_DIR}") + +aux_source_directory(src SOURCES) +ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) + +TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) + +SET_TARGET_PROPERTIES(${fw_name} + PROPERTIES + VERSION ${FULLVER} + SOVERSION ${MAJORVER} + CLEAN_DIRECT_OUTPUT 1 +) + +INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR}) +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 ${pc_dependents}) +SET(PC_LDFLAGS -l${fw_name}) + +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_INSTALL_DIR}/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) + diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 new file mode 100755 index 0000000..bbe9d02 --- /dev/null +++ b/LICENSE.APLv2 @@ -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/TC/_export_env.sh b/TC/_export_env.sh new file mode 100755 index 0000000..72a11ec --- /dev/null +++ b/TC/_export_env.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +. ./config +export TET_INSTALL_PATH=$TET_INSTALL_HOST_PATH # tetware root path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target # tetware target path +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH +export TET_ROOT=$TET_TARGET_PATH diff --git a/TC/_export_target_env.sh b/TC/_export_target_env.sh new file mode 100755 index 0000000..5ddaa53 --- /dev/null +++ b/TC/_export_target_env.sh @@ -0,0 +1,7 @@ +#!/bin/sh +. ./config +export TET_INSTALL_PATH=$TET_INSTALL_TARGET_PATH # path to path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH +export TET_ROOT=$TET_TARGET_PATH diff --git a/TC/build.sh b/TC/build.sh new file mode 100755 index 0000000..72aad6c --- /dev/null +++ b/TC/build.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +. ./_export_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -c -p ./ +tcc -b -j $JOURNAL_RESULT -p ./ +grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/clean.sh b/TC/clean.sh new file mode 100755 index 0000000..29743e0 --- /dev/null +++ b/TC/clean.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +. ./_export_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +RESULT_DIR=results + +tcc -c -p ./ # executing tcc, with clean option (-c) +rm -r $RESULT_DIR +rm -r tet_tmp_dir +rm testcase/tet_captured diff --git a/TC/config b/TC/config new file mode 100644 index 0000000..8b68019 --- /dev/null +++ b/TC/config @@ -0,0 +1,2 @@ +TET_INSTALL_HOST_PATH=/home/idkiller/work/tetware/TETware +TET_INSTALL_TARGET_PATH=/mnt/nfs/tetware/TETware diff --git a/TC/execute.sh b/TC/execute.sh new file mode 100755 index 0000000..a4f6095 --- /dev/null +++ b/TC/execute.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +. ./_export_target_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -e -j $JOURNAL_RESULT -p ./ +grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/testcase/Makefile b/TC/testcase/Makefile new file mode 100755 index 0000000..04df82b --- /dev/null +++ b/TC/testcase/Makefile @@ -0,0 +1,28 @@ +CC = gcc + +C_FILES = $(shell ls *.c) + +PKGS = dlog capi-system-haptic + +#TET_ROOT = /home/idkiller/work/tetware/TETware/tetware-target + +LDFLAGS += $(TET_ROOT)/lib/tet3/tcm_s.o +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -ltcm_s +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -lapi_s +LDFLAGS += `pkg-config --libs $(PKGS)` + +CFLAGS += `pkg-config --cflags $(PKGS)` +CFLAGS += -I. +CFLAGS += -I$(TET_ROOT)/inc/tet3 +CFLAGS += -Wall + +#TARGETS = $(C_FILES:%.c=tc-%) +TCS := $(shell ls -1 *.c | cut -d. -f1) + +all: $(TCS) + +%: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean: + rm -f $(TCS) diff --git a/TC/testcase/tslist b/TC/testcase/tslist new file mode 100644 index 0000000..29af7f6 --- /dev/null +++ b/TC/testcase/tslist @@ -0,0 +1,2 @@ +/testcase/utc_system_haptic_basic +/testcase/utc_system_haptic_play diff --git a/TC/testcase/utc_system_haptic_basic.c b/TC/testcase/utc_system_haptic_basic.c new file mode 100644 index 0000000..f5f49a6 --- /dev/null +++ b/TC/testcase/utc_system_haptic_basic.c @@ -0,0 +1,112 @@ +/* + * 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 <tet_api.h> +#include <haptic.h> + +#define API_NAME_HAPTIC_GET_DEVICE_COUNT "haptic_get_count" +#define API_NAME_HAPTIC_INITALIZE "haptic_initialize" +#define API_NAME_HAPTIC_DEINITALIZE "haptic_deinitialize" + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + + +static void utc_haptic_get_count_p(void); +static void utc_haptic_initialize_p(void); +static void utc_haptic_deinitialize_p(void); +static void utc_haptic_deinitialize_n(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_haptic_get_count_p, POSITIVE_TC_IDX}, + { utc_haptic_initialize_p, POSITIVE_TC_IDX}, + { utc_haptic_deinitialize_p, POSITIVE_TC_IDX}, + { utc_haptic_deinitialize_n, NEGATIVE_TC_IDX}, + { NULL, 0}, +}; + +static void startup(void) +{ + +} + +static void cleanup(void) +{ + /* end of TC */ +} + +static void utc_haptic_get_count_p(void) +{ + int cnt, err; + err = haptic_get_count(&cnt); + + if(err < 0 ){ + dts_fail(API_NAME_HAPTIC_GET_DEVICE_COUNT); + } + else{ + dts_pass(API_NAME_HAPTIC_GET_DEVICE_COUNT); + } +} + +static void utc_haptic_initialize_p(void) +{ + int err = haptic_initialize(); + haptic_deinitialize(); + + if(err < 0){ + dts_fail(API_NAME_HAPTIC_INITALIZE); + } + else{ + dts_pass(API_NAME_HAPTIC_INITALIZE); + } +} + +static void utc_haptic_deinitialize_p(void) +{ + int err; + + haptic_initialize(); + err = haptic_deinitialize(); + + if(err < 0){ + dts_fail(API_NAME_HAPTIC_DEINITALIZE); + } + else{ + dts_pass(API_NAME_HAPTIC_DEINITALIZE); + } +} + +static void utc_haptic_deinitialize_n(void) +{ + int err; + + err = haptic_deinitialize(); + + if(err < 0){ + dts_pass(API_NAME_HAPTIC_DEINITALIZE); + } + else{ + dts_fail(API_NAME_HAPTIC_DEINITALIZE); + } +} diff --git a/TC/testcase/utc_system_haptic_play.c b/TC/testcase/utc_system_haptic_play.c new file mode 100644 index 0000000..62822a0 --- /dev/null +++ b/TC/testcase/utc_system_haptic_play.c @@ -0,0 +1,212 @@ +/* + * 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 <tet_api.h> +#include <haptic.h> + +#define API_NAME_HAPTIC_PLAY_FILE "haptic_vibrate_file" +#define API_NAME_PLAY_MONOTONE "haptic_vibrate_monotone" +#define API_NAME_STOP_PLAY "haptic_stop_device" +#define API_NAME_PLAY_PTN "haptic_play_pattern" +#define API_NAME_STOP_PTN "haptic_stop_pattern" +#define TEST_IVT "/usr/share/immersion/01_Touch/touch_20ms_sharp.ivt" + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_system_haptic_vibrate_monotone_p(void); +static void utc_system_haptic_vibrate_monotone_n_1(void); +static void utc_system_haptic_vibrate_monotone_n_2(void); +static void utc_system_haptic_stop_device_p(void); +static void utc_system_haptic_stop_device_n(void); + +static void utc_system_haptic_vibrate_p(void); +static void utc_system_haptic_vibrate_n(void); + +static void utc_system_haptic_stop_pattern_p(void); +static void utc_system_haptic_stop_pattern_n(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_system_haptic_vibrate_monotone_p, POSITIVE_TC_IDX }, + { utc_system_haptic_vibrate_monotone_n_1, NEGATIVE_TC_IDX }, + { utc_system_haptic_vibrate_monotone_n_2, NEGATIVE_TC_IDX }, + { utc_system_haptic_stop_device_p, POSITIVE_TC_IDX }, + { utc_system_haptic_stop_device_n, NEGATIVE_TC_IDX }, + { utc_system_haptic_vibrate_p, POSITIVE_TC_IDX}, + { utc_system_haptic_vibrate_n, NEGATIVE_TC_IDX}, + { utc_system_haptic_stop_pattern_p, POSITIVE_TC_IDX}, + { utc_system_haptic_stop_pattern_n, NEGATIVE_TC_IDX}, + { NULL, 0}, +}; + + +static void startup(void) +{ + int error = HAPTIC_ERROR_NONE; + + error = haptic_initialize(); + + dts_check_eq("haptic_initialize", error, HAPTIC_ERROR_NONE, "fail initialize in startup"); +} + +static void cleanup(void) +{ + int error = HAPTIC_ERROR_NONE; + + error = haptic_deinitialize(); + + dts_check_eq("haptic_deinitialize", error, HAPTIC_ERROR_NONE, "fail deinitialize in startup"); +} + + +/** + * @brief Positive test case of haptic_vibrate_monotone() + */ +static void utc_system_haptic_vibrate_monotone_p(void) +{ + int error = HAPTIC_ERROR_NONE; + + error = haptic_vibrate_monotone(0, 1000, 50); + if(error != HAPTIC_ERROR_NONE) + dts_fail(API_NAME_PLAY_MONOTONE); + + dts_pass(API_NAME_PLAY_MONOTONE); +} + +/** + * @brief Negative test case of haptic_vibrate_monotone() + */ +static void utc_system_haptic_vibrate_monotone_n_1(void) +{ + int error = HAPTIC_ERROR_NONE; + + error = haptic_vibrate_monotone(-1, 1000, 50); + if(error == HAPTIC_ERROR_NONE) + dts_fail(API_NAME_PLAY_MONOTONE); + + dts_pass(API_NAME_PLAY_MONOTONE); +} + +/** + * @brief Negative test case of haptic_vibrate_monotone() + */ +static void utc_system_haptic_vibrate_monotone_n_2(void) +{ + int error = HAPTIC_ERROR_NONE; + + error = haptic_vibrate_monotone(0, -1, 50); + if(error == HAPTIC_ERROR_NONE) + dts_fail(API_NAME_PLAY_MONOTONE); + + dts_pass(API_NAME_PLAY_MONOTONE); +} + + +/** + * @brief Positive test case of haptic_stop_device() + */ +static void utc_system_haptic_stop_device_p(void) +{ + int error = HAPTIC_ERROR_NONE; + + error = haptic_vibrate_monotone(0, 1000, 50); + if(error != HAPTIC_ERROR_NONE) + dts_fail(API_NAME_STOP_PLAY); + + error = haptic_stop_device(0); + if(error != HAPTIC_ERROR_NONE) + dts_fail(API_NAME_STOP_PLAY); + + dts_pass(API_NAME_STOP_PLAY); +} + +/** + * @brief Negative test case of haptic_stop_device() + */ +static void utc_system_haptic_stop_device_n(void) +{ + int error = HAPTIC_ERROR_NONE; + + error = haptic_stop_device(-1); + if(error == HAPTIC_ERROR_NONE) + dts_fail(API_NAME_STOP_PLAY); + + dts_pass(API_NAME_STOP_PLAY); +} + +static void utc_system_haptic_vibrate_p(void) +{ + haptic_vibration_iter_s ptn[] = { + {0, HAPTIC_LEVEL_5, 500}, + {0, HAPTIC_LEVEL_1, 500}, + }; + + int ptn_id; + if(haptic_play_pattern(ptn, 2, 1, 0, &ptn_id) < 0){ + dts_fail(API_NAME_PLAY_PTN); + }else{ + dts_pass(API_NAME_PLAY_PTN); + } +} + +static void utc_system_haptic_vibrate_n(void) +{ + int ptn_id; + if(haptic_play_pattern(NULL, 7, 1, 0, &ptn_id) < 0){ + dts_pass(API_NAME_PLAY_PTN); + }else{ + dts_fail(API_NAME_PLAY_PTN); + } +} + +static void utc_system_haptic_stop_pattern_p(void) +{ + haptic_vibration_iter_s ptn[] = { + {0, HAPTIC_LEVEL_5, 500}, + {0, HAPTIC_LEVEL_1, 500}, + }; + + int ptn_id; + haptic_play_pattern(ptn, 2, 1, 0, &ptn_id); + + int err = haptic_stop_pattern(ptn_id); + if(err < 0){ + dts_fail(API_NAME_STOP_PTN); + } + else{ + dts_pass(API_NAME_STOP_PTN); + } +} + +static void utc_system_haptic_stop_pattern_n(void) +{ + int err = haptic_stop_pattern(-1); + if(err < 0){ + dts_pass(API_NAME_STOP_PTN); + } + else{ + dts_fail(API_NAME_STOP_PTN); + } + +} diff --git a/TC/tet_scen b/TC/tet_scen new file mode 100755 index 0000000..03f029a --- /dev/null +++ b/TC/tet_scen @@ -0,0 +1,7 @@ +all + ^TEST +##### Scenarios for TEST ##### + +# Test scenario +TEST + :include:/testcase/tslist diff --git a/TC/tetbuild.cfg b/TC/tetbuild.cfg new file mode 100644 index 0000000..f7eda55 --- /dev/null +++ b/TC/tetbuild.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capture option for build operation checking +TET_BUILD_TOOL=make # build with using make command +TET_BUILD_FILE=-f Makefile # execution file (Makefile) for build +TET_API_COMPLIANT=True # use TET API in Test Case ? +TET_PASS_TC_NAME=True # report passed TC name in Journal file? diff --git a/TC/tetclean.cfg b/TC/tetclean.cfg new file mode 100644 index 0000000..02d7030 --- /dev/null +++ b/TC/tetclean.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capture option +TET_CLEAN_TOOL= make clean # clean tool +TET_CLEAN_FILE= Makefile # file for clean +TET_API_COMPLIANT=True # TET API useage +TET_PASS_TC_NAME=True # showing name , passed TC diff --git a/TC/tetexec.cfg b/TC/tetexec.cfg new file mode 100644 index 0000000..ef3e452 --- /dev/null +++ b/TC/tetexec.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capturing execution or not +TET_EXEC_TOOL= # ex) exec : execution tool set up/ Optional +TET_EXEC_FILE= # ex) exectool : execution file/ Optional +TET_API_COMPLIANT=True # Test case or Tool usesTET API? +TET_PASS_TC_NAME=True # showing Passed TC name ? diff --git a/capi-system-haptic.pc.in b/capi-system-haptic.pc.in new file mode 100644 index 0000000..1d79ad0 --- /dev/null +++ b/capi-system-haptic.pc.in @@ -0,0 +1,15 @@ + +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=@LIB_INSTALL_DIR@ +includedir=/usr/include/system + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} + 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..7f4ea39 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,152 @@ +capi-system-haptic (0.1.0-12) unstable; urgency=low + + * fix race condition segfault error in pattern play functions + * Git: slp/api/haptic + * Tag: capi-system-haptic_0.1.0-12 + + -- pius lee <pius.lee@samsung.com> Fri, 01 Jun 2012 16:56:46 +0900 + +capi-system-haptic (0.1.0-11) unstable; urgency=low + + * so version added + * Git: slp/api/haptic + * Tag: capi-system-haptic_0.1.0-11 + + -- pius lee <pius.lee@samsung.com> Thu, 16 Feb 2012 16:53:33 +0900 + +capi-system-haptic (0.1.0-10) unstable; urgency=low + + * additional fix for lower framework + * Git: slp/api/haptic + * Tag: capi-system-haptic_0.1.0-10 + + -- DongGi Jang <dg0402.jang@samsung.com> Thu, 02 Feb 2012 16:41:18 +0900 + +capi-system-haptic (0.1.0-9) unstable; urgency=low + + * fix for lower framework + * Git: slp/api/haptic + * Tag: capi-system-haptic_0.1.0-9 + + -- pius lee <pius.lee@samsung.com> Wed, 04 Jan 2012 16:45:31 +0900 + +capi-system-haptic (0.1.0-8) unstable; urgency=low + + * fix error check for malloc and time type in iter structure, fix document + * Git: slp/api/haptic + * Tag: capi-system-haptic_0.1.0-8 + + -- pius lee <pius.lee@samsung.com> Wed, 07 Dec 2011 10:28:49 +0900 + +capi-system-haptic (0.1.0-7) unstable; urgency=low + + * fix error_ok to error_none + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.1.0-7 + + -- pius lee <pius.lee@samsung.com> Mon, 05 Dec 2011 16:03:56 +0900 + +capi-system-haptic (0.1.0-6) unstable; urgency=low + + * add error logging + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.1.0-6 + + -- pius lee <pius.lee@samsung.com> Fri, 02 Dec 2011 14:50:06 +0900 + +capi-system-haptic (0.1.0-5) unstable; urgency=low + + * replace project name from SLP to Tizen + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.1.0-5 + + -- pius lee <pius.lee@samsung.com> Wed, 23 Nov 2011 13:15:03 +0900 + +capi-system-haptic (0.1.0-4) unstable; urgency=low + + * fix segfault when call stop_pattern before play_pattern. + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.1.0-4 + + -- pius lee <pius.lee@samsung.com> Fri, 11 Nov 2011 19:34:43 +0900 + +capi-system-haptic (0.1.0-3) unstable; urgency=low + + * fix vibration function's ID bugs + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.1.0-3 + + -- pius lee <pius.lee@samsung.com> Mon, 24 Oct 2011 17:26:13 +0900 + +capi-system-haptic (0.1.0-2) unstable; urgency=low + + * Fix TC, fix vibration function's bugs + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.1.0-2 + + -- pius lee <pius.lee@samsung.com> Tue, 27 Sep 2011 22:30:08 +0900 + +capi-system-haptic (0.1.0-1) unstable; urgency=low + + * alpha version update + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.1.0-1 + + -- pius lee <pius.lee@samsung.com> Tue, 27 Sep 2011 21:55:56 +0900 + +capi-system-haptic (0.0.1-6) unstable; urgency=low + + * Now count function return value through output parameter. + * Now play pattern function return id through output parameter. + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.0.1-6 + + -- pius lee <pius.lee@samsung.com> Tue, 27 Sep 2011 16:14:04 +0900 + +capi-system-haptic (0.0.1-5) unstable; urgency=low + + * Fix version number + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.0.1-5 + + -- pius lee <pius.lee@samsung.com> Mon, 26 Sep 2011 21:54:30 +0900 + +capi-system-haptic (0.0.1-4-docfix) unstable; urgency=low + + * Fix documents + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.0.1-4-docfix + + -- pius lee <pius.lee@samsung.com> Mon, 26 Sep 2011 21:09:04 +0900 + +capi-system-haptic (0.0.1-4) unstable; urgency=low + + * renew functions to new way. (merged from experimental branch) + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.0.1-4 + + -- pius lee <pius.lee@samsung.com> Mon, 26 Sep 2011 15:01:40 +0900 + +capi-system-haptic (0.0.1-3) unstable; urgency=low + + * change unknown error to more meaningful + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.0.1-3 + + -- pius lee <pius.lee@samsung.com> Mon, 29 Aug 2011 18:20:36 +0900 + +capi-system-haptic (0.0.1-2) unstable; urgency=low + + * fix doxygen comment in header about haptic_open + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.0.1-2 + + -- pius lee <pius.lee@samsung.com> Thu, 11 Aug 2011 19:15:12 +0900 + +capi-system-haptic (0.0.1-1) unstable; urgency=low + + * Initial upload + * Git: slp-source.sec.samsung.net:slp/api/haptic + * Tag: capi-system-haptic_0.0.1-1 + + -- pius lee <pius.lee@samsung.com> Fri, 05 Aug 2011 13:02:31 +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..747e935 --- /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: ${shlibs: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..aca248d --- /dev/null +++ b/debian/rules @@ -0,0 +1,68 @@ +#!/usr/bin/make -f + +FULLVER ?= $(shell dpkg-parsechangelog | grep Version: | cut -d ' ' -f 2 | cut -d '-' -f 1) +MAJORVER ?= $(shell echo $(FULLVER) | cut -d '.' -f 1) + +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 .. -DFULLVER=${FULLVER} -DMAJORVER=${MAJORVER} + 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..c69473f --- /dev/null +++ b/include/haptic.h @@ -0,0 +1,226 @@ +/* + * 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 = -1, /**< vibration level from settings */ + HAPTIC_LEVEL_0 = 0, /**< vibration level 0 (silence) */ + HAPTIC_LEVEL_1 = 20, /**< vibration level 1 (the lowest) */ + HAPTIC_LEVEL_2 = 40, /**< vibration level 2 (low)*/ + HAPTIC_LEVEL_3 = 60, /**< vibration level 3 (middle) */ + HAPTIC_LEVEL_4 = 80, /**< vibration level 4 (high) */ + HAPTIC_LEVEL_5 = 100, /**< 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 */ + 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 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 + * + * @remark + * level is intensity variation of vibration. it has a value from 0 to 100.\n + * level -1 is reserved for auto changing to saved variable in the settings. + * + * @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 + * @param[in] level The amount of the intensity variation + * + * @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, int level); + +/** + * @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 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. + * + * @remark + * level is intensity variation of vibration. it has a value from 0 to 100.\n + * level -1 is reserved for auto changing to saved variable in the settings. + * + * @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 The amount of the intensity variation in every 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, 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 100644 index 0000000..cbb459f --- /dev/null +++ b/include/haptic_private.h @@ -0,0 +1,34 @@ +/* + * 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(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/packaging/capi-system-haptic.manifest b/packaging/capi-system-haptic.manifest new file mode 100644 index 0000000..b631abe --- /dev/null +++ b/packaging/capi-system-haptic.manifest @@ -0,0 +1,5 @@ +<manifest> +<request> + <domain name="_"/> +</request> +</manifest> diff --git a/packaging/capi-system-haptic.spec b/packaging/capi-system-haptic.spec new file mode 100644 index 0000000..7856378 --- /dev/null +++ b/packaging/capi-system-haptic.spec @@ -0,0 +1,90 @@ +#sbs-git:slp/api/haptic capi-system-haptic 0.1.0 0092e2c55dbf60717ae8f43aee931f2dd1c57157 +Name: capi-system-haptic +Summary: A Haptic library in Tizen C API +Version: 0.1.0 +Release: 23 +Group: TO_BE/FILLED_IN +License: TO BE FILLED IN +Source0: %{name}-%{version}.tar.gz +Source1: capi-system-haptic.manifest +BuildRequires: cmake +BuildRequires: pkgconfig(devman) +BuildRequires: pkgconfig(devman_haptic) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(devman) +BuildRequires: pkgconfig(dlog) + +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description + + +%package devel +Summary: A Haptic library in Tizen C API (Development) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description devel + + + +%prep +%setup -q + + +%build +cp %{SOURCE1} . +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} + + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +mkdir -p %{buildroot}%{_datadir}/license +cp LICENSE.APLv2 %{buildroot}%{_datadir}/license/%{name} + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files +%manifest capi-system-haptic.manifest +%{_libdir}/libcapi-system-haptic.so.* +%{_datadir}/license/%{name} + +%files devel +%{_includedir}/system/*.h +%{_libdir}/pkgconfig/*.pc +%{_libdir}/libcapi-system-haptic.so + +%changelog +* Wed Oct 17 2012 - Jiyoung Yun <jy910.yun@samsung.com> +- fix the build break problem +- Tag : capi-system-haptic_0.1.0-22 + +* Thu Oct 04 2012 - Jiyoung Yun <jy910.yun@samsung.com> +- fix the bug regarding haptic_level_auto +- Tag : capi-system-haptic_0.1.0-21 + +* Fri Sep 21 2012 - Jiyoung Yun <jy910.yun@samsung.com> +- Add smack label +- Tag : capi-system-haptic_0.1.0-20 + +* Thu Sep 06 2012 - Jiyoung Yun <jy910.yun@samsung.com> +- fix TC error +- Tag : capi-system-haptic_0.1.0-19 + +* Thu Aug 16 2012 - Jiyoung Yun <jy910.yun@samsung.com> +- modify the function parameter to control detail feedback level +- Tag : capi-system-haptic_0.1.0-17 + +* Thu Aug 09 2012 - Jiyoung Yun <jy910.yun@samsung.com> +- Revert "add level parameter to monotone vibration function." +- Tag : capi-system-haptic_0.1.0-16 diff --git a/src/haptic.c b/src/haptic.c new file mode 100644 index 0000000..186a92f --- /dev/null +++ b/src/haptic.c @@ -0,0 +1,371 @@ +/* + * 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, +}; + +struct _vibe_pattern { + haptic_vibration_iter_s *iters; + int current; + int size; + int level; + int iter_count; + int pattern_index; + int error; +}; + +static const int UNDEFINED = 0; +static const int START = 1; + +GArray *pattern_table = NULL; + +static int initialize = 0; +static int max_device = 0; + +static int* haptic_ids = NULL; + +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(initialize) + return HAPTIC_ERROR_NONE; + + + 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(haptic_ids[i]); + } + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + } + + haptic_ids[i] = id; + } + + initialize = 1; + + pattern_table = g_array_new(FALSE, TRUE, sizeof(int)); + + _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(haptic_ids[i]); + } + initialize = 0; + if(haptic_ids != NULL) + free(haptic_ids); + + g_array_free(pattern_table, TRUE); + pattern_table = NULL; + + _haptic_deinit(); + + return HAPTIC_ERROR_NONE; +} + + +int haptic_vibrate_monotone(int device_index, int duration_ms, int level) +{ + int ret; + + if(device_index < 0 || device_index > max_device) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + if(level < HAPTIC_LEVEL_AUTO || level > HAPTIC_LEVEL_5) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + device_index = ((device_index < 3) ? device_index : 0); // xxx + + if(!initialize) + RETURN_ERR(HAPTIC_ERROR_NOT_INITIALIZED); + + if(level == HAPTIC_LEVEL_0) + return HAPTIC_ERROR_NONE; + + ret = device_haptic_play_monotone_with_detail_feedback_level(haptic_ids[device_index], duration_ms, 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_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) ? device_index : 0); // 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 int _haptic_play_monotone(int device_index, long duration, int level) +{ + int ret; + + if(device_index < 0 || device_index > max_device) + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + + device_index = ((device_index < 3) ? device_index : 0); // xxx + + if(!initialize) + RETURN_ERR(HAPTIC_ERROR_NOT_INITIALIZED); + + if(level == HAPTIC_LEVEL_AUTO) { + level = HAPTIC_FEEDBACK_LEVEL_AUTO; + }else { + level = level > 100 ? 100 : (level < 0 ? 0 : level); + } + + ret = device_haptic_play_monotone_with_detail_feedback_level(haptic_ids[device_index], duration, level); + + if(ret < 0){ + if(ret == -2) + RETURN_ERR(HAPTIC_ERROR_OPERATION_FAILED); + else + RETURN_ERR(HAPTIC_ERROR_INVALID_PARAMETER); + } + + return HAPTIC_ERROR_NONE; +} + +static gboolean _haptic_play_iter(gpointer data) +{ + int err; + struct _vibe_pattern* pattern = NULL; + + pattern = (struct _vibe_pattern*)data; + + if(pattern == NULL) + return false; + + if(pattern_table == NULL || g_array_index(pattern_table, int, pattern->pattern_index) != START) { + free(pattern->iters); + free(pattern); + return false; + } + if(pattern->iters == NULL) + return false; + int current = pattern->current; + + int device = pattern->iters[current].vibrator_index; + long time = pattern->iters[current].time; + int level = pattern->level; + + // set default device, if can't find given device. + if(device >= max_device || device < 0) + device = 0; + + if(level != 0 || time != 0){ + err = _haptic_play_monotone(device, time, level); + if(err<0){ + pattern->error = err; + return false; + } + } + // pattern play finish + if(++pattern->current >= pattern->size){ + if(pattern->iter_count <= 0){ + free(pattern->iters); + free(pattern); + 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, 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 = level; + vibe_p->iter_count = count; + vibe_p->current = 0; + vibe_p->error= 0; + + for(i=0; i< pattern_table->len; i++){ + if(g_array_index(pattern_table, int, i) == UNDEFINED){ + key = i; + break; + } + } + if(key == -1){ + g_array_append_val(pattern_table, START); + key = pattern_table->len -1; + }else{ + g_array_index(pattern_table, int, key) = START; + } + + vibe_p->pattern_index = key; + + _haptic_play_iter((gpointer)vibe_p); + + int error = vibe_p->error; + if(error < 0){ + free(vibe_p->iters); + free(vibe_p); + + if(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); + + g_array_index(pattern_table, int, id) = UNDEFINED; + + return HAPTIC_ERROR_NONE; +} diff --git a/src/haptic_private.c b/src/haptic_private.c new file mode 100644 index 0000000..29f956c --- /dev/null +++ b/src/haptic_private.c @@ -0,0 +1,64 @@ +/* + * 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 { + 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; + +void _haptic_init() +{ + immersion = access(IMMERSION_DRV_NODE, F_OK) == 0; +} + +void _haptic_deinit() +{ +} + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100755 index 0000000..d312607 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,65 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "capi-system-haptic") +SET(fw_test "capi-system-haptic-test") + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED glib-2.0 ecore-x elementary ecore evas) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -g") +INCLUDE_DIRECTORIES(../include) + +#ADD_EXECUTABLE("system-sensor" system-sensor.c) +#TARGET_LINK_LIBRARIES("system-sensor" ${fw_name} ${${fw_test}_LDFLAGS}) + +aux_source_directory(. sources) +FOREACH(src ${sources}) + GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) + MESSAGE("${src_name}") + ADD_EXECUTABLE(${src_name} ${src}) + IF(EXISTS "${src_name}.edc") + ADD_CUSTOM_TARGET( + "${src_name}.edj" + COMMAND edje_cc + ${CMAKE_CURRENT_SOURCE_DIR}/${src_name}.edc + ${CMAKE_CURRENT_SOURCE_DIR}/${src_name}.edj + ) + ADD_DEPENDENCIES(${src_name} ${src_name}.edj) + ENDIF(EXISTS "${src_name}.edc") + TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${pkgs_LDFLAGS} ${fw_name}) +ENDFOREACH() + +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 *.edj -or + -name *~ \) + | grep -v TC | xargs rm -rf + TARGET distclean + VERBATIM +) + +ENDIF(UNIX) diff --git a/test/system-haptic.c b/test/system-haptic.c new file mode 100644 index 0000000..78a2f2c --- /dev/null +++ b/test/system-haptic.c @@ -0,0 +1,158 @@ +/* + * 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 <stdbool.h> +#include <stdlib.h> +#include <glib.h> +#include <haptic.h> + +static GMainLoop *mainloop; +static int ptn_id; + +static void sig_quit(int signo) +{ + if(mainloop) + { + g_main_loop_quit(mainloop); + } +} + +static gboolean play_ptn(gpointer data) +{ + haptic_vibration_iter_s ptn[] = { + {0, HAPTIC_LEVEL_5, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_5, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_5, 1000}, + }; + + if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + + return false; +} + +static gboolean stop_play(gpointer data) +{ + int err; + int id = (int)data; + + printf("-- stop!! [%d]\n", id); + err = haptic_stop_pattern(id); + if(err < 0){ + printf("-- error!! when stop play!!\n"); + } + + return false; +} +static gboolean stop_and_play(gpointer data) +{ + int err; + int id = (int)data; + + printf("-- stop!! [%d]\n", id); + err = haptic_stop_pattern(id); + if(err < 0){ + printf("-- error!! when stop play!!\n"); + } + +// g_timeout_add(6000, play_ptn, NULL); + g_timeout_add(10000, play_ptn, NULL); + + return false; +} + +static gboolean stop_device(gpointer data) +{ + haptic_stop_device(0); + + return false; +} + +int main(int argc, char *argv[]) +{ + haptic_vibration_iter_s ptn[] = { + {0, HAPTIC_LEVEL_1, 3000}, + {0, HAPTIC_LEVEL_0, 10}, + {0, HAPTIC_LEVEL_3, 2000}, + {0, HAPTIC_LEVEL_0, 10}, + {0, HAPTIC_LEVEL_5, 1000}, + {0, HAPTIC_LEVEL_0, 10}, + {0, HAPTIC_LEVEL_2, 3000}, + }; + + if(haptic_initialize() == HAPTIC_ERROR_NONE){ + printf("haptic device opened\n"); + }else{ + printf("haptic_open fail\n"); + } + + signal(SIGINT, sig_quit); + signal(SIGTERM, sig_quit); + signal(SIGQUIT, sig_quit); + + mainloop = g_main_loop_new(NULL, FALSE); + + if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + g_timeout_add(4000, stop_play, (gpointer)ptn_id); + + if(haptic_play_pattern(ptn, 7, 2, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + g_timeout_add(2000, stop_play, (gpointer)ptn_id); + + if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + g_timeout_add(7000, stop_play, (gpointer)ptn_id); + + if(haptic_play_pattern(ptn, 7, 3, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + g_timeout_add(10, stop_and_play, (gpointer)ptn_id); + + + g_timeout_add(4000, stop_device, NULL); + + + g_main_loop_run(mainloop); + g_main_loop_unref(mainloop); + + if(haptic_deinitialize() == HAPTIC_ERROR_NONE){ + printf("haptic device closed\n"); + }else{ + printf("haptic_close fail\n"); + } + + return 0; +} diff --git a/test/system-haptic2.c b/test/system-haptic2.c new file mode 100644 index 0000000..7087967 --- /dev/null +++ b/test/system-haptic2.c @@ -0,0 +1,105 @@ +/* + * 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 <stdbool.h> +#include <stdlib.h> +#include <glib.h> +#include <haptic.h> + +#define TEST_IVT "/usr/share/immersion/01_Touch/touch_20ms_sharp.ivt" + +static GMainLoop *mainloop; + +static void sig_quit(int signo) +{ + if(mainloop) + { + g_main_loop_quit(mainloop); + } +} + +static char* error_msg(int err){ + switch(err){ + case HAPTIC_ERROR_NONE : + return "HAPTIC_ERROR_NONE"; + case HAPTIC_ERROR_INVALID_PARAMETER : + return "HAPTIC_ERROR_INVALID_PARAMETER"; + case HAPTIC_ERROR_NO_SUCH_FILE : + return "HAPTIC_ERROR_NO_SUCH_FILE"; + case HAPTIC_ERROR_NOT_SUPPORTED_FORMAT : + return "HAPTIC_ERROR_NOT_SUPPORTED_FORMAT"; + case HAPTIC_ERROR_NOT_INITIALIZED : + return "HAPTIC_ERROR_NOT_INITIALIZED"; + case HAPTIC_ERROR_OPERATION_FAILED : + return "HAPTIC_ERROR_OPERATION_FAILED"; + } + return "------??"; +} + +int main(int argc, char *argv[]) +{ + int count, i, err; + if(haptic_initialize() == HAPTIC_ERROR_NONE){ + printf("haptic device opened\n"); + }else{ + printf("haptic_open fail\n"); + } + + signal(SIGINT, sig_quit); + signal(SIGTERM, sig_quit); + signal(SIGQUIT, sig_quit); + + mainloop = g_main_loop_new(NULL, FALSE); + + haptic_get_count(&count); + + printf("count = %d\n", count); + + for(i=0; i<=count;i++){ + printf("play with device(%d)\n", i); + + if((err = haptic_vibrate_monotone(count, 1000)) < 0){ + printf("haptic play fail [%s]\n", error_msg(err)); + }else{ + printf("haptic play success\n"); + } + + if(haptic_stop_device(count) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + + if(haptic_vibrate_file(count, TEST_IVT, 1, HAPTIC_LEVEL_AUTO) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + } + + + g_main_loop_run(mainloop); + g_main_loop_unref(mainloop); + + if(haptic_deinitialize() == HAPTIC_ERROR_NONE){ + printf("haptic device closed\n"); + }else{ + printf("haptic_close fail\n"); + } + + return 0; +} diff --git a/test/system-haptic3.c b/test/system-haptic3.c new file mode 100644 index 0000000..78a2f2c --- /dev/null +++ b/test/system-haptic3.c @@ -0,0 +1,158 @@ +/* + * 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 <stdbool.h> +#include <stdlib.h> +#include <glib.h> +#include <haptic.h> + +static GMainLoop *mainloop; +static int ptn_id; + +static void sig_quit(int signo) +{ + if(mainloop) + { + g_main_loop_quit(mainloop); + } +} + +static gboolean play_ptn(gpointer data) +{ + haptic_vibration_iter_s ptn[] = { + {0, HAPTIC_LEVEL_5, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_5, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_5, 1000}, + }; + + if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + + return false; +} + +static gboolean stop_play(gpointer data) +{ + int err; + int id = (int)data; + + printf("-- stop!! [%d]\n", id); + err = haptic_stop_pattern(id); + if(err < 0){ + printf("-- error!! when stop play!!\n"); + } + + return false; +} +static gboolean stop_and_play(gpointer data) +{ + int err; + int id = (int)data; + + printf("-- stop!! [%d]\n", id); + err = haptic_stop_pattern(id); + if(err < 0){ + printf("-- error!! when stop play!!\n"); + } + +// g_timeout_add(6000, play_ptn, NULL); + g_timeout_add(10000, play_ptn, NULL); + + return false; +} + +static gboolean stop_device(gpointer data) +{ + haptic_stop_device(0); + + return false; +} + +int main(int argc, char *argv[]) +{ + haptic_vibration_iter_s ptn[] = { + {0, HAPTIC_LEVEL_1, 3000}, + {0, HAPTIC_LEVEL_0, 10}, + {0, HAPTIC_LEVEL_3, 2000}, + {0, HAPTIC_LEVEL_0, 10}, + {0, HAPTIC_LEVEL_5, 1000}, + {0, HAPTIC_LEVEL_0, 10}, + {0, HAPTIC_LEVEL_2, 3000}, + }; + + if(haptic_initialize() == HAPTIC_ERROR_NONE){ + printf("haptic device opened\n"); + }else{ + printf("haptic_open fail\n"); + } + + signal(SIGINT, sig_quit); + signal(SIGTERM, sig_quit); + signal(SIGQUIT, sig_quit); + + mainloop = g_main_loop_new(NULL, FALSE); + + if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + g_timeout_add(4000, stop_play, (gpointer)ptn_id); + + if(haptic_play_pattern(ptn, 7, 2, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + g_timeout_add(2000, stop_play, (gpointer)ptn_id); + + if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + g_timeout_add(7000, stop_play, (gpointer)ptn_id); + + if(haptic_play_pattern(ptn, 7, 3, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + g_timeout_add(10, stop_and_play, (gpointer)ptn_id); + + + g_timeout_add(4000, stop_device, NULL); + + + g_main_loop_run(mainloop); + g_main_loop_unref(mainloop); + + if(haptic_deinitialize() == HAPTIC_ERROR_NONE){ + printf("haptic device closed\n"); + }else{ + printf("haptic_close fail\n"); + } + + return 0; +} diff --git a/test/test_lock.c b/test/test_lock.c new file mode 100644 index 0000000..e28f5ec --- /dev/null +++ b/test/test_lock.c @@ -0,0 +1,152 @@ +/* + * 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 <stdbool.h> +#include <stdlib.h> +#include <glib.h> +#include <haptic.h> + +static GMainLoop *mainloop; +static int ptn_id; + +static void sig_quit(int signo) +{ + if(mainloop) + { + g_main_loop_quit(mainloop); + } + + if(haptic_deinitialize() == HAPTIC_ERROR_NONE){ + printf("haptic device closed\n"); + }else{ + printf("haptic_close fail\n"); + } +} + +static gboolean play_ptn(gpointer data) +{ + haptic_vibration_iter_s ptn[] = { + {0, HAPTIC_LEVEL_5, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_5, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_5, 1000}, + }; + + if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + + return false; +} + +static gboolean stop_play(gpointer data) +{ + int err; + int id = (int)data; + + printf("-- stop!! [%d]\n", id); + err = haptic_stop_pattern(id); + if(err < 0){ + printf("-- error!! when stop play!!\n"); + } + + return false; +} +static gboolean stop_and_play(gpointer data) +{ + int err; + int id = (int)data; + + printf("-- stop!! [%d]\n", id); + err = haptic_stop_pattern(id); + if(err < 0){ + printf("-- error!! when stop play!!\n"); + } + +// g_timeout_add(6000, play_ptn, NULL); + g_timeout_add(10000, play_ptn, NULL); + + return false; +} + +static gboolean stop_device(gpointer data) +{ + haptic_stop_device(0); + + return false; +} + +int main(int argc, char *argv[]) +{ + haptic_vibration_iter_s ptn[] = { + {0, HAPTIC_LEVEL_1, 3000}, + {0, HAPTIC_LEVEL_0, 10}, + {0, HAPTIC_LEVEL_3, 2000}, + {0, HAPTIC_LEVEL_0, 10}, + {0, HAPTIC_LEVEL_5, 1000}, + {0, HAPTIC_LEVEL_0, 10}, + {0, HAPTIC_LEVEL_2, 3000}, + }; + + signal(SIGINT, sig_quit); + signal(SIGTERM, sig_quit); + signal(SIGQUIT, sig_quit); + + mainloop = g_main_loop_new(NULL, FALSE); + + if(haptic_initialize() == HAPTIC_ERROR_NONE){ + printf("haptic device opened\n"); + }else{ + printf("haptic_open fail\n"); + } + if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + if(haptic_deinitialize() == HAPTIC_ERROR_NONE){ + printf("haptic device closed\n"); + }else{ + printf("haptic_close fail\n"); + } + if(haptic_initialize() == HAPTIC_ERROR_NONE){ + printf("haptic device opened\n"); + }else{ + printf("haptic_open fail\n"); + } + if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){ + printf("haptic play fail\n"); + }else{ + printf("haptic play success\n"); + } + if(haptic_deinitialize() == HAPTIC_ERROR_NONE){ + printf("haptic device closed\n"); + }else{ + printf("haptic_close fail\n"); + } + + + g_main_loop_run(mainloop); + g_main_loop_unref(mainloop); + + return 0; +} diff --git a/test/test_ui.c b/test/test_ui.c new file mode 100644 index 0000000..5ae5b91 --- /dev/null +++ b/test/test_ui.c @@ -0,0 +1,142 @@ +/* + * 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 <stdbool.h> +#include <stdlib.h> +#include <haptic.h> + +#include <Elementary.h> +#include <Ecore_X.h> + +static haptic_vibration_iter_s ptn[] = { + {0, HAPTIC_LEVEL_5, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_5, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_1, 1000}, + {0, HAPTIC_LEVEL_5, 1000}, +}; + +int ptn_id; + +static void _quit_cb(void *data, Evas_Object* obj, void* event_info) +{ + Evas_Object *win = (Evas_Object *) data; + elm_win_lower(win); +} + +static void _vibe_clicked_cb(void *data, Evas_Object* obj, void* event_info) +{ + printf("initialize!\n"); + haptic_initialize(); + printf("after initialize!\n"); + + printf("play pattern!\n"); + haptic_play_pattern(ptn, 7, 1, 0, &ptn_id); + printf("after play pattern!\n"); +} + +static void _stop_clicked_cb(void *data, Evas_Object* obj, void* event_info) +{ + int err; + printf("stop pattern!\n"); + err = haptic_stop_pattern(ptn_id); + printf("after stop pattern! [%d]\n", err); + + printf("deinitialize!\n"); + haptic_deinitialize(); + printf("after deinitialize!\n"); +} + +static void winmain() +{ + const char* name = "Hapti_UI_TEST"; + int w,h; + + Evas_Object* win; + Evas_Object* bg; + Evas_Object* main_layout; + Evas_Object* btns_box; + Evas_Object* btn_vibe; + Evas_Object* btn_stop; + + Evas* evas; + + win = elm_win_add(NULL, name, ELM_WIN_BASIC); + if(!win) + return; + + elm_win_title_set(win, name); + elm_win_borderless_set(win, EINA_TRUE); + elm_win_autodel_set(win, EINA_TRUE); + evas_object_smart_callback_add(win, "delete,request", _quit_cb, NULL); + ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h); + evas_object_resize(win, w, h); + + evas_object_show(win); + + evas = evas_object_evas_get(win); + + // set background + bg = elm_bg_add(win); + elm_bg_color_set(bg, 0xff, 0xff, 0xff); + evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, bg); + evas_object_show(bg); + + // Base Layout + main_layout = elm_layout_add(win); + elm_layout_theme_set(main_layout, "layout", "application", "default"); + evas_object_size_hint_weight_set(main_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, main_layout); + evas_object_show(main_layout); + + // Indicator + elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW); + + + // add box + btns_box = elm_box_add(win); + elm_box_horizontal_set(btns_box, EINA_TRUE); + elm_win_resize_object_add(win, btns_box); + elm_box_padding_set(btns_box, 10, 0); + evas_object_show(btns_box); + + // add Button + btn_vibe = elm_button_add(main_layout); + btn_stop = elm_button_add(main_layout); + elm_object_text_set(btn_vibe, "Vibe"); + elm_object_text_set(btn_stop, "Stop"); + evas_object_smart_callback_add(btn_vibe, "clicked", _vibe_clicked_cb, NULL); + evas_object_smart_callback_add(btn_stop, "clicked", _stop_clicked_cb, NULL); + + elm_box_pack_end(btns_box, btn_vibe); + elm_box_pack_end(btns_box, btn_stop); + evas_object_show(btn_vibe); + evas_object_show(btn_stop); +} + +EAPI_MAIN int elm_main(int argc, char** argv) +{ + winmain(); + + elm_run(); + elm_shutdown(); + return 0; +} +ELM_MAIN() |