From: Kibum Kim Date: Fri, 6 Jan 2012 15:42:57 +0000 (+0900) Subject: Git init X-Git-Tag: 2.0_alpha~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0b62190f51cfc6938776770083386a856581e303;p=platform%2Fcore%2Fapi%2Fsensor.git Git init --- diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..0a63eea --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Pius Lee diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b6a2175 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,90 @@ + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "capi-system-sensor") + +PROJECT(${fw_name}) + +SET(CMAKE_INSTALL_PREFIX /usr) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +SET(INC_DIR include) +INCLUDE_DIRECTORIES(${INC_DIR}) + +SET(dependents "dlog sensor capi-base-common") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_name} REQUIRED ${dependents}) +FOREACH(flag ${${fw_name}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DTIZEN_DEBUG") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") + +aux_source_directory(src SOURCES) +ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) + +TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) + +INSTALL(TARGETS ${fw_name} DESTINATION lib) +INSTALL( + DIRECTORY ${INC_DIR}/ DESTINATION include/system + FILES_MATCHING + PATTERN "*_private.h" EXCLUDE + PATTERN "${INC_DIR}/*.h" + ) + +SET(PC_NAME ${fw_name}) +SET(PC_REQUIRED ${dependents}) +SET(PC_LDFLAGS -l${fw_name}) +SET(PC_CFLAGS -I\${includedir}/system) + +CONFIGURE_FILE( + ${fw_name}.pc.in + ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc + @ONLY +) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) + +#ADD_SUBDIRECTORY(test) + +IF(UNIX) + +ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution) +ADD_CUSTOM_COMMAND( + DEPENDS clean + COMMENT "distribution clean" + COMMAND find + ARGS . + -not -name config.cmake -and \( + -name tester.c -or + -name Testing -or + -name CMakeFiles -or + -name cmake.depends -or + -name cmake.check_depends -or + -name CMakeCache.txt -or + -name cmake.check_cache -or + -name *.cmake -or + -name Makefile -or + -name core -or + -name core.* -or + -name gmon.out -or + -name install_manifest.txt -or + -name *.pc -or + -name *~ \) + | grep -v TC | xargs rm -rf + TARGET distclean + VERBATIM +) + +ENDIF(UNIX) + diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..bbe9d02 --- /dev/null +++ b/LICENSE @@ -0,0 +1,206 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + + + diff --git a/capi-system-sensor.pc.in b/capi-system-sensor.pc.in new file mode 100644 index 0000000..f758dbd --- /dev/null +++ b/capi-system-sensor.pc.in @@ -0,0 +1,15 @@ + +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=/usr/lib +includedir=/usr/include/system + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} @PC_CFLAGS@ + diff --git a/debian/README b/debian/README new file mode 100644 index 0000000..e69de29 diff --git a/debian/capi-system-sensor-dev.install b/debian/capi-system-sensor-dev.install new file mode 100644 index 0000000..761a28b --- /dev/null +++ b/debian/capi-system-sensor-dev.install @@ -0,0 +1,4 @@ +/usr/include/* +/usr/include/*/* +/usr/lib/pkgconfig/*.pc + diff --git a/debian/capi-system-sensor-dev.postinst b/debian/capi-system-sensor-dev.postinst new file mode 100644 index 0000000..1a24852 --- /dev/null +++ b/debian/capi-system-sensor-dev.postinst @@ -0,0 +1 @@ +#!/bin/sh diff --git a/debian/capi-system-sensor.install b/debian/capi-system-sensor.install new file mode 100644 index 0000000..4a755a4 --- /dev/null +++ b/debian/capi-system-sensor.install @@ -0,0 +1 @@ +/usr/lib/lib*.so* diff --git a/debian/capi-system-sensor.postinst b/debian/capi-system-sensor.postinst new file mode 100644 index 0000000..1a24852 --- /dev/null +++ b/debian/capi-system-sensor.postinst @@ -0,0 +1 @@ +#!/bin/sh diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..2a85778 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,29 @@ +capi-system-sensor (0.1.0-6) unstable; urgency=low + + * fix bug for calibration callback's invalidate user data + * Git: api/sensor + * Tag: capi-system-sensor_0.1.0-6 + + -- Pius Lee Tue, 27 Dec 2011 16:11:32 +0900 + +capi-system-sensor (0.1.0-5) unstable; urgency=low + + * fix bugs in the every read functions + * Git: api/sensor + * Tag: capi-system-sensor_0.1.0-5 + + -- Pius Lee Wed, 21 Dec 2011 20:45:19 +0900 + +capi-system-sensor (0.1.0-4) unstable; urgency=low + + * update version + * Git: api/sensor + * Tag: capi-system-sensor_0.1.0-4 + + -- Pius Lee Thu, 15 Dec 2011 13:53:27 +0900 + +capi-system-sensor (0.0.1-1) unstable; urgency=low + + * Initial release. + + -- Pius Lee Wed, 07 Dec 2011 12:53:15 +0900 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..a8922d8 --- /dev/null +++ b/debian/control @@ -0,0 +1,22 @@ + +Source: capi-system-sensor +Section: libs +Priority: extra +Maintainer: pius lee +Build-Depends: debhelper (>= 5), dlog-dev, libslp-sensor-dev, capi-base-common-dev, libglib2.0-dev + +Package: capi-system-sensor +Architecture: any +Depends: ${shilbs:Depends}, ${misc:Depends} +Description: A Sensor library in Tizen Native API + +Package: capi-system-sensor-dev +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, capi-system-sensor (= ${Source-Version}), dlog-dev, libslp-sensor-dev, capi-base-common-dev +Description: A Sensor library in Tizen Native API (DEV) + +Package: capi-system-sensor-dbg +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, capi-system-sensor (= ${Source-Version}) +Description: A Sensor library in Tizen Native API (DBG) + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..2f99f75 --- /dev/null +++ b/debian/rules @@ -0,0 +1,65 @@ +#!/usr/bin/make -f + +CFLAGS = -Wall -g + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif +CMAKE_ROOT_DIR ?= $(CURDIR) +CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp + +configure: configure-stamp +configure-stamp: + dh_testdir + mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake .. + touch configure-stamp + + +build: build-stamp +build-stamp: configure-stamp + dh_testdir + cd $(CMAKE_BUILD_DIR) && $(MAKE) + touch $@ + +clean: + cd $(CMAKE_ROOT_DIR) + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + rm -f `find . -name *.pc` + rm -rf $(CMAKE_BUILD_DIR) + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + +binary-indep: build install + +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples + dh_install --sourcedir=debian/tmp + dh_installman + dh_link + dh_strip --dbg-package=capi-system-sensor-dbg + dh_fixperms + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure + diff --git a/include/sensor_private.h b/include/sensor_private.h new file mode 100755 index 0000000..7147ae8 --- /dev/null +++ b/include/sensor_private.h @@ -0,0 +1,106 @@ +/* + * 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. + */ + + + + +#ifndef __TIZEN_SYSTEM_SENSOR_PRIVATE_H__ +#define __TIZEN_SYSTEM_SENSOR_PRIVATE_H__ + +#ifdef __cplusplus +extern "C" +{ +#endif + +enum _sensor_ids_index{ + ID_ACCELEOMETER, + ID_GEOMAGNETIC, + ID_GYROSCOPE, + ID_LIGHT, + ID_PROXIMITY, + ID_MOTION, + ID_NUMBERS +}; + +#define CB_NUMBERS (SENSOR_MOTION_FACEDOWN+1) +#define CALIB_CB_NUMBERS (SENSOR_ORIENTATION+1) + +struct sensor_handle_s { + int ids[ID_NUMBERS]; +// sensor_type_e type; + int started[CB_NUMBERS]; + void* cb_func[CB_NUMBERS]; + void* cb_user_data[CB_NUMBERS]; + + void* calib_func[CALIB_CB_NUMBERS]; + void* calib_user_data[CALIB_CB_NUMBERS]; +}; + +#define SENSOR_INIT(handle) \ + do { \ + handle->ids[ID_ACCELEOMETER] = -1; \ + handle->ids[ID_GEOMAGNETIC] = -1; \ + handle->ids[ID_GYROSCOPE] = -1; \ + handle->ids[ID_LIGHT] = -1; \ + handle->ids[ID_PROXIMITY] = -1; \ + handle->ids[ID_MOTION] = -1; \ + handle->started[SENSOR_ACCELEROMETER] = 0; \ + handle->started[SENSOR_MAGNETIC] = 0; \ + handle->started[SENSOR_ORIENTATION] = 0; \ + handle->started[SENSOR_GYROSCOPE] = 0; \ + handle->started[SENSOR_LIGHT] = 0; \ + handle->started[SENSOR_PROXIMITY] = 0; \ + handle->started[SENSOR_MOTION_SNAP] = 0; \ + handle->started[SENSOR_MOTION_SHAKE] = 0; \ + handle->started[SENSOR_MOTION_DOUBLETAP] = 0; \ + handle->started[SENSOR_MOTION_PANNING] = 0; \ + handle->started[SENSOR_MOTION_FACEDOWN] = 0; \ + handle->cb_func[SENSOR_ACCELEROMETER] = NULL; \ + handle->cb_func[SENSOR_MAGNETIC] = NULL; \ + handle->cb_func[SENSOR_ORIENTATION] = NULL; \ + handle->cb_func[SENSOR_GYROSCOPE] = NULL; \ + handle->cb_func[SENSOR_LIGHT] = NULL; \ + handle->cb_func[SENSOR_PROXIMITY] = NULL; \ + handle->cb_func[SENSOR_MOTION_SNAP] = NULL; \ + handle->cb_func[SENSOR_MOTION_SHAKE] = NULL; \ + handle->cb_func[SENSOR_MOTION_DOUBLETAP] = NULL; \ + handle->cb_func[SENSOR_MOTION_PANNING] = NULL; \ + handle->cb_func[SENSOR_MOTION_FACEDOWN] = NULL; \ + handle->cb_user_data[SENSOR_ACCELEROMETER] = NULL; \ + handle->cb_user_data[SENSOR_MAGNETIC] = NULL; \ + handle->cb_user_data[SENSOR_ORIENTATION] = NULL; \ + handle->cb_user_data[SENSOR_GYROSCOPE] = NULL; \ + handle->cb_user_data[SENSOR_LIGHT] = NULL; \ + handle->cb_user_data[SENSOR_PROXIMITY] = NULL; \ + handle->cb_user_data[SENSOR_MOTION_SNAP] = NULL; \ + handle->cb_user_data[SENSOR_MOTION_SHAKE] = NULL; \ + handle->cb_user_data[SENSOR_MOTION_DOUBLETAP] = NULL; \ + handle->cb_user_data[SENSOR_MOTION_PANNING] = NULL; \ + handle->cb_user_data[SENSOR_MOTION_FACEDOWN] = NULL; \ + handle->calib_func[SENSOR_ACCELEROMETER] = NULL; \ + handle->calib_func[SENSOR_MAGNETIC] = NULL; \ + handle->calib_func[SENSOR_ORIENTATION] = NULL; \ + handle->calib_user_data[SENSOR_ACCELEROMETER] = NULL; \ + handle->calib_user_data[SENSOR_MAGNETIC] = NULL; \ + handle->calib_user_data[SENSOR_ORIENTATION] = NULL; \ + }while(0) \ + + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SYSTEM_SENSOR_PRIVATE_H__ diff --git a/include/sensors.h b/include/sensors.h new file mode 100755 index 0000000..fe4fa39 --- /dev/null +++ b/include/sensors.h @@ -0,0 +1,1220 @@ +/* + * 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. + */ + + + + +#ifndef __TIZEN_SYSTEM_SENSOR_H__ +#define __TIZEN_SYSTEM_SENSOR_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_MODULE + * @{ + */ + +/** + * @brief The sensor handle. + */ +typedef struct sensor_handle_s* sensor_h; + +/** +* @brief Enumerations of sensor data accuracy. +*/ +typedef enum +{ + SENSOR_DATA_ACCURACY_UNDEFINED = -1, /**< Undefined accuracy */ + SENSOR_DATA_ACCURACY_BAD = 0, /**< Bad accuracy */ + SENSOR_DATA_ACCURACY_NORMAL = 1, /**< Normal accuracy */ + SENSOR_DATA_ACCURACY_GOOD = 2, /**< Good accuracy */ + SENSOR_DATA_ACCURACY_VERYGOOD = 3 /**< Very good accuracy */ +} sensor_data_accuracy_e; + + +/** +* @brief Enumerations of error code for sensor. +*/ +typedef enum +{ + SENSOR_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + SENSOR_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */ + SENSOR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + SENSOR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_SYSTEM_CLASS | 0x02, /**< Out of memory */ + SENSOR_ERROR_NOT_NEED_CALIBRATION = TIZEN_ERROR_SYSTEM_CLASS | 0x03, /**< Sensor doesn't need calibration */ + SENSOR_ERROR_NOT_SUPPORTED = TIZEN_ERROR_SYSTEM_CLASS | 0x04, /**< Unsupported sensor in current device */ + SENSOR_ERROR_OPERATION_FAILED = TIZEN_ERROR_SYSTEM_CLASS | 0x06, /**< Operation failed */ + +} sensor_error_e; + + +/** +* @brief Enumerations of sensor type. +*/ +typedef enum +{ + SENSOR_ACCELEROMETER, /**< Accelerometer */ + SENSOR_MAGNETIC, /**< Magnetic sensor */ + SENSOR_ORIENTATION, /**< Orientation sensor */ + SENSOR_GYROSCOPE, /**< Gyroscope sensor */ + SENSOR_LIGHT, /**< Light sensor */ + SENSOR_PROXIMITY, /**< Proximity sensor */ + SENSOR_MOTION_SNAP, /**< Snap motion sensor */ + SENSOR_MOTION_SHAKE, /**< Shake motion sensor */ + SENSOR_MOTION_DOUBLETAP, /**< Double tap motion sensor */ + SENSOR_MOTION_PANNING, /**< Panning motion sensor */ + SENSOR_MOTION_FACEDOWN /**< Face to down motion sensor */ +} sensor_type_e; +/** + * @} + */ + + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_SNAP_MODULE + * @{ + */ + +/** + * @brief Enumerations of snap motion event. + */ +typedef enum +{ + SENSOR_MOTION_SNAP_NONE, /**< No Snap */ + SENSOR_MOTION_SNAP_LEFT, /**< Snap left to right */ + SENSOR_MOTION_SNAP_RIGHT, /**< Snap right to left */ +} sensor_motion_snap_e; +/** + * @} + */ + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_SHAKE_MODULE + * @{ + */ + +/** + * @brief Enumerations of shake motion event. + */ +typedef enum +{ + SENSOR_MOTION_SHAKE_NONE, /**< No Shake */ + SENSOR_MOTION_SHAKE_DETECTED, /**< Shake motion detected */ + SENSOR_MOTION_SHAKE_CONTINUING, /**< Shake motion continuing */ + SENSOR_MOTION_SHAKE_FINISHED, /**< Shake motion finished */ + SENSOR_MOTION_SHAKE_BROKEN, /**< Shake motion broken */ +} sensor_motion_shake_e; +/** + * @} + */ + + +/** + * @} +*/ + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_MODULE + * @{ + */ + +/** + * @brief Called when the current sensor reading falls outside of a defined normal range. + * + * @details When something is artificially influencing, such as ferrous metal objects or + * electromagnetic fields (car electrical systems, automobile engines, steel pitons, etc.), this callback is called. + * One way of implementing this callback is to notice a user to make big 8-like gesture with device. + * + * @param[in] user_data The user data passed from the callback registration function + * + * @see sensor_magnetic_set_calibration_cb() + * @see sensor_magnetic_unset_calibration_cb() + * @see sensor_orientation_set_calibration_cb() + * @see sensor_orientation_unset_calibration_cb() + */ +typedef void (*sensor_calibration_cb)(void *user_data); +/** + * @} + */ + + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_ACCELEROMETER_MODULE + * @{ + */ + +/** + * @brief Called when an accelerometer event occurs. + * + * @param[in] accuracy The accuracy of @a x, @a y, and @a z values + * @param[in] x The acceleration minus Gx on the x-axis in [m/s^2] + * @param[in] y The acceleration minus Gy on the y-axis in [m/s^2] + * @param[in] z The acceleration minus Gz on the z-axis in [m/s^2] + * @param[in] user_data The user data passed from the callback registration function + * + * @pre sensor_start() will invoke this callback if you register this callback using sensor_accelerometer_set_cb(). + * + * @see sensor_accelerometer_set_cb() + * @see sensor_accelerometer_unset_cb() + */ +typedef void (*sensor_accelerometer_event_cb)( + sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data); +/** + * @} + */ + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_GYROSCOPE_MODULE + * @{ + */ + +/** + * @brief Called when a gyroscope event occurs. + * + * @remark + * All values are in radians/second and measure the rate of rotation around the X, Y and Z axis. \n + * The coordinate system is the same as is used for the acceleration sensor. Rotation is positive \n + * in the counter-clockwise direction. That is, an observer looking from some positive location \n + * on the @a x, @a y, or @a z axis at a device positioned on the origin would report positive rotation if \n + * the device appeared to be rotating counter clockwise. Note that this is the standard mathematical \n + * definition of positive rotation and does not agree with the definition of roll given earlier. + * + * @param[in] accuracy The accuracy of @a x, @a y, and @a z values + * @param[in] x Angular speed around the x-axis in degree per second + * @param[in] y Angular speed around the y-axis in degree per second + * @param[in] z Angular speed around the z-axis in degree per second + * @param[in] user_data The user data passed from the callback registration function + * @pre sensor_start() will invoke this callback if you register this callback using sensor_gyroscope_set_cb(). + * @see sensor_gyroscope_set_cb() + * @see sensor_gyroscope_unset_cb() + */ +typedef void (*sensor_gyroscope_event_cb)( + sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data); +/** + * @} + */ + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_LIGHT_MODULE + * @{ + */ + +/** + * @brief Called when a light event occurs. + * + * @remark + * All values are neither SI lux units (lx), nor adc.\n + * Values returned by sensor may vary depending on a hardware. In the case of some\n + * HW, level 1 can mean 1 ~ 100 lux, while in some other case, level 1 can mean 1~50 lux.\n + * You should use light level between min and max values obtained \n + * with #sensor_get_spec(). In most cases min is 1 and max is 10. + * + * @param[in] accuracy The accuracy of @a level, @a y, and @a z values + * @param[in] level Actual light level + * @param[in] level Ambient light level between min and max values obtained with #sensor_get_spec().\n + * @param[in] user_data The user data passed from the callback registration function + * @pre sensor_start() will invoke this callback if you register this callback using sensor_light_set_cb(). + * @see sensor_light_set_cb() + * @see sensor_light_unset_cb() + */ +typedef void (*sensor_light_event_cb)( + sensor_data_accuracy_e accuracy, int level, void *user_data); +/** + * @} + */ + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_MAGNETIC_MODULE + * @{ + */ + +/** + * @brief Called when a magnetic event occurs. + * + * @remark @a x, @a y, and @a z values are in micro-Teslas(uT) and measure the ambient magnetic field in the X, Y and Z axis. + * + * @param[in] accuracy The accuracy of @a x, @a y, and @a z values + * @param[in] x Micro-Tesla value from ambient magnetic field on the x-axis + * @param[in] y Micro-Tesla value from ambient magnetic field on the y-axis + * @param[in] z Micro-Tesla value from ambient magnetic field on the z-axis + * @param[in] user_data The user data passed from the callback registration function + * @pre sensor_start() will invoke this callback if you register this callback using sensor_magnetic_set_cb(). + * @see sensor_magnetic_set_cb() + * @see sensor_magnetic_unset_cb() + */ +typedef void (*sensor_magnetic_event_cb)( + sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data); +/** + * @} + */ + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_ORIENTATION_MODULE + * @{ + */ + +/** + * @brief Called when an orientation event occurs. + * + * @remark All values are angles in degrees. + * + * @param[in] accuracy The accuracy of @a x, @a y, and @a z values + * @param[in] azimuth The angle between the magnetic north direction and the y-axis, around the z-axis [0 ~ 359]. \n + * 0 = North, 90 = East, 180 = South, 270 = West + * @param[in] pitch The rotation around x-axis [-180 ~ 180], with positive values when the z-axis moves \n + * toward the y-axis + * @param[in] roll The rotation around y-axis [-90 ~ 90], with positive values when the x-axis moves \n + * toward the z-axis + * @param[in] user_data The user data passed from the callback registration function + * @pre sensor_start() will invoke this callback if you register this callback using sensor_orientation_set_cb(). + * @see sensor_orientation_set_cb() + * @see sensor_orientation_unset_cb() + */ +typedef void (*sensor_orientation_event_cb)( + sensor_data_accuracy_e accuracy, float azimuth, float pitch, float roll, void *user_data); +/** + * @} + */ + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_PROXIMITY_MODULE + * @{ + */ + +/** + * @brief Called when a proximity event occurs. + * + * @param[out] is_near @c true if an object is close to the phone, otherwise @c false + * @param[in] user_data The user data passed from the callback registration function + * @pre sensor_start() will invoke this callback if you register this callback using sensor_proximity_set_cb(). + * @see sensor_proximity_set_cb() + * @see sensor_proximity_unset_cb() + */ +typedef void (*sensor_proximity_event_cb)(bool is_near, void *user_data); +/** + * @} + */ + + + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_SNAP_MODULE + * @{ + */ + +/** + * @brief Called when a snap motion event occurs. + * @image html phone_snap.png + * + * @param[in] snap The type of motion snap + * @param[in] user_data The user data passed from the callback registration function + * @pre sensor_start() will invoke this callback if you register this callback using sensor_motion_snap_set_cb(). + * @see sensor_motion_snap_set_cb() + * @see sensor_motion_snap_unset_cb() + */ +typedef void (*sensor_motion_snap_event_cb) (sensor_motion_snap_e snap, void *user_data); +/** + * @} + */ + + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_SHAKE_MODULE + * @{ + */ + +/** + * @brief Called when a shake motion event occurs. + * + * @param[in] shake The type of motion shake + * @param[in] user_data The user data passed from the callback registration function + * @pre sensor_start() will invoke this callback if you register this callback using sensor_motion_shake_set_cb(). + * @see sensor_motion_shake_set_cb() + * @see sensor_motion_shake_unset_cb() + */ +typedef void (*sensor_motion_shake_event_cb) (sensor_motion_shake_e shake, void *user_data); +/** + * @} + */ + + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_DOUBLETAP_MODULE + * @{ + */ + +/** + * @brief Called when a double tap motion event occurs. + * + * @param[in] user_data The user data passed from the callback registration function + * @pre sensor_start() will invoke this callback if you register this callback using sensor_motion_doubletap_set_cb(). + * @see sensor_motion_doubletap_set_cb() + * @see sensor_motion_doubletap_unset_cb() + */ +typedef void (*sensor_motion_doubletap_event_cb) (void *user_data); +/** + * @} + */ + + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_PANNING_MODULE + * @{ + */ + +/** + * @brief Called when a panning tap motion event occurs. + * @image html phone_panning.png + * + * @param[in] x 1/10 angle on x-axis + * @param[in] y 1/10 angle on y-axis + * @param[in] user_data The user data passed from the callback registration function + * @pre sensor_start() will invoke this callback if you register this callback using sensor_motion_panning_set_cb(). + * @see sensor_motion_panning_set_cb() + * @see sensor_motion_panning_unset_cb() + */ +typedef void (*sensor_motion_panning_event_cb) (int x, int y, void *user_data); +/** + * @} + */ + + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_FACEDOWN_MODULE + * @{ + */ + +/** + * @brief Called when a facedown tap motion event occurs. + * @details + * This event occurs when device is flipped as follows: + * @image html phone_facedown.png + * This motion event will fire only when the device is flipped from face to back. + * It will not occur when the device is flipped from back to face. + * + * @param[in] user_data The user data passed from the callback registration function + * @pre sensor_start() will invoke this callback if you register this callback using sensor_motion_facedown_set_cb(). + * @see sensor_motion_facedown_set_cb() + * @see sensor_motion_facedown_unset_cb() + */ +typedef void (*sensor_motion_facedown_event_cb) (void *user_data); +/** + * @} + */ + + +/** + * @addtogroup CAPI_SYSTEM_SENSOR_MODULE + * @{ + */ + + +/** + * @brief Checks whether the given sensor type is available on a device. + * @details + * You need to check availability of a sensor first because this sensor may not be supported on the device. + * + * @param[in] type The sensor type to check + * @param[out] supported @c true if this sensor type is supported, otherwise @c false + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int sensor_is_supported(sensor_type_e type, bool *supported); + + +/** + * @brief Gets data specification for a sensor type, except motion sensors. + * + * @remark When the given @a type is one of the motion sensors, this function returns #SENSOR_ERROR_INVALID_PARAMETER. + * + * @param[in] type The sensor type to check + * @param[out] max The maximum range of the sensor in the sensor's unit + * @param[out] min The minimum range of the sensor in the sensor's unit + * @param[out] resolution The resolution of the sensor + * + * @return 0 on success, otherwise a negative error value. + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_NOT_SUPPORTED The sensor type is not supported in current device + * + * @pre #sensor_is_supported() + */ +int sensor_get_spec(sensor_type_e type, float *max, float *min, float *resolution); + + +/** + * @brief Creates a sensor handle. + * + * @remarks @a sensor must be released sensor_destroy() by you. + * + * @param[out] sensor A new sensor handle to the sensors + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_OUT_OF_MEMORY Out of memory + * + * @see sensor_destroy() + */ +int sensor_create(sensor_h *sensor); + + +/** + * @brief Destroys the sensor handle and releases all its resources. + * + * @remark After this function is called, the attached sensor will be detached and + * the corresponding sensor connection will be released. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see sensor_create() + */ +int sensor_destroy(sensor_h sensor); + + +/** + * @brief Starts sensor server for the given sensor handle and sensor type. + * @details + * After this function is called, sensor events will occur and + * the specific sensor type related callback function will be called. An application can read sensor data. + * + * @param[in] sensor The sensor handle + * @param[in] type The sensor type + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_NOT_SUPPORTED The sensor type is not supported in current device + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @pre call sensor_create() before using this function. + * @post This function invokes sensor_calibration_cb(), sensor_accelerometer_event_cb(), sensor_magnetic_event_cb(), + * sensor_orientation_event_cb(), sensor_gyroscope_event_cb(), sensor_light_event_cb(), + * sensor_proximity_event_cb(), sensor_motion_snap_event_cb(), sensor_motion_shake_event_cb(), + * sensor_motion_doubletap_event_cb(), sensor_motion_panning_event_cb(), or sensor_motion_facedown_event_cb(). + * + * @see sensor_stop() + */ +int sensor_start(sensor_h sensor, sensor_type_e type); + + +/** + * @brief Stops sensor server for the given sensor handle and type. + * @details The given @a type event will not occur any more and the callback functions also won't be called. + * + * @param[in] sensor The sensor handle + * @param[in] type The sensor type + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * + * @see sensor_start() + */ +int sensor_stop(sensor_h sensor, sensor_type_e type); + + +/** + * @} + * + * @addtogroup CAPI_SYSTEM_SENSOR_ACCELEROMETER_MODULE + * @{ + */ + + +/** + * @brief Registers a callback function to be invoked when an accelerometer event occurs. + * + * @param[in] sensor The sensor handle + * @param[in] interval_ms The interval sensor events are delivered at (in milliseconds) \n + * If @a rate is zero, it uses default value(100ms) + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @post sensor_accelerometer_event_cb() will be invoked. + * + * @see sensor_accelerometer_event_cb() + * @see sensor_accelerometer_unset_cb() + */ +int sensor_accelerometer_set_cb(sensor_h sensor, int interval_ms, sensor_accelerometer_event_cb callback, void *user_data); + + +/** + * @brief Unregister the accelerometer callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @see sensor_accelerometer_set_cb() + */ +int sensor_accelerometer_unset_cb(sensor_h sensor); + + +/** + * @brief Gets sensor data from the accelerometer sensor. + * + * @param[in] sensor The sensor handle + * @param[out] accuracy The accuracy of this data + * @param[out] x The acceleration minus Gx on the x-axis in meters per second squared (m/s^2) + * @param[out] y The acceleration minus Gy on the y-axis in meters per second squared (m/s^2) + * @param[out] z The acceleration minus Gz on the z-axis in meters per second squared (m/s^2) + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * + * @pre In order to read sensor data, an application should call sensor_start(). + */ +int sensor_accelerometer_read_data(sensor_h sensor, sensor_data_accuracy_e *accuracy, float *x, float *y, float *z); + + +/** + * @} + * + * @addtogroup CAPI_SYSTEM_SENSOR_GYROSCOPE_MODULE + * @{ + */ + +/** + * @brief Registers a callback function to be invoked when a gyroscope event occurs. + * + * @param[in] sensor The sensor handle + * @param[in] interval_ms The interval sensor events are delivered in (in milliseconds) \n + * If @a interval_ms is zero, it uses default value (100ms) + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @post sensor_gyroscope_event_cb() will be invoked + * + * @see sensor_gyroscope_event_cb() + * @see sensor_gyroscope_unset_cb() + */ +int sensor_gyroscope_set_cb(sensor_h sensor, int interval_ms, sensor_gyroscope_event_cb callback, void *user_data); + +/** + * @brief Unregister the gyroscope callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @see sensor_gyroscope_set_cb() + */ +int sensor_gyroscope_unset_cb(sensor_h sensor); + +/** + * @brief + * Gets sensor data from the gyroscope sensor. + * + * @param[in] sensor The sensor handle + * @param[out] accuracy The accuracy of this data + * @param[out] x The angular speed around the x-axis in degree per second + * @param[out] y The angular speed around the y-axis in degree per second + * @param[out] z The angular speed around the z-axis in degree per second + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * + * @pre In order to read sensor data, an application should call sensor_start(). + * @see sensor_start() + */ +int sensor_gyroscope_read_data(sensor_h sensor, sensor_data_accuracy_e *accuracy, float *x, float *y, float *z); + +/** + * @} + * + * @addtogroup CAPI_SYSTEM_SENSOR_LIGHT_MODULE + * @{ + */ + +/** + * @brief Registers a callback function to be invoked when a light event occurs. + * + * @param[in] sensor The sensor handle + * @param[in] interval_ms The interval sensor events are delivered in (in milliseconds) \n + * If @a interval_ms is zero, it uses default value (100ms) + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @post sensor_light_event_cb() will be invoked. + * + * @see sensor_light_event_cb() + * @see sensor_light_unset_cb() + */ +int sensor_light_set_cb(sensor_h sensor, int interval_ms, sensor_light_event_cb callback, void *user_data); + +/** + * @brief Unregister the light callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @see sensor_light_set_cb() + */ +int sensor_light_unset_cb(sensor_h sensor); + +/** + * @brief Gets sensor data from the light sensor. + * + * @remark + * All values are neither SI lux units (lx), nor adc.\n + * Values returned by sensor may vary depending on a hardware. In some devices, + * HW level 1 can mean 1 ~ 100 lux, while in others, HW level 1 can mean 1 ~ 50 lux.\n + * You should use light level between min and max values obtained \n + * with #sensor_get_spec(). In most cases min is 1 and max is 10. + * + * @param[in] sensor The sensor handle + * @param[out] accuracy The accuracy of this data + * @param[out] level The ambient light level in SI lux units \n + * @a level is between min and max values obtained with #sensor_get_spec().\n + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @pre In order to read sensor data, an application should call sensor_start(). + * @see #sensor_data_accuracy_e + * @see sensor_start() + */ +int sensor_light_read_data(sensor_h sensor, sensor_data_accuracy_e *accuracy, int *level); + +/** + * @} + * + * @addtogroup CAPI_SYSTEM_SENSOR_MAGNETIC_MODULE + * @{ + */ + +/** + * @brief Registers a callback function to be invoked when a magnetic event occurs. + * + * @param[in] sensor The sensor handle + * @param[in] interval_ms The interval sensor events are delivered in (in milliseconds) \n + * If @a interval_ms is zero, it uses default value (100ms) + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @post sensor_magnetic_event_cb() will be invoked. + * + * @see sensor_magnetic_event_cb() + * @see sensor_magnetic_unset_cb() + */ +int sensor_magnetic_set_cb(sensor_h sensor, int interval_ms, sensor_magnetic_event_cb callback, void *user_data); + +/** + * @brief Unregister the magnetic callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @see sensor_magnetic_set_cb() + */ +int sensor_magnetic_unset_cb(sensor_h sensor); + +/** + * @brief Gets sensor data from the magnetic sensor. + * + * @remark All values are in micro-Teslas (uT) and measure the ambient magnetic field in the X, Y and Z axis. + * + * @param[in] sensor The sensor handle + * @param[out] accuracy The accuracy of this data + * @param[out] x Micro-Tesla value on the x-axis + * @param[out] y Micro-Tesla value on the y-axis + * @param[out] z Micro-Tesla value on the z-axis + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * + * @pre In order to read sensor data, an application should call sensor_start(). + * + * @see sensor_start() + */ +int sensor_magnetic_read_data(sensor_h sensor, sensor_data_accuracy_e *accuracy, float *x, float *y, float *z); + +/** + * @brief Registers a callback function to be invoked when the current sensor reading falls outside of a defined normal range. + * + * @param[in] sensor The sensor handle + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * @retval #SENSOR_ERROR_NOT_NEED_CALIBRATION Sensor doesn't need calibration + * + * @post sensor_calibration_cb() will be invoked. + * + * @see sensor_calibration_cb() + * @see sensor_magnetic_unset_calibration_cb() + */ +int sensor_magnetic_set_calibration_cb(sensor_h sensor, sensor_calibration_cb callback, void *user_data); + +/** + * @brief Unregisters the magnetic calibration callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * @retval #SENSOR_ERROR_NOT_NEED_CALIBRATION Sensor doesn't need calibration + * @see sensor_magnetic_set_calibration_cb() + */ +int sensor_magnetic_unset_calibration_cb(sensor_h sensor); + +/** + * @} + * + * @addtogroup CAPI_SYSTEM_SENSOR_ORIENTATION_MODULE + * @{ + */ + +/** + * @brief Registers a callback function to be invoked when an orientation event occurs. + * + * @param[in] sensor The sensor handle + * @param[in] interval_ms The interval sensor events are delivered in (in milliseconds) \n + * If @a interval_ms is zero, it uses default value (100ms) + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @post sensor_orientation_event_cb() will be invoked. + * + * @see sensor_orientation_event_cb() + * @see sensor_orientation_unset_cb() +*/ +int sensor_orientation_set_cb(sensor_h sensor, int interval_ms, sensor_orientation_event_cb callback, void *user_data); + +/** + * @brief Unregister the orientation callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @see sensor_orientation_set_cb() + */ +int sensor_orientation_unset_cb(sensor_h sensor); + +/** + * @brief Registers a callback function to be invoked when the current sensor reading falls outside of a defined normal range. + * + * @param[in] sensor The sensor handle + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * @retval #SENSOR_ERROR_NOT_NEED_CALIBRATION Sensor doesn't need calibration + * + * @post sensor_calibration_cb() will be invoked. + * + * @see sensor_calibration_cb() + * @see sensor_orientation_unset_calibration_cb() + */ +int sensor_orientation_set_calibration_cb(sensor_h sensor, sensor_calibration_cb callback, void *user_data); + +/** + * @brief Unregister the orientation calibration callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * @retval #SENSOR_ERROR_NOT_NEED_CALIBRATION Sensor doesn't need calibration + * + * @see sensor_orientation_set_calibration_cb() + */ +int sensor_orientation_unset_calibration_cb(sensor_h sensor); + +/** + * @brief Gets sensor data from the orientation sensor. + * + * @remark + * All values are angles in degrees. + * + * @param[in] sensor The sensor handle + * @param[out] accuracy The accuracy of this data + * @param[out] azimuth The angle in degrees between the magnetic north direction and the y-axis, \n + * around the z-axis [0 ~ 359]. 0=North, 90=East, 180=South, 270=West + * @param[out] pitch The rotation in degrees around x-axis [-180 ~ 180], with positive values when the \n + * z-axis moves toward the y-axis + * @param[out] roll The rotation in degrees around y-axis [-90 ~ 90], with positive values when the \n + * x-axis moves toward the z-axis + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * + * @pre In order to read sensor data, an application should call sensor_start(). + * @see sensor_start() + */ +int sensor_orientation_read_data(sensor_h sensor, sensor_data_accuracy_e *accuracy, float *azimuth, float *pitch, float *roll); + +/** + * @} + * + * @addtogroup CAPI_SYSTEM_SENSOR_PROXIMITY_MODULE + * @{ + */ + +/** + * @brief Registers a callback function to be invoked when a proximity event occurs. + * + * @param[in] sensor The sensor handle + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @post sensor_proximity_event_cb() will be invoked. + * + * @see sensor_proximity_event_cb() + * @see sensor_proximity_unset_cb() + */ +int sensor_proximity_set_cb(sensor_h sensor, sensor_proximity_event_cb callback, void *user_data); + +/** + * @brief Unregister the proximity callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @see sensor_proximity_set_cb() + */ +int sensor_proximity_unset_cb(sensor_h sensor); + +/** + * @} + * + * @} + * + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_MODULE + * @{ + * + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_DOUBLETAP_MODULE + * @{ + */ + +/** + * @brief Registers a callback function to be invoked when a motion doubletap event occurs. + * + * @param[in] sensor The sensor handle + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @post sensor_motion_doubletap_event_cb() will be invoked. + * + * @see sensor_motion_doubletap_event_cb() + * @see sensor_motion_doubletap_unset_cb() + */ +int sensor_motion_doubletap_set_cb(sensor_h sensor, sensor_motion_doubletap_event_cb callback, void *user_data); + +/** + * @brief Unregister the doubletap callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @see sensor_motion_doubletap_set_cb() + */ +int sensor_motion_doubletap_unset_cb(sensor_h sensor); + +/** + * @} + * + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_SNAP_MODULE + * @{ + */ + +/** + * @brief Registers a callback function to be invoked when a motion snap event occurs. + * + * @param[in] sensor The sensor handle + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @post sensor_motion_snap_event_cb() will be invoked. + * + * @see sensor_motion_snap_event_cb() + * @see sensor_motion_snap_unset_cb() + */ +int sensor_motion_snap_set_cb(sensor_h sensor, sensor_motion_snap_event_cb callback, void *user_data); + +/** + * @brief Unregister the snap callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @see sensor_motion_snap_set_cb() + */ +int sensor_motion_snap_unset_cb(sensor_h sensor); + +/** + * @} + * + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_SHAKE_MODULE + * @{ + */ + +/** + * @brief Registers a callback function to be invoked when a motion shake event occurs. + * + * @param[in] sensor The sensor handle + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @post sensor_motion_shake_event_cb() will be invoked. + * + * @see sensor_motion_shake_event_cb() + * @see sensor_motion_shake_unset_cb() + */ +int sensor_motion_shake_set_cb(sensor_h sensor, sensor_motion_shake_event_cb callback, void *user_data); + +/** + * @brief Unregister the callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @see sensor_motion_shake_set_cb() + */ +int sensor_motion_shake_unset_cb(sensor_h sensor); + +/** + * @} + * + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_PANNING_MODULE + * @{ + */ + +/** + * @brief Registers a callback function to be invoked when a motion panning event occurs. + * + * @param[in] sensor The sensor handle + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @post sensor_motion_panning_event_cb() will be invoked. + * + * @see sensor_motion_panning_event_cb() + * @see sensor_motion_panning_unset_cb() + */ +int sensor_motion_panning_set_cb(sensor_h sensor, sensor_motion_panning_event_cb callback, void *user_data); + +/** + * @brief Unregister the callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @see sensor_motion_panning_set_cb() + */ +int sensor_motion_panning_unset_cb(sensor_h sensor); + +/** + * @} + * + * @addtogroup CAPI_SYSTEM_SENSOR_MOTION_FACEDOWN_MODULE + * @{ + */ + +/** + * @brief Registers a callback function to be invoked when a motion facedown event occurs. + * + * @param[in] sensor The sensor handle + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @post sensor_motion_facedown_event_cb() will be invoked. + * + * @see sensor_motion_facedown_event_cb() + * @see sensor_motion_facedown_unset_cb() + */ +int sensor_motion_facedown_set_cb(sensor_h sensor, sensor_motion_facedown_event_cb callback, void *user_data); + +/** + * @brief Unregister the facedown callback function. + * + * @param[in] sensor The sensor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_IO_ERROR I/O error + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + * + * @see sensor_motion_facedown_set_cb() + */ +int sensor_motion_facedown_unset_cb(sensor_h sensor); + +/** + * @} + * + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/packaging/capi-system-sensor.spec b/packaging/capi-system-sensor.spec new file mode 100644 index 0000000..588d867 --- /dev/null +++ b/packaging/capi-system-sensor.spec @@ -0,0 +1,53 @@ +Name: capi-system-sensor +Summary: A Sensor library in TIZEN C API +Version: 0.0.1 +Release: 1 +Group: TO_BE/FILLED_IN +License: TO BE FILLED IN +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(sensor) +BuildRequires: pkgconfig(capi-base-common) +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description + + +%package devel +Summary: A Sensor library in TIZEN C API (Development) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description devel + + + +%prep +%setup -q + + +%build +cmake . -DCMAKE_INSTALL_PREFIX=/usr + + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files +%{_libdir}/libcapi-system-sensor.so + +%files devel +%{_includedir}/system/sensors.h +%{_libdir}/pkgconfig/*.pc + + diff --git a/phone_facedown.png b/phone_facedown.png new file mode 100755 index 0000000..5a28ed3 Binary files /dev/null and b/phone_facedown.png differ diff --git a/phone_panning.png b/phone_panning.png new file mode 100755 index 0000000..d6f6f39 Binary files /dev/null and b/phone_panning.png differ diff --git a/phone_snap.png b/phone_snap.png new file mode 100755 index 0000000..bc239d5 Binary files /dev/null and b/phone_snap.png differ diff --git a/src/sensor.c b/src/sensor.c new file mode 100644 index 0000000..f0f4cd3 --- /dev/null +++ b/src/sensor.c @@ -0,0 +1,889 @@ +/* + * 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define _DEBUG 1 + +#ifdef _DEBUG +#undef LOG_TAG +#define LOG_TAG "TIZEN_SYSTEM_SENSOR" +#include +#include +static char* _DONT_USE_THIS_ARRAY_DIRECTLY[] = { + "ACCELEROMETER", + "MAGNETIC", + "ORIENTATION", + "GYROSCOPE", + "LIGHT", + "PROXIMITY", + "MOTION_SNAP", + "MOTION_SHAKE", + "MOTION_DOUBLETAP", + "MOTION_PANNING", + "MOTION_FACEDOWN" +}; + +#define _MSG_SENSOR_ERROR_IO_ERROR "Io Error" +#define _MSG_SENSOR_ERROR_INVALID_PARAMETER "Invalid Parameter" +#define _MSG_SENSOR_ERROR_OUT_OF_MEMORY "Out of Memory" +#define _MSG_SENSOR_ERROR_NOT_NEED_CALIBRATION "Not need calibration" +#define _MSG_SENSOR_ERROR_NOT_SUPPORTED "Not supported" +#define _MSG_SENSOR_ERROR_OPERATION_FAILED "Operation failed" + +#define TYPE_NAME(type) _DONT_USE_THIS_ARRAY_DIRECTLY[type] + +#define DEBUG_PRINT(txt) LOGD("%s : " txt, __FUNCTION__) +#define DEBUG_PRINTF(fmt, ...) LOGD("%s : " fmt, __FUNCTION__, __VA_ARGS__) +#define ERROR_PRINT(err) LOGD("[%s]" _MSG_##err "(0x%08x)", __FUNCTION__, err) +#define ERROR_PRINTF(err, fmt, ...) LOGD("[%s]" _MSG_##err "(0x%08x) : " fmt, __FUNCTION__, err, __VA_ARGS__) +#else +#define TYPE_NAME(type) "" +#define DEBUG_PRINT(txt) +#define DEBUG_PRINTF(fmt, ...) +#define ERROR_PRINT(err) +#define ERROR_PRINTF(err) +#endif + +#define RETURN_VAL_IF(expr, err) \ + do { \ + if (expr) { \ + ERROR_PRINT(err); \ + return (err); \ + } \ + } while(0) + +#define RETURN_ERROR(err) \ + do { \ + ERROR_PRINT(err); \ + return err; \ + } while(0) + + +#define RETURN_IF_NOT_HANDLE(handle) \ + RETURN_VAL_IF(handle == NULL, SENSOR_ERROR_INVALID_PARAMETER) + +#define RETURN_IF_NOT_TYPE(type) \ + RETURN_VAL_IF(type > SENSOR_MOTION_FACEDOWN || type < 0, SENSOR_ERROR_INVALID_PARAMETER) + +#define RETURN_IF_MOTION_TYPE(type) \ + RETURN_VAL_IF(type > SENSOR_PROXIMITY && type <= SENSOR_MOTION_FACEDOWN, SENSOR_ERROR_INVALID_PARAMETER) + +#define RETURN_IF_ERROR(val) \ + RETURN_VAL_IF(val < 0, val) + +sensor_data_accuracy_e _accu_table[] = { + SENSOR_ACCURACY_UNDEFINED, + SENSOR_ACCURACY_BAD, + SENSOR_ACCURACY_NORMAL, + SENSOR_ACCURACY_GOOD, + SENSOR_ACCURACY_VERYGOOD, +}; + +sensor_type_t _TYPE[] = { + ACCELEROMETER_SENSOR, + GEOMAGNETIC_SENSOR, + GEOMAGNETIC_SENSOR, + GYROSCOPE_SENSOR, + LIGHT_SENSOR, + PROXIMITY_SENSOR, + MOTION_SENSOR, + MOTION_SENSOR, + MOTION_SENSOR, + MOTION_SENSOR, + MOTION_SENSOR, +}; + +int _DTYPE[] = { + ACCELEROMETER_BASE_DATA_SET, + GEOMAGNETIC_RAW_DATA_SET, // really magnetic? + GEOMAGNETIC_BASE_DATA_SET, // really orientation? + GYRO_BASE_DATA_SET, + LIGHT_BASE_DATA_SET, + PROXIMITY_BASE_DATA_SET, +}; + +int _EVENT[] = { + ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME, + GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME, // really magnetic? + GEOMAGNETIC_EVENT_ATTITUDE_DATA_REPORT_ON_TIME, // really orientation? + GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME, + LIGHT_EVENT_LEVEL_DATA_REPORT_ON_TIME, // rate = 500ms + PROXIMITY_EVENT_CHANGE_STATE, + MOTION_ENGINE_EVENT_SNAP, + MOTION_ENGINE_EVENT_SHAKE, + MOTION_ENGINE_EVENT_DOUBLETAP, + MOTION_ENGINE_EVENT_PANNING, + MOTION_ENGINE_EVENT_TOP_TO_BOTTOM, +}; + +int _CALIBRATION[] = { + ACCELEROMETER_EVENT_CALIBRATION_NEEDED, + GEOMAGNETIC_EVENT_CALIBRATION_NEEDED, + GEOMAGNETIC_EVENT_CALIBRATION_NEEDED, +}; + +int _sensor_ids[] = { + ID_ACCELEOMETER, + ID_GEOMAGNETIC, + ID_GEOMAGNETIC, + ID_GYROSCOPE, + ID_LIGHT, + ID_PROXIMITY, + ID_MOTION, + ID_MOTION, + ID_MOTION, + ID_MOTION, + ID_MOTION +}; + +#define _SID(id) (_sensor_ids[id]) +#define _ACCU(accuracy) (_accu_table[accuracy + 1]) + +static int _sensor_connect(sensor_h handle, sensor_type_e type) +{ + int id = 0; + bool support = true; + + RETURN_IF_NOT_TYPE(type); + + if(handle->ids[_SID(type)] < 0){ + sensor_is_supported(type, &support); + if(!support) + return SENSOR_ERROR_NOT_SUPPORTED; + + id = sf_connect(_TYPE[type]); + + DEBUG_PRINTF("%s sensor connect legacy=[%d] type=[%d]", TYPE_NAME(type), type, _TYPE[type]); + if(id < 0){ + return id == -2 ? SENSOR_ERROR_IO_ERROR : SENSOR_ERROR_OPERATION_FAILED; + } + DEBUG_PRINTF("%s sensor id created [%d]", TYPE_NAME(type), id); + handle->ids[_SID(type)] = id; + } + return SENSOR_ERROR_NONE; +} + +static void _sensor_callback (unsigned int event_type, sensor_event_data_t* event, void* udata) +{ + int i = 0; + int data_num = 0; + sensor_data_t *data = NULL; + sensor_panning_data_t *panning_data = NULL; + int motion = 0; + int nid = 0; + bool proximity = 0; + + sensor_h sensor = (sensor_h)udata; + + switch(event_type) + { + case MOTION_ENGINE_EVENT_SNAP: + nid = SENSOR_MOTION_SNAP; + break; + case MOTION_ENGINE_EVENT_SHAKE: + nid = SENSOR_MOTION_SHAKE; + break; + case MOTION_ENGINE_EVENT_DOUBLETAP: + nid = SENSOR_MOTION_DOUBLETAP; + break; + case MOTION_ENGINE_EVENT_PANNING: + nid = SENSOR_MOTION_PANNING; + break; + case MOTION_ENGINE_EVENT_TOP_TO_BOTTOM: + nid = SENSOR_MOTION_FACEDOWN; + break; + case ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME : + nid = SENSOR_ACCELEROMETER; + break; + case GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME : + nid = SENSOR_MAGNETIC; + break; + case GEOMAGNETIC_EVENT_ATTITUDE_DATA_REPORT_ON_TIME : + nid = SENSOR_ORIENTATION; + break; + case GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME : + nid = SENSOR_GYROSCOPE; + break; + case LIGHT_EVENT_LEVEL_DATA_REPORT_ON_TIME : + nid = SENSOR_LIGHT; + break; + case PROXIMITY_EVENT_CHANGE_STATE : + nid = SENSOR_PROXIMITY; + break; + } + + if(sensor->cb_func[nid] == NULL || sensor->started[nid] == 0) + return; + + switch(event_type) + { + case MOTION_ENGINE_EVENT_SNAP: + case MOTION_ENGINE_EVENT_SHAKE: + motion = *(int*)event->event_data; + break; + case MOTION_ENGINE_EVENT_PANNING: + panning_data = (sensor_panning_data_t *)event->event_data; + break; + case MOTION_ENGINE_EVENT_DOUBLETAP: + motion = *(int*)event->event_data; + if(motion != MOTION_ENGIEN_DOUBLTAP_DETECTION) + return; + break; + case MOTION_ENGINE_EVENT_TOP_TO_BOTTOM: + motion = *(int*)event->event_data; + if(motion != MOTION_ENGIEN_TOP_TO_BOTTOM_DETECTION) + return; + break; + + case ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME : + case GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME : + case GEOMAGNETIC_EVENT_ATTITUDE_DATA_REPORT_ON_TIME : + case GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME : + case LIGHT_EVENT_LEVEL_DATA_REPORT_ON_TIME : + data = (sensor_data_t*)(event->event_data); + data_num = (event->event_data_size)/sizeof(sensor_data_t); + break; + case PROXIMITY_EVENT_CHANGE_STATE : + proximity = *(int*)(event->event_data) == PROXIMITY_STATE_FAR ? 0 : 1; + break; + default: + DEBUG_PRINTF("unknown typed sensor happen!! event=%d\n", event_type); + return; + + } + + switch(event_type) + { + case MOTION_ENGINE_EVENT_SNAP: + ((sensor_motion_snap_event_cb)sensor->cb_func[nid])(motion, sensor->cb_user_data[nid]); + break; + case MOTION_ENGINE_EVENT_SHAKE: + ((sensor_motion_shake_event_cb)sensor->cb_func[nid])(motion, sensor->cb_user_data[nid]); + break; + case MOTION_ENGINE_EVENT_DOUBLETAP: + ((sensor_motion_doubletap_event_cb)sensor->cb_func[nid])(sensor->cb_user_data[nid]); + break; + case MOTION_ENGINE_EVENT_TOP_TO_BOTTOM: + ((sensor_motion_facedown_event_cb)sensor->cb_func[nid])(sensor->cb_user_data[nid]); + break; + case MOTION_ENGINE_EVENT_PANNING: + ((sensor_motion_panning_event_cb)sensor->cb_func[nid])(panning_data->x, panning_data->y, + sensor->cb_user_data[nid]); + break; + case ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME : + for(i=0; icb_func[nid]) + (_ACCU(data[i].data_accuracy), + data[i].values[0], data[i].values[1], data[i].values[2], + sensor->cb_user_data[nid]); + } + break; + case GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME : + for(i=0; icb_func[nid]) + (_ACCU(data[i].data_accuracy), + data[i].values[0], data[i].values[1], data[i].values[2], + sensor->cb_user_data[nid]); + } + break; + case GEOMAGNETIC_EVENT_ATTITUDE_DATA_REPORT_ON_TIME : + for(i=0; icb_func[nid]) + (_ACCU(data[i].data_accuracy), + data[i].values[0], data[i].values[1], data[i].values[2], + sensor->cb_user_data[nid]); + } + break; + case GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME : + for(i=0; icb_func[nid]) + (_ACCU(data[i].data_accuracy), + data[i].values[0], data[i].values[1], data[i].values[2], + sensor->cb_user_data[nid]); + } + break; + case LIGHT_EVENT_LEVEL_DATA_REPORT_ON_TIME : + for(i=0; icb_func[nid]) + (_ACCU(data[i].data_accuracy), + (int)data[i].values[0], + sensor->cb_user_data[nid]); + } + break; + case PROXIMITY_EVENT_CHANGE_STATE : + ((sensor_proximity_event_cb)sensor->cb_func[nid]) + (proximity, sensor->cb_user_data[nid]); + break; + } +} + +int sensor_is_supported(sensor_type_e type, bool* supported) +{ + DEBUG_PRINT("sensor_is_support"); + + RETURN_IF_NOT_TYPE(type); + + if(supported == NULL) + RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); + + *supported = !(sf_is_sensor_event_available(_TYPE[type], _EVENT[type]) < 0); + DEBUG_PRINTF("%s sensor available function return [%d]", TYPE_NAME(type), *supported); + + return SENSOR_ERROR_NONE; +} + +int sensor_get_spec(sensor_type_e type, float* max, float* min, float* resolution) +{ + sensor_properties_t property; + + DEBUG_PRINT("sensor_get_spec"); + + RETURN_IF_MOTION_TYPE(type); + + RETURN_IF_NOT_TYPE(type); + + if(sf_get_properties(_TYPE[type], &property) < 0) + RETURN_ERROR(SENSOR_ERROR_NOT_SUPPORTED); + + *max = property.sensor_max_range; + *min = property.sensor_min_range; + *resolution = property.sensor_resolution; + + DEBUG_PRINTF("success get %s's format max=%f, min=%f, res=%f\n", TYPE_NAME(type), *max, *min, *resolution); + + return SENSOR_ERROR_NONE; +} + + +int sensor_create(sensor_h* handle) +{ + struct sensor_handle_s* sensor = NULL; + + DEBUG_PRINT("sensor_create"); + + if(handle == NULL) + RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); + + sensor = (struct sensor_handle_s*)malloc( sizeof(struct sensor_handle_s) ); + if(sensor==NULL) + RETURN_ERROR(SENSOR_ERROR_OUT_OF_MEMORY); + else + { + SENSOR_INIT(sensor); + + *handle = (sensor_h)sensor; + + return SENSOR_ERROR_NONE; + } +} + +int sensor_destroy(sensor_h handle) +{ + + int i=0; + bool failed = false; + RETURN_IF_NOT_HANDLE(handle); + + DEBUG_PRINT("sensor_destroy"); + + for(i=0; iids[i] >= 0 ){ + if(sf_disconnect(handle->ids[i]) < 0) + failed = true; + else + handle->ids[i] = -1; + } + } + + free(handle); + handle = NULL; + + return SENSOR_ERROR_NONE; +} + +int sensor_start(sensor_h handle, sensor_type_e type) +{ + int err; + DEBUG_PRINT("sensor_start"); + RETURN_IF_NOT_HANDLE(handle); + RETURN_IF_NOT_TYPE(type); + + if( (err = _sensor_connect(handle, type)) != SENSOR_ERROR_NONE){ + return err; + } + + if (sf_start(handle->ids[_SID(type)], 0) < 0) { + RETURN_ERROR(SENSOR_ERROR_IO_ERROR); + } else { + handle->started[type] = 1; + return SENSOR_ERROR_NONE; + } +} + +int sensor_stop(sensor_h handle, sensor_type_e type) +{ + DEBUG_PRINT("sensor_stop"); + RETURN_IF_NOT_HANDLE(handle); + RETURN_IF_NOT_TYPE(type); + if (sf_stop(handle->ids[_SID(type)]) < 0) { + RETURN_ERROR(SENSOR_ERROR_IO_ERROR); + } else { + handle->started[type] = 0; + return SENSOR_ERROR_NONE; + } +} + +static void _sensor_calibration (unsigned int event_type, sensor_event_data_t* event, void* udata) +{ + sensor_h sensor = (sensor_h)udata; + + switch (event_type) { + case ACCELEROMETER_EVENT_CALIBRATION_NEEDED: + if(sensor->calib_func[SENSOR_ACCELEROMETER] != NULL){ + ((sensor_calibration_cb)sensor->calib_func[SENSOR_ACCELEROMETER])(sensor->calib_user_data[SENSOR_ACCELEROMETER]); + } + break; + case GEOMAGNETIC_EVENT_CALIBRATION_NEEDED: + if(sensor->calib_func[SENSOR_MAGNETIC] != NULL){ + ((sensor_calibration_cb)sensor->calib_func[SENSOR_MAGNETIC])(sensor->calib_user_data[SENSOR_MAGNETIC]); + } + if(sensor->calib_func[SENSOR_ORIENTATION] != NULL){ + ((sensor_calibration_cb)sensor->calib_func[SENSOR_ORIENTATION])(sensor->calib_user_data[SENSOR_ORIENTATION]); + } + break; + default: + DEBUG_PRINTF("not calibration event happened in calibration callback!! event=%d", event_type); + return; + } +} + +static int _sensor_set_calibration_cb(sensor_h handle, sensor_type_e type, sensor_calibration_cb callback, void *user_data) +{ + int ret, err; + + DEBUG_PRINTF("%s sensor register calibration callback", TYPE_NAME(type)); + + RETURN_IF_NOT_HANDLE(handle); + switch(type){ + case SENSOR_ACCELEROMETER: + case SENSOR_MAGNETIC: + case SENSOR_ORIENTATION: + break; + default: + RETURN_ERROR(SENSOR_ERROR_NOT_NEED_CALIBRATION); + } + + ret = sf_is_sensor_event_available( _TYPE[type], _CALIBRATION[type] ); + if (ret != 0 ){ + DEBUG_PRINTF("Unsupported calibration ret=[%d] error=[%d] legacy=[%d] type=[%d] cal_id=[%d]", ret, SENSOR_ERROR_NOT_NEED_CALIBRATION, type, _TYPE[type], _CALIBRATION[type]); + RETURN_ERROR(SENSOR_ERROR_NOT_NEED_CALIBRATION); + } + + if( (err = _sensor_connect(handle, type)) != SENSOR_ERROR_NONE){ + return err; + } + + handle->calib_func[type] = callback; + handle->calib_user_data[type] = user_data; + + DEBUG_PRINTF("type : %s / id : %d / event : %x ", TYPE_NAME(type), handle->ids[_SID(type)], _CALIBRATION[type]); + + ret = sf_register_event(handle->ids[_SID(type)], _CALIBRATION[type], NULL, _sensor_calibration, handle); + if(ret < 0){ + handle->calib_func[type] = NULL; + handle->calib_user_data[type] = NULL; + if(ret == -2) + RETURN_ERROR(SENSOR_ERROR_IO_ERROR); + else + RETURN_ERROR(SENSOR_ERROR_OPERATION_FAILED); + } + + return SENSOR_ERROR_NONE; +} + +static int _sensor_unset_calibration_cb(sensor_h handle, sensor_type_e type) +{ + int ret; + + DEBUG_PRINTF("%s sensor register calibration callback", TYPE_NAME(type)); + + RETURN_IF_NOT_HANDLE(handle); + switch (type) { + case SENSOR_ACCELEROMETER: + case SENSOR_MAGNETIC: + case SENSOR_ORIENTATION: + break; + default: + RETURN_ERROR(SENSOR_ERROR_NOT_NEED_CALIBRATION); + } + + if(handle->calib_func[type] == NULL) + return SENSOR_ERROR_NONE; + + ret = sf_unregister_event(handle->ids[_SID(type)], _CALIBRATION[type]); + + if (ret < 0){ + if(ret == -2) + RETURN_ERROR(SENSOR_ERROR_IO_ERROR); + else + RETURN_ERROR(SENSOR_ERROR_OPERATION_FAILED); + } + + handle->calib_func[type] = NULL; + handle->calib_user_data[type] = NULL; + + return SENSOR_ERROR_NONE; +} + + +static int _sensor_set_data_cb (sensor_h handle, sensor_type_e type, int rate, void* cb, void* user_data) +{ + int err = 0; + event_condition_t condition; + + RETURN_IF_NOT_HANDLE(handle); + RETURN_IF_NOT_TYPE(type); + + DEBUG_PRINTF("sensor register callback %s", TYPE_NAME(type)); + + if(rate < 0){ + RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); + } + + if(rate > 0){ + condition.cond_op = CONDITION_EQUAL; + condition.cond_value1 = rate; + } + + handle->cb_func[type] = cb; + handle->cb_user_data[type] = user_data; + + if( (err = _sensor_connect(handle, type)) != SENSOR_ERROR_NONE){ + DEBUG_PRINTF("%s sensor connect error handle=[%d] legacy=[%d] err=[%d]", TYPE_NAME(type), handle, type, err); + return err; + } + + err = sf_register_event(handle->ids[_SID(type)], _EVENT[type], + (rate > 0 ? &condition : NULL), _sensor_callback, handle); + + DEBUG_PRINTF("%s sensor register function return [%d] event=[%d]", TYPE_NAME(type), err, _EVENT[type]); + + if(err < 0){ + handle->cb_func[type] = NULL; + handle->cb_user_data[type] = NULL; + if(err == -2) + RETURN_ERROR(SENSOR_ERROR_IO_ERROR); + else + RETURN_ERROR(SENSOR_ERROR_OPERATION_FAILED); + } + + return SENSOR_ERROR_NONE; +} + +static int _sensor_unset_data_cb (sensor_h handle, sensor_type_e type) +{ + int error; + DEBUG_PRINTF("sensor unregister callback %s", TYPE_NAME(type)); + RETURN_IF_NOT_HANDLE(handle); + if (handle->ids[_SID(type)] < 0 ) + return SENSOR_ERROR_INVALID_PARAMETER; + + error = sf_unregister_event(handle->ids[_SID(type)], _EVENT[type]); + + if (error < 0){ + if(error == -2) + RETURN_ERROR(SENSOR_ERROR_IO_ERROR); + else + RETURN_ERROR(SENSOR_ERROR_OPERATION_FAILED); + } + + handle->cb_func[type] = NULL; + handle->cb_user_data[type] = NULL; + return SENSOR_ERROR_NONE; +} + +int sensor_accelerometer_set_cb (sensor_h handle, + int rate, sensor_accelerometer_event_cb callback, void *user_data) +{ + return _sensor_set_data_cb(handle, SENSOR_ACCELEROMETER, rate, (void*) callback, user_data); +} + +int sensor_accelerometer_unset_cb (sensor_h handle) +{ + return _sensor_unset_data_cb(handle, SENSOR_ACCELEROMETER); +} + +int sensor_magnetic_set_cb (sensor_h handle, + int rate, sensor_magnetic_event_cb callback, void *user_data) +{ + return _sensor_set_data_cb(handle, SENSOR_MAGNETIC, rate, (void*) callback, user_data); +} + +int sensor_magnetic_unset_cb (sensor_h handle) +{ + return _sensor_unset_data_cb(handle, SENSOR_MAGNETIC); +} + +int sensor_magnetic_set_calibration_cb (sensor_h handle, sensor_calibration_cb callback, void *user_data) +{ + return _sensor_set_calibration_cb(handle, SENSOR_MAGNETIC, callback, user_data); +} +int sensor_magnetic_unset_calibration_cb (sensor_h handle) +{ + return _sensor_unset_calibration_cb(handle, SENSOR_MAGNETIC); +} + +int sensor_orientation_set_cb (sensor_h handle, + int rate, sensor_orientation_event_cb callback, void *user_data) +{ + return _sensor_set_data_cb(handle, SENSOR_ORIENTATION, rate, (void*) callback, user_data); +} + +int sensor_orientation_unset_cb (sensor_h handle) +{ + return _sensor_unset_data_cb(handle, SENSOR_ORIENTATION); +} +int sensor_orientation_set_calibration_cb (sensor_h handle, sensor_calibration_cb callback, void *user_data) +{ + return _sensor_set_calibration_cb(handle, SENSOR_ORIENTATION, callback, user_data); +} +int sensor_orientation_unset_calibration_cb (sensor_h handle) +{ + return _sensor_unset_calibration_cb(handle, SENSOR_ORIENTATION); +} + +int sensor_gyroscope_set_cb (sensor_h handle, + int rate, sensor_gyroscope_event_cb callback, void *user_data) +{ + return _sensor_set_data_cb(handle, SENSOR_GYROSCOPE, rate, (void*) callback, user_data); +} + +int sensor_gyroscope_unset_cb (sensor_h handle) +{ + return _sensor_unset_data_cb(handle, SENSOR_GYROSCOPE); +} + +int sensor_light_set_cb (sensor_h handle, + int rate, sensor_light_event_cb callback, void *user_data) +{ + return _sensor_set_data_cb(handle, SENSOR_LIGHT, rate, (void*) callback, user_data); +} + +int sensor_light_unset_cb (sensor_h handle) +{ + return _sensor_unset_data_cb(handle, SENSOR_LIGHT); +} + +int sensor_proximity_set_cb (sensor_h handle, sensor_proximity_event_cb callback, void *user_data) +{ + return _sensor_set_data_cb(handle, SENSOR_PROXIMITY, 0, (void*) callback, user_data); +} + +int sensor_proximity_unset_cb (sensor_h handle) +{ + return _sensor_unset_data_cb(handle, SENSOR_PROXIMITY); +} + +static int _sensor_read_data(sensor_h handle, sensor_type_e type, + sensor_data_accuracy_e* accuracy, float* values, int values_size) +{ + int err = 0; + sensor_data_t data; + + RETURN_IF_NOT_HANDLE(handle); + if(type > SENSOR_PROXIMITY && type <= SENSOR_MOTION_DOUBLETAP) + RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); + RETURN_IF_NOT_TYPE(type); + + DEBUG_PRINTF("sensor read data %s", TYPE_NAME(type)); + + if( (err = _sensor_connect(handle, type)) != SENSOR_ERROR_NONE) + return err; + if ( sf_get_data(handle->ids[_SID(type)], _DTYPE[type], &data) < 0 ) + { + RETURN_ERROR(SENSOR_ERROR_IO_ERROR); + } + + // this error will never happen. but it exist for more safe code.. + if(values_size > 12 || values_size < 0) + RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); + + if(accuracy != NULL) + *accuracy = _ACCU(data.data_accuracy); + memcpy(values, data.values, values_size * sizeof(float)); + + return SENSOR_ERROR_NONE; +} + +int sensor_accelerometer_read_data (sensor_h handle, + sensor_data_accuracy_e* accuracy, float* x, float* y, float* z) +{ + float values[3] = {0,0,0}; + int err = _sensor_read_data(handle, SENSOR_ACCELEROMETER, accuracy, values, 3); + if(err < 0) return err; + + if(x == NULL || y == NULL || z == NULL) + RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); + + *x = values[0]; + *y = values[1]; + *z = values[2]; + + return SENSOR_ERROR_NONE; +} + +int sensor_magnetic_read_data (sensor_h handle, sensor_data_accuracy_e* accuracy, float* x, float* y, float* z) +{ + float values[3] = {0,0,0}; + int err = _sensor_read_data(handle, SENSOR_MAGNETIC, accuracy, values, 3); + if(err < 0) return err; + + if(x == NULL || y == NULL || z == NULL) + RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); + + *x = values[0]; + *y = values[1]; + *z = values[2]; + + return SENSOR_ERROR_NONE; +} + +int sensor_orientation_read_data (sensor_h handle, sensor_data_accuracy_e* accuracy, float* azimuth, float* pitch, float* roll) +{ + float values[3] = {0,0,0}; + int err = _sensor_read_data(handle, SENSOR_ORIENTATION, accuracy, values, 3); + if(err < 0) return err; + + if(azimuth == NULL || pitch == NULL || roll == NULL) + RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); + + *azimuth = values[0]; + *pitch = values[1]; + *roll = values[2]; + + return SENSOR_ERROR_NONE; +} + +int sensor_gyroscope_read_data (sensor_h handle, sensor_data_accuracy_e* accuracy, float* x, float* y, float* z) +{ + float values[3] = {0,0,0}; + int err = _sensor_read_data(handle, SENSOR_GYROSCOPE, accuracy, values, 3); + if(err < 0) return err; + + if(x == NULL || y == NULL || z == NULL) + RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); + + *x = values[0]; + *y = values[1]; + *z = values[2]; + + return SENSOR_ERROR_NONE; +} + +int sensor_light_read_data (sensor_h handle, sensor_data_accuracy_e* accuracy, int* level) +{ + float values[1] = {0}; + int err = _sensor_read_data(handle, SENSOR_LIGHT, accuracy, values, 1); + if(err < 0) return err; + + if(level == NULL) + RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); + + *level = (int)values[0]; + + return SENSOR_ERROR_NONE; +} + +int sensor_proximity_read_data (sensor_h handle, sensor_data_accuracy_e* accuracy, bool* is_near) +{ + float values[1] = {0}; + int err = _sensor_read_data(handle, SENSOR_PROXIMITY, accuracy, values, 1); + if(err < 0) return err; + + if(is_near == NULL) + RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); + + *is_near = (bool)values[0]; + + return SENSOR_ERROR_NONE; +} + + +int sensor_motion_snap_set_cb (sensor_h handle, sensor_motion_snap_event_cb callback, void *user_data) +{ + return _sensor_set_data_cb(handle, SENSOR_MOTION_SNAP, 0, (void*) callback, user_data); +} + +int sensor_motion_snap_unset_cb (sensor_h handle) +{ + return _sensor_unset_data_cb(handle, SENSOR_MOTION_SNAP); +} + +int sensor_motion_shake_set_cb (sensor_h handle, sensor_motion_shake_event_cb callback, void *user_data) +{ + return _sensor_set_data_cb(handle, SENSOR_MOTION_SHAKE, 0, (void*) callback, user_data); +} + +int sensor_motion_shake_unset_cb (sensor_h handle) +{ + return _sensor_unset_data_cb(handle, SENSOR_MOTION_SHAKE); +} + +int sensor_motion_doubletap_set_cb (sensor_h handle, sensor_motion_doubletap_event_cb callback, void *user_data) +{ + return _sensor_set_data_cb(handle, SENSOR_MOTION_DOUBLETAP, 0, (void*) callback, user_data); +} + +int sensor_motion_doubletap_unset_cb (sensor_h handle) +{ + return _sensor_unset_data_cb(handle, SENSOR_MOTION_DOUBLETAP); +} + +int sensor_motion_panning_set_cb (sensor_h handle, sensor_motion_panning_event_cb callback, void *user_data) +{ + return _sensor_set_data_cb(handle, SENSOR_MOTION_PANNING, 0, (void*) callback, user_data); +} + +int sensor_motion_panning_unset_cb (sensor_h handle) +{ + return _sensor_unset_data_cb(handle, SENSOR_MOTION_PANNING); +} + +int sensor_motion_facedown_set_cb (sensor_h handle, sensor_motion_facedown_event_cb callback, void *user_data) +{ + return _sensor_set_data_cb(handle, SENSOR_MOTION_FACEDOWN, 0, (void*) callback, user_data); +} + +int sensor_motion_facedown_unset_cb (sensor_h handle) +{ + return _sensor_unset_data_cb(handle, SENSOR_MOTION_FACEDOWN); +}