patch tizen_2.0_build
[framework/api/haptic.git] / test / system-haptic.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 static GMainLoop *mainloop;
26 static int ptn_id;
27
28 static void sig_quit(int signo)
29 {
30         if(mainloop)
31         {
32                 g_main_loop_quit(mainloop);
33         }
34 }
35
36 static gboolean play_ptn(gpointer data)
37 {
38     haptic_vibration_iter_s ptn[] = {
39         {0, HAPTIC_LEVEL_5, 1000},
40         {0, HAPTIC_LEVEL_1, 1000},
41         {0, HAPTIC_LEVEL_1, 1000},
42         {0, HAPTIC_LEVEL_5, 1000},
43         {0, HAPTIC_LEVEL_1, 1000},
44         {0, HAPTIC_LEVEL_1, 1000},
45         {0, HAPTIC_LEVEL_5, 1000},
46     };
47
48     if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){
49         printf("haptic play fail\n");
50     }else{
51         printf("haptic play success\n");
52     }
53
54     return false;
55 }
56
57 static gboolean stop_play(gpointer data)
58 {
59     int err;
60     int id = (int)data;
61
62     printf("-- stop!! [%d]\n", id);
63     err = haptic_stop_pattern(id);
64     if(err < 0){
65         printf("-- error!! when stop play!!\n");
66     }
67
68     return false;
69 }
70 static gboolean stop_and_play(gpointer data)
71 {
72     int err;
73     int id = (int)data;
74
75     printf("-- stop!! [%d]\n", id);
76     err = haptic_stop_pattern(id);
77     if(err < 0){
78         printf("-- error!! when stop play!!\n");
79     }
80
81 //    g_timeout_add(6000, play_ptn, NULL);
82     g_timeout_add(10000, play_ptn, NULL);
83
84     return false;
85 }
86
87 static gboolean stop_device(gpointer data)
88 {
89     haptic_stop_device(0);
90
91     return false;
92 }
93
94 int main(int argc, char *argv[])
95 {
96     haptic_vibration_iter_s ptn[] = {
97         {0, HAPTIC_LEVEL_1, 3000},
98         {0, HAPTIC_LEVEL_0, 10},
99         {0, HAPTIC_LEVEL_3, 2000},
100         {0, HAPTIC_LEVEL_0, 10},
101         {0, HAPTIC_LEVEL_5, 1000},
102         {0, HAPTIC_LEVEL_0, 10},
103         {0, HAPTIC_LEVEL_2, 3000},
104     };
105
106         if(haptic_initialize() == HAPTIC_ERROR_NONE){
107                 printf("haptic device opened\n");
108         }else{
109                 printf("haptic_open fail\n");
110         }
111
112         signal(SIGINT, sig_quit);
113         signal(SIGTERM, sig_quit);
114         signal(SIGQUIT, sig_quit);
115
116         mainloop = g_main_loop_new(NULL, FALSE);
117
118     if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){
119         printf("haptic play fail\n");
120     }else{
121         printf("haptic play success\n");
122     }
123     g_timeout_add(4000, stop_play, (gpointer)ptn_id);
124
125     if(haptic_play_pattern(ptn, 7, 2, 0, &ptn_id) < 0){
126         printf("haptic play fail\n");
127     }else{
128         printf("haptic play success\n");
129     }
130     g_timeout_add(2000, stop_play, (gpointer)ptn_id);
131
132     if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){
133         printf("haptic play fail\n");
134     }else{
135         printf("haptic play success\n");
136     }
137     g_timeout_add(7000, stop_play, (gpointer)ptn_id);
138
139     if(haptic_play_pattern(ptn, 7, 3, 0, &ptn_id) < 0){
140         printf("haptic play fail\n");
141     }else{
142         printf("haptic play success\n");
143     }
144     g_timeout_add(10, stop_and_play, (gpointer)ptn_id);
145
146
147     g_timeout_add(4000, stop_device, NULL);
148
149
150         g_main_loop_run(mainloop);
151         g_main_loop_unref(mainloop);
152
153         if(haptic_deinitialize() == HAPTIC_ERROR_NONE){
154                 printf("haptic device closed\n");
155         }else{
156                 printf("haptic_close fail\n");
157         }
158
159         return 0;
160 }