1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/*
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <string.h>
#include <svi.h>
#include <feedback.h>
#include <dlog.h>
#define MAX_PATH_LENGTH 256
#define NOT_ASSIGNED -1
static int _PTN_VIBE[] = {
SVI_VIB_TOUCH_TOUCH,
SVI_VIB_TOUCH_MULTI_TAP,
SVI_VIB_TOUCH_SIP,
SVI_VIB_TOUCH_HOLD,
SVI_VIB_TOUCH_HW_TAP,
SVI_VIB_TOUCH_HW_HOLD
};
static int _PTN_SND[] = {
SVI_SND_TOUCH_TOUCH1,
SVI_SND_TOUCH_MULTI_TAP,
SVI_SND_TOUCH_SIP,
SVI_SND_TOUCH_HOLD,
SVI_SND_TOUCH_HW_TAP,
SVI_SND_TOUCH_HW_HOLD
};
static int _TYPE[] = {
SVI_TYPE_SND,
SVI_TYPE_VIB
};
static int* _TYPE_PTN[] = {
_PTN_SND,
_PTN_VIBE
};
static int svi_handle = NOT_ASSIGNED;
int feedback_initialize()
{
int err;
if(svi_handle == NOT_ASSIGNED){
err = svi_init(&svi_handle);
if(err != SVI_SUCCESS){
svi_fini(svi_handle);
LOGE("[%s] Operation failed(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_OPERATION_FAILED);
return FEEDBACK_ERROR_OPERATION_FAILED;
}
}
return FEEDBACK_ERROR_NONE;
}
int feedback_deinitialize()
{
int err;
if(svi_handle != NOT_ASSIGNED){
err = svi_fini(svi_handle);
if(err != SVI_SUCCESS){
LOGE("[%s] Operation failed(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_OPERATION_FAILED);
return FEEDBACK_ERROR_OPERATION_FAILED;
}
svi_handle = NOT_ASSIGNED;
}
return FEEDBACK_ERROR_NONE;
}
int feedback_play(feedback_pattern_e pattern)
{
int err;
if(svi_handle == NOT_ASSIGNED){
LOGE("[%s] Not Initialized(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_NOT_INITIALIZED);
return FEEDBACK_ERROR_NOT_INITIALIZED;
}
if(pattern < FEEDBACK_PATTERN_TOUCH_TAP || pattern > FEEDBACK_PATTERN_HW_HOLD){
LOGE("[%s] Invalid parameter(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_INVALID_PARAMETER);
return FEEDBACK_ERROR_INVALID_PARAMETER;
}
err = svi_play(svi_handle, _PTN_VIBE[pattern], _PTN_SND[pattern]);
if(err != SVI_SUCCESS){
LOGE("[%s] Operation failed(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_OPERATION_FAILED);
return FEEDBACK_ERROR_OPERATION_FAILED;
}
return FEEDBACK_ERROR_NONE;
}
int feedback_play_type(feedback_type_e type, feedback_pattern_e pattern)
{
int err;
if(svi_handle == NOT_ASSIGNED){
LOGE("[%s] Not Initialized(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_NOT_INITIALIZED);
return FEEDBACK_ERROR_NOT_INITIALIZED;
}
if(pattern < FEEDBACK_PATTERN_TOUCH_TAP || pattern > FEEDBACK_PATTERN_HW_HOLD){
LOGE("[%s] Invalid parameter(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_INVALID_PARAMETER);
return FEEDBACK_ERROR_INVALID_PARAMETER;
}
switch(type) {
case FEEDBACK_TYPE_SOUND :
err = svi_play_sound(svi_handle, _PTN_SND[pattern]);
break;
case FEEDBACK_TYPE_VIBRATION :
err = svi_play_vib(svi_handle, _PTN_VIBE[pattern]);
break;
default :
LOGE("[%s] Invalid parameter(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_INVALID_PARAMETER);
return FEEDBACK_ERROR_INVALID_PARAMETER;
}
if(err != SVI_SUCCESS){
LOGE("[%s] Operation failed(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_OPERATION_FAILED);
return FEEDBACK_ERROR_OPERATION_FAILED;
}
return FEEDBACK_ERROR_NONE;
}
int feedback_get_resource_path(feedback_type_e type, feedback_pattern_e pattern, char** path)
{
int err;
char buf[MAX_PATH_LENGTH];
if(path == NULL){
LOGE("[%s] Invalid parameter(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_INVALID_PARAMETER);
return FEEDBACK_ERROR_INVALID_PARAMETER;
}
if(type < FEEDBACK_TYPE_SOUND || type > FEEDBACK_TYPE_VIBRATION){
LOGE("[%s] Invalid parameter(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_INVALID_PARAMETER);
return FEEDBACK_ERROR_INVALID_PARAMETER;
}
if(pattern < FEEDBACK_PATTERN_TOUCH_TAP || pattern > FEEDBACK_PATTERN_HW_HOLD){
LOGE("[%s] Invalid parameter(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_INVALID_PARAMETER);
return FEEDBACK_ERROR_INVALID_PARAMETER;
}
err = svi_get_path(_TYPE[type], _TYPE_PTN[type][pattern], buf, MAX_PATH_LENGTH);
if(err != SVI_SUCCESS){
LOGE("[%s] Operation failed(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_OPERATION_FAILED);
return FEEDBACK_ERROR_OPERATION_FAILED;
}
*path = strdup(buf);
return FEEDBACK_ERROR_NONE;
}
|