summaryrefslogtreecommitdiff
path: root/legacy/eeze
diff options
context:
space:
mode:
authorStefan Schmidt <stefan@datenfreihafen.org>2012-09-18 14:14:48 +0000
committerStefan Schmidt <stefan@datenfreihafen.org>2012-09-18 14:14:48 +0000
commit535ef37087fe803508b37ca5e55e98edfd242813 (patch)
treea660cc4790f7bb672df505775ef75fc270081fa1 /legacy/eeze
parente0807db1c31979cb79faaa22e24fe8fc6a9a0a4b (diff)
eeze: Add sensor API
Extend eeze to read out sensor data from various sources with a simple API to access for application developers. The sensor backends are eina modules. For now we support a tizen module as well as a fake module for testing. Modules for plain sysfs on a desktop or other sensor frameworks could get integrated. The api is not fixed until 1.8 is out so let me know what you think. Having small wrappers for all kind of infos like eeze_sensor_light_get or eeze_sensor_proximity_get are possible but I did not want to bloat the api from the beginning. SVN revision: 76825
Diffstat (limited to 'legacy/eeze')
-rw-r--r--legacy/eeze/configure.ac17
-rw-r--r--legacy/eeze/src/bin/Makefile.am7
-rw-r--r--legacy/eeze/src/bin/eeze_sensor_test.c137
-rw-r--r--legacy/eeze/src/lib/Eeze.h1
-rw-r--r--legacy/eeze/src/lib/Eeze_Sensor.h250
-rw-r--r--legacy/eeze/src/lib/Makefile.am31
-rw-r--r--legacy/eeze/src/lib/eeze_main.c19
-rw-r--r--legacy/eeze/src/lib/eeze_sensor.c276
-rw-r--r--legacy/eeze/src/lib/eeze_sensor_fake.c166
-rw-r--r--legacy/eeze/src/lib/eeze_sensor_private.h53
-rw-r--r--legacy/eeze/src/lib/eeze_sensor_tizen.c763
11 files changed, 1713 insertions, 7 deletions
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
206 AC_DEFINE(HAVE_IPV6, 1, [Define if IPV6 is supported]) 206 AC_DEFINE(HAVE_IPV6, 1, [Define if IPV6 is supported])
207fi 207fi
208 208
209eeze_sensor_tizen="no"
210PKG_CHECK_EXISTS([capi-system-sensor],
211 [
212 AC_DEFINE([HAVE_EEZE_TIZEN], [1], [Eeze has Tizen sensor support enabled])
213 AM_CONDITIONAL([HAVE_EEZE_TIZEN], [true])
214 eeze_sensor_tizen="yes"
215 ],
216 AM_CONDITIONAL([HAVE_EEZE_TIZEN], [false])
217)
218if test "x$eeze_sensor_tizen" = "xyes";then
219 PKG_CHECK_MODULES([TIZEN_SENSOR], [capi-system-sensor])
220fi
221
209### Checks for header files 222### Checks for header files
210 223
211 224
@@ -230,6 +243,7 @@ EFL_COMPILER_FLAG([-Wshadow])
230### Binary 243### Binary
231 244
232EFL_ENABLE_BIN([eeze-udev-test], ["yes"]) 245EFL_ENABLE_BIN([eeze-udev-test], ["yes"])
246EFL_ENABLE_BIN([eeze_sensor_test], ["yes"])
233EFL_ENABLE_BIN([eeze-mount], ["yes"]) 247EFL_ENABLE_BIN([eeze-mount], ["yes"])
234EFL_ENABLE_BIN([eeze-disk-ls], ["yes"]) 248EFL_ENABLE_BIN([eeze-disk-ls], ["yes"])
235EFL_ENABLE_BIN([eeze-umount], ["yes"]) 249EFL_ENABLE_BIN([eeze-umount], ["yes"])
@@ -281,6 +295,9 @@ echo " eeze_scanner.........: ${have_eeze_scanner}"
281echo 295echo
282echo "IPv6...................: ${have_ipv6}" 296echo "IPv6...................: ${have_ipv6}"
283echo 297echo
298echo "Sensor.................:"
299echo " Tizen................: ${eeze_sensor_tizen}"
300echo
284echo "Documentation..........: ${build_doc}" 301echo "Documentation..........: ${build_doc}"
285echo 302echo
286echo "Compilation............: make (or gmake)" 303echo "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 = \
5@EEZE_CFLAGS@ 5@EEZE_CFLAGS@
6 6
7noinst_PROGRAMS = @EEZE_UDEV_TEST_PRG@ 7noinst_PROGRAMS = @EEZE_UDEV_TEST_PRG@
8EXTRA_PROGRAMS = eeze_udev_test eeze_mount eeze_umount eeze_disk_ls eeze_scanner 8EXTRA_PROGRAMS = eeze_udev_test eeze_mount eeze_umount eeze_disk_ls eeze_scanner eeze_sensor_test
9 9
10if HAVE_EEZE_MOUNT 10if HAVE_EEZE_MOUNT
11 DISK_PROGS = @EEZE_MOUNT_PRG@ @EEZE_UMOUNT_PRG@ @EEZE_DISK_LS_PRG@ 11 DISK_PROGS = @EEZE_MOUNT_PRG@ @EEZE_UMOUNT_PRG@ @EEZE_DISK_LS_PRG@
@@ -23,6 +23,11 @@ eeze_udev_test_SOURCES = eeze_udev_test.c
23eeze_udev_test_CPPFLAGS = -I$(top_srcdir)/src/lib @EEZE_CFLAGS@ 23eeze_udev_test_CPPFLAGS = -I$(top_srcdir)/src/lib @EEZE_CFLAGS@
24eeze_udev_test_LDADD = $(top_builddir)/src/lib/libeeze.la @EEZE_LIBS@ 24eeze_udev_test_LDADD = $(top_builddir)/src/lib/libeeze.la @EEZE_LIBS@
25 25
26bin_PROGRAMS += @EEZE_SENSOR_TEST_PRG@
27eeze_sensor_test_SOURCES = eeze_sensor_test.c
28eeze_sensor_test_CPPFLAGS = -I$(top_srcdir)/src/lib @EEZE_CFLAGS@
29eeze_sensor_test_LDADD = $(top_builddir)/src/lib/libeeze.la @EEZE_LIBS@
30
26if HAVE_EEZE_MOUNT 31if HAVE_EEZE_MOUNT
27 eeze_mount_SOURCES = eeze_mount.c 32 eeze_mount_SOURCES = eeze_mount.c
28 eeze_mount_CFLAGS = -I$(top_srcdir)/src/lib $(EEZE_CFLAGS) @LIBMOUNT_CFLAGS@ @ECORE_FILE_CFLAGS@ 33 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 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif /* ifdef HAVE_CONFIG_H */
4
5#include <Eeze.h>
6#include <Ecore.h>
7#include <stdio.h>
8
9#include <Eeze_Sensor.h>
10
11/*
12 TODO
13 if you want a continual flow maybe eeze_sensor_flow_set(sens, EINA_TRUE); (by
14 default they are alll EINA_FALSE - ie dont provide a flow of events).
15*/
16
17static Eina_Bool
18event_cb(void *data EINA_UNUSED, int ev_type, void *event)
19{
20 Eeze_Sensor_Obj *sens = NULL;
21 float x, y, z;
22 int acc;
23 unsigned long long timestamp;
24
25 sens = event;
26 if (!sens) printf("can't find sensor!\n");
27 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
28 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
29
30 if (ev_type == EEZE_SENSOR_EVENT_ACCELEROMETER)
31 {
32 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
33 printf("Accelerometer callback: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
34 }
35 else if (ev_type == EEZE_SENSOR_EVENT_FACEDOWN)
36 printf("Facedown callback at time: %lli\n", timestamp);
37 else if (ev_type == EEZE_SENSOR_EVENT_DOUBLETAP)
38 printf("Doubletap callback at time: %lli\n", timestamp);
39 else if (ev_type == EEZE_SENSOR_EVENT_SHAKE)
40 {
41 if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n");
42 printf("Shake callback: accuracy %i, x %f at time: %lli\n", acc, x, timestamp);
43 }
44
45 return ECORE_CALLBACK_PASS_ON;
46}
47
48int
49main(void)
50{
51 Eeze_Sensor_Obj *sens;
52 float x, y, z;
53 int acc;
54 unsigned long long timestamp;
55
56 ecore_init();
57 eeze_init();
58
59 printf("=== Test sync reads: ===\n");
60 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC);
61 if (!sens) printf("can't find an magnetic sensor!\n");
62 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
63 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
64 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
65 printf("Magnetic output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
66 eeze_sensor_free(sens);
67
68 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER);
69 if (!sens) printf("can't find an accelerometer sensor!\n");
70 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
71 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
72 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
73 printf("Accel output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
74 eeze_sensor_free(sens);
75
76 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION);
77 if (!sens) printf("can't find an orientation sensor!\n");
78 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
79 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
80 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
81 printf("Orientation output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
82 eeze_sensor_free(sens);
83
84 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE);
85 if (!sens) printf("can't find an gyroscope sensor!\n");
86 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
87 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
88 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
89 printf("Gyroscope output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
90 eeze_sensor_free(sens);
91
92 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY);
93 if (!sens) printf("can't find an proximity sensor!\n");
94 if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n");
95 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
96 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
97 printf("Proximity output: accuracy %i, distance %f at time: %lli\n", acc, x, timestamp);
98 eeze_sensor_free(sens);
99
100 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
101 if (!sens) printf("can't find an light sensor!\n");
102 if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n");
103 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
104 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
105 printf("Light output: accuracy %i, lux %f at time: %lli\n", acc, x, timestamp);
106
107 sleep(1);
108
109 /* Get updated values on a sensor. Read out is synchronous */
110 eeze_sensor_read(sens);
111 if (!sens) printf("can't find an light sensor!\n");
112 if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n");
113 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
114 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
115 printf("Light output: accuracy %i, lux %f at time: %lli\n", acc, x, timestamp);
116 eeze_sensor_free(sens);
117
118 printf("=== Test async reads / events: ===\n");
119 /* Async read request for sensors. You have to register an event handler for it first and then
120 * request the read out */
121 ecore_event_handler_add(EEZE_SENSOR_EVENT_ACCELEROMETER, event_cb, NULL);
122 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER);
123 eeze_sensor_async_read(sens, NULL);
124
125 /* Set callbacks for motion events coming in */
126 ecore_event_handler_add(EEZE_SENSOR_EVENT_FACEDOWN, event_cb, NULL);
127 ecore_event_handler_add(EEZE_SENSOR_EVENT_DOUBLETAP, event_cb, NULL);
128
129 ecore_main_loop_begin();
130
131 eeze_sensor_free(sens);
132 eeze_shutdown();
133 ecore_shutdown();
134
135 return 0;
136}
137
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 @@
30 @li @ref find Functions which find types of devices 30 @li @ref find Functions which find types of devices
31 @li @ref disk Disk functions 31 @li @ref disk Disk functions
32 @li @ref net Net functions 32 @li @ref net Net functions
33 @li @ref sensor Sensor functions
33 @verbatim 34 @verbatim
34 Pants 35 Pants
35 @endverbatim 36 @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 @@
1#ifndef EEZE_SENSOR_H
2#define EEZE_SENSOR_H
3
4#ifdef EAPI
5# undef EAPI
6#endif
7
8#ifdef __GNUC__
9# if __GNUC__ >= 4
10# define EAPI __attribute__ ((visibility("default")))
11# else
12# define EAPI
13# endif
14#else
15# define EAPI
16#endif
17
18#include <Eina.h>
19
20/**
21 * @file Eeze_Sensor.h
22 * @brief Sensor information
23 * @since 1.8
24 *
25 * Eeze sensor functions allow you to gather sensor information from different sensor sources
26 * available on the hardware. It supports a plugin architecture to support different hardware
27 * platforms and devices.
28 *
29 * @addtogroup sensor Sensor
30 * @{
31 */
32
33/**
34 * @enum Eeze_Sensor_Type
35 * @since 1.8
36 *
37 * All sensor types known by Eeze Sensor. This list of types include real physical types like
38 * proximity or light as well as "aggregated" types like putting a device down on the dsiplay side
39 * (facedown).
40 */
41typedef enum
42{
43 EEZE_SENSOR_TYPE_ACCELEROMETER, /**< Accelerometer sensor */
44 EEZE_SENSOR_TYPE_MAGNETIC, /**< Magnetic sensor */
45 EEZE_SENSOR_TYPE_ORIENTATION, /**< Orientation sensor */
46 EEZE_SENSOR_TYPE_GYROSCOPE, /**< Gyroscope sensor */
47 EEZE_SENSOR_TYPE_LIGHT, /**< Light sensor */
48 EEZE_SENSOR_TYPE_PROXIMITY, /**< Proximity sensor */
49 EEZE_SENSOR_TYPE_MOTION_SNAP, /**< Snap motion sensor */
50 EEZE_SENSOR_TYPE_MOTION_SHAKE, /**< Shake motion sensor */
51 EEZE_SENSOR_TYPE_MOTION_DOUBLETAP, /**< Doubletap motion sensor */
52 EEZE_SENSOR_TYPE_MOTION_PANNING, /**< Panning motion sensor */
53 EEZE_SENSOR_TYPE_MOTION_FACEDOWN, /**< Facedown motion sensor */
54 /* Non-Tizen from here */
55 EEZE_SENSOR_TYPE_BAROMETER, /**< Barometer sensor */
56 EEZE_SENSOR_TYPE_TEMPERATURE, /**< Temperature sensor */
57 EEZE_SENSOR_TYPE_LAST = 0xFF /**< Last item to mark end of enum */
58} Eeze_Sensor_Type;
59
60/**
61 * @defgroup Sensor_Events Available eeze sensor events
62 * @brief Sensor events that are emitted from the library as ecore events
63 *
64 * Event types used to regoister ecore_event_handler on. These events are used for
65 * #eeze_sensor_async_read to deliver read out data. It is also used for generated events like
66 * facedown or shake.
67 * @since 1.8
68 * @{
69 */
70EAPI int EEZE_SENSOR_EVENT_ACCELEROMETER;
71EAPI int EEZE_SENSOR_EVENT_MAGNETIC;
72EAPI int EEZE_SENSOR_EVENT_ORIENTATION;
73EAPI int EEZE_SENSOR_EVENT_GYROSCOPE;
74EAPI int EEZE_SENSOR_EVENT_LIGHT;
75EAPI int EEZE_SENSOR_EVENT_PROXIMITY;
76EAPI int EEZE_SENSOR_EVENT_SNAP;
77EAPI int EEZE_SENSOR_EVENT_SHAKE;
78EAPI int EEZE_SENSOR_EVENT_DOUBLETAP;
79EAPI int EEZE_SENSOR_EVENT_PANNING;
80EAPI int EEZE_SENSOR_EVENT_FACEDOWN;
81EAPI int EEZE_SENSOR_EVENT_BAROMETER;
82EAPI int EEZE_SENSOR_EVENT_TEMPERATURE;
83/**@}*/
84
85/**
86 * @typedef Eeze_Sensor
87 * @since 1.8
88 *
89 * Handle for an Eeze_Sensor.
90 */
91typedef struct _Eeze_Sensor
92{
93 Eina_Array *modules_array; /**< Array of available runtime modules */
94 Eina_Hash *modules; /**< Hash with loaded modules */
95} Eeze_Sensor;
96
97/**
98 * @typedef Eeze_Sensor_Obj;
99 * @since 1.8
100 *
101 * Object for a sensor type. Keeps information about the type and holds the data for the accessor
102 * functions. As this information gets also updated by async reads it might be a good idea to check
103 * the timestamp value to see when the data has been updated. The timestamp is given as unix epoch
104 * (seconds since 00:00:00 UTC on 1 January 1970).
105 */
106typedef struct _Eeze_Sensor_Obj
107{
108 unsigned int type; /**< Sensor type see #Eeze_Sensor_Type */
109 int accuracy; /**< Accuracy of the sensor value */
110 float data[3]; /**< Sensor data depending on the sensor type */
111 unsigned long long timestamp; /**< Timestamp of data read */
112 Eina_Bool continuous_flow; /**< FUTURE USE: Continuous flow of sensor read out */
113} Eeze_Sensor_Obj;
114
115#ifdef __cplusplus
116extern "C" {
117#endif
118
119/**
120 * @brief Create sensor object to operate on.
121 * @param type Sensor type to create object from.
122 * @return Sensor object for the given type.
123 *
124 * Takes the sensor type and create an object for it to operate on. During this it also does an
125 * initial sensor data read to fill the sensor data into the object.
126 * The #eeze_sensor_free function must be used to destroy the object and release its memory.
127 * @since 1.8
128 */
129EAPI Eeze_Sensor_Obj *eeze_sensor_new(Eeze_Sensor_Type type);
130
131/**
132 * @brief Free a sensor object.
133 * @param sens Sensor object to operate on.
134 *
135 * Free an sensor object when it is no longer needed.
136 * @since 1.8
137 */
138EAPI void eeze_sensor_free(Eeze_Sensor_Obj *sens);
139
140/**
141 * @brief Get accuracy from sensor object.
142 * @param sens Sensor object to operate on.
143 * @param accuracy Pointer to write accurancy value into.
144 * @return EINA_TRUE for success and EINA_FALSE for failure
145 *
146 * Accessor function to get the accurancy property from the sensor object.
147 * @since 1.8
148 */
149EAPI Eina_Bool eeze_sensor_accuracy_get(Eeze_Sensor_Obj *sens, int *accuracy);
150
151/**
152 * @brief Get data from all three data properties
153 * @param sens Sensor object to operate on.
154 * @param x Pointer to write first data property value into.
155 * @param y Pointer to write second data property value into.
156 * @param z Pointer to write third data property value into.
157 * @return EINA_TRUE for success and EINA_FALSE for failure
158 *
159 * Accessor function to get all three data properties from the sensor object. This is used for sensor
160 * types that offer all three values. Like acceleromter and magnetic.
161 * @since 1.8
162 */
163EAPI Eina_Bool eeze_sensor_xyz_get(Eeze_Sensor_Obj *sens, float *x, float *y, float *z);
164
165/**
166 * @brief Get data from first two data properties
167 * @param sens Sensor object to operate on.
168 * @param x Pointer to write first data property value into.
169 * @param y Pointer to write second data property value into.
170 * @return EINA_TRUE for success and EINA_FALSE for failure
171 *
172 * Accessor function to get the first two data properties from the sensor object. This is used for sensor
173 * types that offer two values. Like panning.
174 * @since 1.8
175 */
176EAPI Eina_Bool eeze_sensor_xy_get(Eeze_Sensor_Obj *sens, float *x, float *y);
177
178/**
179 * @brief Get the data from first data property
180 * @param sens Sensor object to operate on.
181 * @param x Pointer to write first data property value into.
182 * @return EINA_TRUE for success and EINA_FALSE for failure
183 *
184 * Accessor function to get the first data property from the sensor object. This is used for sensor
185 * types that only offer one value. Like light or proximity.
186 * @since 1.8
187 */
188EAPI Eina_Bool eeze_sensor_x_get(Eeze_Sensor_Obj *sens, float *x);
189
190/**
191 * @brief Get timestamp from sensor object.
192 * @param sens Sensor object to operate on.
193 * @param timestamp Pointer to write timestamp value into.
194 * @return EINA_TRUE for success and EINA_FALSE for failure
195 *
196 * Accessor function to get the timestamp property from the sensor object.
197 * @since 1.8
198 */
199EAPI Eina_Bool eeze_sensor_timestamp_get(Eeze_Sensor_Obj *sens, unsigned long long *timestamp);
200
201/**
202 * @brief Read out sensor data
203 * @param sens Sensor object to operate on.
204 * @return EINA_TRUE for success and EINA_FALSE for failure
205 *
206 * This function reads sensor data from the device and fills the sensor object with the data. This
207 * call is synchronuos and blocks until the data is read out and updated in the sensor object.
208 * For simple applications this is fine and the easiest way to use the API.
209 * @since 1.8
210 */
211EAPI Eina_Bool eeze_sensor_read(Eeze_Sensor_Obj *sens);
212
213/**
214 * @brief Asynchronous read out sensor data
215 * @param sens Sensor object to operate on.
216 * @param user_data Data to pass to the callback function.
217 * @return EINA_TRUE for success and EINA_FALSE for failure
218 *
219 * This function reads sensor data from the device and fills the sensor object with the data. The
220 * read is done asynchronously and thus does not block after calling. Instead the given callback
221 * function is called once the read is finished and the object filled.
222 * @since 1.8
223 */
224EAPI Eina_Bool eeze_sensor_async_read(Eeze_Sensor_Obj *sens, void *user_data);
225
226/**
227 * @brief Helper function to access the sensor handle
228 * @return The sensor handle to operate on
229 *
230 * @since 1.8
231 */
232EAPI Eeze_Sensor *eeze_sensor_handle_get(void);
233
234/**
235 * @brief Fetch the sensor object by type from the sensor object list
236 * @param type Sensor type to fetch from the list of sensor objects.
237 * @return The sensor object matching the given type
238 *
239 * @since 1.8
240 */
241EAPI Eeze_Sensor_Obj *eeze_sensor_obj_get(Eeze_Sensor_Type type);
242
243Eina_Bool eeze_sensor_init(void);
244void eeze_sensor_shutdown(void);
245
246#ifdef __cplusplus
247}
248#endif
249/** @} */
250#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 @@
1MAINTAINERCLEANFILES = Makefile.in 1MAINTAINERCLEANFILES = Makefile.in
2 2
3AM_CPPFLAGS = @EEZE_CFLAGS@ 3AM_CPPFLAGS = @EEZE_CFLAGS@ \
4-DPACKAGE_LIB_DIR=\"$(libdir)\"
4 5
5includes_HEADERS = Eeze.h Eeze_Net.h 6includes_HEADERS = Eeze.h Eeze_Net.h Eeze_Sensor.h
6 7
7libeeze_la_SOURCES = \ 8libeeze_la_SOURCES = \
8eeze_main.c \ 9eeze_main.c \
@@ -13,7 +14,8 @@ eeze_udev_private.h \
13eeze_udev_private.c \ 14eeze_udev_private.c \
14eeze_udev_syspath.c \ 15eeze_udev_syspath.c \
15eeze_udev_walk.c \ 16eeze_udev_walk.c \
16eeze_udev_watch.c 17eeze_udev_watch.c \
18eeze_sensor.c
17 19
18if HAVE_EEZE_MOUNT 20if HAVE_EEZE_MOUNT
19 AM_CFLAGS = @EEZE_CFLAGS@ @LIBMOUNT_CFLAGS@ @ECORE_FILE_CFLAGS@ 21 AM_CFLAGS = @EEZE_CFLAGS@ @LIBMOUNT_CFLAGS@ @ECORE_FILE_CFLAGS@
@@ -35,9 +37,26 @@ endif
35lib_LTLIBRARIES = libeeze.la 37lib_LTLIBRARIES = libeeze.la
36includesdir = $(includedir)/eeze-@VMAJ@ 38includesdir = $(includedir)/eeze-@VMAJ@
37 39
40libeeze_la_LIBADD = @EEZE_LIBS@
41
38if HAVE_EEZE_MOUNT 42if HAVE_EEZE_MOUNT
39 libeeze_la_LIBADD = @EEZE_LIBS@ @LIBMOUNT_LIBS@ @ECORE_FILE_LIBS@ 43 libeeze_la_LIBADD += @LIBMOUNT_LIBS@ @ECORE_FILE_LIBS@
40else
41 libeeze_la_LIBADD = @EEZE_LIBS@
42endif 44endif
45
43libeeze_la_LDFLAGS = -no-undefined -version-info @version_info@ @release_info@ 46libeeze_la_LDFLAGS = -no-undefined -version-info @version_info@ @release_info@
47
48# Sensor modules
49pkgdir = $(libdir)/eeze-sensor
50if HAVE_EEZE_TIZEN
51pkg_LTLIBRARIES = eeze-sensor-tizen.la
52eeze_sensor_tizen_la_SOURCES = eeze_sensor_tizen.c
53eeze_sensor_tizen_la_LDFLAGS = -no-undefined -module -avoid-version @TIZEN_SENSOR_LIBS@
54eeze_sensor_tizen_la_LIBTOOLFLAGS = --tag=disable-static
55else
56pkg_LTLIBRARIES = eeze-sensor-fake.la
57eeze_sensor_fake_la_SOURCES = eeze_sensor_fake.c
58eeze_sensor_fake_la_LDFLAGS = -no-undefined -module -avoid-version
59eeze_sensor_fake_la_LIBTOOLFLAGS = --tag=disable-static
60endif
61
62
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 @@
5#include <Ecore.h> 5#include <Ecore.h>
6#include <Eeze.h> 6#include <Eeze.h>
7#include <Eeze_Disk.h> 7#include <Eeze_Disk.h>
8#include <Eeze_Sensor.h>
8#include "eeze_udev_private.h" 9#include "eeze_udev_private.h"
9#include "eeze_net_private.h" 10#include "eeze_net_private.h"
10#include "eeze_disk_private.h" 11#include "eeze_disk_private.h"
@@ -13,6 +14,7 @@ _udev *udev;
13 14
14int _eeze_udev_log_dom = -1; 15int _eeze_udev_log_dom = -1;
15int _eeze_net_log_dom = -1; 16int _eeze_net_log_dom = -1;
17int _eeze_sensor_log_dom = -1;
16int _eeze_init_count = 0; 18int _eeze_init_count = 0;
17 19
18static Eeze_Version _version = { VMAJ, VMIN, VMIC, VREV }; 20static Eeze_Version _version = { VMAJ, VMIN, VMIC, VREV };
@@ -40,6 +42,12 @@ eeze_init(void)
40 goto eina_net_fail; 42 goto eina_net_fail;
41 } 43 }
42 44
45 _eeze_sensor_log_dom = eina_log_domain_register("eeze_sensor", EINA_COLOR_BLUE);
46 if (_eeze_sensor_log_dom < 0)
47 {
48 EINA_LOG_ERR("Could not register 'eeze_sensor' log domain.");
49 goto eina_sensor_fail;
50 }
43 51
44 if (!ecore_init()) 52 if (!ecore_init())
45 goto ecore_fail; 53 goto ecore_fail;
@@ -57,9 +65,16 @@ eeze_init(void)
57 EINA_LOG_ERR("Error initializing eeze_net subsystems!"); 65 EINA_LOG_ERR("Error initializing eeze_net subsystems!");
58 goto net_fail; 66 goto net_fail;
59 } 67 }
68 if (!eeze_sensor_init())
69 {
70 EINA_LOG_ERR("Error initializing eeze_sensor subsystems!");
71 goto sensor_fail;
72 }
60 73
61 return _eeze_init_count; 74 return _eeze_init_count;
62 75
76sensor_fail:
77 eeze_net_shutdown();
63net_fail: 78net_fail:
64 udev_unref(udev); 79 udev_unref(udev);
65fail: 80fail:
@@ -69,6 +84,9 @@ eeze_fail:
69#endif 84#endif
70 ecore_shutdown(); 85 ecore_shutdown();
71ecore_fail: 86ecore_fail:
87 eina_log_domain_unregister(_eeze_sensor_log_dom);
88 _eeze_sensor_log_dom = -1;
89eina_sensor_fail:
72 eina_log_domain_unregister(_eeze_net_log_dom); 90 eina_log_domain_unregister(_eeze_net_log_dom);
73 _eeze_net_log_dom = -1; 91 _eeze_net_log_dom = -1;
74eina_net_fail: 92eina_net_fail:
@@ -94,6 +112,7 @@ eeze_shutdown(void)
94#ifdef HAVE_EEZE_MOUNT 112#ifdef HAVE_EEZE_MOUNT
95 eeze_disk_shutdown(); 113 eeze_disk_shutdown();
96#endif 114#endif
115 eeze_sensor_shutdown();
97 eeze_net_shutdown(); 116 eeze_net_shutdown();
98 ecore_shutdown(); 117 ecore_shutdown();
99 eina_log_domain_unregister(_eeze_udev_log_dom); 118 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 @@
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <Eina.h>
8#include <Ecore.h>
9#include <Eeze_Sensor.h>
10#include "eeze_sensor_private.h"
11
12Eeze_Sensor *g_handle;
13
14/* Priority order for modules. The one with the highest order of the available ones will be used */
15static const char *_module_priority[] = {
16 "tizen",
17 "fake",
18 NULL
19};
20
21EAPI Eeze_Sensor *
22eeze_sensor_handle_get(void)
23{
24 return g_handle;
25}
26
27Eeze_Sensor_Module *
28_highest_priority_module_get(void)
29{
30 Eeze_Sensor_Module *module = NULL;
31 int i = 0;
32
33 while (_module_priority[i] != NULL)
34 {
35 module = eina_hash_find(g_handle->modules, _module_priority[i]);
36 if (module) return module;
37 i++;
38 }
39 return NULL;
40}
41
42EAPI Eeze_Sensor_Obj *
43eeze_sensor_obj_get(Eeze_Sensor_Type sensor_type)
44{
45 Eina_List *l;
46 Eeze_Sensor_Obj *obj;
47 Eeze_Sensor_Module *module;
48
49 module = _highest_priority_module_get();
50
51 if (!module) return NULL;
52
53 EINA_LIST_FOREACH(module->sensor_list, l, obj)
54 {
55 if (obj->type == sensor_type)
56 {
57 return obj;
58 }
59 }
60 return NULL;
61}
62
63static void
64eeze_sensor_modules_load(void)
65{
66 /* Check for available runtime modules and load them */
67 g_handle->modules_array = eina_module_list_get(NULL, PACKAGE_LIB_DIR "/eeze-sensor/", 0, NULL, NULL);
68 /* FIXME check for modules also in HOME and other locations */
69
70 if (!g_handle->modules_array)
71 {
72 ERR("No modules found!");
73 return;
74 }
75
76 eina_module_list_load(g_handle->modules_array);
77}
78
79static void
80eeze_sensor_modules_unload(void)
81{
82 if (!g_handle->modules_array) return;
83 eina_module_list_unload(g_handle->modules_array);
84 eina_module_list_free(g_handle->modules_array);
85 eina_array_free(g_handle->modules_array);
86 g_handle->modules_array = NULL;
87}
88
89Eina_Bool
90eeze_sensor_module_register(const char *name, Eeze_Sensor_Module *mod)
91{
92 Eeze_Sensor_Module *module = NULL;
93
94 if (!mod) return EINA_FALSE;
95
96 module = calloc(1, sizeof(Eeze_Sensor_Module));
97 if (!module) return EINA_FALSE;
98
99 module = mod;
100
101 if (!module->init) return EINA_FALSE;
102 if (!(module->init())) return EINA_FALSE;
103
104 INF("Registered module %s", name);
105
106 return eina_hash_add(g_handle->modules, name, module);
107}
108
109Eina_Bool
110eeze_sensor_module_unregister(const char *name)
111{
112 DBG("Unregister module %s", name);
113
114 Eeze_Sensor_Module *module = NULL;
115
116 module = eina_hash_find(g_handle->modules, name);
117 if (module->shutdown)
118 module->shutdown();
119
120 return eina_hash_del(g_handle->modules, name, NULL);
121}
122
123EAPI Eeze_Sensor_Obj *
124eeze_sensor_new(Eeze_Sensor_Type type)
125{
126 Eeze_Sensor_Obj *sens;
127 Eeze_Sensor *handle;
128 Eeze_Sensor_Module *module = NULL;
129
130 handle = eeze_sensor_handle_get();
131 if (!handle) return NULL;
132
133 sens = calloc(1, sizeof(Eeze_Sensor_Obj));
134 if (!sens) return NULL;
135
136 sens = eeze_sensor_obj_get(type);
137
138 module = _highest_priority_module_get();
139 if (!module) return EINA_FALSE;
140
141 if (!module->read) return NULL;
142
143 if (module->read(sens->type, sens))
144 {
145 return sens;
146 }
147 else
148 return NULL;
149}
150
151EAPI void
152eeze_sensor_free(Eeze_Sensor_Obj *sens)
153{
154 if (!sens) return;
155 free(sens);
156}
157
158EAPI Eina_Bool
159eeze_sensor_accuracy_get(Eeze_Sensor_Obj *sens, int *accuracy)
160{
161 if (!sens) return EINA_FALSE;
162
163 *accuracy = sens->accuracy;
164 return EINA_TRUE;
165}
166
167EAPI Eina_Bool
168eeze_sensor_xyz_get(Eeze_Sensor_Obj *sens, float *x, float *y, float *z)
169{
170 if (!sens) return EINA_FALSE;
171
172 *x = sens->data[0];
173 *y = sens->data[1];
174 *z = sens->data[2];
175 return EINA_TRUE;
176}
177
178EAPI Eina_Bool
179eeze_sensor_xy_get(Eeze_Sensor_Obj *sens, float *x, float *y)
180{
181 if (!sens) return EINA_FALSE;
182
183 *x = sens->data[0];
184 *y = sens->data[1];
185 return EINA_TRUE;
186}
187
188EAPI Eina_Bool
189eeze_sensor_x_get(Eeze_Sensor_Obj *sens, float *x)
190{
191 if (!sens) return EINA_FALSE;
192
193 *x = sens->data[0];
194 return EINA_TRUE;
195}
196
197EAPI Eina_Bool
198eeze_sensor_timestamp_get(Eeze_Sensor_Obj *sens, unsigned long long *timestamp)
199{
200 if (!sens) return EINA_FALSE;
201
202 *timestamp = sens->timestamp;
203 return EINA_TRUE;
204}
205
206EAPI Eina_Bool
207eeze_sensor_read(Eeze_Sensor_Obj *sens)
208{
209 Eeze_Sensor *handle = NULL;
210 Eeze_Sensor_Module *module = NULL;
211
212 if (!sens) return EINA_FALSE;
213
214 handle = eeze_sensor_handle_get();
215 if (!handle) return EINA_FALSE;
216
217 module = _highest_priority_module_get();
218 if (!module) return EINA_FALSE;
219
220 if (module->read)
221 return module->read(sens->type, sens);
222
223 return EINA_FALSE;
224}
225
226EAPI Eina_Bool
227eeze_sensor_async_read(Eeze_Sensor_Obj *sens, void *user_data)
228{
229 Eeze_Sensor_Module *module = NULL;
230 Eeze_Sensor *handle = NULL;
231
232 handle = eeze_sensor_handle_get();
233 if (!handle) return EINA_FALSE;
234
235 module = _highest_priority_module_get();
236 if (!module) return EINA_FALSE;
237 if (module->async_read)
238 return module->async_read(sens->type, user_data);
239
240 return EINA_FALSE;
241}
242
243void
244eeze_sensor_shutdown(void)
245{
246 eeze_sensor_modules_unload();
247 free(g_handle);
248 g_handle = NULL;
249
250 eina_shutdown();
251}
252
253Eina_Bool
254eeze_sensor_init(void)
255{
256 if (!eina_init()) return EINA_FALSE;
257
258 g_handle = calloc(1, sizeof(Eeze_Sensor));
259 if (!g_handle) return EINA_FALSE;
260
261 g_handle->modules_array = NULL;
262 g_handle->modules = eina_hash_string_small_new(NULL);
263 if (!g_handle->modules) return EINA_FALSE;
264
265 EEZE_SENSOR_EVENT_SNAP = ecore_event_type_new();
266 EEZE_SENSOR_EVENT_SHAKE = ecore_event_type_new();
267 EEZE_SENSOR_EVENT_DOUBLETAP = ecore_event_type_new();
268 EEZE_SENSOR_EVENT_PANNING = ecore_event_type_new();
269 EEZE_SENSOR_EVENT_FACEDOWN = ecore_event_type_new();
270 EEZE_SENSOR_EVENT_ACCELEROMETER = ecore_event_type_new();
271
272 eeze_sensor_modules_load();
273
274 return EINA_TRUE;
275}
276
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 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <stdio.h>
6#include <time.h>
7
8#include <Eina.h>
9#include <Ecore.h>
10#include <Eeze_Sensor.h>
11#include "eeze_sensor_private.h"
12
13Eeze_Sensor_Module *esensor_module;
14
15Eina_Bool
16fake_init(void)
17{
18 /* Set a list with fake sensors */
19 Eeze_Sensor_Type type;
20
21 for (type = 0; type <= EEZE_SENSOR_TYPE_LAST; type++)
22 {
23 Eeze_Sensor_Obj *obj = calloc(1, sizeof(Eeze_Sensor_Obj));
24 obj->type = type;
25 esensor_module->sensor_list = eina_list_append(esensor_module->sensor_list, obj);
26 }
27
28 return EINA_TRUE;
29}
30
31Eina_Bool
32fake_shutdown(void)
33{
34 return EINA_TRUE;
35}
36
37Eina_Bool
38fake_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
39{
40 Eeze_Sensor_Obj *obj;
41
42 obj = eeze_sensor_obj_get(sensor_type);
43 if (obj == NULL)
44 {
45 ERR("No matching sensor object found in list");
46 return EINA_FALSE;
47 }
48
49 switch (sensor_type)
50 {
51 case EEZE_SENSOR_TYPE_ACCELEROMETER:
52 case EEZE_SENSOR_TYPE_MAGNETIC:
53 case EEZE_SENSOR_TYPE_ORIENTATION:
54 case EEZE_SENSOR_TYPE_GYROSCOPE:
55 obj->accuracy = 0;
56 obj->data[0] = 7;
57 obj->data[1] = 23;
58 obj->data[2] = 42;
59 obj->timestamp = time(NULL);
60 break;
61
62 case EEZE_SENSOR_TYPE_LIGHT:
63 case EEZE_SENSOR_TYPE_PROXIMITY:
64 case EEZE_SENSOR_TYPE_BAROMETER:
65 case EEZE_SENSOR_TYPE_TEMPERATURE:
66 obj->accuracy = 0;
67 obj->data[0] = 7;
68 obj->timestamp = time(NULL);
69 break;
70
71 default:
72 ERR("Not possible to read from this sensor type.");
73 return EINA_FALSE;
74 }
75
76 memcpy(lobj, obj, sizeof(Eeze_Sensor_Obj));
77
78 return EINA_TRUE;
79}
80
81Eina_Bool
82fake_async_read(Eeze_Sensor_Type sensor_type, void *user_data EINA_UNUSED)
83{
84 Eeze_Sensor_Obj *obj = NULL;
85
86 obj = eeze_sensor_obj_get(sensor_type);
87 if (obj == NULL)
88 {
89 ERR("No matching sensor object found in list.");
90 return EINA_FALSE;
91 }
92
93 switch (sensor_type)
94 {
95 case EEZE_SENSOR_TYPE_ACCELEROMETER:
96 ecore_event_add(EEZE_SENSOR_EVENT_ACCELEROMETER, obj, NULL, NULL);
97 case EEZE_SENSOR_TYPE_MAGNETIC:
98 case EEZE_SENSOR_TYPE_ORIENTATION:
99 case EEZE_SENSOR_TYPE_GYROSCOPE:
100 obj->accuracy = 0;
101 obj->data[0] = 7;
102 obj->data[1] = 23;
103 obj->data[2] = 42;
104 obj->timestamp = time(NULL);
105 break;
106
107 case EEZE_SENSOR_TYPE_LIGHT:
108 case EEZE_SENSOR_TYPE_PROXIMITY:
109 case EEZE_SENSOR_TYPE_BAROMETER:
110 case EEZE_SENSOR_TYPE_TEMPERATURE:
111 obj->accuracy = 0;
112 obj->data[0] = 7;
113 obj->timestamp = time(NULL);
114 break;
115
116 case EEZE_SENSOR_TYPE_MOTION_SNAP:
117 break;
118
119 case EEZE_SENSOR_TYPE_MOTION_SHAKE:
120 break;
121
122 case EEZE_SENSOR_TYPE_MOTION_PANNING:
123 break;
124
125 default:
126 ERR("Not possible to set a callback for this sensor type.");
127 return EINA_FALSE;
128 }
129
130 return EINA_TRUE;
131}
132
133Eina_Bool
134sensor_fake_init(void)
135{
136 /* Check to avoid multi-init */
137 if (esensor_module) return EINA_FALSE;
138
139 /* Set module function pointer to allow calls into the module */
140 esensor_module = calloc(1, sizeof(Eeze_Sensor_Module));
141 if (!esensor_module) return EINA_FALSE;
142
143 esensor_module->init = fake_init;
144 esensor_module->shutdown = fake_shutdown;
145 esensor_module->read = fake_read;
146 esensor_module->async_read = fake_async_read;
147
148 if (!eeze_sensor_module_register("fake", esensor_module))
149 {
150 ERR("Failed to register fake module.");
151 return EINA_FALSE;
152 }
153
154 return EINA_TRUE;
155}
156
157void
158sensor_fake_shutdown(void)
159{
160 eeze_sensor_module_unregister("fake");
161 free(esensor_module);
162 esensor_module = NULL;
163}
164
165EINA_MODULE_INIT(sensor_fake_init);
166EINA_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 @@
1#ifndef EEZE_SENSOR_PRIVATE_H
2#define EEZE_SENSOR_PRIVATE_H
3#include <stdio.h>
4#include <stdlib.h>
5#include <stdbool.h>
6
7#include <Eeze_Sensor.h>
8
9#ifndef EEZE_SENSOR_COLOR_DEFAULT
10#define EEZE_SENSOR_COLOR_DEFAULT EINA_COLOR_BLUE
11#endif
12extern int _eeze_sensor_log_dom;
13#ifdef CRI
14#undef CRI
15#endif
16
17#ifdef ERR
18#undef ERR
19#endif
20#ifdef INF
21#undef INF
22#endif
23#ifdef WARN
24#undef WARN
25#endif
26#ifdef DBG
27#undef DBG
28#endif
29
30#define CRI(...) EINA_LOG_DOM_CRIT(_eeze_sensor_log_dom, __VA_ARGS__)
31#define DBG(...) EINA_LOG_DOM_DBG(_eeze_sensor_log_dom, __VA_ARGS__)
32#define INF(...) EINA_LOG_DOM_INFO(_eeze_sensor_log_dom, __VA_ARGS__)
33#define WARN(...) EINA_LOG_DOM_WARN(_eeze_sensor_log_dom, __VA_ARGS__)
34#define ERR(...) EINA_LOG_DOM_ERR(_eeze_sensor_log_dom, __VA_ARGS__)
35
36/**
37 * @typedef Eeze_Sensor_Module;
38 * @since 1.8
39 *
40 * Loadable module data structure.
41 */
42typedef struct _Eeze_Sensor_Module
43{
44 Eina_Bool (*init)(void); /**< Pointer to module init function */
45 Eina_Bool (*shutdown)(void); /**< Pointer to module shutdown function */
46 Eina_Bool (*async_read)(Eeze_Sensor_Type sensor_type, void *user_data); /**< Pointer to module async_read function */
47 Eina_Bool (*read)(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *obj); /**< Pointer to module read function */
48 Eina_List *sensor_list; /**< List of sensor objects attached to the module */
49} Eeze_Sensor_Module;
50
51Eina_Bool eeze_sensor_module_register(const char *name, Eeze_Sensor_Module *mod);
52Eina_Bool eeze_sensor_module_unregister(const char *name);
53#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 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <system/sensors.h>
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <stdbool.h>
10
11#include <Eina.h>
12#include <Eeze_Sensor.h>
13#include "eeze_sensor_private.h"
14
15Eeze_Sensor_Module *esensor_module;
16sensor_h sensor_handle; // Tizen sensor handle
17
18static sensor_type_e
19eeze_to_tizen(Eeze_Sensor_Type type)
20{
21 switch (type)
22 {
23 case EEZE_SENSOR_TYPE_ACCELEROMETER:
24 return SENSOR_ACCELEROMETER;
25
26 case EEZE_SENSOR_TYPE_MAGNETIC:
27 return SENSOR_MAGNETIC;
28
29 case EEZE_SENSOR_TYPE_ORIENTATION:
30 return SENSOR_ORIENTATION;
31
32 case EEZE_SENSOR_TYPE_GYROSCOPE:
33 return SENSOR_GYROSCOPE;
34
35 case EEZE_SENSOR_TYPE_LIGHT:
36 return SENSOR_LIGHT;
37
38 case EEZE_SENSOR_TYPE_PROXIMITY:
39 return SENSOR_PROXIMITY;
40
41 case EEZE_SENSOR_TYPE_MOTION_SNAP:
42 return SENSOR_MOTION_SNAP;
43
44 case EEZE_SENSOR_TYPE_MOTION_SHAKE:
45 return SENSOR_MOTION_SHAKE;
46
47 case EEZE_SENSOR_TYPE_MOTION_DOUBLETAP:
48 return SENSOR_MOTION_DOUBLETAP;
49
50 case EEZE_SENSOR_TYPE_MOTION_PANNING:
51 return SENSOR_MOTION_PANNING;
52
53 case EEZE_SENSOR_TYPE_MOTION_FACEDOWN:
54 return SENSOR_MOTION_FACEDOWN;
55
56 default:
57 ERR("No matching Tizen sensor type available.");
58 return -1;
59 }
60}
61
62void
63accelerometer_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
64{
65 Eeze_Sensor_Obj *obj = NULL;
66
67 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ACCELEROMETER);
68 if (obj == NULL)
69 {
70 ERR("No matching sensor object found in list.");
71 return;
72 }
73 obj->accuracy = accuracy;
74 obj->data[0] = x;
75 obj->data[1] = y;
76 obj->data[2] = z;
77 obj->timestamp = timestamp;
78 ecore_event_add(EEZE_SENSOR_EVENT_ACCELEROMETER, obj, NULL, NULL);
79 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_ACCELEROMETER));
80}
81
82void
83magnetic_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
84{
85 Eeze_Sensor_Obj *obj = NULL;
86
87 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MAGNETIC);
88 if (obj == NULL)
89 {
90 ERR("No matching sensor object found in list.");
91 return;
92 }
93 obj->accuracy = accuracy;
94 obj->data[0] = x;
95 obj->data[1] = y;
96 obj->data[2] = z;
97 obj->timestamp = timestamp;
98 ecore_event_add(EEZE_SENSOR_EVENT_MAGNETIC, obj, NULL, NULL);
99 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MAGNETIC));
100}
101
102void
103orientation_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float azimuth, float pitch, float roll, void *user_data)
104{
105 Eeze_Sensor_Obj *obj = NULL;
106
107 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ORIENTATION);
108 if (obj == NULL)
109 {
110 ERR("No matching sensor object found in list.");
111 return;
112 }
113 obj->accuracy = accuracy;
114 obj->data[0] = azimuth;
115 obj->data[1] = pitch;
116 obj->data[2] = roll;
117 obj->timestamp = timestamp;
118 ecore_event_add(EEZE_SENSOR_EVENT_ORIENTATION, obj, NULL, NULL);
119 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_ORIENTATION));
120}
121
122void
123gyroscope_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
124{
125 Eeze_Sensor_Obj *obj = NULL;
126
127 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_GYROSCOPE);
128 if (obj == NULL)
129 {
130 ERR("No matching sensor object found in list.");
131 return;
132 }
133 obj->accuracy = accuracy;
134 obj->data[0] = x;
135 obj->data[1] = y;
136 obj->data[2] = z;
137 obj->timestamp = timestamp;
138 ecore_event_add(EEZE_SENSOR_EVENT_GYROSCOPE, obj, NULL, NULL);
139 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_GYROSCOPE));
140}
141
142void
143light_cb(unsigned long long timestamp, float lux, void *user_data)
144{
145 Eeze_Sensor_Obj *obj = NULL;
146
147 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_LIGHT);
148 if (obj == NULL)
149 {
150 ERR("No matching sensor object found in list.");
151 return;
152 }
153 obj->accuracy = 0;
154 obj->data[0] = lux;
155 obj->timestamp = timestamp;
156 ecore_event_add(EEZE_SENSOR_EVENT_LIGHT, obj, NULL, NULL);
157 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_LIGHT));
158}
159
160void
161proximity_cb(unsigned long long timestamp, float distance, void *user_data)
162{
163 Eeze_Sensor_Obj *obj = NULL;
164
165 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_PROXIMITY);
166 if (obj == NULL)
167 {
168 ERR("No matching sensor object found in list.");
169 return;
170 }
171 obj->accuracy = 0;
172 obj->data[0] = distance;
173 obj->timestamp = timestamp;
174 ecore_event_add(EEZE_SENSOR_EVENT_PROXIMITY, obj, NULL, NULL);
175 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_PROXIMITY));
176}
177
178void
179snap_cb(unsigned long long timestamp, sensor_motion_snap_e snap, void *user_data)
180{
181 Eeze_Sensor_Obj *obj = NULL;
182
183 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_SNAP);
184 if (obj == NULL)
185 {
186 ERR("No matching sensor object found in list.");
187 return;
188 }
189 obj->data[0] = snap;
190 obj->timestamp = timestamp;
191 ecore_event_add(EEZE_SENSOR_EVENT_SNAP, obj, NULL, NULL);
192 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_SNAP));
193}
194
195void
196shake_cb(unsigned long long timestamp, sensor_motion_shake_e shake, void *user_data)
197{
198 Eeze_Sensor_Obj *obj = NULL;
199
200 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_SHAKE);
201 if (obj == NULL)
202 {
203 ERR("No matching sensor object found in list.");
204 return;
205 }
206 obj->data[0] = shake;
207 obj->timestamp = timestamp;
208 ecore_event_add(EEZE_SENSOR_EVENT_SHAKE, obj, NULL, NULL);
209 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_SHAKE));
210}
211
212void
213panning_cb(unsigned long long timestamp, int x, int y, void *user_data)
214{
215 Eeze_Sensor_Obj *obj = NULL;
216
217 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_PANNING);
218 if (obj == NULL)
219 {
220 ERR("No matching sensor object found in list.");
221 return;
222 }
223 obj->data[0] = x;
224 obj->data[1] = y;
225 obj->timestamp = timestamp;
226 ecore_event_add(EEZE_SENSOR_EVENT_PANNING, obj, NULL, NULL);
227 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_PANNING));
228}
229
230void
231facedown_cb(unsigned long long timestamp, void *user_data)
232{
233 Eeze_Sensor_Obj *obj = NULL;
234
235 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_FACEDOWN);
236 if (obj == NULL)
237 {
238 ERR("No matching sensor object found in list.");
239 return;
240 }
241 obj->timestamp = timestamp;
242 ecore_event_add(EEZE_SENSOR_EVENT_FACEDOWN, obj, NULL, NULL);
243}
244
245void
246doubletap_cb(unsigned long long timestamp, void *user_data)
247{
248 Eeze_Sensor_Obj *obj = NULL;
249
250 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_DOUBLETAP);
251 if (obj == NULL)
252 {
253 ERR("No matching sensor object found in list.");
254 return;
255 }
256 obj->timestamp = timestamp;
257 ecore_event_add(EEZE_SENSOR_EVENT_DOUBLETAP, obj, NULL, NULL);
258}
259
260void
261accelerometer_read_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
262{
263 Eeze_Sensor_Obj *obj = NULL;
264
265 sensor_accelerometer_unset_cb(sensor_handle);
266
267 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ACCELEROMETER);
268 if (obj == NULL)
269 {
270 ERR("No matching sensor object found in list.");
271 return;
272 }
273 obj->accuracy = accuracy;
274 obj->data[0] = x;
275 obj->data[1] = y;
276 obj->data[2] = z;
277 obj->timestamp = timestamp;
278 ecore_event_add(EEZE_SENSOR_EVENT_ACCELEROMETER, obj, NULL, NULL);
279 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_ACCELEROMETER));
280}
281
282void
283magnetic_read_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
284{
285 Eeze_Sensor_Obj *obj = NULL;
286
287 sensor_magnetic_unset_cb(sensor_handle);
288
289 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MAGNETIC);
290 if (obj == NULL)
291 {
292 ERR("No matching sensor object found in list.");
293 return;
294 }
295 obj->accuracy = accuracy;
296 obj->data[0] = x;
297 obj->data[1] = y;
298 obj->data[2] = z;
299 obj->timestamp = timestamp;
300 ecore_event_add(EEZE_SENSOR_EVENT_MAGNETIC, obj, NULL, NULL);
301 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MAGNETIC));
302}
303
304void
305orientation_read_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float azimuth, float pitch, float roll, void *user_data)
306{
307 Eeze_Sensor_Obj *obj = NULL;
308
309 sensor_orientation_unset_cb(sensor_handle);
310
311 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ORIENTATION);
312 if (obj == NULL)
313 {
314 ERR("No matching sensor object found in list.");
315 return;
316 }
317 obj->accuracy = accuracy;
318 obj->data[0] = azimuth;
319 obj->data[1] = pitch;
320 obj->data[2] = roll;
321 obj->timestamp = timestamp;
322 ecore_event_add(EEZE_SENSOR_EVENT_ORIENTATION, obj, NULL, NULL);
323 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_ORIENTATION));
324}
325
326void
327gyroscope_read_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
328{
329 Eeze_Sensor_Obj *obj = NULL;
330
331 sensor_gyroscope_unset_cb(sensor_handle);
332
333 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_GYROSCOPE);
334 if (obj == NULL)
335 {
336 ERR("No matching sensor object found in list.");
337 return;
338 }
339 obj->accuracy = accuracy;
340 obj->data[0] = x;
341 obj->data[1] = y;
342 obj->data[2] = z;
343 obj->timestamp = timestamp;
344 ecore_event_add(EEZE_SENSOR_EVENT_GYROSCOPE, obj, NULL, NULL);
345 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_GYROSCOPE));
346}
347
348void
349light_read_cb(unsigned long long timestamp, float lux, void *user_data)
350{
351 Eeze_Sensor_Obj *obj = NULL;
352
353 sensor_light_unset_cb(sensor_handle);
354
355 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_LIGHT);
356 if (obj == NULL)
357 {
358 ERR("No matching sensor object found in list.");
359 return;
360 }
361 obj->accuracy = 0;
362 obj->data[0] = lux;
363 obj->timestamp = timestamp;
364 ecore_event_add(EEZE_SENSOR_EVENT_LIGHT, obj, NULL, NULL);
365 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_LIGHT));
366}
367
368void
369proximity_read_cb(unsigned long long timestamp, float distance, void *user_data)
370{
371 Eeze_Sensor_Obj *obj = NULL;
372
373 sensor_proximity_unset_cb(sensor_handle);
374
375 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_PROXIMITY);
376 if (obj == NULL)
377 {
378 ERR("No matching sensor object found in list.");
379 return;
380 }
381 obj->accuracy = 0;
382 obj->data[0] = distance;
383 obj->timestamp = timestamp;
384 ecore_event_add(EEZE_SENSOR_EVENT_PROXIMITY, obj, NULL, NULL);
385 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_PROXIMITY));
386}
387
388void
389snap_read_cb(unsigned long long timestamp, sensor_motion_snap_e snap, void *user_data)
390{
391 Eeze_Sensor_Obj *obj = NULL;
392
393 sensor_motion_snap_unset_cb(sensor_handle);
394
395 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_SNAP);
396 if (obj == NULL)
397 {
398 ERR("No matching sensor object found in list.");
399 return;
400 }
401 obj->data[0] = snap;
402 obj->timestamp = timestamp;
403 ecore_event_add(EEZE_SENSOR_EVENT_SNAP, obj, NULL, NULL);
404 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_SNAP));
405}
406
407void
408shake_read_cb(unsigned long long timestamp, sensor_motion_shake_e shake, void *user_data)
409{
410 Eeze_Sensor_Obj *obj = NULL;
411
412 sensor_motion_shake_unset_cb(sensor_handle);
413
414 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_SHAKE);
415 if (obj == NULL)
416 {
417 ERR("No matching sensor object found in list.");
418 return;
419 }
420 obj->data[0] = shake;
421 obj->timestamp = timestamp;
422 ecore_event_add(EEZE_SENSOR_EVENT_SHAKE, obj, NULL, NULL);
423 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_SHAKE));
424}
425
426void
427panning_read_cb(unsigned long long timestamp, int x, int y, void *user_data)
428{
429 Eeze_Sensor_Obj *obj = NULL;
430
431 sensor_motion_panning_unset_cb(sensor_handle);
432
433 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_PANNING);
434 if (obj == NULL)
435 {
436 ERR("No matching sensor object found in list.");
437 return;
438 }
439 obj->data[0] = x;
440 obj->data[1] = y;
441 obj->timestamp = timestamp;
442 ecore_event_add(EEZE_SENSOR_EVENT_PANNING, obj, NULL, NULL);
443 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_PANNING));
444}
445
446void
447facedown_read_cb(unsigned long long timestamp, void *user_data)
448{
449 sensor_motion_facedown_unset_cb(sensor_handle);
450 ecore_event_add(EEZE_SENSOR_EVENT_FACEDOWN, obj, NULL, NULL);
451 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_MOTION_TYPE_FACEDOWN));
452}
453
454void
455doubletap_read_cb(unsigned long long timestamp, void *user_data)
456{
457 sensor_motion_doubletap_unset_cb(sensor_handle);
458 ecore_event_add(EEZE_SENSOR_EVENT_DOUBLETAP, obj, NULL, NULL);
459 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_MOTION_TYPE_DOUBLETAP));
460}
461
462Eina_Bool
463eeze_sensor_tizen_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
464{
465 sensor_data_accuracy_e accuracy;
466 float x, y, z;
467 float azimuth, pitch, roll, lux, distance;
468 bool supported;
469 sensor_type_e type;
470 Eeze_Sensor_Obj *obj;
471
472 type = eeze_to_tizen(sensor_type);
473
474 sensor_is_supported(type, &supported);
475 if (!supported)
476 {
477 ERR("Sensor type %d not available on this device.", type);
478 return EINA_FALSE;
479 }
480
481 sensor_start(handle->sensor_handle, type);
482 obj = eeze_sensor_obj_get(sensor_type);
483 if (obj == NULL)
484 {
485 ERR("No matching sensor object found in list.");
486 return EINA_FALSE;
487 }
488
489 switch (type)
490 {
491 case SENSOR_ACCELEROMETER:
492 sensor_accelerometer_read_data(sensor_handle, &accuracy, &x, &y, &z);
493 obj->accuracy = accuracy;
494 obj->data[0] = x;
495 obj->data[1] = y;
496 obj->data[2] = z;
497 break;
498
499 case SENSOR_MAGNETIC:
500 sensor_magnetic_read_data(sensor_handle, &accuracy, &x, &y, &z);
501 obj->accuracy = accuracy;
502 obj->data[0] = x;
503 obj->data[1] = y;
504 obj->data[2] = z;
505 break;
506
507 case SENSOR_ORIENTATION:
508 sensor_orientation_read_data(sensor_handle, &accuracy, &azimuth, &pitch, &roll);
509 obj->accuracy = accuracy;
510 obj->data[0] = azimuth;
511 obj->data[1] = pitch;
512 obj->data[2] = roll;
513 break;
514
515 case SENSOR_GYROSCOPE:
516 sensor_gyroscope_read_data(sensor_handle, &accuracy, &x, &y, &z);
517 obj->accuracy = accuracy;
518 obj->data[0] = x;
519 obj->data[1] = y;
520 obj->data[2] = z;
521 break;
522
523 case SENSOR_LIGHT:
524 sensor_light_read_data(sensor_handle, &lux);
525 obj->accuracy = 0;
526 obj->data[0] = lux;
527 break;
528
529 case SENSOR_PROXIMITY:
530 sensor_proximity_read_data(sensor_handle, &distance);
531 obj->accuracy = 0;
532 obj->data[0] = distance;
533 break;
534
535 default:
536 ERR("Not possible to read from this sensor type.");
537 return EINA_FALSE;
538 }
539
540 memcpy(lobj, obj, sizeof(Eeze_Sensor_Obj));
541
542 sensor_stop(sensor_handle, type);
543 return EINA_TRUE;
544}
545
546// FIXME ho to handle this without explicit callback setting
547#if 0
548Eina_Bool
549eeze_sensor_tizen_cb_set(Eeze_Sensor *handle, Eeze_Sensor_Type sensor_type, void *cb_function, void *user_data)
550{
551 sensor_type_e type;
552
553 type = eeze_to_tizen(sensor_type);
554
555 handle->cb_function = cb_function;
556
557 sensor_start(handle->sensor_handle, type);
558
559 switch (type)
560 {
561 case SENSOR_ACCELEROMETER:
562 sensor_accelerometer_set_cb(handle->sensor_handle, 0, accelerometer_cb, handle);
563 break;
564
565 case SENSOR_MAGNETIC:
566 sensor_magnetic_set_cb(handle->sensor_handle, 0, magnetic_cb, handle);
567 break;
568
569 case SENSOR_ORIENTATION:
570 sensor_orientation_set_cb(handle->sensor_handle, 0, orientation_cb, handle);
571 break;
572
573 case SENSOR_GYROSCOPE:
574 sensor_gyroscope_set_cb(handle->sensor_handle, 0, gyroscope_cb, handle);
575 break;
576
577 case SENSOR_LIGHT:
578 sensor_light_set_cb(handle->sensor_handle, 0, light_cb, handle);
579 break;
580
581 case SENSOR_PROXIMITY:
582 sensor_proximity_set_cb(handle->sensor_handle, 0, proximity_cb, handle);
583 break;
584
585 case SENSOR_MOTION_SNAP:
586 sensor_motion_snap_set_cb(handle->sensor_handle, snap_cb, handle);
587 break;
588
589 case SENSOR_MOTION_SHAKE:
590 sensor_motion_shake_set_cb(handle->sensor_handle, shake_cb, handle);
591 break;
592
593 case SENSOR_MOTION_PANNING:
594 sensor_motion_panning_set_cb(handle->sensor_handle, panning_cb, handle);
595 break;
596
597 default:
598 ERR("Not possible to set a callback for this sensor type.");
599 return EINA_FALSE;
600 }
601 return EINA_TRUE;
602}
603#endif
604
605Eina_Bool
606eeze_sensor_tizen_async_read(Eeze_Sensor_Type sensor_type, void *user_data)
607{
608 sensor_type_e type;
609
610 type = eeze_to_tizen(sensor_type);
611
612 sensor_start(sensor_handle, type);
613
614 switch (type)
615 {
616 case SENSOR_ACCELEROMETER:
617 sensor_accelerometer_set_cb(sensor_handle, 0, accelerometer_read_cb, NULL);
618 break;
619
620 case SENSOR_MAGNETIC:
621 sensor_magnetic_set_cb(sensor_handle, 0, magnetic_read_cb, NULL);
622 break;
623
624 case SENSOR_ORIENTATION:
625 sensor_orientation_set_cb(sensor_handle, 0, orientation_read_cb, NULL);
626 break;
627
628 case SENSOR_GYROSCOPE:
629 sensor_gyroscope_set_cb(sensor_handle, 0, gyroscope_read_cb, NULL);
630 break;
631
632 case SENSOR_LIGHT:
633 sensor_light_set_cb(sensor_handle, 0, light_read_cb, NULL);
634 break;
635
636 case SENSOR_PROXIMITY:
637 sensor_proximity_set_cb(sensor_handle, 0, proximity_read_cb, NULL);
638 break;
639
640 case SENSOR_MOTION_SNAP:
641 sensor_motion_snap_set_cb(sensor_handle, snap_read_cb, NULL);
642 break;
643
644 case SENSOR_MOTION_SHAKE:
645 sensor_motion_shake_set_cb(sensor_handle, shake_read_cb, NULL);
646 break;
647
648 case SENSOR_MOTION_DOUBLETAP:
649 sensor_motion_doubletap_set_cb(sensor_handle, doubletap_read_cb, NULL);
650 break;
651
652 case SENSOR_MOTION_PANNING:
653 sensor_motion_panning_set_cb(sensor_handle, panning_read_cb, NULL);
654 break;
655
656 case SENSOR_MOTION_FACEDOWN:
657 sensor_motion_facedown_set_cb(sensor_handle, facedown_read_cb, NULL);
658 break;
659
660 default:
661 ERR("Not possible to set a callback for this sensor type.");
662 return EINA_FALSE;
663 }
664 return EINA_TRUE;
665}
666
667static void
668eeze_sensor_tizen_sensors_find(void)
669{
670 sensor_type_e type;
671 bool supported = 0;
672
673 /* FIXME: Make this safe against changes in the enum. But how? */
674 for (type = SENSOR_ACCELEROMETER; type <= SENSOR_MOTION_FACEDOWN; type++)
675 {
676 sensor_is_supported(type, &supported);
677 if (supported)
678 {
679 Eeze_Sensor_Obj *obj = calloc(1, sizeof(Eeze_Sensor_Obj));
680 obj->type = type;
681 esensor_module->sensor_list = eina_list_append(esensor_module->sensor_list, obj);
682 }
683 }
684}
685
686Eina_Bool
687eeze_sensor_tizen_shutdown(void)
688{
689 Eeze_Sensor_Obj *obj;
690
691 EINA_LIST_FREE(esensor_module->sensor_list, obj)
692 free(obj);
693
694 sensor_start(sensor_handle, SENSOR_MOTION_FACEDOWN);
695 sensor_start(sensor_handle, SENSOR_MOTION_DOUBLETAP);
696 sensor_start(sensor_handle, SENSOR_MOTION_SHAKE);
697 if (sensor_destroy(sensor_handle) != 0)
698 {
699 ERR("Failing to destroy sensor handle.");
700 return EINA_FALSE;
701 }
702
703 return EINA_TRUE;
704}
705
706Eina_Bool
707eeze_sensor_tizen_init(void)
708{
709
710 if (sensor_create(&sensor_handle) != 0)
711 {
712 ERR("Failing to create sensor handle.");
713 return EINA_FALSE;
714 }
715
716 eeze_sensor_tizen_sensors_find();
717
718 /* FIXME add other motion events in here */
719 sensor_start(sensor_handle, SENSOR_MOTION_FACEDOWN);
720 sensor_start(sensor_handle, SENSOR_MOTION_DOUBLETAP);
721 sensor_motion_doubletap_set_cb(sensor_handle, doubletap_cb, handle);
722 sensor_motion_facedown_set_cb(sensor_handle, facedown_cb, handle);
723
724 return EINA_TRUE;
725}
726
727Eina_Bool
728sensor_tizen_init(void)
729{
730 /* Check to avoid multi-init */
731 if (esensor_module) return EINA_FALSE;
732
733 /* Set module function pointer to allow calls into the module */
734 esensor_module = calloc(1, sizeof(Eeze_Sensor_Module));
735 if (!esensor_module) return EINA_FALSE;
736
737 esensor_module->init = eeze_sensor_tizen_init;
738 esensor_module->shutdown = eeze_sensor_tizen_shutdown;
739 esensor_module->read = eeze_sensor_tizen_read;
740 esensor_module->async_read = eeze_sensor_tizen_async_read;
741
742 if (!eeze_sensor_module_register("tizen", esensor_module))
743 {
744 ERR("Failed to register tizen module");
745 return EINA_FALSE;
746 }
747
748 return EINA_TRUE;
749}
750
751void
752sensor_tizen_shutdown(void)
753{
754 sensor_stop(sensor_handle, SENSOR_MOTION_FACEDOWN);
755 sensor_stop(sensor_handle, SENSOR_MOTION_DOUBLETAP);
756 eeze_sensor_module_unregister("tizen");
757 free(esensor_module);
758 esensor_module = NULL;
759}
760
761EINA_MODULE_INIT(sensor_tizen_init);
762EINA_MODULE_SHUTDOWN(sensor_tizen_shutdown);
763