7 static GMainLoop *mainloop;
10 static void sig_quit(int signo)
14 g_main_loop_quit(mainloop);
18 static gboolean play_ptn(gpointer data)
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},
30 if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){
31 printf("haptic play fail\n");
33 printf("haptic play success\n");
39 static gboolean stop_play(gpointer data)
44 printf("-- stop!! [%d]\n", id);
45 err = haptic_stop_pattern(id);
47 printf("-- error!! when stop play!!\n");
52 static gboolean stop_and_play(gpointer data)
57 printf("-- stop!! [%d]\n", id);
58 err = haptic_stop_pattern(id);
60 printf("-- error!! when stop play!!\n");
63 // g_timeout_add(6000, play_ptn, NULL);
64 g_timeout_add(10000, play_ptn, NULL);
69 static gboolean stop_device(gpointer data)
71 haptic_stop_device(0);
76 int main(int argc, char *argv[])
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},
88 if(haptic_initialize() == HAPTIC_ERROR_NONE){
89 printf("haptic device opened\n");
91 printf("haptic_open fail\n");
94 signal(SIGINT, sig_quit);
95 signal(SIGTERM, sig_quit);
96 signal(SIGQUIT, sig_quit);
98 mainloop = g_main_loop_new(NULL, FALSE);
100 if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){
101 printf("haptic play fail\n");
103 printf("haptic play success\n");
105 g_timeout_add(4000, stop_play, (gpointer)ptn_id);
107 if(haptic_play_pattern(ptn, 7, 2, 0, &ptn_id) < 0){
108 printf("haptic play fail\n");
110 printf("haptic play success\n");
112 g_timeout_add(2000, stop_play, (gpointer)ptn_id);
114 if(haptic_play_pattern(ptn, 7, 1, 0, &ptn_id) < 0){
115 printf("haptic play fail\n");
117 printf("haptic play success\n");
119 g_timeout_add(7000, stop_play, (gpointer)ptn_id);
121 if(haptic_play_pattern(ptn, 7, 3, 0, &ptn_id) < 0){
122 printf("haptic play fail\n");
124 printf("haptic play success\n");
126 g_timeout_add(10, stop_and_play, (gpointer)ptn_id);
129 g_timeout_add(4000, stop_device, NULL);
132 g_main_loop_run(mainloop);
133 g_main_loop_unref(mainloop);
135 if(haptic_deinitialize() == HAPTIC_ERROR_NONE){
136 printf("haptic device closed\n");
138 printf("haptic_close fail\n");