summaryrefslogtreecommitdiff
path: root/include/sensor.h
blob: 9f57e43cc57541cb3147c0b7f03f360f8f92df5c (plain)
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/*
 *  libslp-sensor
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: JuHyun Kim <jh8212.kim@samsung.com>
 * 
 * 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.
 *
 */ 



#ifndef __SAMSUNG_LINUX_SENSOR_COMMON_H__
#define __SAMSUNG_LINUX_SENSOR_COMMON_H__

#ifndef DEPRECATED
#define DEPRECATED __attribute__((deprecated))
#endif

#ifdef __cplusplus
extern "C"
{
#endif

#include <sys/types.h>

/**
 * @defgroup SENSOR_FRAMEWORK SensorFW
 * To support the unified API for the various sensors
 */

/**
 * @defgroup SENSOR_FRAMEWORK_COMMON Sensor Framework Common API
 * @ingroup SENSOR_FRAMEWORK
 * 
 * These APIs are used to control the sensors.
 * @{
 */

/**
 * @file sensor.h
 * @brief   Sensor Framework common API header file
 *      for supporting application layer and communicate between App and Sensor Framework
 *      server.
 *
 * @author  JuHyun Kim(jh8212.kim@samsung.com)
 * @version 1.0
*/


typedef enum {
	UNKNOWN_SENSOR				= 0x0000,
	ACCELEROMETER_SENSOR		= 0x0001,	
	GEOMAGNETIC_SENSOR			= 0x0002,
	LIGHT_SENSOR				= 0x0004,	
	PROXIMITY_SENSOR			= 0x0008,
	THERMOMETER_SENSOR			= 0x0010,
	GYROSCOPE_SENSOR			= 0x0020,	
	BAROMETER_SENSOR			= 0x0040,
	MOTION_SENSOR 				= 0x0080,
	FUSION_SENSOR 				= 0x0100,
} sensor_type_t;

/*header for each sensor type*/
#include <sensor_accel.h>
#include <sensor_geomag.h>
#include <sensor_light.h>
#include <sensor_proxi.h>
#include <sensor_motion.h>
#include <sensor_gyro.h>
#include <sensor_barometer.h>
#include <sensor_fusion.h>

#define MAX_KEY_LEN 64
#define MAX_VALUE_SIZE 12

typedef enum {
	CONDITION_NO_OP,
	CONDITION_EQUAL,
	CONDITION_GREAT_THAN,
	CONDITION_LESS_THAN,	
} condition_op_t;

typedef struct {
	condition_op_t cond_op;
	float cond_value1;
} event_condition_t;


typedef struct {
	size_t event_data_size;
	void *event_data;
} sensor_event_data_t;

typedef void (*sensor_callback_func_t)(unsigned int, sensor_event_data_t *, void *);  /**/

enum sensor_data_unit_idx {
	SENSOR_UNDEFINED_UNIT,
	SENSOR_UNIT_METRE_PER_SECOND_SQUARED,
	SENSOR_UNIT_MICRO_TESLA,
	SENSOR_UNIT_DEGREE,
	SENSOR_UNIT_LUX,
	SENSOR_UNIT_CENTIMETER,	
	SENSOR_UNIT_LEVEL_1_TO_10,
	SENSOR_UNIT_STATE_ON_OFF,
	SENSOR_UNIT_DEGREE_PER_SECOND,
	SENSOR_UNIT_IDX_END
};

enum sensor_data_accuracy {
	SENSOR_ACCURACY_UNDEFINED = -1,
	SENSOR_ACCURACY_BAD = 0,
	SENSOR_ACCURACY_NORMAL =1,
	SENSOR_ACCURACY_GOOD = 2,
	SENSOR_ACCURACY_VERYGOOD = 3
};

enum sensor_start_option {
	SENSOR_OPTION_DEFAULT = 0,
	SENSOR_OPTION_ALWAYS_ON = 1,
};

typedef struct {
	int data_accuracy;
	int data_unit_idx;
	unsigned long long time_stamp;
	int values_num;
	float values[MAX_VALUE_SIZE];
} sensor_data_t;

typedef struct {
	int x;
	int y;
} sensor_panning_data_t;


typedef struct {
	int sensor_unit_idx;
	float sensor_min_range;
	float sensor_max_range;
	float sensor_resolution;
	char sensor_name[MAX_KEY_LEN];
	char sensor_vendor[MAX_KEY_LEN];
} sensor_properties_t;

typedef struct {
	int sensor_unit_idx;
	float sensor_min_range;
	float sensor_max_range;
	float sensor_resolution;
} sensor_data_properties_t;


/**
 * @fn int sf_is_sensor_event_available ( sensor_type_t desired_sensor_type , unsigned int desired_event_type )
 * @brief This API loads the in parameter available list with the type of sensor available for operation . Some of the supported types are ACCELEROMETER_SENSOR_TYPE, GEOMAGNETIC_SENSOR_TYPE etc. This API will return 0 when it is available and negative value when it does not available.
 * @param[in] desired_sensor_type your desired sensor type to check
 * @param[in] desired_event_type your desired event type to check , if you want to check only sensor-available , set "0" value
 * @return if it succeed, it return zero value(available) , otherwise negative value return (not available)
 */
int sf_is_sensor_event_available ( sensor_type_t desired_sensor_type , unsigned int desired_event_type );

/**
 * @fn int sf_get_data_properties(unsigned data_id, sensor_dada_properties_t *return_data_properties)
 * @brief This API loads the properties of data ID like unit of sensor data, max/min range of sensor data etc to the output parameter sensor_data_properties.
 * @param[in] data_id your desired data ID
 * @param[out] return_data_properties property information of your desired data ID
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_get_data_properties(unsigned int data_id, sensor_data_properties_t *return_data_properties);

/**
 * @fn int sf_get_properties(sensor_type_t sensor_type, sensor_properties_t *return_properties)
 * @brief This API loads the properties of sensor type like unit of sensor data, max/min range of sensor data etc to the output parameter sensor_properties.
 * @param[in] sensor_type your desired sensor type
 * @param[out] return_properties property information of your desired sensor
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_get_properties(sensor_type_t sensor_type, sensor_properties_t *return_properties);


/**
 * @fn int sf_set_property(sensor_type_t sensor_type, unsigned int property_id, long value)
 * @brief This API set the property of sensor type like calibration, enable wakeup event, etc
 * @param[in] sensor_type your desired sensor type, property_id your desired property ID, value for property input
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_set_property(sensor_type_t sensor_type, unsigned int property_id, long value);


/**
 * @fn int sf_connect(sensor_type_t sensor_type)
 * @brief  This API connects a sensor type to respective sensor. The application calls with the type of the sensor (ex. ACCELEROMETER_SENSOR) and on basis of that server takes decision of which plug-in to be connected. Once sensor connected application can proceed for data processing. This API returns a positive handle which should be used by application to communicate on sensor type. 
 * @param[in] sensor_type your desired sensor type
 * @return if it succeed, it return handle value( >=0 ) , otherwise negative value return
 */
int sf_connect(sensor_type_t sensor_type);


/**
 * @fn int sf_disconnect(int handle)
 * @brief This API disconnects an attached sensor from an application. Application must use the handle retuned after attaching the sensor. After detaching, the corresponding handle will be released.
 * @param[in] handle received handle value by sf_connect()
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_disconnect(int handle);


/**
 * @fn int sf_start(int handle , int option)
 * @brief This API sends a start command to sensor server. This intimates server that the client side is ready to handle data and start processing. The parameter option should be '0' for current usages.
 * @param[in] handle received handle value by sf_connect()
 * @param[in] option With SENSOR_OPTION_DEFAULT, it stops to sense when LCD is off, and with SENSOR_OPTION_ALWAYS_ON, it continues to sense even when LCD is off
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_start(int handle , int option);


/**
 * @fn int sf_stop(int handle)
 * @brief This API sends a stop command to the Sensor server indicating that the data processing is stopped from application side for this time.
 * @param[in] handle received handle value by sf_connect()
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_stop(int handle);

/**
 * @fn int sf_register_event(int handle , unsigned int event_type , event_conditon_t *event_condition , sensor_callback_func_t cb , void *cb_data )
 * @brief This API registers a user defined callback function with a connected sensor for a particular event. This callback function will be called when there is a change in the state of respective sensor. cb_data will be the parameter used during the callback call. Callback interval can be adjusted using even_contion_t argument.
 * @param[in] handle received handle value by sf_connect()
 * @param[in] event_type your desired event_type to register it
 * @param[in] event_condition input event_condition for special event. if you want to register without event_condition, just use a NULL value
 * @param[in] cb your define callback function
 * @param[in] cb_data	your option data that will be send when your define callback function called. if you don't have any option data, just use a NULL value
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_register_event(int handle , unsigned int event_type , event_condition_t *event_condition , sensor_callback_func_t cb , void *cb_data );


/**
 * @fn int sf_unregister_event(int handle, unsigned int event_type)
 * @brief This API de-registers a user defined callback function with a sensor registered with the specified handle. After unsubscribe, no event will be sent to the application. 
 * @param[in] handle received handle value by sf_connect()
 * @param[in] event_type your desired event_type that you want to unregister event
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_unregister_event(int handle, unsigned int event_type);


/**
 * @fn int sf_get_data(int handle , unsigned int data_id , sensor_data_t* values)
 * @brief This API gets raw data from a sensor with connecting the sensor-server. The type of sensor is supplied and return data is stored in the output parameter values [].
 * @param[in] handle received handle value by sf_connect()
 * @param[in] data_id predefined data_ID as every sensor in own header - sensor_xxx.h , enum xxx_data_id {}
 * @param[out] values return values
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_get_data(int handle , unsigned int data_id , sensor_data_t* values);


/**
 * @fn int sf_check_rotation( unsigned long *curr_state)
 * @brief  This API used to get the current rotation state. (i.e. ROTATION_EVENT_0, ROTATION_EVENT_90, ROTATION_EVENT_180 & ROTATION_EVENT_270 ). This API will directly access the sensor without connection process with the sensor-server. Result will be stored in the output parameter state.
 * @param[out] curr_state it will return enum accelerometer_rotate_state value
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_check_rotation( unsigned long *curr_state);


/**
 * @fn int sf_set_wakeup(sensor_type_t sensor_type)
 * @brief  This API used to set wakeup AP.
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_set_wakeup(sensor_type_t sensor_type);


/**
 * @fn int sf_unset_wakeup(sensor_type_t sensor_type)
 * @brief  This API used to unset wakeup function.
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_unset_wakeup(sensor_type_t sensor_type);


/**
 * @fn int sf_is_wakeup_supported(void)
 * @brief  This API will return 0 when it is available and negative value when it does not available
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_is_wakeup_supported(sensor_type_t sensor_type);



/**
 * @fn int sf_is_wakeup_enabled(void)
 * @brief  This API check that wakeup is setted or unsetted
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_is_wakeup_enabled(sensor_type_t sensor_type);



/**
 * @fn int sf_change_event_condition(int handle, unsigned int event_type, event_condition_t *event_condition)
 * @brief This API change a user defined callback function condition with a sensor registered with the specified handle.
 * @param[in] handle received handle value by sf_connect()
 * @param[in] event_type your desired event_type that you want to unregister event
 * @param[in] event_condition your desired event condition that you want to change event
 * @return if it succeed, it return zero value , otherwise negative value return
 */
int sf_change_event_condition(int handle, unsigned int event_type, event_condition_t *event_condition);


/**
 * @fn int sf_change_sensor_option(int handle, int option)
 * @brief This API change sensor option .
 * @param[in] handle received handle value by sf_connect()
 * @param[in] option your desired option that you want to turn on sensor during LCD OFF
 * @return if it succeed, it return zero value , otherwise negative value return
 */

int sf_change_sensor_option(int handle, int option);
/**
  * @}
 */

#ifdef __cplusplus
}
#endif


#endif
//! End of a file