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