mobile-lua: add additional LABELLED_BY relation
[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  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <device/haptic.h>
18 #include "logger.h"
19 #include "smart_notification.h"
20
21 static haptic_device_h handle;
22 static haptic_effect_h effect_handle;
23
24 #define RED  "\x1B[31m"
25 #define RESET "\033[0m"
26
27 /**
28  * @brief Initializer for haptic module
29  *
30  */
31 void haptic_module_init(void)
32 {
33         int num;
34
35         if (!device_haptic_get_count(&num)) {
36                 DEBUG(RED "Haptic device received!" RESET);
37         } else {
38                 ERROR("Cannot receive haptic device count");
39                 return;
40         }
41
42         if (!device_haptic_open(0, &handle)) {
43                 DEBUG(RED "Device connected!" RESET);
44         } else {
45                 ERROR("Cannot open haptic device");
46         }
47 }
48
49 /**
50  * @brief Disconnect haptic handle
51  *
52  */
53 void haptic_module_disconnect(void)
54 {
55         if (!handle) {
56                 ERROR("Haptic handle lost");
57                 return;
58         }
59         if (!device_haptic_close(handle)) {
60                 DEBUG("Haptic disconnected");
61         } else {
62                 ERROR("Haptic close error");
63         }
64 }
65
66 /**
67  * @brief Start vibrations
68  *
69  */
70 void haptic_vibrate_start(void)
71 {
72         if (!handle) {
73                 ERROR("Haptic handle lost");
74                 return;
75         }
76         if (!device_haptic_vibrate(handle, 1000, 100, &effect_handle)) {
77                 DEBUG(RED "Vibrations started!" RESET);
78         } else {
79                 ERROR("Cannot start vibration");
80         }
81 }
82
83 /**
84  * @brief Stop vibrations
85  *
86  */
87 void haptic_vibrate_stop(void)
88 {
89         if (!handle) {
90                 ERROR("Haptic handle lost");
91                 return;
92         }
93         if (!device_haptic_stop(handle, &effect_handle)) {
94                 ERROR("Vibrations stopped!");
95         } else {
96                 DEBUG(RED "Cannot stop vibration" RESET);
97         }
98 }