patch tizen_2.0_build
[framework/api/haptic.git] / test / test_lock.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         if(haptic_deinitialize() == HAPTIC_ERROR_NONE){
18                 printf("haptic device closed\n");
19         }else{
20                 printf("haptic_close fail\n");
21         }
22 }
23
24 static gboolean play_ptn(gpointer data)
25 {
26     haptic_vibration_iter_s ptn[] = {
27         {0, HAPTIC_LEVEL_5, 1000},
28         {0, HAPTIC_LEVEL_1, 1000},
29         {0, HAPTIC_LEVEL_1, 1000},
30         {0, HAPTIC_LEVEL_5, 1000},
31         {0, HAPTIC_LEVEL_1, 1000},
32         {0, HAPTIC_LEVEL_1, 1000},
33         {0, HAPTIC_LEVEL_5, 1000},
34     };
35
36     if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){
37         printf("haptic play fail\n");
38     }else{
39         printf("haptic play success\n");
40     }
41
42     return false;
43 }
44
45 static gboolean stop_play(gpointer data)
46 {
47     int err;
48     int id = (int)data;
49
50     printf("-- stop!! [%d]\n", id);
51     err = haptic_stop_pattern(id);
52     if(err < 0){
53         printf("-- error!! when stop play!!\n");
54     }
55
56     return false;
57 }
58 static gboolean stop_and_play(gpointer data)
59 {
60     int err;
61     int id = (int)data;
62
63     printf("-- stop!! [%d]\n", id);
64     err = haptic_stop_pattern(id);
65     if(err < 0){
66         printf("-- error!! when stop play!!\n");
67     }
68
69 //    g_timeout_add(6000, play_ptn, NULL);
70     g_timeout_add(10000, play_ptn, NULL);
71
72     return false;
73 }
74
75 static gboolean stop_device(gpointer data)
76 {
77     haptic_stop_device(0);
78
79     return false;
80 }
81
82 int main(int argc, char *argv[])
83 {
84     haptic_vibration_iter_s ptn[] = {
85         {0, HAPTIC_LEVEL_1, 3000},
86         {0, HAPTIC_LEVEL_0, 10},
87         {0, HAPTIC_LEVEL_3, 2000},
88         {0, HAPTIC_LEVEL_0, 10},
89         {0, HAPTIC_LEVEL_5, 1000},
90         {0, HAPTIC_LEVEL_0, 10},
91         {0, HAPTIC_LEVEL_2, 3000},
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_initialize() == HAPTIC_ERROR_NONE){
101                 printf("haptic device opened\n");
102         }else{
103                 printf("haptic_open fail\n");
104         }
105     if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){
106         printf("haptic play fail\n");
107     }else{
108         printf("haptic play success\n");
109     }
110         if(haptic_deinitialize() == HAPTIC_ERROR_NONE){
111                 printf("haptic device closed\n");
112         }else{
113                 printf("haptic_close fail\n");
114         }
115         if(haptic_initialize() == HAPTIC_ERROR_NONE){
116                 printf("haptic device opened\n");
117         }else{
118                 printf("haptic_open fail\n");
119         }
120     if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){
121         printf("haptic play fail\n");
122     }else{
123         printf("haptic play success\n");
124     }
125         if(haptic_deinitialize() == HAPTIC_ERROR_NONE){
126                 printf("haptic device closed\n");
127         }else{
128                 printf("haptic_close fail\n");
129         }
130
131
132         g_main_loop_run(mainloop);
133         g_main_loop_unref(mainloop);
134
135         return 0;
136 }