patch tizen_2.0_build
[framework/api/haptic.git] / test / system-haptic2.c
1 /*
2  * 
3  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4  * PROPRIETARY/CONFIDENTIAL
5  * 
6  * This software is the confidential and proprietary information of SAMSUNG 
7  * ELECTRONICS ("Confidential Information"). You agree and acknowledge that 
8  * this software is owned by Samsung and you shall not disclose such 
9  * Confidential Information and shall use it only in accordance with the terms 
10  * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG 
11  * make no representations or warranties about the suitability of the software, 
12  * either express or implied, including but not limited to the implied 
13  * warranties of merchantability, fitness for a particular purpose, or 
14  * non-infringement. SAMSUNG shall not be liable for any damages suffered by 
15  * licensee arising out of or related to this software.
16  * 
17  */
18
19 #include <stdio.h>
20 #include <stdbool.h>
21 #include <stdlib.h>
22 #include <glib.h>
23 #include <haptic.h>
24
25 #define TEST_IVT "/usr/share/immersion/01_Touch/touch_20ms_sharp.ivt"
26
27 static GMainLoop *mainloop;
28
29 static void sig_quit(int signo)
30 {
31         if(mainloop)
32         {
33                 g_main_loop_quit(mainloop);
34         }
35 }
36
37 static char* error_msg(int err){
38     switch(err){
39         case HAPTIC_ERROR_NONE                  :
40             return "HAPTIC_ERROR_NONE";
41         case HAPTIC_ERROR_INVALID_PARAMETER     :
42             return "HAPTIC_ERROR_INVALID_PARAMETER";
43         case HAPTIC_ERROR_NO_SUCH_FILE          :
44             return "HAPTIC_ERROR_NO_SUCH_FILE";
45         case HAPTIC_ERROR_NOT_SUPPORTED_FORMAT  :
46             return "HAPTIC_ERROR_NOT_SUPPORTED_FORMAT";
47         case HAPTIC_ERROR_NOT_INITIALIZED       :
48             return "HAPTIC_ERROR_NOT_INITIALIZED";
49         case HAPTIC_ERROR_OPERATION_FAILED      :
50             return "HAPTIC_ERROR_OPERATION_FAILED";
51     }
52     return "------??";
53 }
54
55 int main(int argc, char *argv[])
56 {
57     int count, i, err;
58         if(haptic_initialize() == HAPTIC_ERROR_NONE){
59                 printf("haptic device opened\n");
60         }else{
61                 printf("haptic_open fail\n");
62         }
63
64         signal(SIGINT, sig_quit);
65         signal(SIGTERM, sig_quit);
66         signal(SIGQUIT, sig_quit);
67
68         mainloop = g_main_loop_new(NULL, FALSE);
69
70     haptic_get_count(&count);
71
72     printf("count = %d\n", count);
73
74     for(i=0; i<=count;i++){
75         printf("play with device(%d)\n", i);
76
77         if((err = haptic_vibrate_monotone(count, 1000)) < 0){
78             printf("haptic play fail [%s]\n", error_msg(err));
79         }else{
80             printf("haptic play success\n");
81         }
82
83         if(haptic_stop_device(count) < 0){
84             printf("haptic play fail\n");
85         }else{
86             printf("haptic play success\n");
87         }
88
89         if(haptic_vibrate_file(count, TEST_IVT, 1, HAPTIC_LEVEL_AUTO) < 0){
90             printf("haptic play fail\n");
91         }else{
92             printf("haptic play success\n");
93         }
94     }
95
96
97         g_main_loop_run(mainloop);
98         g_main_loop_unref(mainloop);
99
100         if(haptic_deinitialize() == HAPTIC_ERROR_NONE){
101                 printf("haptic device closed\n");
102         }else{
103                 printf("haptic_close fail\n");
104         }
105
106         return 0;
107 }