summaryrefslogtreecommitdiff
path: root/src/modules/eeze
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2013-01-03 20:37:42 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2013-01-03 20:37:42 +0000
commit68188ac0c89407cb35a0f04f86ad44b0deb95bdb (patch)
tree0ddf76421ab114f162c5a113f65119a6662d6a54 /src/modules/eeze
parentf7cc32f78bf86c804a3f3ae7b8428a408092fbdf (diff)
efl: merge eeze.
Changes also in this commit: * fix missing EAPI in symbols used by modules * removed old libudev and libmount support as agreed by discomfitor/zmike * replaced __UNUSED__ with EINA_UNUSED * fixed docs hierarchy SVN revision: 82100
Diffstat (limited to 'src/modules/eeze')
-rw-r--r--src/modules/eeze/eeze_sensor_fake.c191
-rw-r--r--src/modules/eeze/eeze_sensor_tizen.c869
2 files changed, 1060 insertions, 0 deletions
diff --git a/src/modules/eeze/eeze_sensor_fake.c b/src/modules/eeze/eeze_sensor_fake.c
new file mode 100644
index 0000000000..2bb10c150f
--- /dev/null
+++ b/src/modules/eeze/eeze_sensor_fake.c
@@ -0,0 +1,191 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <stdio.h>
6#include <sys/time.h>
7
8#include <Eina.h>
9#include <Ecore.h>
10#include <Eeze_Sensor.h>
11#include "eeze_sensor_private.h"
12
13/* This small Eeze_Sensor module is meant to be used as a test harness for
14 * developing. It does not gather any real data from hardware sensors. It uses
15 * fixed values for the data, but provides the correct timestamp value.
16 */
17
18Eeze_Sensor_Module *esensor_module;
19
20Eina_Bool
21fake_init(void)
22{
23 /* For the fake module we prepare a list with all potential sensors. Even if
24 * we only have a small subset at the moment.
25 */
26 Eeze_Sensor_Type type;
27
28 for (type = 0; type <= EEZE_SENSOR_TYPE_LAST; type++)
29 {
30 Eeze_Sensor_Obj *obj = calloc(1, sizeof(Eeze_Sensor_Obj));
31 obj->type = type;
32 esensor_module->sensor_list = eina_list_append(esensor_module->sensor_list, obj);
33 }
34
35 return EINA_TRUE;
36}
37
38/* We don't have anything to clear when we get unregistered from the core here.
39 * This is different in other modules.
40 */
41Eina_Bool
42fake_shutdown(void)
43{
44 return EINA_TRUE;
45}
46
47Eina_Bool
48fake_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
49{
50 Eeze_Sensor_Obj *obj = NULL;
51 struct timeval tv;
52
53 obj = eeze_sensor_obj_get(sensor_type);
54 if (obj == NULL)
55 {
56 ERR("No matching sensor object found in list");
57 return EINA_FALSE;
58 }
59
60 switch (sensor_type)
61 {
62 case EEZE_SENSOR_TYPE_ACCELEROMETER:
63 case EEZE_SENSOR_TYPE_MAGNETIC:
64 case EEZE_SENSOR_TYPE_ORIENTATION:
65 case EEZE_SENSOR_TYPE_GYROSCOPE:
66 /* This is only a test harness so we supply hardcoded values here */
67 obj->accuracy = -1;
68 obj->data[0] = 7;
69 obj->data[1] = 23;
70 obj->data[2] = 42;
71 gettimeofday(&tv, NULL);
72 obj->timestamp = ((tv.tv_sec * 1000000) + tv.tv_usec);
73 break;
74
75 case EEZE_SENSOR_TYPE_LIGHT:
76 case EEZE_SENSOR_TYPE_PROXIMITY:
77 case EEZE_SENSOR_TYPE_BAROMETER:
78 case EEZE_SENSOR_TYPE_TEMPERATURE:
79 obj->accuracy = -1;
80 obj->data[0] = 7;
81 gettimeofday(&tv, NULL);
82 obj->timestamp = ((tv.tv_sec * 1000000) + tv.tv_usec);
83 break;
84
85 default:
86 ERR("Not possible to read from this sensor type.");
87 free(obj);
88 return EINA_FALSE;
89 }
90
91 memcpy(lobj, obj, sizeof(Eeze_Sensor_Obj));
92 free(obj);
93
94 return EINA_TRUE;
95}
96
97Eina_Bool
98fake_async_read(Eeze_Sensor_Type sensor_type, void *user_data EINA_UNUSED)
99{
100 Eeze_Sensor_Obj *obj = NULL;
101 struct timeval tv;
102
103 obj = eeze_sensor_obj_get(sensor_type);
104 if (obj == NULL)
105 {
106 ERR("No matching sensor object found in list.");
107 return EINA_FALSE;
108 }
109
110 switch (sensor_type)
111 {
112 case EEZE_SENSOR_TYPE_ACCELEROMETER:
113 ecore_event_add(EEZE_SENSOR_EVENT_ACCELEROMETER, obj, NULL, NULL);
114 case EEZE_SENSOR_TYPE_MAGNETIC:
115 case EEZE_SENSOR_TYPE_ORIENTATION:
116 case EEZE_SENSOR_TYPE_GYROSCOPE:
117 obj->accuracy = -1;
118 obj->data[0] = 7;
119 obj->data[1] = 23;
120 obj->data[2] = 42;
121 gettimeofday(&tv, NULL);
122 obj->timestamp = ((tv.tv_sec * 1000000) + tv.tv_usec);
123 break;
124
125 case EEZE_SENSOR_TYPE_LIGHT:
126 case EEZE_SENSOR_TYPE_PROXIMITY:
127 case EEZE_SENSOR_TYPE_BAROMETER:
128 case EEZE_SENSOR_TYPE_TEMPERATURE:
129 obj->accuracy = -1;
130 obj->data[0] = 7;
131 gettimeofday(&tv, NULL);
132 obj->timestamp = ((tv.tv_sec * 1000000) + tv.tv_usec);
133 break;
134
135 default:
136 ERR("Not possible to set a callback for this sensor type.");
137 free(obj);
138 return EINA_FALSE;
139 }
140 free(obj);
141 return EINA_TRUE;
142}
143
144/* This function gets called when the module is loaded from the disk. Its the
145 * entry point to anything in this module. After settign ourself up we register
146 * into the core of eeze sensor to make our functionality available.
147 */
148Eina_Bool
149sensor_fake_init(void)
150{
151 /* Check to avoid multi-init */
152 if (esensor_module) return EINA_FALSE;
153
154 /* Set module function pointer to allow calls into the module */
155 esensor_module = calloc(1, sizeof(Eeze_Sensor_Module));
156 if (!esensor_module) return EINA_FALSE;
157
158 /* Setup our function pointers to allow the core accessing this modules
159 * functions
160 */
161 esensor_module->init = fake_init;
162 esensor_module->shutdown = fake_shutdown;
163 esensor_module->read = fake_read;
164 esensor_module->async_read = fake_async_read;
165
166 if (!eeze_sensor_module_register("fake", esensor_module))
167 {
168 ERR("Failed to register fake module.");
169 return EINA_FALSE;
170 }
171 return EINA_TRUE;
172}
173
174/* Cleanup when the module gets unloaded. Unregister ourself from the core to
175 * avoid calls into a not loaded module.
176 */
177void
178sensor_fake_shutdown(void)
179{
180 Eeze_Sensor_Obj *sens;
181
182 eeze_sensor_module_unregister("fake");
183 EINA_LIST_FREE(esensor_module->sensor_list, sens)
184 free(sens);
185
186 free(esensor_module);
187 esensor_module = NULL;
188}
189
190EINA_MODULE_INIT(sensor_fake_init);
191EINA_MODULE_SHUTDOWN(sensor_fake_shutdown);
diff --git a/src/modules/eeze/eeze_sensor_tizen.c b/src/modules/eeze/eeze_sensor_tizen.c
new file mode 100644
index 0000000000..55db220a1b
--- /dev/null
+++ b/src/modules/eeze/eeze_sensor_tizen.c
@@ -0,0 +1,869 @@
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 <Ecore.h>
13#include <Eeze_Sensor.h>
14#include "eeze_sensor_private.h"
15
16Eeze_Sensor_Module *esensor_module;
17/* Tizen sensor handle */
18sensor_h sensor_handle;
19
20/* The Tizen sensor type ENUM has shown to not be stable regarding its
21 * numbering scheme so we better translate between the Tizen types and the
22 * ones we use here.
23 */
24static sensor_type_e
25eeze_to_tizen(Eeze_Sensor_Type type)
26{
27 switch (type)
28 {
29 case EEZE_SENSOR_TYPE_ACCELEROMETER:
30 return SENSOR_ACCELEROMETER;
31
32 case EEZE_SENSOR_TYPE_MAGNETIC:
33 return SENSOR_MAGNETIC;
34
35 case EEZE_SENSOR_TYPE_ORIENTATION:
36 return SENSOR_ORIENTATION;
37
38 case EEZE_SENSOR_TYPE_GYROSCOPE:
39 return SENSOR_GYROSCOPE;
40
41 case EEZE_SENSOR_TYPE_LIGHT:
42 return SENSOR_LIGHT;
43
44 case EEZE_SENSOR_TYPE_PROXIMITY:
45 return SENSOR_PROXIMITY;
46
47 case EEZE_SENSOR_TYPE_MOTION_SNAP:
48 return SENSOR_MOTION_SNAP;
49
50 case EEZE_SENSOR_TYPE_MOTION_SHAKE:
51 return SENSOR_MOTION_SHAKE;
52
53 case EEZE_SENSOR_TYPE_MOTION_DOUBLETAP:
54 return SENSOR_MOTION_DOUBLETAP;
55
56 case EEZE_SENSOR_TYPE_MOTION_PANNING:
57 return SENSOR_MOTION_PANNING;
58
59 case EEZE_SENSOR_TYPE_MOTION_FACEDOWN:
60 return SENSOR_MOTION_FACEDOWN;
61
62 default:
63 ERR("No matching Tizen sensor type available.");
64 return -1;
65 }
66}
67
68/* All following callback function work with the same scheme.
69 * They are callbacks coming in from the tizen system sensor library. With the
70 * data we receive we update the matching sensor object to always have the
71 * latest data available. That includes updating the timestamp to show when the
72 * data was measured from the underlying system.
73 * After that we send out an ecore event to let all interested parties now that
74 * new data is available and then stop the sensor server to safe power. It will be
75 * started again the next time data gets requested.
76 */
77void
78accelerometer_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
79{
80 Eeze_Sensor_Obj *obj = NULL;
81
82 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ACCELEROMETER);
83 if (obj == NULL)
84 {
85 ERR("No matching sensor object found in list.");
86 return;
87 }
88 obj->accuracy = accuracy;
89 obj->data[0] = x;
90 obj->data[1] = y;
91 obj->data[2] = z;
92 obj->timestamp = timestamp;
93 ecore_event_add(EEZE_SENSOR_EVENT_ACCELEROMETER, obj, NULL, NULL);
94 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_ACCELEROMETER));
95}
96
97void
98magnetic_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
99{
100 Eeze_Sensor_Obj *obj = NULL;
101
102 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MAGNETIC);
103 if (obj == NULL)
104 {
105 ERR("No matching sensor object found in list.");
106 return;
107 }
108 obj->accuracy = accuracy;
109 obj->data[0] = x;
110 obj->data[1] = y;
111 obj->data[2] = z;
112 obj->timestamp = timestamp;
113 ecore_event_add(EEZE_SENSOR_EVENT_MAGNETIC, obj, NULL, NULL);
114 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MAGNETIC));
115}
116
117void
118orientation_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float azimuth, float pitch, float roll, void *user_data)
119{
120 Eeze_Sensor_Obj *obj = NULL;
121
122 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ORIENTATION);
123 if (obj == NULL)
124 {
125 ERR("No matching sensor object found in list.");
126 return;
127 }
128 obj->accuracy = accuracy;
129 obj->data[0] = azimuth;
130 obj->data[1] = pitch;
131 obj->data[2] = roll;
132 obj->timestamp = timestamp;
133 ecore_event_add(EEZE_SENSOR_EVENT_ORIENTATION, obj, NULL, NULL);
134 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_ORIENTATION));
135}
136
137void
138gyroscope_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
139{
140 Eeze_Sensor_Obj *obj = NULL;
141
142 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_GYROSCOPE);
143 if (obj == NULL)
144 {
145 ERR("No matching sensor object found in list.");
146 return;
147 }
148 obj->accuracy = accuracy;
149 obj->data[0] = x;
150 obj->data[1] = y;
151 obj->data[2] = z;
152 obj->timestamp = timestamp;
153 ecore_event_add(EEZE_SENSOR_EVENT_GYROSCOPE, obj, NULL, NULL);
154 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_GYROSCOPE));
155}
156
157void
158light_cb(unsigned long long timestamp, float lux, void *user_data)
159{
160 Eeze_Sensor_Obj *obj = NULL;
161
162 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_LIGHT);
163 if (obj == NULL)
164 {
165 ERR("No matching sensor object found in list.");
166 return;
167 }
168 /* We have to set this ourselves because we don't get it for this type */
169 obj->accuracy = -1;
170 obj->data[0] = lux;
171 obj->timestamp = timestamp;
172 ecore_event_add(EEZE_SENSOR_EVENT_LIGHT, obj, NULL, NULL);
173 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_LIGHT));
174}
175
176void
177proximity_cb(unsigned long long timestamp, float distance, void *user_data)
178{
179 Eeze_Sensor_Obj *obj = NULL;
180
181 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_PROXIMITY);
182 if (obj == NULL)
183 {
184 ERR("No matching sensor object found in list.");
185 return;
186 }
187 /* We have to set this ourselves because we don't get it for this type */
188 obj->accuracy = -1;
189 obj->data[0] = distance;
190 obj->timestamp = timestamp;
191 ecore_event_add(EEZE_SENSOR_EVENT_PROXIMITY, obj, NULL, NULL);
192 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_PROXIMITY));
193}
194
195void
196snap_cb(unsigned long long timestamp, sensor_motion_snap_e snap, void *user_data)
197{
198 Eeze_Sensor_Obj *obj = NULL;
199
200 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_SNAP);
201 if (obj == NULL)
202 {
203 ERR("No matching sensor object found in list.");
204 return;
205 }
206 /* We have to set this ourselves because we don't get it for this type */
207 obj->accuracy = -1;
208 obj->data[0] = snap;
209 obj->timestamp = timestamp;
210 ecore_event_add(EEZE_SENSOR_EVENT_SNAP, obj, NULL, NULL);
211 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_SNAP));
212}
213
214void
215shake_cb(unsigned long long timestamp, sensor_motion_shake_e shake, void *user_data)
216{
217 Eeze_Sensor_Obj *obj = NULL;
218
219 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_SHAKE);
220 if (obj == NULL)
221 {
222 ERR("No matching sensor object found in list.");
223 return;
224 }
225 /* We have to set this ourselves because we don't get it for this type */
226 obj->accuracy = -1;
227 obj->data[0] = shake;
228 obj->timestamp = timestamp;
229 ecore_event_add(EEZE_SENSOR_EVENT_SHAKE, obj, NULL, NULL);
230 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_SHAKE));
231}
232
233void
234panning_cb(unsigned long long timestamp, int x, int y, void *user_data)
235{
236 Eeze_Sensor_Obj *obj = NULL;
237
238 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_PANNING);
239 if (obj == NULL)
240 {
241 ERR("No matching sensor object found in list.");
242 return;
243 }
244 /* We have to set this ourselves because we don't get it for this type */
245 obj->accuracy = -1;
246 obj->data[0] = x;
247 obj->data[1] = y;
248 obj->timestamp = timestamp;
249 ecore_event_add(EEZE_SENSOR_EVENT_PANNING, obj, NULL, NULL);
250 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_PANNING));
251}
252
253void
254facedown_cb(unsigned long long timestamp, void *user_data)
255{
256 Eeze_Sensor_Obj *obj = NULL;
257
258 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_FACEDOWN);
259 if (obj == NULL)
260 {
261 ERR("No matching sensor object found in list.");
262 return;
263 }
264 /* We have to set this ourselves because we don't get it for this type */
265 obj->accuracy = -1;
266 obj->timestamp = timestamp;
267 ecore_event_add(EEZE_SENSOR_EVENT_FACEDOWN, obj, NULL, NULL);
268 /* We are not stopping the sensor here because we want to keep it as a motion
269 * event coming in at any time.
270 */
271}
272
273void
274doubletap_cb(unsigned long long timestamp, void *user_data)
275{
276 Eeze_Sensor_Obj *obj = NULL;
277
278 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_DOUBLETAP);
279 if (obj == NULL)
280 {
281 ERR("No matching sensor object found in list.");
282 return;
283 }
284 /* We have to set this ourselves because we don't get it for this type */
285 obj->accuracy = -1;
286 obj->timestamp = timestamp;
287 ecore_event_add(EEZE_SENSOR_EVENT_DOUBLETAP, obj, NULL, NULL);
288 /* We are not stopping the sensor here because we want to keep it as a motion
289 * event coming in at any time.
290 */
291}
292
293void
294accelerometer_read_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
295{
296 Eeze_Sensor_Obj *obj = NULL;
297
298 sensor_accelerometer_unset_cb(sensor_handle);
299
300 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ACCELEROMETER);
301 if (obj == NULL)
302 {
303 ERR("No matching sensor object found in list.");
304 return;
305 }
306 obj->accuracy = accuracy;
307 obj->data[0] = x;
308 obj->data[1] = y;
309 obj->data[2] = z;
310 obj->timestamp = timestamp;
311 ecore_event_add(EEZE_SENSOR_EVENT_ACCELEROMETER, obj, NULL, NULL);
312 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_ACCELEROMETER));
313}
314
315void
316magnetic_read_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
317{
318 Eeze_Sensor_Obj *obj = NULL;
319
320 sensor_magnetic_unset_cb(sensor_handle);
321
322 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MAGNETIC);
323 if (obj == NULL)
324 {
325 ERR("No matching sensor object found in list.");
326 return;
327 }
328 obj->accuracy = accuracy;
329 obj->data[0] = x;
330 obj->data[1] = y;
331 obj->data[2] = z;
332 obj->timestamp = timestamp;
333 ecore_event_add(EEZE_SENSOR_EVENT_MAGNETIC, obj, NULL, NULL);
334 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MAGNETIC));
335}
336
337void
338orientation_read_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float azimuth, float pitch, float roll, void *user_data)
339{
340 Eeze_Sensor_Obj *obj = NULL;
341
342 sensor_orientation_unset_cb(sensor_handle);
343
344 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ORIENTATION);
345 if (obj == NULL)
346 {
347 ERR("No matching sensor object found in list.");
348 return;
349 }
350 obj->accuracy = accuracy;
351 obj->data[0] = azimuth;
352 obj->data[1] = pitch;
353 obj->data[2] = roll;
354 obj->timestamp = timestamp;
355 ecore_event_add(EEZE_SENSOR_EVENT_ORIENTATION, obj, NULL, NULL);
356 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_ORIENTATION));
357}
358
359void
360gyroscope_read_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
361{
362 Eeze_Sensor_Obj *obj = NULL;
363
364 sensor_gyroscope_unset_cb(sensor_handle);
365
366 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_GYROSCOPE);
367 if (obj == NULL)
368 {
369 ERR("No matching sensor object found in list.");
370 return;
371 }
372 obj->accuracy = accuracy;
373 obj->data[0] = x;
374 obj->data[1] = y;
375 obj->data[2] = z;
376 obj->timestamp = timestamp;
377 ecore_event_add(EEZE_SENSOR_EVENT_GYROSCOPE, obj, NULL, NULL);
378 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_GYROSCOPE));
379}
380
381void
382light_read_cb(unsigned long long timestamp, float lux, void *user_data)
383{
384 Eeze_Sensor_Obj *obj = NULL;
385
386 sensor_light_unset_cb(sensor_handle);
387
388 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_LIGHT);
389 if (obj == NULL)
390 {
391 ERR("No matching sensor object found in list.");
392 return;
393 }
394 /* We have to set this ourselves because we don't get it for this type */
395 obj->accuracy = -1;
396 obj->data[0] = lux;
397 obj->timestamp = timestamp;
398 ecore_event_add(EEZE_SENSOR_EVENT_LIGHT, obj, NULL, NULL);
399 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_LIGHT));
400}
401
402void
403proximity_read_cb(unsigned long long timestamp, float distance, void *user_data)
404{
405 Eeze_Sensor_Obj *obj = NULL;
406
407 sensor_proximity_unset_cb(sensor_handle);
408
409 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_PROXIMITY);
410 if (obj == NULL)
411 {
412 ERR("No matching sensor object found in list.");
413 return;
414 }
415 /* We have to set this ourselves because we don't get it for this type */
416 bj->accuracy = -1;
417 obj->data[0] = distance;
418 obj->timestamp = timestamp;
419 ecore_event_add(EEZE_SENSOR_EVENT_PROXIMITY, obj, NULL, NULL);
420 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_PROXIMITY));
421}
422
423void
424snap_read_cb(unsigned long long timestamp, sensor_motion_snap_e snap, void *user_data)
425{
426 Eeze_Sensor_Obj *obj = NULL;
427
428 sensor_motion_snap_unset_cb(sensor_handle);
429
430 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_SNAP);
431 if (obj == NULL)
432 {
433 ERR("No matching sensor object found in list.");
434 return;
435 }
436 /* We have to set this ourselves because we don't get it for this type */
437 obj->accuracy = -1;
438 obj->data[0] = snap;
439 obj->timestamp = timestamp;
440 ecore_event_add(EEZE_SENSOR_EVENT_SNAP, obj, NULL, NULL);
441 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_SNAP));
442}
443
444void
445shake_read_cb(unsigned long long timestamp, sensor_motion_shake_e shake, void *user_data)
446{
447 Eeze_Sensor_Obj *obj = NULL;
448
449 sensor_motion_shake_unset_cb(sensor_handle);
450
451 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_SHAKE);
452 if (obj == NULL)
453 {
454 ERR("No matching sensor object found in list.");
455 return;
456 }
457 /* We have to set this ourselves because we don't get it for this type */
458 obj->accuracy = -1;
459 obj->data[0] = shake;
460 obj->timestamp = timestamp;
461 ecore_event_add(EEZE_SENSOR_EVENT_SHAKE, obj, NULL, NULL);
462 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_SHAKE));
463}
464
465void
466panning_read_cb(unsigned long long timestamp, int x, int y, void *user_data)
467{
468 Eeze_Sensor_Obj *obj = NULL;
469
470 sensor_motion_panning_unset_cb(sensor_handle);
471
472 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_PANNING);
473 if (obj == NULL)
474 {
475 ERR("No matching sensor object found in list.");
476 return;
477 }
478 /* We have to set this ourselves because we don't get it for this type */
479 obj->accuracy = -1;
480 obj->data[0] = x;
481 obj->data[1] = y;
482 obj->timestamp = timestamp;
483 ecore_event_add(EEZE_SENSOR_EVENT_PANNING, obj, NULL, NULL);
484 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_PANNING));
485}
486
487void
488facedown_read_cb(unsigned long long timestamp, void *user_data)
489{
490 Eeze_Sensor_Obj *obj = NULL;
491
492 sensor_motion_facedown_unset_cb(sensor_handle);
493
494 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_FACEDOWN);
495 if (obj == NULL)
496 {
497 ERR("No matching sensor object found in list.");
498 return;
499 }
500 /* We have to set this ourselves because we don't get it for this type */
501 obj->accuracy = -1;
502 obj->timestamp = timestamp;
503 ecore_event_add(EEZE_SENSOR_EVENT_FACEDOWN, obj, NULL, NULL);
504 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_FACEDOWN));
505}
506
507void
508doubletap_read_cb(unsigned long long timestamp, void *user_data)
509{
510 Eeze_Sensor_Obj *obj = NULL;
511
512 sensor_motion_doubletap_unset_cb(sensor_handle);
513
514 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_MOTION_DOUBLETAP);
515 if (obj == NULL)
516 {
517 ERR("No matching sensor object found in list.");
518 return;
519 }
520 /* We have to set this ourselves because we don't get it for this type */
521 obj->accuracy = -1;
522 obj->timestamp = timestamp;
523 ecore_event_add(EEZE_SENSOR_EVENT_DOUBLETAP, obj, NULL, NULL);
524 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_DOUBLETAP));
525}
526
527/* Synchronous read function for sensor data. It uses the blocking calls to read
528 * out the data and returns after it finishes the readout. Be aware that this
529 * might take quite some time depending on the sensor and how it is connected to
530 * the system. Normally it is better to use the asynchronous reading functions.
531 */
532Eina_Bool
533eeze_sensor_tizen_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
534{
535 sensor_data_accuracy_e accuracy;
536 float x, y, z;
537 float azimuth, pitch, roll, lux, distance;
538 bool supported;
539 sensor_type_e type;
540 Eeze_Sensor_Obj *obj;
541
542 type = eeze_to_tizen(sensor_type);
543
544 /* Don't attempt to do anything if the sensor is not available on the system
545 * we are running on.
546 */
547 sensor_is_supported(type, &supported);
548 if (!supported)
549 {
550 ERR("Sensor type %d not available on this device.", type);
551 return EINA_FALSE;
552 }
553
554 sensor_start(sensor_handle, type);
555 obj = eeze_sensor_obj_get(sensor_type);
556 if (obj == NULL)
557 {
558 ERR("No matching sensor object found in list.");
559 return EINA_FALSE;
560 }
561
562 switch (type)
563 {
564 case SENSOR_ACCELEROMETER:
565 sensor_accelerometer_read_data(sensor_handle, &accuracy, &x, &y, &z);
566 obj->accuracy = accuracy;
567 obj->data[0] = x;
568 obj->data[1] = y;
569 obj->data[2] = z;
570 obj->timestamp = 0;
571 break;
572
573 case SENSOR_MAGNETIC:
574 sensor_magnetic_read_data(sensor_handle, &accuracy, &x, &y, &z);
575 obj->accuracy = accuracy;
576 obj->data[0] = x;
577 obj->data[1] = y;
578 obj->data[2] = z;
579 obj->timestamp = 0;
580 break;
581
582 case SENSOR_ORIENTATION:
583 sensor_orientation_read_data(sensor_handle, &accuracy, &azimuth, &pitch, &roll);
584 obj->accuracy = accuracy;
585 obj->data[0] = azimuth;
586 obj->data[1] = pitch;
587 obj->data[2] = roll;
588 obj->timestamp = 0;
589 break;
590
591 case SENSOR_GYROSCOPE:
592 sensor_gyroscope_read_data(sensor_handle, &accuracy, &x, &y, &z);
593 obj->accuracy = accuracy;
594 obj->data[0] = x;
595 obj->data[1] = y;
596 obj->data[2] = z;
597 obj->timestamp = 0;
598 break;
599
600 case SENSOR_LIGHT:
601 sensor_light_read_data(sensor_handle, &lux);
602 /* As we do not get any accuracy value from the system we go with -1 */
603 obj->accuracy = -1;
604 obj->data[0] = lux;
605 obj->timestamp = 0;
606 break;
607
608 case SENSOR_PROXIMITY:
609 sensor_proximity_read_data(sensor_handle, &distance);
610 /* As we do not get any accuracy value from the system we go with -1 */
611 obj->accuracy = -1;
612 obj->data[0] = distance;
613 obj->timestamp = 0;
614 break;
615
616 default:
617 ERR("Not possible to read from this sensor type.");
618 free(obj);
619 return EINA_FALSE;
620 }
621
622 memcpy(lobj, obj, sizeof(Eeze_Sensor_Obj));
623 free(obj);
624 sensor_stop(sensor_handle, type);
625 return EINA_TRUE;
626}
627
628// FIXME ho to handle this without explicit callback setting
629#if 0
630Eina_Bool
631eeze_sensor_tizen_cb_set(Eeze_Sensor *handle, Eeze_Sensor_Type sensor_type, void *cb_function, void *user_data)
632{
633 sensor_type_e type;
634
635 type = eeze_to_tizen(sensor_type);
636
637 handle->cb_function = cb_function;
638
639 sensor_start(sensor_handle, type);
640
641 switch (type)
642 {
643 case SENSOR_ACCELEROMETER:
644 sensor_accelerometer_set_cb(sensor_handle, 0, accelerometer_cb, handle);
645 break;
646
647 case SENSOR_MAGNETIC:
648 sensor_magnetic_set_cb(sensor_handle, 0, magnetic_cb, handle);
649 break;
650
651 case SENSOR_ORIENTATION:
652 sensor_orientation_set_cb(sensor_handle, 0, orientation_cb, handle);
653 break;
654
655 case SENSOR_GYROSCOPE:
656 sensor_gyroscope_set_cb(sensor_handle, 0, gyroscope_cb, handle);
657 break;
658
659 case SENSOR_LIGHT:
660 sensor_light_set_cb(sensor_handle, 0, light_cb, handle);
661 break;
662
663 case SENSOR_PROXIMITY:
664 sensor_proximity_set_cb(sensor_handle, 0, proximity_cb, handle);
665 break;
666
667 case SENSOR_MOTION_SNAP:
668 sensor_motion_snap_set_cb(sensor_handle, snap_cb, handle);
669 break;
670
671 case SENSOR_MOTION_SHAKE:
672 sensor_motion_shake_set_cb(sensor_handle, shake_cb, handle);
673 break;
674
675 case SENSOR_MOTION_PANNING:
676 sensor_motion_panning_set_cb(sensor_handle, panning_cb, handle);
677 break;
678
679 default:
680 ERR("Not possible to set a callback for this sensor type.");
681 return EINA_FALSE;
682 }
683 return EINA_TRUE;
684}
685#endif
686
687/* For the asynchronous reads we only start the sensor her and trigger the
688 * readout. The callbacks above are actually taking care about putting the data
689 * into the matching sensor objects and informing all subscribers with an ecore
690 * event. The public API function does actually return right away with the cached
691 * data. This is handled in the core and not in the different modules though.
692 */
693Eina_Bool
694eeze_sensor_tizen_async_read(Eeze_Sensor_Type sensor_type, void *user_data)
695{
696 sensor_type_e type;
697
698 type = eeze_to_tizen(sensor_type);
699
700 sensor_start(sensor_handle, type);
701
702 switch (type)
703 {
704 case SENSOR_ACCELEROMETER:
705 sensor_accelerometer_set_cb(sensor_handle, 0, accelerometer_read_cb, NULL);
706 break;
707
708 case SENSOR_MAGNETIC:
709 sensor_magnetic_set_cb(sensor_handle, 0, magnetic_read_cb, NULL);
710 break;
711
712 case SENSOR_ORIENTATION:
713 sensor_orientation_set_cb(sensor_handle, 0, orientation_read_cb, NULL);
714 break;
715
716 case SENSOR_GYROSCOPE:
717 sensor_gyroscope_set_cb(sensor_handle, 0, gyroscope_read_cb, NULL);
718 break;
719
720 case SENSOR_LIGHT:
721 sensor_light_set_cb(sensor_handle, 0, light_read_cb, NULL);
722 break;
723
724 case SENSOR_PROXIMITY:
725 sensor_proximity_set_cb(sensor_handle, 0, proximity_read_cb, NULL);
726 break;
727
728 case SENSOR_MOTION_SNAP:
729 sensor_motion_snap_set_cb(sensor_handle, snap_read_cb, NULL);
730 break;
731
732 case SENSOR_MOTION_SHAKE:
733 sensor_motion_shake_set_cb(sensor_handle, shake_read_cb, NULL);
734 break;
735
736 case SENSOR_MOTION_DOUBLETAP:
737 sensor_motion_doubletap_set_cb(sensor_handle, doubletap_read_cb, NULL);
738 break;
739
740 case SENSOR_MOTION_PANNING:
741 sensor_motion_panning_set_cb(sensor_handle, panning_read_cb, NULL);
742 break;
743
744 case SENSOR_MOTION_FACEDOWN:
745 sensor_motion_facedown_set_cb(sensor_handle, facedown_read_cb, NULL);
746 break;
747
748 default:
749 ERR("Not possible to set a callback for this sensor type.");
750 return EINA_FALSE;
751 }
752 return EINA_TRUE;
753}
754
755/* Go through all potential Tizen sensor and test if they are available on the
756 * system we are running on. If yes, create a matching sensor object and put it
757 * the list of available sensor for the core.
758 */
759static void
760eeze_sensor_tizen_sensors_find(void)
761{
762 sensor_type_e type;
763 bool supported = 0;
764
765 /* FIXME: Make this safe against changes in the enum. But how? */
766 for (type = SENSOR_ACCELEROMETER; type <= SENSOR_MOTION_FACEDOWN; type++)
767 {
768 sensor_is_supported(type, &supported);
769 if (supported)
770 {
771 Eeze_Sensor_Obj *obj = calloc(1, sizeof(Eeze_Sensor_Obj));
772 obj->type = type;
773 esensor_module->sensor_list = eina_list_append(esensor_module->sensor_list, obj);
774 }
775 }
776}
777
778/* Cleanup when getting the shutdown callback from core */
779Eina_Bool
780eeze_sensor_tizen_shutdown(void)
781{
782 Eeze_Sensor_Obj *obj;
783
784 EINA_LIST_FREE(esensor_module->sensor_list, obj)
785 free(obj);
786
787 sensor_start(sensor_handle, SENSOR_MOTION_FACEDOWN);
788 sensor_start(sensor_handle, SENSOR_MOTION_DOUBLETAP);
789 sensor_start(sensor_handle, SENSOR_MOTION_SHAKE);
790 if (sensor_destroy(sensor_handle) != 0)
791 {
792 ERR("Failing to destroy sensor handle.");
793 return EINA_FALSE;
794 }
795 return EINA_TRUE;
796}
797
798/* Callback from core once we registered as a module. Create the Tizen sensor
799 * handle and find all available sensors.
800 */
801Eina_Bool
802eeze_sensor_tizen_init(void)
803{
804
805 if (sensor_create(&sensor_handle) != 0)
806 {
807 ERR("Failing to create sensor handle.");
808 return EINA_FALSE;
809 }
810
811 eeze_sensor_tizen_sensors_find();
812
813 /* FIXME add other motion events in here */
814 sensor_start(sensor_handle, SENSOR_MOTION_FACEDOWN);
815 sensor_start(sensor_handle, SENSOR_MOTION_DOUBLETAP);
816 sensor_motion_doubletap_set_cb(sensor_handle, doubletap_cb, NULL);
817 sensor_motion_facedown_set_cb(sensor_handle, facedown_cb, NULL);
818
819 return EINA_TRUE;
820}
821
822/* This function gets called when the module is loaded from the disk. Its the
823 * entry point to anything in this module. After setting ourself up we register
824 * into the core of eeze sensor to make our functionality available.
825 */
826Eina_Bool
827sensor_tizen_init(void)
828{
829 /* Check to avoid multi-init */
830 if (esensor_module) return EINA_FALSE;
831
832 /* Set module function pointer to allow calls into the module */
833 esensor_module = calloc(1, sizeof(Eeze_Sensor_Module));
834 if (!esensor_module) return EINA_FALSE;
835
836 esensor_module->init = eeze_sensor_tizen_init;
837 esensor_module->shutdown = eeze_sensor_tizen_shutdown;
838 esensor_module->read = eeze_sensor_tizen_read;
839 esensor_module->async_read = eeze_sensor_tizen_async_read;
840
841 if (!eeze_sensor_module_register("tizen", esensor_module))
842 {
843 ERR("Failed to register tizen module");
844 return EINA_FALSE;
845 }
846 return EINA_TRUE;
847}
848
849/* Cleanup when the module gets unloaded. Unregister ourself from the core to
850 * avoid calls into a not loaded module.
851 */
852void
853sensor_tizen_shutdown(void)
854{
855 Eeze_Sensor_Obj *sens;
856
857 sensor_stop(sensor_handle, SENSOR_MOTION_FACEDOWN);
858 sensor_stop(sensor_handle, SENSOR_MOTION_DOUBLETAP);
859 eeze_sensor_module_unregister("tizen");
860 EINA_LIST_FREE(esensor_module->sensor_list, sens)
861 free(sens);
862
863 free(esensor_module);
864 esensor_module = NULL;
865}
866
867EINA_MODULE_INIT(sensor_tizen_init);
868EINA_MODULE_SHUTDOWN(sensor_tizen_shutdown);
869