Import changes from tizen 2.2
[platform/core/system/devman.git] / SLP_devman_PG.h
1 /*
2  * devman
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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
18
19 /**
20  *
21  * @ingroup SLP_PG
22  * @defgroup SLP_PG_DEVMAN Device Manager
23  * @{
24
25 <h1 class="pg">Introduction</h1>
26
27 <h2 class="pg">Purpose</h2>
28 The purpose of this document is to describe how applications can use Device Manager APIs. This document gives programming guidelines to application engineers.
29
30 <h2 class="pg">Scope</h2>
31 The scope of this document is limited to Device Manager API usage.
32
33 <br>
34 <h1 class="pg">Device Manager Library Overview</h1>
35 <h2 class="pg">General Device Manager</h2>
36 Device Manager library is provided to control the device and to get data about several devices. You can get the data about battery, charger, display and so on.<br>
37 Devman library uses sysfs for interfaces with device drivers and kernel. sysfs is a virtual file system provided by Linux 2.6 or above. Please refer to the web site,
38 http://www.kernel.org/pub/linux/kernel/people/mochel/doc/papers/ols-2005/mochel.pdf for more information about sysfs.
39 The following figure shows the basic architecture of devman library
40
41 <h3 class="pg" align="center">Device Manager Architecture</h3>
42 @image html SLP_devman_PG_architecture.png
43 <br>
44 <h2 class="pg">Haptic Device Manager</h2>
45 <h3 class="pg" align="center">Haptic Vibration Functional Level Architecture</h3>
46 @image html SLP_devman_PG_haptic_architecture.png
47
48 The client side is available in the form of a shared library to all the processes, whereas the server is a daemon.
49 As shown in the diagram applications/middleware frameworks can have the haptic vibration client library in the process context.
50 <br><br>
51 The haptic vibration client is available in form of a shared library. This library has APIs which support various features.
52 These features are playing a rhythmical vibration pattern, playing a monotonous vibration pattern, etc.
53 Applications can call these APIs to give vibration feedback on any event. This could also be used to indicate any events or changes of a state to the user.
54 <br><br>
55 The server interacts with the device driver interfaces and generates vibration feedback.
56 <br><br>
57 <h3 class="pg">Haptic Vibration Features</h3>
58 <b>Haptic client features</b>
59 -#      Available in shared library form.<br>
60 -#      Provides set of APIs to play haptic vibration patterns.<br>
61 -#      Provide unique access control mechanism through client server architecture.<br>
62 -#      Provision to play rhythmical vibration patterns.<br>
63 -#      Provides functionality for application to play a different vibration pattern for a different event.<br>
64 -#      Provides support for user defined duration for monotone playing or iteration for pattern playing.<br>
65 -#      Provides immediate stop control over the vibrations played.<br><br>
66
67 <b>Haptic server features</b>
68 -#      The actual implementation of the functionality supported by haptic-vibration library has been implemented through haptic-server.<br>
69 -#      Haptic-server processes the vibration pattern's play/stop requests sent by application through the haptic client library.<br>
70 -#      There is an internal database maintained for different patterns and their specification.<br>
71 -#      When application requests a particular pattern, haptic server checks this database for the specification of that pattern.<br>
72 -#      After getting data from database, server sends these specific details to device driver which plays the pattern.<br>
73 -#      Server can maintain multiple requests at a time on a priority basis.<br><br>
74
75 <h1 class="pg">Device Manager Funtions</h1>
76
77 <h2 class="pg">General Device Manager APIs</h2>
78 <i><b>API : device_get_battery_pct</b></i><br>
79 <b>Parameter :</b> void<br>
80 <b>Return :</b> int<br>
81 <b>Functionality :</b> This API is used to get the remaining battery percentage. On success, integer value(0~100) that indicate remaining battery percentage is returned.
82 Or a negative value (-1) is returned on failure.
83 <br><br>
84 <i><b>API : device_is_battery_full</b></i><br>
85 <b>Parameter :</b> void<br>
86 <b>Return :</b> int <br>
87 <b>Functionality :</b> This API is used to get the fully charged status of battery. On fully charged, the integer value (1) is returned,
88 (0) is returned if battery is not fully charged, a negative value (-1) is returned on failure.
89 <br><br>
90 <i><b>API : device_get_display_brt</b></i>
91 <br><b>Parameter In :</b> display_num_t num
92 <br><b>Return :</b> int
93 <br><b>Functionality :</b> This API is used to get the current brightness of the display from sysfs.
94 The function returns the current brightness value on success and a negative value (-1) on failure.
95 <br><br>
96 <b>Enumerate values:</b>
97 @code
98 // Display number
99 typedef enum {
100         DEV_DISPLAY_0,
101         DEV_DISPLAY_1,
102         DEV_MAIN_DISPLAY        = DEV_DISPLAY_0,
103 } display_num_t;
104 @endcode
105
106 <i><b>API : device_set_display_brt</b></i>
107 <br><b>Parameter In :</b> display_num_t num
108 <br><b>Parameter In :</b> int val
109 <br><b>Return :</b> int
110 <br><b>Functionality :</b> This API is used to set the current brightness of the display using sysfs.
111 The parameter val should be set as a brightnesss value of your target.
112 The function returns the current brightness value on success and a negative value (-1) on failure.
113 <br><br>
114 <i><b>API : device_get_display_gamma</b></i>
115 <br></b>Parameter In :</b> display_num_t num
116 <br><b>Return :</b> int
117 <br><b>Functionality :</b> This API is used to get the current gamma value of the display from sysfs.
118 The function returns the current brightness value on success and a negative value (-1) on failure.
119 <br><br>
120 <i><b>API : device_set_display_brt</b></i>
121 <br><b>Parameter In :</b> display_num_t num
122 <br><b>Parameter In :</b> int val
123 <br><b>Return :</b> int
124 <br><b>Functionality :</b> This API is used to set the current brightness of the display using sysfs.
125 The parameter val should be set as a brightnesss value of your target.
126 The function returns the current brightness value on success and a negative value (-1) on failure.
127 <br><br>
128 <i><b>API : device_get_display_gamma</b></i>
129 <br><b>Parameter In :</b> display_num_t num
130 <br><b>Return :</b> int
131 <br><b>Functionality :</b> This API is used to get the current gamma value of the display from sysfs.
132 The function returns the current brightness value on success and a negative value (-1) on failure.
133 <b>Enumerate values:</b>
134 @code
135 // LCD gamma values
136 typedef enum {
137         LCD_GAMMA_22 = 1,            // 8500K , 2.2 GAMMA
138         LCD_GAMMA_19 = 2,            // 8500K , 1.9 GAMMA
139         LCD_GAMMA_17 = 3,            // 8500K , 1.7 GAMMA
140         LCD_GAMMA_NORMAL =      LCD_GAMMA_22, // Normal screen
141         LCD_GAMMA_PLAY_RECORD = LCD_GAMMA_19, // Playing or recording cam
142         LCD_GAMMA_PREVIEW =     LCD_GAMMA_17, // Preview
143         LCD_GAMMA_MOVIE =       LCD_GAMMA_19, // Movie
144         LCD_GAMMA_CAMERA =      11,               // Camera
145 } display_gamma_t;
146 @endcode
147
148 <i><b>API : device_power_suspend</b></i>
149 <br><b>Parameter :</b> void
150 <br><b>Return :</b> int
151 <br><b>Functionality :</b> This API is used to make the phone go to a suspend (sleep) state.
152 The suspend state consumes little battery power. If the caller process does not have the permission which is root, it returns failure.
153 The function returns 0 on success and a negative value (-1) on failure.
154 <br><br>
155 <i><b>API : device_get_property</b></i>
156 <br><b>Parameter In :</b> devtype_t devtype
157 <br><b>Parameter In :</b> int property
158 <br><b>Parameter Out :</b>  int *value
159 <br><b>Return :</b> int
160 <br><b>Functionality :</b>This generic API is used to get the property values of supported devices.
161 If the caller process does not have permission, it returns failure.
162 The function returns 0 on success and a negative value (-1) on failure.
163 <br><br>
164 <i><b>API : device_set_property</b></i>
165 <br><b>Parameter In :</b> devtype_t devtype
166 <br><b>Parameter In :</b> int property
167 <br><b>Parameter In :</b> int value
168 <br><b>Return :</b> int
169 <br><b>Functionality :</b>This generic API is used to set the property values of supported devices.
170 If the caller process does not have permission, it returns failure.
171 The function returns 0 on success and a negative value (-1) on failure.
172
173 <h2 class="pg">Haptic Device Manager APIs</h2>
174 <i><b>API : device_haptic_open</b></i>
175 <br><b>Parameter In :</b> haptic_dev_idx dev_idx , unsigned int mode
176 <br><b>Return :</b> int
177 <br><b>Functionality :</b> This API opens a Haptic-vibration device. On success it returns a dev_handle value.
178 In case of failure it returns a negative value. If the device is already open it returns (-1). <br>
179 The first in parameter dev_idx should be from a predefined haptic-device-index which is available in the typedef enum haptic_dev_idx.
180 The DEV_IDX_0 means first haptic-device-index of target , the DEV_IDX_1 means second haptic-device-index of target and the DEV_IDX_ALL means both of them.
181 The availability of the dev_idx value is dependent on the real target. Normally, set a DEV_IDX_0 value to the first haptic-device.<br>
182 The second in parameter mode is reserved for future so just set a 0 value<br>
183 <b>Note:</b> The device_haptic_open() must be called before all other haptic APIs are called.
184 The device_haptic_open() should have a matching call to device_haptic_close().
185 Applications call the device_haptic_open() only once if possible during application startup and call the device_haptic_close() during application shutdown.
186
187 <b>Enumerate values:</b>
188 @code
189 //Haptic_dev_idx ;
190 typedef enum haptic_dev_idx_t {
191         DEV_IDX_0               =       0x01,
192         DEV_IDX_1               =       0x02,
193         DEV_IDX_ALL            =        0x04,
194 };
195 @endcode
196
197 <i><b>API : device_haptic_close</b></i>
198 <br><b>Parameter In :</b> int dev_handle
199 <br><b>Parameter Return :</b> int
200 <br><b>Functionality :</b> This API closes a Haptic-vibration device. On success it returns a zero value.
201 In case of failure it returns a negative value. If the device is already closed it returns (-1).  <br>
202 The first in parameter dev_handle should be from the return value of device_haptic_open().
203 <br><br>
204 <i><b>API : device_haptic_play_pattern</b></i>
205 <br><b>Parameter In :</b> int dev_handle , int pattern , int iteration , int feedback_level
206 <br><b>Parameter Return :</b> int
207 <br><b>Functionality :</b> This API plays a predefined rhythmic haptic-vibration pattern. <br>
208 The first in parameter dev_handle should be from the return value of device_haptic_open().<br>
209 The second in parameter pattern should be from a predefined pattern list which is available in an enumeration (effectvibe_pattern_list).
210 These patterns are rhythmic vibration patterns. <br>
211 The third in parameter iteration sets the number of iterations to be played. This should be less than the maximum iteration range set for the device (currently its 255).  <br>
212 The fourth in parameter is the vibration feedback intensity level. This level is already predefined by enumeration type value from HAPTIC _FEEDBACK_LEVEL_1
213 to HAPTIC _FEEDBACK_LEVEL_5. If you want to use the value selected by the user in the Setting application menu, just set -1 value.<br>
214 On success it returns a zero value. In case of failure it returns a negative value. <br>
215 <b>Note:</b> The actual behavior of the feedback play pattern and the intensity depends on the target hardware.
216
217 <b>Enumerate values:</b>
218 @code
219 //Effectvibe_pattern_list
220 enum effectvibe_pattern_list {
221         EFFCTVIBE_TOUCH = 0,
222         EFFCTVIBE_HW_TOUCH,
223         EFFCTVIBE_NOTIFICATION,
224         EFFCTVIBE_INCOMING_CALL01,
225         EFFCTVIBE_INCOMING_CALL02,
226         EFFCTVIBE_INCOMONG_CALL03,
227         EFFCTVIBE_ALERTS_CALL,
228         EFFCTVIBE_OPERATION,
229         EFFCTVIBE_SILENT_MODE,
230         EFFCTVIBE_PATTERN_END
231 };
232
233 //Feedback Level ;
234 enum {
235         HAPTIC_FEEDBACK_LEVEL_AUTO = -1,
236         HAPTIC_FEEDBACK_LEVEL_1 = 1,
237         HAPTIC_FEEDBACK_LEVEL_2 = 2,
238         HAPTIC_FEEDBACK_LEVEL_3 = 3,
239         HAPTIC_FEEDBACK_LEVEL_4 = 4,
240         HAPTIC_FEEDBACK_LEVEL_5 = 5,
241 };
242
243 //definition for infinite iteration ;
244 #define HAPTIC_INFINITE_ITERATION       256
245 @endcode
246
247 <i><b>API : device_haptic_play_file</b></i>
248 <br><b>Parameter In :</b> int dev_handle , const char *file_name , int iteration , int feedback_level
249 <br><b>Parameter Return :</b> int
250 <br><b>Functionality :</b>This API plays a predefined rhythmic haptic-vibration pattern file (only supports .ivt type file, Immersion VibeTonz).<br>
251 The first in parameter dev_handle should be from the return value of device_haptic_open().<br>
252 The second in parameter file_name sets rhythmic vibration pattern file with path. It only supports .ivt type pattern file. <br>
253 The third in parameter iteration sets the number of iterations to be played. This should be less than the maximum iteration range set for the device (currently its 255).
254 If you want to play indefinitely, use HAPTIC_INFINITE_ITERATION defined value. But it depends on the target hardware.<br>
255 The fourth in parameter is the vibration feedback intensity level. This level is already predefined by enumeration type value from HAPTIC _FEEDBACK_LEVEL_1
256 to HAPTIC _FEEDBACK_LEVEL_5. If you want to use the value selected by the user in the Setting application menu, just set HAPTIC_FEEDBACK_LEVEL_AUTO value.
257 (But the application must have a main loop to use the HAPTIC_FEEDBACK_LEVEL_AUTO value ) <br>
258 On success it returns a zero value. In case of failure it returns a negative value. <br>
259 <b>Note:</b> The actual behavior of the feedback play pattern and the intensity depends on the target hardware.
260 <br><br>
261 <i><b>API : device_haptic_play_monotone</b></i>
262 <br><b>Parameter In :</b> int dev_handle ,  int duration
263 <br><b>Parameter Return :</b> int
264 <br><b>Functionality :</b>This API plays a monotonous haptic-vibration pattern with a constant intensity.
265 In this monotone play, the intensity used is the value that the user has selected in the Setting application menu.<br>
266 The first in parameter dev_handle should be from the return value of device_haptic_open().<br>
267 The second in parameter duration defines the length of time this vibration should be played. This duration is in milliseconds.  <br>
268 On success it returns a zero value. In case of failure it returns a negative value. <br>
269 <b>Note:</b> The actual behavior of the feedback played and the intensity depends on the target hardware.
270 <br><br>
271 <i><b>API : device_haptic_stop_play</b></i>
272 <br><b>Parameter In :</b> int dev_handle
273 <br><b>Parameter Return :</b> int
274 <br><b>Functionality :</b> This API stops the current vibration being played.<br>
275 The first in parameter dev_handle should be from the return value of device_haptic_open().<br>
276 On success it returns a zero value. In case of failure it returns a negative value.
277 <br><br>
278 <i><b>API : device_haptic_get_pattern_duration</b></i>
279 <br><b>Parameter In :</b> int dev_handle ,  int pattern
280 <br><b>Parameter Out :</b> int *duration
281 <br><b>Parameter Return :</b> int
282 <br><b>Functionality :</b>This API gets a duration time value from a predefined rhythmic vibration pattern.<br>
283 The first in parameter dev_handle should be from the return value of device_haptic_open().<br>
284 The second in parameter pattern should be from a predefined pattern list which is available in an enumeration (effectvibe_pattern_list).<br>
285 The application can get a duration time value from the third out parameter duration when this API succeeds. The unit of duration is ms (millisecond)<br>
286 On success it returns a zero value. In case of failure it returns a negative value. <br>
287 <b>Note:</b> The actual behavior of the feedback played and the intensity depends on the target hardware.
288 <br><br>
289 <i><b>API : device_haptic_get_file_duration</b></i>
290 <br><b>Parameter In :</b> int dev_handle ,  const char *file_name
291 <br><b>Parameter Out :</b> int *duration
292 <br><b>Parameter Return :</b> int
293 <br><b>Functionality :</b>This API gets a duration time value from a predefined rhythmic vibration pattern file (only supports .ivt type file).<br>
294 The first in parameter dev_handle should be from the return value of device_haptic_open().<br>
295 The second in parameter file_name sets rhythmic vibration pattern file with path. It only supports .ivt type pattern file.<br>
296 The application can get a duration time value from the third out parameter duration when this API succeeds. The unit of duration is ms (millisecond)<br>
297 On success it returns a zero value. In case of failure it returns a negative value. <br>
298 <b>Note:</b>The actual behavior of the feedback played and the intensity depends on the target hardware.<br>
299
300 <br><b>Sample Code <Simple program showing how to use haptic-vibration APIs></b>
301 @code
302 #include <stdio.h>
303 #include <devman_haptic.h>
304 #define HAPTIC_TEST_ITERATION 10
305
306 int main()
307 {
308         int ret_val=0;
309         int dev_handle;
310
311         printf("\n Haptic vibration test : Start of the program \n");
312
313         //Open the haptic device
314         dev_handle = device_haptic_open(DEV_IDX_0,0);
315         if(dev_handle < 0)
316                 return -1;
317
318         //Play a rhythmic pattern
319         ret_val = device_haptic_play_pattern(dev_handle, EFFCTVIBE_NOTIFICATION,
320                         HAPTIC_TEST_ITERATION , HAPTIC_FEEDBACK_LEVEL_3);
321         if(ret_val !=0)
322                 return -1;
323
324         //Play a monotone pattern for 1s == 1000ms
325         ret_val = device_haptic_play_monotone(dev_handle, 1000);
326         if(ret_val !=0)
327                 return -1;
328
329         //Demo for a stop pattern API, playing a monotone for 10s
330         ret_val = device_haptic_play_monotone(dev_handle, 10000);
331         if(ret_val !=0)
332                 return -1;
333
334         sleep(1);
335
336         //Stop the pattern immediately
337         ret_val = device_haptic_stop_play(dev_handle);
338         if(ret_val !=0)
339                 return -1;
340
341         //Close the device
342         ret_val = device_haptic_close(dev_handle);
343         if(ret_val !=0)
344                 return -1;
345 }
346 @endcode
347
348  @}
349 **/