[LICENSE] change to Flora-1.1 license
[profile/tv/apps/native/screen-reader.git] / src / screen_reader_haptic.c
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * This file is a modified version of BSD licensed file and
5  * licensed under the Flora License, Version 1.1 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * Please, see the LICENSE file for the original copyright owner and
18  * license.
19  */
20
21 #include <device/haptic.h>
22 #include "logger.h"
23 #include "smart_notification.h"
24
25 static haptic_device_h handle;
26 static haptic_effect_h effect_handle;
27
28 #define RED  "\x1B[31m"
29 #define RESET "\033[0m"
30
31 /**
32  * @brief Initializer for haptic module
33  *
34  */
35 void haptic_module_init(void)
36 {
37    int num;
38
39    if(!device_haptic_get_count(&num))
40       {
41          DEBUG(RED"Haptic device received!"RESET);
42       }
43    else
44       {
45          ERROR("Cannot receive haptic device count");
46          return;
47       }
48
49    if(!device_haptic_open(0, &handle))
50       {
51          DEBUG(RED"Device connected!"RESET);
52       }
53    else
54       {
55          ERROR("Cannot open haptic device");
56       }
57 }
58
59 /**
60  * @brief Disconnect haptic handle
61  *
62  */
63 void haptic_module_disconnect(void)
64 {
65    if(!handle)
66       {
67          ERROR("Haptic handle lost");
68          return;
69       }
70    if(!device_haptic_close(handle))
71       {
72          DEBUG("Haptic disconnected");
73       }
74    else
75       {
76          ERROR("Haptic close error");
77       }
78 }
79
80 /**
81  * @brief Start vibrations
82  *
83  */
84 void haptic_vibrate_start(void)
85 {
86    if(!handle)
87       {
88          ERROR("Haptic handle lost");
89          return;
90       }
91    if(!device_haptic_vibrate(handle, 1000, 100, &effect_handle))
92       {
93          DEBUG(RED"Vibrations started!"RESET);
94       }
95    else
96       {
97          ERROR("Cannot start vibration");
98       }
99 }
100
101 /**
102  * @brief Stop vibrations
103  *
104  */
105 void haptic_vibrate_stop(void)
106 {
107    if(!handle)
108       {
109          ERROR("Haptic handle lost");
110          return;
111       }
112    if(!device_haptic_stop(handle, &effect_handle))
113       {
114          ERROR("Vibrations stopped!");
115       }
116    else
117       {
118          DEBUG(RED"Cannot stop vibration"RESET);
119       }
120 }