Merge "Add function to generate description from nested object hierarchy" into tizen
[profile/tv/apps/native/screen-reader.git] / src / screen_reader_haptic.c
1 #include <device/haptic.h>
2 #include "logger.h"
3 #include "smart_notification.h"
4
5 static haptic_device_h handle;
6 static haptic_effect_h effect_handle;
7
8 #define RED  "\x1B[31m"
9 #define RESET "\033[0m"
10
11 /**
12  * @brief Initializer for haptic module
13  *
14  */
15 void haptic_module_init(void)
16 {
17     int num;
18
19     if(!device_haptic_get_count(&num))
20       {
21          DEBUG(RED"Haptic device received!"RESET);
22       }
23     else
24       {
25          ERROR("Cannot receive haptic device count");
26          return;
27       }
28
29     if(!device_haptic_open(0, &handle))
30       {
31          DEBUG(RED"Device connected!"RESET);
32       }
33     else
34       {
35          ERROR("Cannot open haptic device");
36       }
37 }
38
39 /**
40  * @brief Disconnect haptic handle
41  *
42  */
43 void haptic_module_disconnect(void)
44 {
45     if(!handle)
46       {
47          ERROR("Haptic handle lost");
48          return;
49       }
50     if(!device_haptic_close(handle))
51       {
52          DEBUG("Haptic disconnected");
53       }
54     else
55       {
56          ERROR("Haptic close error");
57       }
58 }
59
60 /**
61  * @brief Start vibrations
62  *
63  */
64 void haptic_vibrate_start(void)
65 {
66     if(!handle)
67       {
68          ERROR("Haptic handle lost");
69          return;
70       }
71     if(!device_haptic_vibrate(handle, 1000, 100, &effect_handle))
72       {
73          DEBUG(RED"Vibrations started!"RESET);
74       }
75     else
76       {
77          ERROR("Cannot start vibration");
78       }
79 }
80
81 /**
82  * @brief Stop vibrations
83  *
84  */
85 void haptic_vibrate_stop(void)
86 {
87     if(!handle)
88       {
89          ERROR("Haptic handle lost");
90          return;
91       }
92     if(!device_haptic_stop(handle, &effect_handle))
93       {
94          ERROR("Vibrations stopped!");
95       }
96     else
97       {
98          DEBUG(RED"Cannot stop vibration"RESET);
99       }
100 }