4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #ifndef __SENSOR_INTERNAL_H__
21 #define __SENSOR_INTERNAL_H__
24 #define API __attribute__((visibility("default")))
28 #include <sys/types.h>
30 /*header for common sensor type*/
31 #include <sensor_types.h>
32 #include <sensor_deprecated.h>
33 #include <sensor_internal_deprecated.h>
40 typedef void (*sensor_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data);
41 typedef void (*sensorhub_cb_t)(sensor_t sensor, unsigned int event_type, sensorhub_data_t *data, void *user_data);
42 typedef void (*sensor_accuracy_changed_cb_t) (sensor_t sensor, unsigned long long timestamp, int accuracy, void *user_data);
45 * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors.
47 * @param[in] type the type of sensors requested.
48 * @param[out] list the list of sensors matching the asked type, the caller should explicitly free this list.
49 * @param[out] sensor count the count of sensors contained in the list.
50 * @return true on success, otherwise false.
52 bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count);
55 * @brief Get the default sensor for a given type.
57 * @param[in] type the type of a sensor requested.
58 * @return the default sensor matching the asked type on success, otherwise NULL.
60 sensor_t sensord_get_sensor(sensor_type_t type);
63 * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors.
65 * @param[in] type the type of sensors requested.
66 * @param[out] list the list of sensors matching the asked type, the caller should explicitly free this list.
67 * @param[out] sensor count the count of sensors contained in the list.
68 * @return 0 on success, otherwise a negative error value
69 * @retval 0 Successful
70 * @retval -EPERM Operation not permitted
71 * @retval -EACCES Permission denied
72 * @retval -ENODATA NO sensor available
74 int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count);
77 * @brief Get the default sensor for a given type.
79 * @param[in] type the type of a sensor requested.
80 * @param[out] a sensor matching the asked type.
81 * @return 0 on success, otherwise a negative error value
82 * @retval 0 Successful
83 * @retval -EPERM Operation not permitted
84 * @retval -EACCES Permission denied
86 int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor);
89 * @brief Get the type of this sensor.
91 * @param[in] sensor a sensor to get type.
92 * @param[out] type the type of this sensor.
93 * @return return true on success, otherwise false.
95 bool sensord_get_type(sensor_t sensor, sensor_type_t *type);
98 * @brief Get the name string of this sensor.
100 * @param[in] sensor a sensor to get name.
101 * @return the name string of this sensor on success, otherwise NULL.
103 const char* sensord_get_name(sensor_t sensor);
106 * @brief Get the vendor string of this sensor.
108 * @param[in] sensor a sensor to get vendor.
109 * @return the vendor string of this sensor on success, otherwise NULL.
111 const char* sensord_get_vendor(sensor_t sensor);
114 * @brief Get the privilege of this sensor.
116 * @param[in] sensor a sensor to get privilege.
117 * @param[out] privilege the privilege of this sensor.
118 * @return true on success, otherwise false.
120 bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege);
123 * @brief Get the minimum range of this sensor in the sensor's unit.
125 * @param[in] sensor a sensor to get minimum range.
126 * @param[out] min_range the minimum range of this sensor in the sensor's unit.
127 * @return true on success, otherwise false.
129 bool sensord_get_min_range(sensor_t sensor, float *min_range);
132 * @brief Get the maximum range of this sensor in the sensor's unit.
134 * @param[in] sensor a sensor to get maximum range.
135 * @param[out] max_range the maximum range of this sensor in the sensor's unit.
136 * @return true on success, otherwise false.
138 bool sensord_get_max_range(sensor_t sensor, float *max_range);
141 * @brief Get the resolution of this sensor in the sensor's unit.
143 * @param[in] sensor a sensor to get resolution.
144 * @param[out] resolution the resolution of this sensor in the sensor's unit.
145 * @return true on success, otherwise false.
147 bool sensord_get_resolution(sensor_t sensor, float *resolution);
150 * @brief Get the minimum interval allowed between two events in microsecond or zero if this sensor only returns a value when the data it's measuring changes.
152 * @param[in] sensor a sensor to get minimum interval.
153 * @param[out] min_interval the minimum interval of this sensor.
154 * @return true on success, otherwise false.
156 bool sensord_get_min_interval(sensor_t sensor, int *min_interval);
159 * @brief Get the number of events reserved for this sensor in the batch mode FIFO.
161 * @param[in] sensor a sensor to get the number of fifo count
162 * @param[out] fifo_count the number of events reserved for this sensor in the batch mode FIFO
163 * @return true on success, otherwise false
165 bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count);
168 * @brief Get the maximum number of events of this sensor that could be batched. If this value is zero it indicates that batch mode is not supported for this sensor.
170 * @param[in] sensor a sensor to the maximum number of events that could be batched.
171 * @param[out] max_batch_count the maximum number of events of this sensor that could be batched.
172 * @return true on success, otherwise false.
174 bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count);
177 * @brief Get the supported event types of this sensor.
179 * @param[in] sensor a sensor to get the supported event types.
180 * @param[out] event_types the array containing supported event types of this sensor, the caller should explicitly free this array.
181 * @param[out] count the count of the supported event types of this sensor.
182 * @return true on success, otherwise false.
184 bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count);
187 * @brief Check a given event type is supporeted by this sensor.
189 * @param[in] sensor a sensor to check a given event type is supporeted.
190 * @param[out] event_type an event type to be checked whether supported or not.
191 * @param[out] supported whether a given event is supported or not in this sensor.
192 * @return true on success, otherwise false.
194 bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported);
197 * @brief Check a wakeup supported or not by this sensor.
199 * @param[in] sensor a sensor to check a given event type is supporeted.
200 * @return true on success, otherwise false.
202 bool sensord_is_wakeup_supported(sensor_t sensor);
205 * @brief Connect a given sensor and get a handle of a given sensor.
207 * @param[in] sensor a sensor to connect
208 * @return a handle of a given sensor on success, otherwise negative value
210 int sensord_connect(sensor_t sensor);
213 * @brief Disconnect a given sensor.
215 * @param[in] handle a handle to disconnect.
216 * @return true on success, otherwise false.
218 bool sensord_disconnect(int handle);
221 * @brief Register a callback with a connected sensor for a given event_type. This callback will be called when a given event occurs in a connected sensor.
223 * @param[in] handle a handle represensting a connected sensor.
224 * @param[in] event_type an event type to register
225 * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval.
226 * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds.
227 * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
228 * @param[in] cb a callback which is called when a given event occurs
229 * @param[in] user_data the callback is called with user_data
230 * @return true on success, otherwise false.
232 bool sensord_register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data);
235 * @brief Register a callback with a connected context sensor for a given event_type. This callback will be called when a given event occurs in a connected context sensor.
237 * @param[in] handle a handle represensting a connected context sensor.
238 * @param[in] event_type an event type to register
239 * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval.
240 * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds.
241 * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
242 * @param[in] cb a callback which is called when a given event occurs
243 * @param[in] user_data the callback is called with user_data
244 * @return true on success, otherwise false.
246 bool sensord_register_hub_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data);
249 * @brief Unregister a event with a connected sensor. After unregistering, that event will not be sent.
251 * @param[in] handle a handle represensting a connected sensor.
252 * @param[in] event_type an event type to unregister.
253 * @return true on success, otherwise false.
255 bool sensord_unregister_event(int handle, unsigned int event_type);
258 * @brief Register a callback with a connected sensor. This callback will be called when the accuracy of a sensor has changed.
260 * @param[in] handle a handle represensting a connected sensor.
261 * @param[in] cb a callback which is called when he accuracy of a sensor has changed.
262 * @param[in] user_data the callback is called with user_data
263 * @return true on success, otherwise false.
265 bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data);
268 * @brief Unregister a callback with a connected sensor. After unregistering, sensor_accuray_change_cb will not be called.
270 * @param[in] handle a handle represensting a connected sensor.
271 * @return true on success, otherwise false.
273 bool sensord_unregister_accuracy_cb(int handle);
276 * @brief Start listening events with a connected sensor.
278 * @param[in] handle a handle represensting a connected sensor.
279 * @param[in] option either one of SENSOR_OPTION_DEFAULT and SENSOR_OPTION_ALWAYS_ON.
280 * with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
281 * with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
282 * @return true on success, otherwise false.
284 bool sensord_start(int handle, int option);
287 * @brief Stop listening events with a connected sensor.
289 * @param[in] handle a handle represensting a connected sensor.
290 * @return true on success, otherwise false.
292 bool sensord_stop(int handle);
295 * @brief Change the interval of a specifed event type in a connected sensor.
297 * @param[in] handle a handle represensting a connected sensor.
298 * @param[in] event_type an event type to change interval.
299 * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval.
300 * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds.
301 * @return true on success, otherwise false.
303 bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval);
306 * @brief Change the max batch latency of a specifed event type in a connected sensor.
308 * @param[in] handle a handle represensting a connected sensor.
309 * @param[in] event_type an event type to change max batch latency
310 * @param[in] max_batch_latency an event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
311 * @return true on success, otherwise false.
313 bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency);
316 * @brief Change the option of a connected sensor.
318 * @param[in] handle a handle represensting a connected sensor.
319 * @param[in] option either one of SENSOR_OPTION_DEFAULT and SENSOR_OPTION_ALWAYS_ON.
320 * with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
321 * with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
322 * @return true on success, otherwise false.
324 bool sensord_set_option(int handle, int option);
327 * @brief Set the attribute to a connected sensor
329 * @param[in] handle a handle represensting a connected sensor.
330 * @param[in] attribute an attribute to change
331 * @param[in] value an attribute value
332 * @return 0 on success, otherwise a negative error value
333 * @retval 0 Successful
334 * @retval -EINVAL Invalid parameter
335 * @retval -EPERM Operation not permitted
337 int sensord_set_attribute_int(int handle, int attribute, int value);
340 * @brief Set the attribute to a connected sensor
342 * @param[in] handle a handle represensting a connected sensor.
343 * @param[in] attribute an attribute to change
344 * @param[in] value an attribute value
345 * @param[in] value_len the length of value
346 * @return 0 on success, otherwise a negative error value
347 * @retval 0 Successful
348 * @retval -EINVAL Invalid parameter
349 * @retval -EPERM Operation not permitted
351 int sensord_set_attribute_str(int handle, int attribute, const char *value, int len);
354 * @brief Send data to sensorhub
356 * @param[in] handle a handle represensting a connected context sensor.
357 * @param[in] data it holds data to send to sensorhub
358 * @param[in] data_len the length of data
359 * @return true on success, otherwise false.
361 bool sensord_send_sensorhub_data(int handle, const char *data, int data_len);
362 bool sensord_send_command(int handle, const char *command, int command_len);
365 * @brief get sensor data from a connected sensor
367 * @param[in] handle a handle represensting a connected context sensor.
368 * @param[in] data_id it specifies data to get
369 * @param[out] sensor_data data from connected sensor
370 * @return true on success, otherwise false.
372 bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data);
375 * @brief flush sensor data from a connected sensor
377 * @param[in] handle a handle represensting a connected context sensor.
378 * @return true on success, otherwise false.
380 bool sensord_flush(int handle);
382 typedef void (*sensor_external_command_cb_t)(int handle, const char* data, int data_cnt, void *user_data);
384 int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data);
385 bool sensord_external_disconnect(int handle);
386 bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt);
388 bool sensord_set_passive_mode(int handle, bool passive);