diff --git a/legacy/eeze/configure.ac b/legacy/eeze/configure.ac index 5d17a25e9d..ea23ea8d45 100644 --- a/legacy/eeze/configure.ac +++ b/legacy/eeze/configure.ac @@ -206,6 +206,19 @@ if test "x${have_ipv6}" = "xyes" ; then AC_DEFINE(HAVE_IPV6, 1, [Define if IPV6 is supported]) fi +eeze_sensor_tizen="no" +PKG_CHECK_EXISTS([capi-system-sensor], + [ + AC_DEFINE([HAVE_EEZE_TIZEN], [1], [Eeze has Tizen sensor support enabled]) + AM_CONDITIONAL([HAVE_EEZE_TIZEN], [true]) + eeze_sensor_tizen="yes" + ], + AM_CONDITIONAL([HAVE_EEZE_TIZEN], [false]) +) +if test "x$eeze_sensor_tizen" = "xyes";then + PKG_CHECK_MODULES([TIZEN_SENSOR], [capi-system-sensor]) +fi + ### Checks for header files @@ -230,6 +243,7 @@ EFL_COMPILER_FLAG([-Wshadow]) ### Binary EFL_ENABLE_BIN([eeze-udev-test], ["yes"]) +EFL_ENABLE_BIN([eeze_sensor_test], ["yes"]) EFL_ENABLE_BIN([eeze-mount], ["yes"]) EFL_ENABLE_BIN([eeze-disk-ls], ["yes"]) EFL_ENABLE_BIN([eeze-umount], ["yes"]) @@ -281,6 +295,9 @@ echo " eeze_scanner.........: ${have_eeze_scanner}" echo echo "IPv6...................: ${have_ipv6}" echo +echo "Sensor.................:" +echo " Tizen................: ${eeze_sensor_tizen}" +echo echo "Documentation..........: ${build_doc}" echo echo "Compilation............: make (or gmake)" diff --git a/legacy/eeze/src/bin/Makefile.am b/legacy/eeze/src/bin/Makefile.am index 280006d835..1e69a4f953 100644 --- a/legacy/eeze/src/bin/Makefile.am +++ b/legacy/eeze/src/bin/Makefile.am @@ -5,7 +5,7 @@ EEZE_CFLAGS = \ @EEZE_CFLAGS@ noinst_PROGRAMS = @EEZE_UDEV_TEST_PRG@ -EXTRA_PROGRAMS = eeze_udev_test eeze_mount eeze_umount eeze_disk_ls eeze_scanner +EXTRA_PROGRAMS = eeze_udev_test eeze_mount eeze_umount eeze_disk_ls eeze_scanner eeze_sensor_test if HAVE_EEZE_MOUNT DISK_PROGS = @EEZE_MOUNT_PRG@ @EEZE_UMOUNT_PRG@ @EEZE_DISK_LS_PRG@ @@ -23,6 +23,11 @@ eeze_udev_test_SOURCES = eeze_udev_test.c eeze_udev_test_CPPFLAGS = -I$(top_srcdir)/src/lib @EEZE_CFLAGS@ eeze_udev_test_LDADD = $(top_builddir)/src/lib/libeeze.la @EEZE_LIBS@ +bin_PROGRAMS += @EEZE_SENSOR_TEST_PRG@ +eeze_sensor_test_SOURCES = eeze_sensor_test.c +eeze_sensor_test_CPPFLAGS = -I$(top_srcdir)/src/lib @EEZE_CFLAGS@ +eeze_sensor_test_LDADD = $(top_builddir)/src/lib/libeeze.la @EEZE_LIBS@ + if HAVE_EEZE_MOUNT eeze_mount_SOURCES = eeze_mount.c eeze_mount_CFLAGS = -I$(top_srcdir)/src/lib $(EEZE_CFLAGS) @LIBMOUNT_CFLAGS@ @ECORE_FILE_CFLAGS@ diff --git a/legacy/eeze/src/bin/eeze_sensor_test.c b/legacy/eeze/src/bin/eeze_sensor_test.c new file mode 100644 index 0000000000..3b8008a933 --- /dev/null +++ b/legacy/eeze/src/bin/eeze_sensor_test.c @@ -0,0 +1,137 @@ +#ifdef HAVE_CONFIG_H +# include +#endif /* ifdef HAVE_CONFIG_H */ + +#include +#include +#include + +#include + +/* + TODO + if you want a continual flow maybe eeze_sensor_flow_set(sens, EINA_TRUE); (by + default they are alll EINA_FALSE - ie dont provide a flow of events). +*/ + +static Eina_Bool +event_cb(void *data EINA_UNUSED, int ev_type, void *event) +{ + Eeze_Sensor_Obj *sens = NULL; + float x, y, z; + int acc; + unsigned long long timestamp; + + sens = event; + if (!sens) printf("can't find sensor!\n"); + if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); + if (!eeze_sensor_timestamp_get(sens, ×tamp)) printf("fail get timestamp\n"); + + if (ev_type == EEZE_SENSOR_EVENT_ACCELEROMETER) + { + if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n"); + printf("Accelerometer callback: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp); + } + else if (ev_type == EEZE_SENSOR_EVENT_FACEDOWN) + printf("Facedown callback at time: %lli\n", timestamp); + else if (ev_type == EEZE_SENSOR_EVENT_DOUBLETAP) + printf("Doubletap callback at time: %lli\n", timestamp); + else if (ev_type == EEZE_SENSOR_EVENT_SHAKE) + { + if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n"); + printf("Shake callback: accuracy %i, x %f at time: %lli\n", acc, x, timestamp); + } + + return ECORE_CALLBACK_PASS_ON; +} + +int +main(void) +{ + Eeze_Sensor_Obj *sens; + float x, y, z; + int acc; + unsigned long long timestamp; + + ecore_init(); + eeze_init(); + + printf("=== Test sync reads: ===\n"); + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC); + if (!sens) printf("can't find an magnetic sensor!\n"); + if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n"); + if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); + if (!eeze_sensor_timestamp_get(sens, ×tamp)) printf("fail get timestamp\n"); + printf("Magnetic output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp); + eeze_sensor_free(sens); + + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER); + if (!sens) printf("can't find an accelerometer sensor!\n"); + if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n"); + if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); + if (!eeze_sensor_timestamp_get(sens, ×tamp)) printf("fail get timestamp\n"); + printf("Accel output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp); + eeze_sensor_free(sens); + + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION); + if (!sens) printf("can't find an orientation sensor!\n"); + if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n"); + if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); + if (!eeze_sensor_timestamp_get(sens, ×tamp)) printf("fail get timestamp\n"); + printf("Orientation output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp); + eeze_sensor_free(sens); + + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE); + if (!sens) printf("can't find an gyroscope sensor!\n"); + if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n"); + if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); + if (!eeze_sensor_timestamp_get(sens, ×tamp)) printf("fail get timestamp\n"); + printf("Gyroscope output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp); + eeze_sensor_free(sens); + + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY); + if (!sens) printf("can't find an proximity sensor!\n"); + if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n"); + if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); + if (!eeze_sensor_timestamp_get(sens, ×tamp)) printf("fail get timestamp\n"); + printf("Proximity output: accuracy %i, distance %f at time: %lli\n", acc, x, timestamp); + eeze_sensor_free(sens); + + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); + if (!sens) printf("can't find an light sensor!\n"); + if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n"); + if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); + if (!eeze_sensor_timestamp_get(sens, ×tamp)) printf("fail get timestamp\n"); + printf("Light output: accuracy %i, lux %f at time: %lli\n", acc, x, timestamp); + + sleep(1); + + /* Get updated values on a sensor. Read out is synchronous */ + eeze_sensor_read(sens); + if (!sens) printf("can't find an light sensor!\n"); + if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n"); + if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); + if (!eeze_sensor_timestamp_get(sens, ×tamp)) printf("fail get timestamp\n"); + printf("Light output: accuracy %i, lux %f at time: %lli\n", acc, x, timestamp); + eeze_sensor_free(sens); + + printf("=== Test async reads / events: ===\n"); + /* Async read request for sensors. You have to register an event handler for it first and then + * request the read out */ + ecore_event_handler_add(EEZE_SENSOR_EVENT_ACCELEROMETER, event_cb, NULL); + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER); + eeze_sensor_async_read(sens, NULL); + + /* Set callbacks for motion events coming in */ + ecore_event_handler_add(EEZE_SENSOR_EVENT_FACEDOWN, event_cb, NULL); + ecore_event_handler_add(EEZE_SENSOR_EVENT_DOUBLETAP, event_cb, NULL); + + ecore_main_loop_begin(); + + eeze_sensor_free(sens); + eeze_shutdown(); + ecore_shutdown(); + + return 0; +} + diff --git a/legacy/eeze/src/lib/Eeze.h b/legacy/eeze/src/lib/Eeze.h index b6df1d5957..9103493d13 100644 --- a/legacy/eeze/src/lib/Eeze.h +++ b/legacy/eeze/src/lib/Eeze.h @@ -30,6 +30,7 @@ @li @ref find Functions which find types of devices @li @ref disk Disk functions @li @ref net Net functions + @li @ref sensor Sensor functions @verbatim Pants @endverbatim diff --git a/legacy/eeze/src/lib/Eeze_Sensor.h b/legacy/eeze/src/lib/Eeze_Sensor.h new file mode 100644 index 0000000000..83556b6833 --- /dev/null +++ b/legacy/eeze/src/lib/Eeze_Sensor.h @@ -0,0 +1,250 @@ +#ifndef EEZE_SENSOR_H +#define EEZE_SENSOR_H + +#ifdef EAPI +# undef EAPI +#endif + +#ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EAPI __attribute__ ((visibility("default"))) +# else +# define EAPI +# endif +#else +# define EAPI +#endif + +#include + +/** + * @file Eeze_Sensor.h + * @brief Sensor information + * @since 1.8 + * + * Eeze sensor functions allow you to gather sensor information from different sensor sources + * available on the hardware. It supports a plugin architecture to support different hardware + * platforms and devices. + * + * @addtogroup sensor Sensor + * @{ + */ + +/** + * @enum Eeze_Sensor_Type + * @since 1.8 + * + * All sensor types known by Eeze Sensor. This list of types include real physical types like + * proximity or light as well as "aggregated" types like putting a device down on the dsiplay side + * (facedown). + */ +typedef enum +{ + EEZE_SENSOR_TYPE_ACCELEROMETER, /**< Accelerometer sensor */ + EEZE_SENSOR_TYPE_MAGNETIC, /**< Magnetic sensor */ + EEZE_SENSOR_TYPE_ORIENTATION, /**< Orientation sensor */ + EEZE_SENSOR_TYPE_GYROSCOPE, /**< Gyroscope sensor */ + EEZE_SENSOR_TYPE_LIGHT, /**< Light sensor */ + EEZE_SENSOR_TYPE_PROXIMITY, /**< Proximity sensor */ + EEZE_SENSOR_TYPE_MOTION_SNAP, /**< Snap motion sensor */ + EEZE_SENSOR_TYPE_MOTION_SHAKE, /**< Shake motion sensor */ + EEZE_SENSOR_TYPE_MOTION_DOUBLETAP, /**< Doubletap motion sensor */ + EEZE_SENSOR_TYPE_MOTION_PANNING, /**< Panning motion sensor */ + EEZE_SENSOR_TYPE_MOTION_FACEDOWN, /**< Facedown motion sensor */ + /* Non-Tizen from here */ + EEZE_SENSOR_TYPE_BAROMETER, /**< Barometer sensor */ + EEZE_SENSOR_TYPE_TEMPERATURE, /**< Temperature sensor */ + EEZE_SENSOR_TYPE_LAST = 0xFF /**< Last item to mark end of enum */ +} Eeze_Sensor_Type; + +/** + * @defgroup Sensor_Events Available eeze sensor events + * @brief Sensor events that are emitted from the library as ecore events + * + * Event types used to regoister ecore_event_handler on. These events are used for + * #eeze_sensor_async_read to deliver read out data. It is also used for generated events like + * facedown or shake. + * @since 1.8 + * @{ + */ +EAPI int EEZE_SENSOR_EVENT_ACCELEROMETER; +EAPI int EEZE_SENSOR_EVENT_MAGNETIC; +EAPI int EEZE_SENSOR_EVENT_ORIENTATION; +EAPI int EEZE_SENSOR_EVENT_GYROSCOPE; +EAPI int EEZE_SENSOR_EVENT_LIGHT; +EAPI int EEZE_SENSOR_EVENT_PROXIMITY; +EAPI int EEZE_SENSOR_EVENT_SNAP; +EAPI int EEZE_SENSOR_EVENT_SHAKE; +EAPI int EEZE_SENSOR_EVENT_DOUBLETAP; +EAPI int EEZE_SENSOR_EVENT_PANNING; +EAPI int EEZE_SENSOR_EVENT_FACEDOWN; +EAPI int EEZE_SENSOR_EVENT_BAROMETER; +EAPI int EEZE_SENSOR_EVENT_TEMPERATURE; +/**@}*/ + +/** + * @typedef Eeze_Sensor + * @since 1.8 + * + * Handle for an Eeze_Sensor. + */ +typedef struct _Eeze_Sensor +{ + Eina_Array *modules_array; /**< Array of available runtime modules */ + Eina_Hash *modules; /**< Hash with loaded modules */ +} Eeze_Sensor; + +/** + * @typedef Eeze_Sensor_Obj; + * @since 1.8 + * + * Object for a sensor type. Keeps information about the type and holds the data for the accessor + * functions. As this information gets also updated by async reads it might be a good idea to check + * the timestamp value to see when the data has been updated. The timestamp is given as unix epoch + * (seconds since 00:00:00 UTC on 1 January 1970). + */ +typedef struct _Eeze_Sensor_Obj +{ + unsigned int type; /**< Sensor type see #Eeze_Sensor_Type */ + int accuracy; /**< Accuracy of the sensor value */ + float data[3]; /**< Sensor data depending on the sensor type */ + unsigned long long timestamp; /**< Timestamp of data read */ + Eina_Bool continuous_flow; /**< FUTURE USE: Continuous flow of sensor read out */ +} Eeze_Sensor_Obj; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create sensor object to operate on. + * @param type Sensor type to create object from. + * @return Sensor object for the given type. + * + * Takes the sensor type and create an object for it to operate on. During this it also does an + * initial sensor data read to fill the sensor data into the object. + * The #eeze_sensor_free function must be used to destroy the object and release its memory. + * @since 1.8 + */ +EAPI Eeze_Sensor_Obj *eeze_sensor_new(Eeze_Sensor_Type type); + +/** + * @brief Free a sensor object. + * @param sens Sensor object to operate on. + * + * Free an sensor object when it is no longer needed. + * @since 1.8 + */ +EAPI void eeze_sensor_free(Eeze_Sensor_Obj *sens); + +/** + * @brief Get accuracy from sensor object. + * @param sens Sensor object to operate on. + * @param accuracy Pointer to write accurancy value into. + * @return EINA_TRUE for success and EINA_FALSE for failure + * + * Accessor function to get the accurancy property from the sensor object. + * @since 1.8 + */ +EAPI Eina_Bool eeze_sensor_accuracy_get(Eeze_Sensor_Obj *sens, int *accuracy); + +/** + * @brief Get data from all three data properties + * @param sens Sensor object to operate on. + * @param x Pointer to write first data property value into. + * @param y Pointer to write second data property value into. + * @param z Pointer to write third data property value into. + * @return EINA_TRUE for success and EINA_FALSE for failure + * + * Accessor function to get all three data properties from the sensor object. This is used for sensor + * types that offer all three values. Like acceleromter and magnetic. + * @since 1.8 + */ +EAPI Eina_Bool eeze_sensor_xyz_get(Eeze_Sensor_Obj *sens, float *x, float *y, float *z); + +/** + * @brief Get data from first two data properties + * @param sens Sensor object to operate on. + * @param x Pointer to write first data property value into. + * @param y Pointer to write second data property value into. + * @return EINA_TRUE for success and EINA_FALSE for failure + * + * Accessor function to get the first two data properties from the sensor object. This is used for sensor + * types that offer two values. Like panning. + * @since 1.8 + */ +EAPI Eina_Bool eeze_sensor_xy_get(Eeze_Sensor_Obj *sens, float *x, float *y); + +/** + * @brief Get the data from first data property + * @param sens Sensor object to operate on. + * @param x Pointer to write first data property value into. + * @return EINA_TRUE for success and EINA_FALSE for failure + * + * Accessor function to get the first data property from the sensor object. This is used for sensor + * types that only offer one value. Like light or proximity. + * @since 1.8 + */ +EAPI Eina_Bool eeze_sensor_x_get(Eeze_Sensor_Obj *sens, float *x); + +/** + * @brief Get timestamp from sensor object. + * @param sens Sensor object to operate on. + * @param timestamp Pointer to write timestamp value into. + * @return EINA_TRUE for success and EINA_FALSE for failure + * + * Accessor function to get the timestamp property from the sensor object. + * @since 1.8 + */ +EAPI Eina_Bool eeze_sensor_timestamp_get(Eeze_Sensor_Obj *sens, unsigned long long *timestamp); + +/** + * @brief Read out sensor data + * @param sens Sensor object to operate on. + * @return EINA_TRUE for success and EINA_FALSE for failure + * + * This function reads sensor data from the device and fills the sensor object with the data. This + * call is synchronuos and blocks until the data is read out and updated in the sensor object. + * For simple applications this is fine and the easiest way to use the API. + * @since 1.8 + */ +EAPI Eina_Bool eeze_sensor_read(Eeze_Sensor_Obj *sens); + +/** + * @brief Asynchronous read out sensor data + * @param sens Sensor object to operate on. + * @param user_data Data to pass to the callback function. + * @return EINA_TRUE for success and EINA_FALSE for failure + * + * This function reads sensor data from the device and fills the sensor object with the data. The + * read is done asynchronously and thus does not block after calling. Instead the given callback + * function is called once the read is finished and the object filled. + * @since 1.8 + */ +EAPI Eina_Bool eeze_sensor_async_read(Eeze_Sensor_Obj *sens, void *user_data); + +/** + * @brief Helper function to access the sensor handle + * @return The sensor handle to operate on + * + * @since 1.8 + */ +EAPI Eeze_Sensor *eeze_sensor_handle_get(void); + +/** + * @brief Fetch the sensor object by type from the sensor object list + * @param type Sensor type to fetch from the list of sensor objects. + * @return The sensor object matching the given type + * + * @since 1.8 + */ +EAPI Eeze_Sensor_Obj *eeze_sensor_obj_get(Eeze_Sensor_Type type); + +Eina_Bool eeze_sensor_init(void); +void eeze_sensor_shutdown(void); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/legacy/eeze/src/lib/Makefile.am b/legacy/eeze/src/lib/Makefile.am index b14e44d401..c946f3c79f 100644 --- a/legacy/eeze/src/lib/Makefile.am +++ b/legacy/eeze/src/lib/Makefile.am @@ -1,8 +1,9 @@ MAINTAINERCLEANFILES = Makefile.in -AM_CPPFLAGS = @EEZE_CFLAGS@ +AM_CPPFLAGS = @EEZE_CFLAGS@ \ +-DPACKAGE_LIB_DIR=\"$(libdir)\" -includes_HEADERS = Eeze.h Eeze_Net.h +includes_HEADERS = Eeze.h Eeze_Net.h Eeze_Sensor.h libeeze_la_SOURCES = \ eeze_main.c \ @@ -13,7 +14,8 @@ eeze_udev_private.h \ eeze_udev_private.c \ eeze_udev_syspath.c \ eeze_udev_walk.c \ -eeze_udev_watch.c +eeze_udev_watch.c \ +eeze_sensor.c if HAVE_EEZE_MOUNT AM_CFLAGS = @EEZE_CFLAGS@ @LIBMOUNT_CFLAGS@ @ECORE_FILE_CFLAGS@ @@ -35,9 +37,26 @@ endif lib_LTLIBRARIES = libeeze.la includesdir = $(includedir)/eeze-@VMAJ@ +libeeze_la_LIBADD = @EEZE_LIBS@ + if HAVE_EEZE_MOUNT - libeeze_la_LIBADD = @EEZE_LIBS@ @LIBMOUNT_LIBS@ @ECORE_FILE_LIBS@ -else - libeeze_la_LIBADD = @EEZE_LIBS@ + libeeze_la_LIBADD += @LIBMOUNT_LIBS@ @ECORE_FILE_LIBS@ endif + libeeze_la_LDFLAGS = -no-undefined -version-info @version_info@ @release_info@ + +# Sensor modules +pkgdir = $(libdir)/eeze-sensor +if HAVE_EEZE_TIZEN +pkg_LTLIBRARIES = eeze-sensor-tizen.la +eeze_sensor_tizen_la_SOURCES = eeze_sensor_tizen.c +eeze_sensor_tizen_la_LDFLAGS = -no-undefined -module -avoid-version @TIZEN_SENSOR_LIBS@ +eeze_sensor_tizen_la_LIBTOOLFLAGS = --tag=disable-static +else +pkg_LTLIBRARIES = eeze-sensor-fake.la +eeze_sensor_fake_la_SOURCES = eeze_sensor_fake.c +eeze_sensor_fake_la_LDFLAGS = -no-undefined -module -avoid-version +eeze_sensor_fake_la_LIBTOOLFLAGS = --tag=disable-static +endif + + diff --git a/legacy/eeze/src/lib/eeze_main.c b/legacy/eeze/src/lib/eeze_main.c index b9954cfd31..e2b878b20b 100644 --- a/legacy/eeze/src/lib/eeze_main.c +++ b/legacy/eeze/src/lib/eeze_main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "eeze_udev_private.h" #include "eeze_net_private.h" #include "eeze_disk_private.h" @@ -13,6 +14,7 @@ _udev *udev; int _eeze_udev_log_dom = -1; int _eeze_net_log_dom = -1; +int _eeze_sensor_log_dom = -1; int _eeze_init_count = 0; static Eeze_Version _version = { VMAJ, VMIN, VMIC, VREV }; @@ -40,6 +42,12 @@ eeze_init(void) goto eina_net_fail; } + _eeze_sensor_log_dom = eina_log_domain_register("eeze_sensor", EINA_COLOR_BLUE); + if (_eeze_sensor_log_dom < 0) + { + EINA_LOG_ERR("Could not register 'eeze_sensor' log domain."); + goto eina_sensor_fail; + } if (!ecore_init()) goto ecore_fail; @@ -57,9 +65,16 @@ eeze_init(void) EINA_LOG_ERR("Error initializing eeze_net subsystems!"); goto net_fail; } + if (!eeze_sensor_init()) + { + EINA_LOG_ERR("Error initializing eeze_sensor subsystems!"); + goto sensor_fail; + } return _eeze_init_count; +sensor_fail: + eeze_net_shutdown(); net_fail: udev_unref(udev); fail: @@ -69,6 +84,9 @@ eeze_fail: #endif ecore_shutdown(); ecore_fail: + eina_log_domain_unregister(_eeze_sensor_log_dom); + _eeze_sensor_log_dom = -1; +eina_sensor_fail: eina_log_domain_unregister(_eeze_net_log_dom); _eeze_net_log_dom = -1; eina_net_fail: @@ -94,6 +112,7 @@ eeze_shutdown(void) #ifdef HAVE_EEZE_MOUNT eeze_disk_shutdown(); #endif + eeze_sensor_shutdown(); eeze_net_shutdown(); ecore_shutdown(); eina_log_domain_unregister(_eeze_udev_log_dom); diff --git a/legacy/eeze/src/lib/eeze_sensor.c b/legacy/eeze/src/lib/eeze_sensor.c new file mode 100644 index 0000000000..ccd6c18f56 --- /dev/null +++ b/legacy/eeze/src/lib/eeze_sensor.c @@ -0,0 +1,276 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include "eeze_sensor_private.h" + +Eeze_Sensor *g_handle; + +/* Priority order for modules. The one with the highest order of the available ones will be used */ +static const char *_module_priority[] = { + "tizen", + "fake", + NULL +}; + +EAPI Eeze_Sensor * +eeze_sensor_handle_get(void) +{ + return g_handle; +} + +Eeze_Sensor_Module * +_highest_priority_module_get(void) +{ + Eeze_Sensor_Module *module = NULL; + int i = 0; + + while (_module_priority[i] != NULL) + { + module = eina_hash_find(g_handle->modules, _module_priority[i]); + if (module) return module; + i++; + } + return NULL; +} + +EAPI Eeze_Sensor_Obj * +eeze_sensor_obj_get(Eeze_Sensor_Type sensor_type) +{ + Eina_List *l; + Eeze_Sensor_Obj *obj; + Eeze_Sensor_Module *module; + + module = _highest_priority_module_get(); + + if (!module) return NULL; + + EINA_LIST_FOREACH(module->sensor_list, l, obj) + { + if (obj->type == sensor_type) + { + return obj; + } + } + return NULL; +} + +static void +eeze_sensor_modules_load(void) +{ + /* Check for available runtime modules and load them */ + g_handle->modules_array = eina_module_list_get(NULL, PACKAGE_LIB_DIR "/eeze-sensor/", 0, NULL, NULL); + /* FIXME check for modules also in HOME and other locations */ + + if (!g_handle->modules_array) + { + ERR("No modules found!"); + return; + } + + eina_module_list_load(g_handle->modules_array); +} + +static void +eeze_sensor_modules_unload(void) +{ + if (!g_handle->modules_array) return; + eina_module_list_unload(g_handle->modules_array); + eina_module_list_free(g_handle->modules_array); + eina_array_free(g_handle->modules_array); + g_handle->modules_array = NULL; +} + +Eina_Bool +eeze_sensor_module_register(const char *name, Eeze_Sensor_Module *mod) +{ + Eeze_Sensor_Module *module = NULL; + + if (!mod) return EINA_FALSE; + + module = calloc(1, sizeof(Eeze_Sensor_Module)); + if (!module) return EINA_FALSE; + + module = mod; + + if (!module->init) return EINA_FALSE; + if (!(module->init())) return EINA_FALSE; + + INF("Registered module %s", name); + + return eina_hash_add(g_handle->modules, name, module); +} + +Eina_Bool +eeze_sensor_module_unregister(const char *name) +{ + DBG("Unregister module %s", name); + + Eeze_Sensor_Module *module = NULL; + + module = eina_hash_find(g_handle->modules, name); + if (module->shutdown) + module->shutdown(); + + return eina_hash_del(g_handle->modules, name, NULL); +} + +EAPI Eeze_Sensor_Obj * +eeze_sensor_new(Eeze_Sensor_Type type) +{ + Eeze_Sensor_Obj *sens; + Eeze_Sensor *handle; + Eeze_Sensor_Module *module = NULL; + + handle = eeze_sensor_handle_get(); + if (!handle) return NULL; + + sens = calloc(1, sizeof(Eeze_Sensor_Obj)); + if (!sens) return NULL; + + sens = eeze_sensor_obj_get(type); + + module = _highest_priority_module_get(); + if (!module) return EINA_FALSE; + + if (!module->read) return NULL; + + if (module->read(sens->type, sens)) + { + return sens; + } + else + return NULL; +} + +EAPI void +eeze_sensor_free(Eeze_Sensor_Obj *sens) +{ + if (!sens) return; + free(sens); +} + +EAPI Eina_Bool +eeze_sensor_accuracy_get(Eeze_Sensor_Obj *sens, int *accuracy) +{ + if (!sens) return EINA_FALSE; + + *accuracy = sens->accuracy; + return EINA_TRUE; +} + +EAPI Eina_Bool +eeze_sensor_xyz_get(Eeze_Sensor_Obj *sens, float *x, float *y, float *z) +{ + if (!sens) return EINA_FALSE; + + *x = sens->data[0]; + *y = sens->data[1]; + *z = sens->data[2]; + return EINA_TRUE; +} + +EAPI Eina_Bool +eeze_sensor_xy_get(Eeze_Sensor_Obj *sens, float *x, float *y) +{ + if (!sens) return EINA_FALSE; + + *x = sens->data[0]; + *y = sens->data[1]; + return EINA_TRUE; +} + +EAPI Eina_Bool +eeze_sensor_x_get(Eeze_Sensor_Obj *sens, float *x) +{ + if (!sens) return EINA_FALSE; + + *x = sens->data[0]; + return EINA_TRUE; +} + +EAPI Eina_Bool +eeze_sensor_timestamp_get(Eeze_Sensor_Obj *sens, unsigned long long *timestamp) +{ + if (!sens) return EINA_FALSE; + + *timestamp = sens->timestamp; + return EINA_TRUE; +} + +EAPI Eina_Bool +eeze_sensor_read(Eeze_Sensor_Obj *sens) +{ + Eeze_Sensor *handle = NULL; + Eeze_Sensor_Module *module = NULL; + + if (!sens) return EINA_FALSE; + + handle = eeze_sensor_handle_get(); + if (!handle) return EINA_FALSE; + + module = _highest_priority_module_get(); + if (!module) return EINA_FALSE; + + if (module->read) + return module->read(sens->type, sens); + + return EINA_FALSE; +} + +EAPI Eina_Bool +eeze_sensor_async_read(Eeze_Sensor_Obj *sens, void *user_data) +{ + Eeze_Sensor_Module *module = NULL; + Eeze_Sensor *handle = NULL; + + handle = eeze_sensor_handle_get(); + if (!handle) return EINA_FALSE; + + module = _highest_priority_module_get(); + if (!module) return EINA_FALSE; + if (module->async_read) + return module->async_read(sens->type, user_data); + + return EINA_FALSE; +} + +void +eeze_sensor_shutdown(void) +{ + eeze_sensor_modules_unload(); + free(g_handle); + g_handle = NULL; + + eina_shutdown(); +} + +Eina_Bool +eeze_sensor_init(void) +{ + if (!eina_init()) return EINA_FALSE; + + g_handle = calloc(1, sizeof(Eeze_Sensor)); + if (!g_handle) return EINA_FALSE; + + g_handle->modules_array = NULL; + g_handle->modules = eina_hash_string_small_new(NULL); + if (!g_handle->modules) return EINA_FALSE; + + EEZE_SENSOR_EVENT_SNAP = ecore_event_type_new(); + EEZE_SENSOR_EVENT_SHAKE = ecore_event_type_new(); + EEZE_SENSOR_EVENT_DOUBLETAP = ecore_event_type_new(); + EEZE_SENSOR_EVENT_PANNING = ecore_event_type_new(); + EEZE_SENSOR_EVENT_FACEDOWN = ecore_event_type_new(); + EEZE_SENSOR_EVENT_ACCELEROMETER = ecore_event_type_new(); + + eeze_sensor_modules_load(); + + return EINA_TRUE; +} + diff --git a/legacy/eeze/src/lib/eeze_sensor_fake.c b/legacy/eeze/src/lib/eeze_sensor_fake.c new file mode 100644 index 0000000000..f75e123f02 --- /dev/null +++ b/legacy/eeze/src/lib/eeze_sensor_fake.c @@ -0,0 +1,166 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#include +#include +#include +#include "eeze_sensor_private.h" + +Eeze_Sensor_Module *esensor_module; + +Eina_Bool +fake_init(void) +{ + /* Set a list with fake sensors */ + Eeze_Sensor_Type type; + + for (type = 0; type <= EEZE_SENSOR_TYPE_LAST; type++) + { + Eeze_Sensor_Obj *obj = calloc(1, sizeof(Eeze_Sensor_Obj)); + obj->type = type; + esensor_module->sensor_list = eina_list_append(esensor_module->sensor_list, obj); + } + + return EINA_TRUE; +} + +Eina_Bool +fake_shutdown(void) +{ + return EINA_TRUE; +} + +Eina_Bool +fake_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj) +{ + Eeze_Sensor_Obj *obj; + + obj = eeze_sensor_obj_get(sensor_type); + if (obj == NULL) + { + ERR("No matching sensor object found in list"); + return EINA_FALSE; + } + + switch (sensor_type) + { + case EEZE_SENSOR_TYPE_ACCELEROMETER: + case EEZE_SENSOR_TYPE_MAGNETIC: + case EEZE_SENSOR_TYPE_ORIENTATION: + case EEZE_SENSOR_TYPE_GYROSCOPE: + obj->accuracy = 0; + obj->data[0] = 7; + obj->data[1] = 23; + obj->data[2] = 42; + obj->timestamp = time(NULL); + break; + + case EEZE_SENSOR_TYPE_LIGHT: + case EEZE_SENSOR_TYPE_PROXIMITY: + case EEZE_SENSOR_TYPE_BAROMETER: + case EEZE_SENSOR_TYPE_TEMPERATURE: + obj->accuracy = 0; + obj->data[0] = 7; + obj->timestamp = time(NULL); + break; + + default: + ERR("Not possible to read from this sensor type."); + return EINA_FALSE; + } + + memcpy(lobj, obj, sizeof(Eeze_Sensor_Obj)); + + return EINA_TRUE; +} + +Eina_Bool +fake_async_read(Eeze_Sensor_Type sensor_type, void *user_data EINA_UNUSED) +{ + Eeze_Sensor_Obj *obj = NULL; + + obj = eeze_sensor_obj_get(sensor_type); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return EINA_FALSE; + } + + switch (sensor_type) + { + case EEZE_SENSOR_TYPE_ACCELEROMETER: + ecore_event_add(EEZE_SENSOR_EVENT_ACCELEROMETER, obj, NULL, NULL); + case EEZE_SENSOR_TYPE_MAGNETIC: + case EEZE_SENSOR_TYPE_ORIENTATION: + case EEZE_SENSOR_TYPE_GYROSCOPE: + obj->accuracy = 0; + obj->data[0] = 7; + obj->data[1] = 23; + obj->data[2] = 42; + obj->timestamp = time(NULL); + break; + + case EEZE_SENSOR_TYPE_LIGHT: + case EEZE_SENSOR_TYPE_PROXIMITY: + case EEZE_SENSOR_TYPE_BAROMETER: + case EEZE_SENSOR_TYPE_TEMPERATURE: + obj->accuracy = 0; + obj->data[0] = 7; + obj->timestamp = time(NULL); + break; + + case EEZE_SENSOR_TYPE_MOTION_SNAP: + break; + + case EEZE_SENSOR_TYPE_MOTION_SHAKE: + break; + + case EEZE_SENSOR_TYPE_MOTION_PANNING: + break; + + default: + ERR("Not possible to set a callback for this sensor type."); + return EINA_FALSE; + } + + return EINA_TRUE; +} + +Eina_Bool +sensor_fake_init(void) +{ + /* Check to avoid multi-init */ + if (esensor_module) return EINA_FALSE; + + /* Set module function pointer to allow calls into the module */ + esensor_module = calloc(1, sizeof(Eeze_Sensor_Module)); + if (!esensor_module) return EINA_FALSE; + + esensor_module->init = fake_init; + esensor_module->shutdown = fake_shutdown; + esensor_module->read = fake_read; + esensor_module->async_read = fake_async_read; + + if (!eeze_sensor_module_register("fake", esensor_module)) + { + ERR("Failed to register fake module."); + return EINA_FALSE; + } + + return EINA_TRUE; +} + +void +sensor_fake_shutdown(void) +{ + eeze_sensor_module_unregister("fake"); + free(esensor_module); + esensor_module = NULL; +} + +EINA_MODULE_INIT(sensor_fake_init); +EINA_MODULE_SHUTDOWN(sensor_fake_shutdown); diff --git a/legacy/eeze/src/lib/eeze_sensor_private.h b/legacy/eeze/src/lib/eeze_sensor_private.h new file mode 100644 index 0000000000..89575adf46 --- /dev/null +++ b/legacy/eeze/src/lib/eeze_sensor_private.h @@ -0,0 +1,53 @@ +#ifndef EEZE_SENSOR_PRIVATE_H +#define EEZE_SENSOR_PRIVATE_H +#include +#include +#include + +#include + +#ifndef EEZE_SENSOR_COLOR_DEFAULT +#define EEZE_SENSOR_COLOR_DEFAULT EINA_COLOR_BLUE +#endif +extern int _eeze_sensor_log_dom; +#ifdef CRI +#undef CRI +#endif + +#ifdef ERR +#undef ERR +#endif +#ifdef INF +#undef INF +#endif +#ifdef WARN +#undef WARN +#endif +#ifdef DBG +#undef DBG +#endif + +#define CRI(...) EINA_LOG_DOM_CRIT(_eeze_sensor_log_dom, __VA_ARGS__) +#define DBG(...) EINA_LOG_DOM_DBG(_eeze_sensor_log_dom, __VA_ARGS__) +#define INF(...) EINA_LOG_DOM_INFO(_eeze_sensor_log_dom, __VA_ARGS__) +#define WARN(...) EINA_LOG_DOM_WARN(_eeze_sensor_log_dom, __VA_ARGS__) +#define ERR(...) EINA_LOG_DOM_ERR(_eeze_sensor_log_dom, __VA_ARGS__) + +/** + * @typedef Eeze_Sensor_Module; + * @since 1.8 + * + * Loadable module data structure. + */ +typedef struct _Eeze_Sensor_Module +{ + Eina_Bool (*init)(void); /**< Pointer to module init function */ + Eina_Bool (*shutdown)(void); /**< Pointer to module shutdown function */ + Eina_Bool (*async_read)(Eeze_Sensor_Type sensor_type, void *user_data); /**< Pointer to module async_read function */ + Eina_Bool (*read)(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *obj); /**< Pointer to module read function */ + Eina_List *sensor_list; /**< List of sensor objects attached to the module */ +} Eeze_Sensor_Module; + +Eina_Bool eeze_sensor_module_register(const char *name, Eeze_Sensor_Module *mod); +Eina_Bool eeze_sensor_module_unregister(const char *name); +#endif // EEZE_SENSOR_PRIVATE_H diff --git a/legacy/eeze/src/lib/eeze_sensor_tizen.c b/legacy/eeze/src/lib/eeze_sensor_tizen.c new file mode 100644 index 0000000000..5134d4c7d4 --- /dev/null +++ b/legacy/eeze/src/lib/eeze_sensor_tizen.c @@ -0,0 +1,763 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include +#include +#include + +#include +#include +#include "eeze_sensor_private.h" + +Eeze_Sensor_Module *esensor_module; +sensor_h sensor_handle; // Tizen sensor handle + +static sensor_type_e +eeze_to_tizen(Eeze_Sensor_Type type) +{ + switch (type) + { + case EEZE_SENSOR_TYPE_ACCELEROMETER: + return SENSOR_ACCELEROMETER; + + case EEZE_SENSOR_TYPE_MAGNETIC: + return SENSOR_MAGNETIC; + + case EEZE_SENSOR_TYPE_ORIENTATION: + return SENSOR_ORIENTATION; + + case EEZE_SENSOR_TYPE_GYROSCOPE: + return SENSOR_GYROSCOPE; + + case EEZE_SENSOR_TYPE_LIGHT: + return SENSOR_LIGHT; + + case EEZE_SENSOR_TYPE_PROXIMITY: + return SENSOR_PROXIMITY; + + case EEZE_SENSOR_TYPE_MOTION_SNAP: + return SENSOR_MOTION_SNAP; + + case EEZE_SENSOR_TYPE_MOTION_SHAKE: + return SENSOR_MOTION_SHAKE; + + case EEZE_SENSOR_TYPE_MOTION_DOUBLETAP: + return SENSOR_MOTION_DOUBLETAP; + + case EEZE_SENSOR_TYPE_MOTION_PANNING: + return SENSOR_MOTION_PANNING; + + case EEZE_SENSOR_TYPE_MOTION_FACEDOWN: + return SENSOR_MOTION_FACEDOWN; + + default: + ERR("No matching Tizen sensor type available."); + return -1; + } +} + +void +accelerometer_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ACCELEROMETER); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->accuracy = accuracy; + obj->data[0] = x; + obj->data[1] = y; + obj->data[2] = z; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_ACCELEROMETER, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_ACCELEROMETER)); +} + +void +magnetic_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MAGNETIC); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->accuracy = accuracy; + obj->data[0] = x; + obj->data[1] = y; + obj->data[2] = z; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_MAGNETIC, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MAGNETIC)); +} + +void +orientation_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float azimuth, float pitch, float roll, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ORIENTATION); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->accuracy = accuracy; + obj->data[0] = azimuth; + obj->data[1] = pitch; + obj->data[2] = roll; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_ORIENTATION, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_ORIENTATION)); +} + +void +gyroscope_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_GYROSCOPE); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->accuracy = accuracy; + obj->data[0] = x; + obj->data[1] = y; + obj->data[2] = z; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_GYROSCOPE, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_GYROSCOPE)); +} + +void +light_cb(unsigned long long timestamp, float lux, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_LIGHT); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->accuracy = 0; + obj->data[0] = lux; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_LIGHT, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_LIGHT)); +} + +void +proximity_cb(unsigned long long timestamp, float distance, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_PROXIMITY); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->accuracy = 0; + obj->data[0] = distance; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_PROXIMITY, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_PROXIMITY)); +} + +void +snap_cb(unsigned long long timestamp, sensor_motion_snap_e snap, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_SNAP); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->data[0] = snap; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_SNAP, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_SNAP)); +} + +void +shake_cb(unsigned long long timestamp, sensor_motion_shake_e shake, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_SHAKE); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->data[0] = shake; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_SHAKE, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_SHAKE)); +} + +void +panning_cb(unsigned long long timestamp, int x, int y, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_PANNING); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->data[0] = x; + obj->data[1] = y; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_PANNING, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_PANNING)); +} + +void +facedown_cb(unsigned long long timestamp, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_FACEDOWN); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_FACEDOWN, obj, NULL, NULL); +} + +void +doubletap_cb(unsigned long long timestamp, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_DOUBLETAP); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_DOUBLETAP, obj, NULL, NULL); +} + +void +accelerometer_read_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + sensor_accelerometer_unset_cb(sensor_handle); + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ACCELEROMETER); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->accuracy = accuracy; + obj->data[0] = x; + obj->data[1] = y; + obj->data[2] = z; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_ACCELEROMETER, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_ACCELEROMETER)); +} + +void +magnetic_read_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + sensor_magnetic_unset_cb(sensor_handle); + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MAGNETIC); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->accuracy = accuracy; + obj->data[0] = x; + obj->data[1] = y; + obj->data[2] = z; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_MAGNETIC, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MAGNETIC)); +} + +void +orientation_read_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float azimuth, float pitch, float roll, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + sensor_orientation_unset_cb(sensor_handle); + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ORIENTATION); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->accuracy = accuracy; + obj->data[0] = azimuth; + obj->data[1] = pitch; + obj->data[2] = roll; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_ORIENTATION, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_ORIENTATION)); +} + +void +gyroscope_read_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + sensor_gyroscope_unset_cb(sensor_handle); + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_GYROSCOPE); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->accuracy = accuracy; + obj->data[0] = x; + obj->data[1] = y; + obj->data[2] = z; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_GYROSCOPE, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_GYROSCOPE)); +} + +void +light_read_cb(unsigned long long timestamp, float lux, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + sensor_light_unset_cb(sensor_handle); + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_LIGHT); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->accuracy = 0; + obj->data[0] = lux; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_LIGHT, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_LIGHT)); +} + +void +proximity_read_cb(unsigned long long timestamp, float distance, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + sensor_proximity_unset_cb(sensor_handle); + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_PROXIMITY); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->accuracy = 0; + obj->data[0] = distance; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_PROXIMITY, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_PROXIMITY)); +} + +void +snap_read_cb(unsigned long long timestamp, sensor_motion_snap_e snap, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + sensor_motion_snap_unset_cb(sensor_handle); + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_SNAP); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->data[0] = snap; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_SNAP, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_SNAP)); +} + +void +shake_read_cb(unsigned long long timestamp, sensor_motion_shake_e shake, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + sensor_motion_shake_unset_cb(sensor_handle); + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_SHAKE); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->data[0] = shake; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_SHAKE, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_SHAKE)); +} + +void +panning_read_cb(unsigned long long timestamp, int x, int y, void *user_data) +{ + Eeze_Sensor_Obj *obj = NULL; + + sensor_motion_panning_unset_cb(sensor_handle); + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_PANNING); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return; + } + obj->data[0] = x; + obj->data[1] = y; + obj->timestamp = timestamp; + ecore_event_add(EEZE_SENSOR_EVENT_PANNING, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_PANNING)); +} + +void +facedown_read_cb(unsigned long long timestamp, void *user_data) +{ + sensor_motion_facedown_unset_cb(sensor_handle); + ecore_event_add(EEZE_SENSOR_EVENT_FACEDOWN, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_MOTION_TYPE_FACEDOWN)); +} + +void +doubletap_read_cb(unsigned long long timestamp, void *user_data) +{ + sensor_motion_doubletap_unset_cb(sensor_handle); + ecore_event_add(EEZE_SENSOR_EVENT_DOUBLETAP, obj, NULL, NULL); + sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_MOTION_TYPE_DOUBLETAP)); +} + +Eina_Bool +eeze_sensor_tizen_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj) +{ + sensor_data_accuracy_e accuracy; + float x, y, z; + float azimuth, pitch, roll, lux, distance; + bool supported; + sensor_type_e type; + Eeze_Sensor_Obj *obj; + + type = eeze_to_tizen(sensor_type); + + sensor_is_supported(type, &supported); + if (!supported) + { + ERR("Sensor type %d not available on this device.", type); + return EINA_FALSE; + } + + sensor_start(handle->sensor_handle, type); + obj = eeze_sensor_obj_get(sensor_type); + if (obj == NULL) + { + ERR("No matching sensor object found in list."); + return EINA_FALSE; + } + + switch (type) + { + case SENSOR_ACCELEROMETER: + sensor_accelerometer_read_data(sensor_handle, &accuracy, &x, &y, &z); + obj->accuracy = accuracy; + obj->data[0] = x; + obj->data[1] = y; + obj->data[2] = z; + break; + + case SENSOR_MAGNETIC: + sensor_magnetic_read_data(sensor_handle, &accuracy, &x, &y, &z); + obj->accuracy = accuracy; + obj->data[0] = x; + obj->data[1] = y; + obj->data[2] = z; + break; + + case SENSOR_ORIENTATION: + sensor_orientation_read_data(sensor_handle, &accuracy, &azimuth, &pitch, &roll); + obj->accuracy = accuracy; + obj->data[0] = azimuth; + obj->data[1] = pitch; + obj->data[2] = roll; + break; + + case SENSOR_GYROSCOPE: + sensor_gyroscope_read_data(sensor_handle, &accuracy, &x, &y, &z); + obj->accuracy = accuracy; + obj->data[0] = x; + obj->data[1] = y; + obj->data[2] = z; + break; + + case SENSOR_LIGHT: + sensor_light_read_data(sensor_handle, &lux); + obj->accuracy = 0; + obj->data[0] = lux; + break; + + case SENSOR_PROXIMITY: + sensor_proximity_read_data(sensor_handle, &distance); + obj->accuracy = 0; + obj->data[0] = distance; + break; + + default: + ERR("Not possible to read from this sensor type."); + return EINA_FALSE; + } + + memcpy(lobj, obj, sizeof(Eeze_Sensor_Obj)); + + sensor_stop(sensor_handle, type); + return EINA_TRUE; +} + +// FIXME ho to handle this without explicit callback setting +#if 0 +Eina_Bool +eeze_sensor_tizen_cb_set(Eeze_Sensor *handle, Eeze_Sensor_Type sensor_type, void *cb_function, void *user_data) +{ + sensor_type_e type; + + type = eeze_to_tizen(sensor_type); + + handle->cb_function = cb_function; + + sensor_start(handle->sensor_handle, type); + + switch (type) + { + case SENSOR_ACCELEROMETER: + sensor_accelerometer_set_cb(handle->sensor_handle, 0, accelerometer_cb, handle); + break; + + case SENSOR_MAGNETIC: + sensor_magnetic_set_cb(handle->sensor_handle, 0, magnetic_cb, handle); + break; + + case SENSOR_ORIENTATION: + sensor_orientation_set_cb(handle->sensor_handle, 0, orientation_cb, handle); + break; + + case SENSOR_GYROSCOPE: + sensor_gyroscope_set_cb(handle->sensor_handle, 0, gyroscope_cb, handle); + break; + + case SENSOR_LIGHT: + sensor_light_set_cb(handle->sensor_handle, 0, light_cb, handle); + break; + + case SENSOR_PROXIMITY: + sensor_proximity_set_cb(handle->sensor_handle, 0, proximity_cb, handle); + break; + + case SENSOR_MOTION_SNAP: + sensor_motion_snap_set_cb(handle->sensor_handle, snap_cb, handle); + break; + + case SENSOR_MOTION_SHAKE: + sensor_motion_shake_set_cb(handle->sensor_handle, shake_cb, handle); + break; + + case SENSOR_MOTION_PANNING: + sensor_motion_panning_set_cb(handle->sensor_handle, panning_cb, handle); + break; + + default: + ERR("Not possible to set a callback for this sensor type."); + return EINA_FALSE; + } + return EINA_TRUE; +} +#endif + +Eina_Bool +eeze_sensor_tizen_async_read(Eeze_Sensor_Type sensor_type, void *user_data) +{ + sensor_type_e type; + + type = eeze_to_tizen(sensor_type); + + sensor_start(sensor_handle, type); + + switch (type) + { + case SENSOR_ACCELEROMETER: + sensor_accelerometer_set_cb(sensor_handle, 0, accelerometer_read_cb, NULL); + break; + + case SENSOR_MAGNETIC: + sensor_magnetic_set_cb(sensor_handle, 0, magnetic_read_cb, NULL); + break; + + case SENSOR_ORIENTATION: + sensor_orientation_set_cb(sensor_handle, 0, orientation_read_cb, NULL); + break; + + case SENSOR_GYROSCOPE: + sensor_gyroscope_set_cb(sensor_handle, 0, gyroscope_read_cb, NULL); + break; + + case SENSOR_LIGHT: + sensor_light_set_cb(sensor_handle, 0, light_read_cb, NULL); + break; + + case SENSOR_PROXIMITY: + sensor_proximity_set_cb(sensor_handle, 0, proximity_read_cb, NULL); + break; + + case SENSOR_MOTION_SNAP: + sensor_motion_snap_set_cb(sensor_handle, snap_read_cb, NULL); + break; + + case SENSOR_MOTION_SHAKE: + sensor_motion_shake_set_cb(sensor_handle, shake_read_cb, NULL); + break; + + case SENSOR_MOTION_DOUBLETAP: + sensor_motion_doubletap_set_cb(sensor_handle, doubletap_read_cb, NULL); + break; + + case SENSOR_MOTION_PANNING: + sensor_motion_panning_set_cb(sensor_handle, panning_read_cb, NULL); + break; + + case SENSOR_MOTION_FACEDOWN: + sensor_motion_facedown_set_cb(sensor_handle, facedown_read_cb, NULL); + break; + + default: + ERR("Not possible to set a callback for this sensor type."); + return EINA_FALSE; + } + return EINA_TRUE; +} + +static void +eeze_sensor_tizen_sensors_find(void) +{ + sensor_type_e type; + bool supported = 0; + + /* FIXME: Make this safe against changes in the enum. But how? */ + for (type = SENSOR_ACCELEROMETER; type <= SENSOR_MOTION_FACEDOWN; type++) + { + sensor_is_supported(type, &supported); + if (supported) + { + Eeze_Sensor_Obj *obj = calloc(1, sizeof(Eeze_Sensor_Obj)); + obj->type = type; + esensor_module->sensor_list = eina_list_append(esensor_module->sensor_list, obj); + } + } +} + +Eina_Bool +eeze_sensor_tizen_shutdown(void) +{ + Eeze_Sensor_Obj *obj; + + EINA_LIST_FREE(esensor_module->sensor_list, obj) + free(obj); + + sensor_start(sensor_handle, SENSOR_MOTION_FACEDOWN); + sensor_start(sensor_handle, SENSOR_MOTION_DOUBLETAP); + sensor_start(sensor_handle, SENSOR_MOTION_SHAKE); + if (sensor_destroy(sensor_handle) != 0) + { + ERR("Failing to destroy sensor handle."); + return EINA_FALSE; + } + + return EINA_TRUE; +} + +Eina_Bool +eeze_sensor_tizen_init(void) +{ + + if (sensor_create(&sensor_handle) != 0) + { + ERR("Failing to create sensor handle."); + return EINA_FALSE; + } + + eeze_sensor_tizen_sensors_find(); + + /* FIXME add other motion events in here */ + sensor_start(sensor_handle, SENSOR_MOTION_FACEDOWN); + sensor_start(sensor_handle, SENSOR_MOTION_DOUBLETAP); + sensor_motion_doubletap_set_cb(sensor_handle, doubletap_cb, handle); + sensor_motion_facedown_set_cb(sensor_handle, facedown_cb, handle); + + return EINA_TRUE; +} + +Eina_Bool +sensor_tizen_init(void) +{ + /* Check to avoid multi-init */ + if (esensor_module) return EINA_FALSE; + + /* Set module function pointer to allow calls into the module */ + esensor_module = calloc(1, sizeof(Eeze_Sensor_Module)); + if (!esensor_module) return EINA_FALSE; + + esensor_module->init = eeze_sensor_tizen_init; + esensor_module->shutdown = eeze_sensor_tizen_shutdown; + esensor_module->read = eeze_sensor_tizen_read; + esensor_module->async_read = eeze_sensor_tizen_async_read; + + if (!eeze_sensor_module_register("tizen", esensor_module)) + { + ERR("Failed to register tizen module"); + return EINA_FALSE; + } + + return EINA_TRUE; +} + +void +sensor_tizen_shutdown(void) +{ + sensor_stop(sensor_handle, SENSOR_MOTION_FACEDOWN); + sensor_stop(sensor_handle, SENSOR_MOTION_DOUBLETAP); + eeze_sensor_module_unregister("tizen"); + free(esensor_module); + esensor_module = NULL; +} + +EINA_MODULE_INIT(sensor_tizen_init); +EINA_MODULE_SHUTDOWN(sensor_tizen_shutdown); +