summaryrefslogtreecommitdiff
path: root/legacy/eeze
diff options
context:
space:
mode:
authorStefan Schmidt <stefan@datenfreihafen.org>2012-12-13 14:17:14 +0000
committerStefan Schmidt <stefan@datenfreihafen.org>2012-12-13 14:17:14 +0000
commit77b2e630027d057221c471906344d9a588f54f3d (patch)
tree3b2fa2d89557965cb6731aed3fee36bfb4eee94f /legacy/eeze
parentbafa56598bc115d7a4f225f52cc715dd41df5bd6 (diff)
eeze/sensor: Add more documentation and comment the code.
SVN revision: 80861
Diffstat (limited to 'legacy/eeze')
-rw-r--r--legacy/eeze/src/bin/eeze_sensor_test.c1
-rw-r--r--legacy/eeze/src/lib/Eeze_Sensor.h31
-rw-r--r--legacy/eeze/src/lib/eeze_sensor.c61
-rw-r--r--legacy/eeze/src/lib/eeze_sensor_private.h24
-rw-r--r--legacy/eeze/src/modules/eeze_sensor_fake.c34
-rw-r--r--legacy/eeze/src/modules/eeze_sensor_tizen.c82
6 files changed, 197 insertions, 36 deletions
diff --git a/legacy/eeze/src/bin/eeze_sensor_test.c b/legacy/eeze/src/bin/eeze_sensor_test.c
index d158ee1de6..2c7387691e 100644
--- a/legacy/eeze/src/bin/eeze_sensor_test.c
+++ b/legacy/eeze/src/bin/eeze_sensor_test.c
@@ -171,4 +171,3 @@ main(void)
171 171
172 return 0; 172 return 0;
173} 173}
174
diff --git a/legacy/eeze/src/lib/Eeze_Sensor.h b/legacy/eeze/src/lib/Eeze_Sensor.h
index a853ab72fc..0f53f0b601 100644
--- a/legacy/eeze/src/lib/Eeze_Sensor.h
+++ b/legacy/eeze/src/lib/Eeze_Sensor.h
@@ -52,7 +52,9 @@
52 * 52 *
53 * All sensor types known by Eeze Sensor. This list of types include real 53 * All sensor types known by Eeze Sensor. This list of types include real
54 * physical types like proximity or light as well as "aggregated" types like 54 * physical types like proximity or light as well as "aggregated" types like
55 * facedown or doubletap. 55 * facedown or doubletap. All types with MOTION in their name can be used as
56 * real events coming from the underlying system. This is not supported on all
57 * systems.
56 * 58 *
57 * @since 1.8 59 * @since 1.8
58 */ 60 */
@@ -81,7 +83,9 @@ typedef enum
81 * 83 *
82 * Event types used to register ecore_event_handler on. These events are used 84 * Event types used to register ecore_event_handler on. These events are used
83 * for #eeze_sensor_async_read to deliver read out data. It is also used for 85 * for #eeze_sensor_async_read to deliver read out data. It is also used for
84 * generated events like facedown or shake. 86 * generated events like facedown or shake. Subscribing to these events in your
87 * application allowsyou to react on these changes in an efficient way without
88 * polling for new updates and wasting power and computing cycles.
85 * 89 *
86 * @since 1.8 90 * @since 1.8
87 * @{ 91 * @{
@@ -142,6 +146,10 @@ extern "C" {
142 * to do. Create the object from the type and everything else the operates on 146 * to do. Create the object from the type and everything else the operates on
143 * this object. 147 * this object.
144 * 148 *
149 * This also takes into account what runtime modules are loaded and handles
150 * them in a given priority to pick up the best sensor source for your sensor
151 * object.
152 *
145 * @since 1.8 153 * @since 1.8
146 */ 154 */
147EAPI Eeze_Sensor_Obj *eeze_sensor_new(Eeze_Sensor_Type type); 155EAPI Eeze_Sensor_Obj *eeze_sensor_new(Eeze_Sensor_Type type);
@@ -150,7 +158,8 @@ EAPI Eeze_Sensor_Obj *eeze_sensor_new(Eeze_Sensor_Type type);
150 * @brief Free a sensor object. 158 * @brief Free a sensor object.
151 * @param sens Sensor object to operate on. 159 * @param sens Sensor object to operate on.
152 * 160 *
153 * Free an sensor object when it is no longer needed. 161 * Free an sensor object when it is no longer needed. Always use this function
162 * to cleanup unused sensor objects.
154 * 163 *
155 * @since 1.8 164 * @since 1.8
156 */ 165 */
@@ -239,7 +248,10 @@ EAPI Eina_Bool eeze_sensor_timestamp_get(Eeze_Sensor_Obj *sens, unsigned long lo
239 * This function reads sensor data from the device and fills the sensor object 248 * This function reads sensor data from the device and fills the sensor object
240 * with the data. This call is synchronous and blocks until the data is read out 249 * with the data. This call is synchronous and blocks until the data is read out
241 * and updated in the sensor object. For simple applications this is fine and 250 * and updated in the sensor object. For simple applications this is fine and
242 * the easiest way to use the API. 251 * the easiest way to use the API. A more efficient way is to use
252 * #eeze_sensor_async_read which allows the sensor readout to happen in the
253 * background and the application would check the timestamp of the data to
254 * determine how recent the data is.
243 * 255 *
244 * @since 1.8 256 * @since 1.8
245 */ 257 */
@@ -253,8 +265,15 @@ EAPI Eina_Bool eeze_sensor_read(Eeze_Sensor_Obj *sens);
253 * 265 *
254 * This function reads sensor data from the device and fills the sensor object 266 * This function reads sensor data from the device and fills the sensor object
255 * with the data. The read is done asynchronously and thus does not block after 267 * with the data. The read is done asynchronously and thus does not block after
256 * calling. Instead the given callback function is called once the read is 268 * calling. Instead the given the application can determine how recent the
257 * finished and the object filled. 269 * values are from the timestamp value that can be accessed through
270 * #eeze_sensor_timestamp_get.
271 *
272 * This function is more efficient but needs a bit more work in the application.
273 * An easier way is to use the synchronous #eeze_sensor_read functions. The
274 * downside of it is that it blocks until the data was read out from the
275 * physical sensor. That might be a long time depending on the hardware and its
276 * interface.
258 * 277 *
259 * @since 1.8 278 * @since 1.8
260 */ 279 */
diff --git a/legacy/eeze/src/lib/eeze_sensor.c b/legacy/eeze/src/lib/eeze_sensor.c
index 4c23c34978..566c4c5d96 100644
--- a/legacy/eeze/src/lib/eeze_sensor.c
+++ b/legacy/eeze/src/lib/eeze_sensor.c
@@ -11,10 +11,10 @@
11 11
12Eeze_Sensor *g_handle; 12Eeze_Sensor *g_handle;
13 13
14/* Priority order for modules. The one with the highest order of the available ones will be used. 14/* Priority order for modules. The one with the highest order of the available
15 * This in good enough for now as we only have two modules and one is a test harness anyway. If the 15 * ones will be used. This in good enough for now as we only have two modules
16 * number of modules grows we might re-think the priority handling, but we should do this when the 16 * and one is a test harness anyway. If the number of modules grows we might
17 * need arise. 17 * re-think the priority handling, but we should do this when the need arise.
18 */ 18 */
19static const char *_module_priority[] = { 19static const char *_module_priority[] = {
20 "tizen", 20 "tizen",
@@ -22,6 +22,9 @@ static const char *_module_priority[] = {
22 NULL 22 NULL
23}; 23};
24 24
25/* Search through the list of loaded module and return the one with the highest
26 * priority.
27 */
25Eeze_Sensor_Module * 28Eeze_Sensor_Module *
26_highest_priority_module_get(void) 29_highest_priority_module_get(void)
27{ 30{
@@ -37,6 +40,9 @@ _highest_priority_module_get(void)
37 return NULL; 40 return NULL;
38} 41}
39 42
43/* Utility function to take the given sensor type and get the matching sensor
44 * object from the highest priority module.
45 */
40EAPI Eeze_Sensor_Obj * 46EAPI Eeze_Sensor_Obj *
41eeze_sensor_obj_get(Eeze_Sensor_Type sensor_type) 47eeze_sensor_obj_get(Eeze_Sensor_Type sensor_type)
42{ 48{
@@ -69,7 +75,8 @@ eeze_sensor_modules_load(void)
69 /* Check for available runtime modules and load them. In some cases the 75 /* Check for available runtime modules and load them. In some cases the
70 * un-installed modules to be used from the local build dir. Coverage check 76 * un-installed modules to be used from the local build dir. Coverage check
71 * is one of these items. We do load the modules from the builddir if the 77 * is one of these items. We do load the modules from the builddir if the
72 * environment is set. Normal case is to use installed modules from system */ 78 * environment is set. Normal case is to use installed modules from system
79 */
73 if (getenv("EEZE_USE_IN_TREE_MODULES")) 80 if (getenv("EEZE_USE_IN_TREE_MODULES"))
74 g_handle->modules_array = eina_module_list_get(NULL, PACKAGE_BUILD_DIR "/src/modules/.libs/", 0, NULL, NULL); 81 g_handle->modules_array = eina_module_list_get(NULL, PACKAGE_BUILD_DIR "/src/modules/.libs/", 0, NULL, NULL);
75 else 82 else
@@ -80,7 +87,6 @@ eeze_sensor_modules_load(void)
80 ERR("No modules found!"); 87 ERR("No modules found!");
81 return; 88 return;
82 } 89 }
83
84 eina_module_list_load(g_handle->modules_array); 90 eina_module_list_load(g_handle->modules_array);
85} 91}
86 92
@@ -94,6 +100,10 @@ eeze_sensor_modules_unload(void)
94 g_handle->modules_array = NULL; 100 g_handle->modules_array = NULL;
95} 101}
96 102
103/* This function is offered to the modules to register itself after they have
104 * been loaded in initialized. They stay in the hash funtion until they
105 * unregister themself.
106 */
97Eina_Bool 107Eina_Bool
98eeze_sensor_module_register(const char *name, Eeze_Sensor_Module *mod) 108eeze_sensor_module_register(const char *name, Eeze_Sensor_Module *mod)
99{ 109{
@@ -114,6 +124,9 @@ eeze_sensor_module_register(const char *name, Eeze_Sensor_Module *mod)
114 return eina_hash_add(g_handle->modules, name, module); 124 return eina_hash_add(g_handle->modules, name, module);
115} 125}
116 126
127/* This function is offered to the modules to unregsiter itself. When requested
128 * we remove them safely from the hash.
129 */
117Eina_Bool 130Eina_Bool
118eeze_sensor_module_unregister(const char *name) 131eeze_sensor_module_unregister(const char *name)
119{ 132{
@@ -128,6 +141,13 @@ eeze_sensor_module_unregister(const char *name)
128 return eina_hash_del(g_handle->modules, name, NULL); 141 return eina_hash_del(g_handle->modules, name, NULL);
129} 142}
130 143
144/* Create a new sensor object for a given sensor type. This functions allocates
145 * the needed memory and links it with the matching sensor from the loaded
146 * modules. It also does an initial synchronous read to fill the sensor object
147 * with values.
148 * Make sure to use the eeze_sensor_free function to remove this sensor object
149 * when it is no longer needed.
150 */
131EAPI Eeze_Sensor_Obj * 151EAPI Eeze_Sensor_Obj *
132eeze_sensor_new(Eeze_Sensor_Type type) 152eeze_sensor_new(Eeze_Sensor_Type type)
133{ 153{
@@ -145,14 +165,20 @@ eeze_sensor_new(Eeze_Sensor_Type type)
145 165
146 if (!module->read) return NULL; 166 if (!module->read) return NULL;
147 167
168 /* The read is asynchronous here as we want to make sure that the sensor
169 * object has valid data when created. As we give back cached values we
170 * have a race condition when we do a asynchronous read here and the
171 * application asks for cached data before the reply came in. This logic has
172 * the downside that the sensor creation takes longer. But that is only a
173 *initial cost.
174 */
148 if (module->read(sens->type, sens)) 175 if (module->read(sens->type, sens))
149 { 176 return sens;
150 return sens; 177
151 } 178 return NULL;
152 else
153 return NULL;
154} 179}
155 180
181/* Free sensor object created with eeze_sensor_new */
156EAPI void 182EAPI void
157eeze_sensor_free(Eeze_Sensor_Obj *sens) 183eeze_sensor_free(Eeze_Sensor_Obj *sens)
158{ 184{
@@ -160,6 +186,10 @@ eeze_sensor_free(Eeze_Sensor_Obj *sens)
160 free(sens); 186 free(sens);
161} 187}
162 188
189/* All of the below getter function do access the cached data from the last
190 * sensor read. It is way faster this way but also means that the timestamp
191 * should be checked to ensure recent data if needed.
192 */
163EAPI Eina_Bool 193EAPI Eina_Bool
164eeze_sensor_accuracy_get(Eeze_Sensor_Obj *sens, int *accuracy) 194eeze_sensor_accuracy_get(Eeze_Sensor_Obj *sens, int *accuracy)
165{ 195{
@@ -208,6 +238,9 @@ eeze_sensor_timestamp_get(Eeze_Sensor_Obj *sens, unsigned long long *timestamp)
208 return EINA_TRUE; 238 return EINA_TRUE;
209} 239}
210 240
241/* Synchronous read. Blocked until the data was readout from the hardware
242 * sensor
243 */
211EAPI Eina_Bool 244EAPI Eina_Bool
212eeze_sensor_read(Eeze_Sensor_Obj *sens) 245eeze_sensor_read(Eeze_Sensor_Obj *sens)
213{ 246{
@@ -224,6 +257,9 @@ eeze_sensor_read(Eeze_Sensor_Obj *sens)
224 return EINA_FALSE; 257 return EINA_FALSE;
225} 258}
226 259
260/* Asynchronous read. Schedule a new read out that will update the cached values
261 * as soon as it arrives.
262 */
227EAPI Eina_Bool 263EAPI Eina_Bool
228eeze_sensor_async_read(Eeze_Sensor_Obj *sens, void *user_data) 264eeze_sensor_async_read(Eeze_Sensor_Obj *sens, void *user_data)
229{ 265{
@@ -263,6 +299,7 @@ eeze_sensor_init(void)
263 g_handle->modules = eina_hash_string_small_new(NULL); 299 g_handle->modules = eina_hash_string_small_new(NULL);
264 if (!g_handle->modules) return EINA_FALSE; 300 if (!g_handle->modules) return EINA_FALSE;
265 301
302 /* Make sure we create new ecore event types before using them */
266 EEZE_SENSOR_EVENT_SNAP = ecore_event_type_new(); 303 EEZE_SENSOR_EVENT_SNAP = ecore_event_type_new();
267 EEZE_SENSOR_EVENT_SHAKE = ecore_event_type_new(); 304 EEZE_SENSOR_EVENT_SHAKE = ecore_event_type_new();
268 EEZE_SENSOR_EVENT_DOUBLETAP = ecore_event_type_new(); 305 EEZE_SENSOR_EVENT_DOUBLETAP = ecore_event_type_new();
@@ -270,8 +307,8 @@ eeze_sensor_init(void)
270 EEZE_SENSOR_EVENT_FACEDOWN = ecore_event_type_new(); 307 EEZE_SENSOR_EVENT_FACEDOWN = ecore_event_type_new();
271 EEZE_SENSOR_EVENT_ACCELEROMETER = ecore_event_type_new(); 308 EEZE_SENSOR_EVENT_ACCELEROMETER = ecore_event_type_new();
272 309
310 /* Core is ready so we can load the modules from disk now */
273 eeze_sensor_modules_load(); 311 eeze_sensor_modules_load();
274 312
275 return EINA_TRUE; 313 return EINA_TRUE;
276} 314}
277
diff --git a/legacy/eeze/src/lib/eeze_sensor_private.h b/legacy/eeze/src/lib/eeze_sensor_private.h
index 5464ae8f2d..88c45e2367 100644
--- a/legacy/eeze/src/lib/eeze_sensor_private.h
+++ b/legacy/eeze/src/lib/eeze_sensor_private.h
@@ -13,7 +13,6 @@ extern int _eeze_sensor_log_dom;
13#ifdef CRI 13#ifdef CRI
14#undef CRI 14#undef CRI
15#endif 15#endif
16
17#ifdef ERR 16#ifdef ERR
18#undef ERR 17#undef ERR
19#endif 18#endif
@@ -62,6 +61,29 @@ typedef struct _Eeze_Sensor_Module
62 Eina_List *sensor_list; /**< List of sensor objects attached to the module */ 61 Eina_List *sensor_list; /**< List of sensor objects attached to the module */
63} Eeze_Sensor_Module; 62} Eeze_Sensor_Module;
64 63
64/**
65 * @brief Register a module to eeze_sensor core.
66 * @param name Module name used for reference internally.
67 * @param mod Sensor module to be registered.
68 * @return EINA_TRUE is the module was successfully registered. EINA_FALSE is not.
69 *
70 * Private functions for modules to register itself to eeze sensor core to
71 * advertise their functionality. These registered modules will then be accessed
72 * based on a priority that is currently hardcoded in the code. Once more module
73 * are available we need to re-consider this approach.
74 *
75 * @since 1.8
76 */
65Eina_Bool eeze_sensor_module_register(const char *name, Eeze_Sensor_Module *mod); 77Eina_Bool eeze_sensor_module_register(const char *name, Eeze_Sensor_Module *mod);
78
79/**
80 * @brief Unregister a module from eeze_sensor core.
81 * @param name Module name used for reference internally.
82 * @return EINA_TRUE is the module was successfully unregistered. EINA_FALSE is not.
83 *
84 * Private functions for modules to unregister itself from eeze sensor core.
85 *
86 * @since 1.8
87 */
66Eina_Bool eeze_sensor_module_unregister(const char *name); 88Eina_Bool eeze_sensor_module_unregister(const char *name);
67#endif // EEZE_SENSOR_PRIVATE_H 89#endif // EEZE_SENSOR_PRIVATE_H
diff --git a/legacy/eeze/src/modules/eeze_sensor_fake.c b/legacy/eeze/src/modules/eeze_sensor_fake.c
index cbb65ac8bc..ab2373d5be 100644
--- a/legacy/eeze/src/modules/eeze_sensor_fake.c
+++ b/legacy/eeze/src/modules/eeze_sensor_fake.c
@@ -10,9 +10,9 @@
10#include <Eeze_Sensor.h> 10#include <Eeze_Sensor.h>
11#include "eeze_sensor_private.h" 11#include "eeze_sensor_private.h"
12 12
13/* This small Eeze_Sensor module is meant to be used as a test harness for developing. It does not 13/* This small Eeze_Sensor module is meant to be used as a test harness for
14 * gather any real data from hardware sensors. It uses fixed values for the data, but provides the 14 * developing. It does not gather any real data from hardware sensors. It uses
15 * correct timestamp value. 15 * fixed values for the data, but provides the correct timestamp value.
16 */ 16 */
17 17
18Eeze_Sensor_Module *esensor_module; 18Eeze_Sensor_Module *esensor_module;
@@ -20,7 +20,9 @@ Eeze_Sensor_Module *esensor_module;
20Eina_Bool 20Eina_Bool
21fake_init(void) 21fake_init(void)
22{ 22{
23 /* Set a list with fake sensors */ 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 */
24 Eeze_Sensor_Type type; 26 Eeze_Sensor_Type type;
25 27
26 for (type = 0; type <= EEZE_SENSOR_TYPE_LAST; type++) 28 for (type = 0; type <= EEZE_SENSOR_TYPE_LAST; type++)
@@ -33,6 +35,9 @@ fake_init(void)
33 return EINA_TRUE; 35 return EINA_TRUE;
34} 36}
35 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 */
36Eina_Bool 41Eina_Bool
37fake_shutdown(void) 42fake_shutdown(void)
38{ 43{
@@ -58,7 +63,8 @@ fake_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
58 case EEZE_SENSOR_TYPE_MAGNETIC: 63 case EEZE_SENSOR_TYPE_MAGNETIC:
59 case EEZE_SENSOR_TYPE_ORIENTATION: 64 case EEZE_SENSOR_TYPE_ORIENTATION:
60 case EEZE_SENSOR_TYPE_GYROSCOPE: 65 case EEZE_SENSOR_TYPE_GYROSCOPE:
61 obj->accuracy = 0; 66 /* This is only a test harness so we supply hardcoded values here */
67 obj->accuracy = -1;
62 obj->data[0] = 7; 68 obj->data[0] = 7;
63 obj->data[1] = 23; 69 obj->data[1] = 23;
64 obj->data[2] = 42; 70 obj->data[2] = 42;
@@ -70,7 +76,7 @@ fake_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
70 case EEZE_SENSOR_TYPE_PROXIMITY: 76 case EEZE_SENSOR_TYPE_PROXIMITY:
71 case EEZE_SENSOR_TYPE_BAROMETER: 77 case EEZE_SENSOR_TYPE_BAROMETER:
72 case EEZE_SENSOR_TYPE_TEMPERATURE: 78 case EEZE_SENSOR_TYPE_TEMPERATURE:
73 obj->accuracy = 0; 79 obj->accuracy = -1;
74 obj->data[0] = 7; 80 obj->data[0] = 7;
75 gettimeofday(&tv, NULL); 81 gettimeofday(&tv, NULL);
76 obj->timestamp = ((tv.tv_sec * 1000000) + tv.tv_usec); 82 obj->timestamp = ((tv.tv_sec * 1000000) + tv.tv_usec);
@@ -106,7 +112,7 @@ fake_async_read(Eeze_Sensor_Type sensor_type, void *user_data EINA_UNUSED)
106 case EEZE_SENSOR_TYPE_MAGNETIC: 112 case EEZE_SENSOR_TYPE_MAGNETIC:
107 case EEZE_SENSOR_TYPE_ORIENTATION: 113 case EEZE_SENSOR_TYPE_ORIENTATION:
108 case EEZE_SENSOR_TYPE_GYROSCOPE: 114 case EEZE_SENSOR_TYPE_GYROSCOPE:
109 obj->accuracy = 0; 115 obj->accuracy = -1;
110 obj->data[0] = 7; 116 obj->data[0] = 7;
111 obj->data[1] = 23; 117 obj->data[1] = 23;
112 obj->data[2] = 42; 118 obj->data[2] = 42;
@@ -118,7 +124,7 @@ fake_async_read(Eeze_Sensor_Type sensor_type, void *user_data EINA_UNUSED)
118 case EEZE_SENSOR_TYPE_PROXIMITY: 124 case EEZE_SENSOR_TYPE_PROXIMITY:
119 case EEZE_SENSOR_TYPE_BAROMETER: 125 case EEZE_SENSOR_TYPE_BAROMETER:
120 case EEZE_SENSOR_TYPE_TEMPERATURE: 126 case EEZE_SENSOR_TYPE_TEMPERATURE:
121 obj->accuracy = 0; 127 obj->accuracy = -1;
122 obj->data[0] = 7; 128 obj->data[0] = 7;
123 gettimeofday(&tv, NULL); 129 gettimeofday(&tv, NULL);
124 obj->timestamp = ((tv.tv_sec * 1000000) + tv.tv_usec); 130 obj->timestamp = ((tv.tv_sec * 1000000) + tv.tv_usec);
@@ -128,10 +134,13 @@ fake_async_read(Eeze_Sensor_Type sensor_type, void *user_data EINA_UNUSED)
128 ERR("Not possible to set a callback for this sensor type."); 134 ERR("Not possible to set a callback for this sensor type.");
129 return EINA_FALSE; 135 return EINA_FALSE;
130 } 136 }
131
132 return EINA_TRUE; 137 return EINA_TRUE;
133} 138}
134 139
140/* This function gets called when the module is loaded from the disk. Its the
141 * entry point to anything in this module. After settign ourself up we register
142 * into the core of eeze sensor to make our functionality available.
143 */
135Eina_Bool 144Eina_Bool
136sensor_fake_init(void) 145sensor_fake_init(void)
137{ 146{
@@ -142,6 +151,9 @@ sensor_fake_init(void)
142 esensor_module = calloc(1, sizeof(Eeze_Sensor_Module)); 151 esensor_module = calloc(1, sizeof(Eeze_Sensor_Module));
143 if (!esensor_module) return EINA_FALSE; 152 if (!esensor_module) return EINA_FALSE;
144 153
154 /* Setup our function pointers to allow the core accessing this modules
155 * functions
156 */
145 esensor_module->init = fake_init; 157 esensor_module->init = fake_init;
146 esensor_module->shutdown = fake_shutdown; 158 esensor_module->shutdown = fake_shutdown;
147 esensor_module->read = fake_read; 159 esensor_module->read = fake_read;
@@ -152,10 +164,12 @@ sensor_fake_init(void)
152 ERR("Failed to register fake module."); 164 ERR("Failed to register fake module.");
153 return EINA_FALSE; 165 return EINA_FALSE;
154 } 166 }
155
156 return EINA_TRUE; 167 return EINA_TRUE;
157} 168}
158 169
170/* Cleanup when the module gets unloaded. Unregister ourself from the core to
171 * avoid calls into a not loaded module.
172 */
159void 173void
160sensor_fake_shutdown(void) 174sensor_fake_shutdown(void)
161{ 175{
diff --git a/legacy/eeze/src/modules/eeze_sensor_tizen.c b/legacy/eeze/src/modules/eeze_sensor_tizen.c
index ffcc263e66..29154883e5 100644
--- a/legacy/eeze/src/modules/eeze_sensor_tizen.c
+++ b/legacy/eeze/src/modules/eeze_sensor_tizen.c
@@ -14,8 +14,13 @@
14#include "eeze_sensor_private.h" 14#include "eeze_sensor_private.h"
15 15
16Eeze_Sensor_Module *esensor_module; 16Eeze_Sensor_Module *esensor_module;
17sensor_h sensor_handle; // Tizen sensor handle 17/* Tizen sensor handle */
18sensor_h sensor_handle;
18 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 */
19static sensor_type_e 24static sensor_type_e
20eeze_to_tizen(Eeze_Sensor_Type type) 25eeze_to_tizen(Eeze_Sensor_Type type)
21{ 26{
@@ -60,6 +65,15 @@ eeze_to_tizen(Eeze_Sensor_Type type)
60 } 65 }
61} 66}
62 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 */
63void 77void
64accelerometer_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data) 78accelerometer_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
65{ 79{
@@ -151,7 +165,8 @@ light_cb(unsigned long long timestamp, float lux, void *user_data)
151 ERR("No matching sensor object found in list."); 165 ERR("No matching sensor object found in list.");
152 return; 166 return;
153 } 167 }
154 obj->accuracy = 0; 168 /* We have to set this ourselves because we don't get it for this type */
169 obj->accuracy = -1;
155 obj->data[0] = lux; 170 obj->data[0] = lux;
156 obj->timestamp = timestamp; 171 obj->timestamp = timestamp;
157 ecore_event_add(EEZE_SENSOR_EVENT_LIGHT, obj, NULL, NULL); 172 ecore_event_add(EEZE_SENSOR_EVENT_LIGHT, obj, NULL, NULL);
@@ -169,7 +184,8 @@ proximity_cb(unsigned long long timestamp, float distance, void *user_data)
169 ERR("No matching sensor object found in list."); 184 ERR("No matching sensor object found in list.");
170 return; 185 return;
171 } 186 }
172 obj->accuracy = 0; 187 /* We have to set this ourselves because we don't get it for this type */
188 obj->accuracy = -1;
173 obj->data[0] = distance; 189 obj->data[0] = distance;
174 obj->timestamp = timestamp; 190 obj->timestamp = timestamp;
175 ecore_event_add(EEZE_SENSOR_EVENT_PROXIMITY, obj, NULL, NULL); 191 ecore_event_add(EEZE_SENSOR_EVENT_PROXIMITY, obj, NULL, NULL);
@@ -187,6 +203,8 @@ snap_cb(unsigned long long timestamp, sensor_motion_snap_e snap, void *user_data
187 ERR("No matching sensor object found in list."); 203 ERR("No matching sensor object found in list.");
188 return; 204 return;
189 } 205 }
206 /* We have to set this ourselves because we don't get it for this type */
207 obj->accuracy = -1;
190 obj->data[0] = snap; 208 obj->data[0] = snap;
191 obj->timestamp = timestamp; 209 obj->timestamp = timestamp;
192 ecore_event_add(EEZE_SENSOR_EVENT_SNAP, obj, NULL, NULL); 210 ecore_event_add(EEZE_SENSOR_EVENT_SNAP, obj, NULL, NULL);
@@ -204,6 +222,8 @@ shake_cb(unsigned long long timestamp, sensor_motion_shake_e shake, void *user_d
204 ERR("No matching sensor object found in list."); 222 ERR("No matching sensor object found in list.");
205 return; 223 return;
206 } 224 }
225 /* We have to set this ourselves because we don't get it for this type */
226 obj->accuracy = -1;
207 obj->data[0] = shake; 227 obj->data[0] = shake;
208 obj->timestamp = timestamp; 228 obj->timestamp = timestamp;
209 ecore_event_add(EEZE_SENSOR_EVENT_SHAKE, obj, NULL, NULL); 229 ecore_event_add(EEZE_SENSOR_EVENT_SHAKE, obj, NULL, NULL);
@@ -221,6 +241,8 @@ panning_cb(unsigned long long timestamp, int x, int y, void *user_data)
221 ERR("No matching sensor object found in list."); 241 ERR("No matching sensor object found in list.");
222 return; 242 return;
223 } 243 }
244 /* We have to set this ourselves because we don't get it for this type */
245 obj->accuracy = -1;
224 obj->data[0] = x; 246 obj->data[0] = x;
225 obj->data[1] = y; 247 obj->data[1] = y;
226 obj->timestamp = timestamp; 248 obj->timestamp = timestamp;
@@ -239,8 +261,13 @@ facedown_cb(unsigned long long timestamp, void *user_data)
239 ERR("No matching sensor object found in list."); 261 ERR("No matching sensor object found in list.");
240 return; 262 return;
241 } 263 }
264 /* We have to set this ourselves because we don't get it for this type */
265 obj->accuracy = -1;
242 obj->timestamp = timestamp; 266 obj->timestamp = timestamp;
243 ecore_event_add(EEZE_SENSOR_EVENT_FACEDOWN, obj, NULL, NULL); 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 */
244} 271}
245 272
246void 273void
@@ -254,8 +281,13 @@ doubletap_cb(unsigned long long timestamp, void *user_data)
254 ERR("No matching sensor object found in list."); 281 ERR("No matching sensor object found in list.");
255 return; 282 return;
256 } 283 }
284 /* We have to set this ourselves because we don't get it for this type */
285 obj->accuracy = -1;
257 obj->timestamp = timestamp; 286 obj->timestamp = timestamp;
258 ecore_event_add(EEZE_SENSOR_EVENT_DOUBLETAP, obj, NULL, NULL); 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 */
259} 291}
260 292
261void 293void
@@ -359,6 +391,7 @@ light_read_cb(unsigned long long timestamp, float lux, void *user_data)
359 ERR("No matching sensor object found in list."); 391 ERR("No matching sensor object found in list.");
360 return; 392 return;
361 } 393 }
394 /* We have to set this ourselves because we don't get it for this type */
362 obj->accuracy = -1; 395 obj->accuracy = -1;
363 obj->data[0] = lux; 396 obj->data[0] = lux;
364 obj->timestamp = timestamp; 397 obj->timestamp = timestamp;
@@ -379,7 +412,8 @@ proximity_read_cb(unsigned long long timestamp, float distance, void *user_data)
379 ERR("No matching sensor object found in list."); 412 ERR("No matching sensor object found in list.");
380 return; 413 return;
381 } 414 }
382 obj->accuracy = -1; 415 /* We have to set this ourselves because we don't get it for this type */
416 bj->accuracy = -1;
383 obj->data[0] = distance; 417 obj->data[0] = distance;
384 obj->timestamp = timestamp; 418 obj->timestamp = timestamp;
385 ecore_event_add(EEZE_SENSOR_EVENT_PROXIMITY, obj, NULL, NULL); 419 ecore_event_add(EEZE_SENSOR_EVENT_PROXIMITY, obj, NULL, NULL);
@@ -399,6 +433,7 @@ snap_read_cb(unsigned long long timestamp, sensor_motion_snap_e snap, void *user
399 ERR("No matching sensor object found in list."); 433 ERR("No matching sensor object found in list.");
400 return; 434 return;
401 } 435 }
436 /* We have to set this ourselves because we don't get it for this type */
402 obj->accuracy = -1; 437 obj->accuracy = -1;
403 obj->data[0] = snap; 438 obj->data[0] = snap;
404 obj->timestamp = timestamp; 439 obj->timestamp = timestamp;
@@ -419,6 +454,7 @@ shake_read_cb(unsigned long long timestamp, sensor_motion_shake_e shake, void *u
419 ERR("No matching sensor object found in list."); 454 ERR("No matching sensor object found in list.");
420 return; 455 return;
421 } 456 }
457 /* We have to set this ourselves because we don't get it for this type */
422 obj->accuracy = -1; 458 obj->accuracy = -1;
423 obj->data[0] = shake; 459 obj->data[0] = shake;
424 obj->timestamp = timestamp; 460 obj->timestamp = timestamp;
@@ -439,6 +475,7 @@ panning_read_cb(unsigned long long timestamp, int x, int y, void *user_data)
439 ERR("No matching sensor object found in list."); 475 ERR("No matching sensor object found in list.");
440 return; 476 return;
441 } 477 }
478 /* We have to set this ourselves because we don't get it for this type */
442 obj->accuracy = -1; 479 obj->accuracy = -1;
443 obj->data[0] = x; 480 obj->data[0] = x;
444 obj->data[1] = y; 481 obj->data[1] = y;
@@ -460,6 +497,8 @@ facedown_read_cb(unsigned long long timestamp, void *user_data)
460 ERR("No matching sensor object found in list."); 497 ERR("No matching sensor object found in list.");
461 return; 498 return;
462 } 499 }
500 /* We have to set this ourselves because we don't get it for this type */
501 obj->accuracy = -1;
463 obj->timestamp = timestamp; 502 obj->timestamp = timestamp;
464 ecore_event_add(EEZE_SENSOR_EVENT_FACEDOWN, obj, NULL, NULL); 503 ecore_event_add(EEZE_SENSOR_EVENT_FACEDOWN, obj, NULL, NULL);
465 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_FACEDOWN)); 504 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_FACEDOWN));
@@ -478,11 +517,18 @@ doubletap_read_cb(unsigned long long timestamp, void *user_data)
478 ERR("No matching sensor object found in list."); 517 ERR("No matching sensor object found in list.");
479 return; 518 return;
480 } 519 }
520 /* We have to set this ourselves because we don't get it for this type */
521 obj->accuracy = -1;
481 obj->timestamp = timestamp; 522 obj->timestamp = timestamp;
482 ecore_event_add(EEZE_SENSOR_EVENT_DOUBLETAP, obj, NULL, NULL); 523 ecore_event_add(EEZE_SENSOR_EVENT_DOUBLETAP, obj, NULL, NULL);
483 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_DOUBLETAP)); 524 sensor_stop(sensor_handle, eeze_to_tizen(EEZE_SENSOR_TYPE_MOTION_DOUBLETAP));
484} 525}
485 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 */
486Eina_Bool 532Eina_Bool
487eeze_sensor_tizen_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj) 533eeze_sensor_tizen_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
488{ 534{
@@ -495,6 +541,9 @@ eeze_sensor_tizen_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
495 541
496 type = eeze_to_tizen(sensor_type); 542 type = eeze_to_tizen(sensor_type);
497 543
544 /* Don't attempt to do anything if the sensor is not available on the system
545 * we are running on.
546 */
498 sensor_is_supported(type, &supported); 547 sensor_is_supported(type, &supported);
499 if (!supported) 548 if (!supported)
500 { 549 {
@@ -550,6 +599,7 @@ eeze_sensor_tizen_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
550 599
551 case SENSOR_LIGHT: 600 case SENSOR_LIGHT:
552 sensor_light_read_data(sensor_handle, &lux); 601 sensor_light_read_data(sensor_handle, &lux);
602 /* As we do not get any accuracy value from the system we go with -1 */
553 obj->accuracy = -1; 603 obj->accuracy = -1;
554 obj->data[0] = lux; 604 obj->data[0] = lux;
555 obj->timestamp = 0; 605 obj->timestamp = 0;
@@ -557,6 +607,7 @@ eeze_sensor_tizen_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
557 607
558 case SENSOR_PROXIMITY: 608 case SENSOR_PROXIMITY:
559 sensor_proximity_read_data(sensor_handle, &distance); 609 sensor_proximity_read_data(sensor_handle, &distance);
610 /* As we do not get any accuracy value from the system we go with -1 */
560 obj->accuracy = -1; 611 obj->accuracy = -1;
561 obj->data[0] = distance; 612 obj->data[0] = distance;
562 obj->timestamp = 0; 613 obj->timestamp = 0;
@@ -632,6 +683,12 @@ eeze_sensor_tizen_cb_set(Eeze_Sensor *handle, Eeze_Sensor_Type sensor_type, void
632} 683}
633#endif 684#endif
634 685
686/* For the asynchronous reads we only start the sensor her and trigger the
687 * readout. The callbacks above are actually taking care about putting the data
688 * into the matching sensor objects and informing all subscribers with an ecore
689 * event. The public API function does actually return right away with the cached
690 * data. This is handled in the core and not in the different modules though.
691 */
635Eina_Bool 692Eina_Bool
636eeze_sensor_tizen_async_read(Eeze_Sensor_Type sensor_type, void *user_data) 693eeze_sensor_tizen_async_read(Eeze_Sensor_Type sensor_type, void *user_data)
637{ 694{
@@ -694,6 +751,10 @@ eeze_sensor_tizen_async_read(Eeze_Sensor_Type sensor_type, void *user_data)
694 return EINA_TRUE; 751 return EINA_TRUE;
695} 752}
696 753
754/* Go through all potential Tizen sensor and test if they are available on the
755 * system we are running on. If yes, create a matching sensor object and put it
756 * the list of available sensor for the core.
757 */
697static void 758static void
698eeze_sensor_tizen_sensors_find(void) 759eeze_sensor_tizen_sensors_find(void)
699{ 760{
@@ -713,6 +774,7 @@ eeze_sensor_tizen_sensors_find(void)
713 } 774 }
714} 775}
715 776
777/* Cleanup when getting the shutdown callback from core */
716Eina_Bool 778Eina_Bool
717eeze_sensor_tizen_shutdown(void) 779eeze_sensor_tizen_shutdown(void)
718{ 780{
@@ -729,10 +791,12 @@ eeze_sensor_tizen_shutdown(void)
729 ERR("Failing to destroy sensor handle."); 791 ERR("Failing to destroy sensor handle.");
730 return EINA_FALSE; 792 return EINA_FALSE;
731 } 793 }
732
733 return EINA_TRUE; 794 return EINA_TRUE;
734} 795}
735 796
797/* Callback from core once we registered as a module. Create the Tizen sensor
798 * handle and find all available sensors.
799 */
736Eina_Bool 800Eina_Bool
737eeze_sensor_tizen_init(void) 801eeze_sensor_tizen_init(void)
738{ 802{
@@ -754,6 +818,10 @@ eeze_sensor_tizen_init(void)
754 return EINA_TRUE; 818 return EINA_TRUE;
755} 819}
756 820
821/* This function gets called when the module is loaded from the disk. Its the
822 * entry point to anything in this module. After setting ourself up we register
823 * into the core of eeze sensor to make our functionality available.
824 */
757Eina_Bool 825Eina_Bool
758sensor_tizen_init(void) 826sensor_tizen_init(void)
759{ 827{
@@ -774,10 +842,12 @@ sensor_tizen_init(void)
774 ERR("Failed to register tizen module"); 842 ERR("Failed to register tizen module");
775 return EINA_FALSE; 843 return EINA_FALSE;
776 } 844 }
777
778 return EINA_TRUE; 845 return EINA_TRUE;
779} 846}
780 847
848/* Cleanup when the module gets unloaded. Unregister ourself from the core to
849 * avoid calls into a not loaded module.
850 */
781void 851void
782sensor_tizen_shutdown(void) 852sensor_tizen_shutdown(void)
783{ 853{