summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaël Bouchaud (yoz) <yoz@efl.so>2016-09-03 19:49:35 +0200
committerMichaël Bouchaud (yoz) <yoz@efl.so>2016-09-05 03:39:46 +0200
commita128042fce1b85c9540ecc6a4b47babc71e75a1d (patch)
treeba8ef3aa40df39b067163671b93406cabfb3ad4a
parente94857af3a4f81b3b3edd00595217d2dae68639d (diff)
Imfos: In the end I will not keep this name. The project became bigger.devs/yoz/imfos
Now the modules take a new turn. The new goal of this module is to track human activity and environments.
-rwxr-xr-xsrc/modules/Makefile_imfos.mk14
-rwxr-xr-xsrc/modules/imfos/e_mod_config.c176
-rwxr-xr-xsrc/modules/imfos/e_mod_main.c96
-rwxr-xr-xsrc/modules/imfos/e_mod_main.h15
-rw-r--r--src/modules/imfos/imfos_devices.c290
-rw-r--r--src/modules/imfos/imfos_devices.h60
-rwxr-xr-xsrc/modules/imfos/imfos_v4l.c169
-rwxr-xr-xsrc/modules/imfos/imfos_v4l.h10
8 files changed, 701 insertions, 129 deletions
diff --git a/src/modules/Makefile_imfos.mk b/src/modules/Makefile_imfos.mk
index afa8b538f..4388fd285 100755
--- a/src/modules/Makefile_imfos.mk
+++ b/src/modules/Makefile_imfos.mk
@@ -11,12 +11,14 @@ src_modules_imfos_module_la_LIBADD = $(MOD_LIBS) @IMFOS_LIBS@
11src_modules_imfos_module_la_CPPFLAGS = $(MOD_CPPFLAGS) @IMFOS_CFLAGS@ 11src_modules_imfos_module_la_CPPFLAGS = $(MOD_CPPFLAGS) @IMFOS_CFLAGS@
12src_modules_imfos_module_la_LDFLAGS = $(MOD_LDFLAGS) 12src_modules_imfos_module_la_LDFLAGS = $(MOD_LDFLAGS)
13src_modules_imfos_module_la_SOURCES = src/modules/imfos/e_mod_main.h \ 13src_modules_imfos_module_la_SOURCES = src/modules/imfos/e_mod_main.h \
14 src/modules/imfos/e_mod_main.c \ 14 src/modules/imfos/e_mod_main.c \
15 src/modules/imfos/e_mod_config.c \ 15 src/modules/imfos/e_mod_config.c \
16 src/modules/imfos/imfos_v4l.c \ 16 src/modules/imfos/imfos_devices.c \
17 src/modules/imfos/imfos_v4l.h \ 17 src/modules/imfos/imfos_devices.h \
18 src/modules/imfos/imfos_face.cpp \ 18 src/modules/imfos/imfos_v4l.c \
19 src/modules/imfos/imfos_face.h 19 src/modules/imfos/imfos_v4l.h \
20 src/modules/imfos/imfos_face.cpp \
21 src/modules/imfos/imfos_face.h
20 22
21PHONIES += imfos install-imfos 23PHONIES += imfos install-imfos
22imfos: $(imfospkg_LTLIBRARIES) $(imfos_DATA) 24imfos: $(imfospkg_LTLIBRARIES) $(imfos_DATA)
diff --git a/src/modules/imfos/e_mod_config.c b/src/modules/imfos/e_mod_config.c
index dfd4a4146..00bf04def 100755
--- a/src/modules/imfos/e_mod_config.c
+++ b/src/modules/imfos/e_mod_config.c
@@ -1,14 +1,27 @@
1#include <e.h> 1#include <e.h>
2#include <Eeze.h>
2#include "e_mod_main.h" 3#include "e_mod_main.h"
4#include "imfos_devices.h"
3 5
6typedef struct _Imfos_Config_Panel
7{
8 Evas_Object *main;
9 Evas_Object *current;
10 Imfos_Device *dev;
11 Imfos_Device *config;
12
13} Imfos_Config_Panel;
14
15static void _v4l_create(void);
16static void _device_create(void);
4static void *_create_data(E_Config_Dialog *cfd); 17static void *_create_data(E_Config_Dialog *cfd);
5static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); 18static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
6static void _fill_data(E_Config_Dialog_Data *cfdata); 19static void _fill_data(E_Config_Dialog_Data *cfdata);
7static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata); 20static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
8static int _apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); 21static int _apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
9 22
10Imfos_Config *imfos_config = NULL; 23Imfos_Config_Panel *_tmp_cfg = NULL;
11 24static Evas_Object *_imfos_cam_widget = NULL;
12int flipped = EINA_FALSE; 25int flipped = EINA_FALSE;
13 26
14 27
@@ -39,12 +52,17 @@ e_mod_config_imfos(Evas_Object *parent, const char *params EINA_UNUSED)
39static void * 52static void *
40_create_data(E_Config_Dialog *cfd) 53_create_data(E_Config_Dialog *cfd)
41{ 54{
55 _tmp_cfg = calloc(1, sizeof(Imfos_Config_Panel));
42 return NULL; 56 return NULL;
43} 57}
44 58
45static void 59static void
46_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) 60_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
47{ 61{
62 free(_tmp_cfg->config);
63 free(_tmp_cfg);
64 _tmp_cfg = NULL;
65 _imfos_cam_widget = NULL;
48} 66}
49 67
50static void 68static void
@@ -52,18 +70,162 @@ _fill_data(E_Config_Dialog_Data *cfdata)
52{ 70{
53} 71}
54 72
55static Evas_Object * 73static void
56_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) 74_imfos_device_changed(void *data)
75{
76 Imfos_Device *dev;
77
78 dev = data;
79 if (_tmp_cfg->dev)
80 imfos_devices_cancel(_tmp_cfg->dev);
81 _tmp_cfg->dev = dev;
82 _tmp_cfg->config = malloc(sizeof(Imfos_Device));
83 /* Warning just a copy ! */
84 memcpy(_tmp_cfg->config, dev, sizeof(Imfos_Device));
85 if (_tmp_cfg->current)
86 evas_object_del(_tmp_cfg->current);
87 _tmp_cfg->current = e_widget_list_add(evas_object_evas_get(_tmp_cfg->main), 0, 0);
88 e_widget_list_object_append(_tmp_cfg->main, _tmp_cfg->current, 1, 0, 0.5);
89 _device_create();
90 printf ("sel %s\n", dev->name);
91
92}
93
94static void
95_imfos_cam_widget_delete(void *data, Evas *evas, Evas_Object *obj, void *event_info)
57{ 96{
58 Evas_Object *list, *o; 97 Imfos_Device *dev;
98
99 dev = data;
100 printf("deleting cam widget\n");
101
102 dev->param.v4l.cam = NULL;
103 imfos_devices_cancel(dev);
104}
105
106static void
107_fill_devices(Evas *evas, Evas_Object *list)
108{
109 const Eina_List *devices, *l;
110 Imfos_Device *dev;
111 char buf[1024];
112 Evas_Object *o;
113
114 EINA_LIST_FOREACH(imfos_config->devices, l, dev)
115 {
116 snprintf(buf, sizeof(buf), "%s(%s)", dev->name, dev->dev_name);
117 e_widget_ilist_append(list, NULL, buf, _imfos_device_changed, dev, NULL);
118 printf("dev %s(%s)\n", dev->name, dev->dev_name);
119 }
120 e_widget_ilist_selected_set(list, 1);
121 _imfos_device_changed(eina_list_data_get(imfos_config->devices));
122}
123
124static void
125_v4l_create(void)
126{
127 Evas_Object *o;
128 Evas *evas;
129 Evas_Object *list;
130
131
132 list = _tmp_cfg->current;
133 evas = evas_object_evas_get(_tmp_cfg->current);
59 134
60 list = e_widget_list_add(evas, 0, 0); 135 printf("V4l panel\n");
136 o = evas_object_image_filled_add(evas);
137 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
138 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
139 evas_object_size_hint_min_set(o, 320, 240);
140 e_widget_list_object_append(list, o, 1, 1, 0.5);
141 _tmp_cfg->dev->param.v4l.cam = o;
142// if (_tmp_cfg->config->enabled)
143// imfos_devices_run(_tmp_cfg->dev);
144 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL, _imfos_cam_widget_delete, _tmp_cfg->dev);
61 145
62 o = e_widget_check_add(evas, "Flip camera", &flipped); 146 o = e_widget_check_add(evas, "Flip camera", &flipped);
147 e_widget_list_object_append(list, o, 1, 0, 0.5);
148
149 o = e_widget_check_add(evas, "Set as the fallback", &flipped);
150 e_widget_list_object_append(list, o, 1, 0, 0.5);
151}
63 152
153static void
154_device_create(void)
155{
156 Evas_Object *o;
157 Evas *evas;
158 Evas_Object *list;
159 char buf[4096];
160
161 list = _tmp_cfg->current;
162 evas = evas_object_evas_get(_tmp_cfg->current);
163
164 printf("Device Create\n");
165 o = e_widget_check_add(evas, "Enabled",
166 (int *)&_tmp_cfg->config->enabled);
167 e_widget_list_object_append(list, o, 1, 0, 0.0);
168 snprintf(buf, sizeof(buf), "Name : %s", _tmp_cfg->config->name);
169 o = e_widget_label_add(evas, buf);
170 e_widget_list_object_append(list, o, 1, 0, 0.0);
171 snprintf(buf, sizeof(buf), "System path : %s", _tmp_cfg->config->syspath);
172 o = e_widget_label_add(evas, buf);
173 e_widget_list_object_append(list, o, 1, 0, 0.0);
174 snprintf(buf, sizeof(buf), "Device path : %s", _tmp_cfg->config->dev_name);
175 o = e_widget_label_add(evas, buf);
176 e_widget_list_object_append(list, o, 1, 0, 0.0);
177 o = e_widget_check_add(evas, "Lock the device path",
178 (int *)&_tmp_cfg->config->dev_name_locked);
179 e_widget_list_object_append(list, o, 1, 0, 0.0);
180 _v4l_create();
181 o = e_widget_slider_add(evas, 1, 0, "Priority : %d", -100.0, 100.0, 5.0, 50,
182 NULL, &_tmp_cfg->config->priority, 110);
183 e_widget_list_object_append(list, o, 1, 0, 0.5);
184 o = e_widget_check_add(evas, "async", (int *)&_tmp_cfg->config->async);
185 e_widget_list_object_append(list, o, 1, 0, 0.5);
186 o = e_widget_check_add(evas, "Timeout", (int *)&_tmp_cfg->config->timeout_enabled);
187 e_widget_list_object_append(list, o, 1, 0, 0.5);
188 o = e_widget_slider_add(evas, 1, 0, "Timeout (%2.0f)", 0.0, 64580.0, 5.0, 0,
189 NULL, &_tmp_cfg->config->timeout, 110);
190 e_widget_list_object_append(list, o, 1, 0, 0.5);
191// o = e_widget_radio_group_new((int*) &(_tmp_cfg->config->powersave_min_state));
192// e_widget_list_object_append(list, o, 1, 0, 0.5);
193 o = e_widget_check_add(evas, "Force the login when detected",
194 (int*)&_tmp_cfg->config->auto_login);
195 e_widget_list_object_append(list, o, 1, 0, 0.5);
196 o = e_widget_check_add(evas, "Force the logoff when missmatch",
197 (int*)&_tmp_cfg->config->auto_logout);
198 e_widget_list_object_append(list, o, 1, 0, 0.5);
199 o = e_widget_check_add(evas, "Report the screensaver when detected",
200 (int*)&_tmp_cfg->config->auto_screen_on);
64 e_widget_list_object_append(list, o, 1, 0, 0.5); 201 e_widget_list_object_append(list, o, 1, 0, 0.5);
202 o = e_widget_check_add(evas, "Enable the screensaver when missmatch",
203 (int*)&_tmp_cfg->config->auto_screen_off);
204 e_widget_list_object_append(list, o, 1, 0, 0.5);
205
206
207 /*
208 powersave_min_state
209 */
210
211}
212
213
214static Evas_Object *
215_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
216{
217 Evas_Object *list, *list_cam, *devices_list, *o;
218
219 _tmp_cfg->main = e_widget_list_add(evas, 0, 1);
220
221 o = e_widget_ilist_add(evas, 0, 0, NULL);
222 e_widget_ilist_multi_select_set(o, EINA_FALSE);
223 evas_object_size_hint_min_set(o, 160, 240);
224 e_widget_list_object_append(_tmp_cfg->main, o, 1, 0, 0.5);
225 evas_object_show(o);
65 226
66 return list; 227 _fill_devices(evas, o);
228 return _tmp_cfg->main;
67} 229}
68 230
69static int 231static int
diff --git a/src/modules/imfos/e_mod_main.c b/src/modules/imfos/e_mod_main.c
index 18749707d..fdfba1cdd 100755
--- a/src/modules/imfos/e_mod_main.c
+++ b/src/modules/imfos/e_mod_main.c
@@ -1,61 +1,113 @@
1#include <e.h>
2#include "e_mod_main.h" 1#include "e_mod_main.h"
3#include "e_mod_config.h" 2#include "e_mod_config.h"
4#include "imfos_v4l.h" 3#include "imfos_v4l.h"
4#include "imfos_devices.h"
5 5
6#define IMFOS_TIMEOUT 10 6#define IMFOS_TIMEOUT 10
7 7
8static E_Config_DD *_imfos_conf = NULL; 8static E_Config_DD *_conf_edd = NULL;
9static E_Config_DD *_conf_edd_device = NULL;
10static Ecore_Timer *_imfos_timer = NULL;
9 11
10static Imfos_Config *_imfos_config = NULL; 12Imfos_Config *imfos_config = NULL;
11static E_Config_DD *_imfos_config_edd = NULL; 13static E_Config_DD *imfos_config_edd = NULL;
12 14
13EAPI E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Imfos" }; 15EAPI E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Imfos" };
14 16
15static void _e_mod_imfos(void); 17static void _e_mod_imfos(void);
18static Eina_Bool _run(void *);
16 19
17static Eina_Bool 20static Eina_Bool
18_run(void *data EINA_UNUSED) 21_run(void *data EINA_UNUSED)
19{ 22{
20 _e_mod_imfos(); 23// imfos_v4l_run(imfos_config);
21}
22
23static void
24_e_mod_imfos(void)
25{
26 Imfos_V4l_Conf *conf;
27
28 conf = calloc(1, sizeof(Imfos_V4l_Conf));
29 conf->timeout = IMFOS_TIMEOUT;
30 imfos_v4l_run(conf);
31} 24}
32 25
33EAPI void * 26EAPI void *
34e_modapi_init(E_Module *m) 27e_modapi_init(E_Module *m)
35{ 28{
36 printf("Loading ...\n"); 29 printf("Loading ...\n");
30 _conf_edd = E_CONFIG_DD_NEW("Config", Imfos_Config);
31 _conf_edd_device = E_CONFIG_DD_NEW("Device", Imfos_Device);
32#undef T
33#undef D
34#define T Imfos_Device
35#define D _conf_edd_device
36 E_CONFIG_VAL(D, T, enabled, INT);
37 E_CONFIG_VAL(D, T, name, STR);
38 E_CONFIG_VAL(D, T, dev_name, STR);
39 E_CONFIG_VAL(D, T, dev_name_locked, INT);
40 E_CONFIG_VAL(D, T, capacities, INT);
41 E_CONFIG_VAL(D, T, powersave_min_state, INT);
42 E_CONFIG_VAL(D, T, priority, INT);
43 E_CONFIG_VAL(D, T, async, INT);
44 E_CONFIG_VAL(D, T, timeout, INT);
45 E_CONFIG_VAL(D, T, auto_screen_on, INT);
46 E_CONFIG_VAL(D, T, auto_screen_off, INT);
47 E_CONFIG_VAL(D, T, auto_logout, INT);
48 E_CONFIG_VAL(D, T, auto_login, INT);
49 E_CONFIG_VAL(D, T, catch_time_average, INT);
50 E_CONFIG_VAL(D, T, catch_count, INT);
51 E_CONFIG_VAL(D, T, param.v4l.flip, INT);
52 E_CONFIG_VAL(D, T, param.v4l.init_time_average, INT);
53 E_CONFIG_VAL(D, T, param.wifi.ssid, STR);
54 E_CONFIG_VAL(D, T, param.bluetooth.id, STR);
55#undef T
56#undef D
57#define T Imfos_Config
58#define D _conf_edd
59 E_CONFIG_VAL(D, T, config_version, UINT);
60 E_CONFIG_LIST(D, T, devices, _conf_edd_device);
61 imfos_config = e_config_domain_load("module.imfos", _conf_edd);
62 if ((!imfos_config)
63 || (imfos_config->config_version != IMFOS_CONFIG_VERSION))
64 E_FREE(imfos_config);
65 if (!imfos_config)
66 {
67 imfos_config = calloc(1, sizeof(Imfos_Config));
68 imfos_config->config_version = IMFOS_CONFIG_VERSION;
69 }
70 /*
71 E_CONFIG_LIMIT(imfos_config->poll_interval, 1, 3600);
72 E_CONFIG_LIMIT(imfos_config->poll_interval_max, 1, 3600);
73 E_CONFIG_LIMIT(imfos_config->poll_interval_powersave, 1, 3600);
74 */
75 imfos_devices_init();
37 imfos_v4l_init(); 76 imfos_v4l_init();
38 77
39 _imfos_config_edd = E_CONFIG_DD_NEW("Config", Imfos_Config); 78
40 E_CONFIG_VAL(_imfos_config_edd, Imfos_Config, orient, INT); 79 e_configure_registry_category_add("advanced", 80, _("Advanced"), NULL,
41 e_configure_registry_category_add("advanced", 80, _("Advanced"), NULL, "preferences-advanced"); 80 "preferences-advanced");
42 e_configure_registry_item_add("advanced/imfos", 20, "Imfos", NULL, "preference-imfos", e_mod_config_imfos); 81 e_configure_registry_item_add("advanced/imfos", 20, "Imfos", NULL,
43 ecore_timer_add(50.0, _run, NULL); 82 "preference-imfos", e_mod_config_imfos);
83 e_config_domain_save("module.imfos", _conf_edd, imfos_config);
84
85// _imfos_timer = ecore_timer_add(50.0, _run, NULL);
86
44 return m; 87 return m;
45} 88}
46 89
47EAPI int 90EAPI int
48e_modapi_shutdown(E_Module *m EINA_UNUSED) 91e_modapi_shutdown(E_Module *m EINA_UNUSED)
49{ 92{
50 E_CONFIG_DD_FREE(_imfos_config_edd); 93 e_configure_registry_item_del("advanced/imfos");
51 free(_imfos_config); 94 e_configure_registry_category_del("advanced");
95
96 ecore_timer_del(_imfos_timer);
97
98 E_CONFIG_DD_FREE(_conf_edd);
99 E_CONFIG_DD_FREE(_conf_edd_device);
100 free(imfos_config);
52 imfos_v4l_shutdown(); 101 imfos_v4l_shutdown();
102 imfos_devices_shutdown();
103
53 return 1; 104 return 1;
54} 105}
55 106
56EAPI int 107EAPI int
57e_modapi_save(E_Module *m EINA_UNUSED) 108e_modapi_save(E_Module *m EINA_UNUSED)
58{ 109{
110 e_config_domain_save("module.imfos", _conf_edd, imfos_config);
59 return 1; 111 return 1;
60} 112}
61 113
diff --git a/src/modules/imfos/e_mod_main.h b/src/modules/imfos/e_mod_main.h
index a673b4001..2bcc75cbf 100755
--- a/src/modules/imfos/e_mod_main.h
+++ b/src/modules/imfos/e_mod_main.h
@@ -1,6 +1,11 @@
1#ifndef _E_MOD_MAIN_H 1#ifndef _E_MOD_MAIN_H
2#define _E_MOD_MAIN_H 2#define _E_MOD_MAIN_H
3 3
4#include <e.h>
5#include "imfos_devices.h"
6
7#define IMFOS_CONFIG_VERSION 1
8
4#ifdef _cplusplus 9#ifdef _cplusplus
5extern "C++" 10extern "C++"
6#endif 11#endif
@@ -22,13 +27,9 @@ typedef enum _Imfos_Orient Imfos_Orient;
22 27
23struct _Imfos_Config 28struct _Imfos_Config
24{ 29{
25 Imfos_Orient orient; 30 unsigned int config_version;
26 //E_Config_Dialog *cfd; 31 Eina_List *devices;
27}; 32 E_Config_Dialog *cfd;
28
29struct _Config_Item {
30 Imfos_Orient orient;
31 const char *path;
32}; 33};
33 34
34extern Imfos_Config *imfos_config; 35extern Imfos_Config *imfos_config;
diff --git a/src/modules/imfos/imfos_devices.c b/src/modules/imfos/imfos_devices.c
new file mode 100644
index 000000000..5f7b46052
--- /dev/null
+++ b/src/modules/imfos/imfos_devices.c
@@ -0,0 +1,290 @@
1#include "e_mod_main.h"
2#include "imfos_devices.h"
3#include "imfos_v4l.h"
4#include <Eeze.h>
5
6static Imfos_Device *_imfos_devices_add(const char *syspath, int type);
7static void _imfos_devices_del(Imfos_Device *dev);
8static void _imfos_devices_eeze_events(const char *syspath, Eeze_Udev_Event ev, void *data, Eeze_Udev_Watch *watch);
9
10static Eina_List *_delayed_jobs = NULL;
11static Eeze_Udev_Watch *_eeze_watcher = NULL;
12
13
14static Imfos_Device *
15_imfos_devices_new(const char *syspath)
16{
17 Imfos_Device *dev;
18
19 dev = calloc(1, sizeof(Imfos_Device));
20 dev->syspath = eina_stringshare_ref(syspath);
21 dev->name = eeze_udev_syspath_get_sysattr(syspath, "name");
22 dev->dev_name = eeze_udev_syspath_get_property(syspath, "DEVNAME");
23 printf("New device %s(%s)\n", dev->name, dev->dev_name);
24 return dev;
25}
26
27
28static void
29_imfos_devices_del(Imfos_Device *dev)
30{
31 eina_stringshare_del(dev->syspath);
32 eina_stringshare_del(dev->name);
33 eina_stringshare_del(dev->dev_name);
34 free(dev);
35}
36
37static Eina_Bool
38_imfos_devices_check_capabilities(const char *syspath, const char *dev_name)
39{
40 /* TODO check capacities */
41 return EINA_TRUE;
42}
43
44static Imfos_Device *
45_imfos_devices_add(const char *syspath, int type)
46{
47 Eina_List *l;
48 Imfos_Device *dev;
49 const char *name;
50 const char *dev_name;
51
52 name = eeze_udev_syspath_get_sysattr(syspath, "name");
53 dev_name = eeze_udev_syspath_get_property(syspath, "DEVNAME");
54 printf("New device %s(%s) know(%d)\n", name, dev_name, eina_list_count(imfos_config->devices));
55
56 EINA_LIST_FOREACH(imfos_config->devices, l, dev)
57 {
58 if (dev->name == name)
59 {
60 printf("Found by name %s\n");
61 break;
62 }
63 }
64 if (dev)
65 {
66 printf("Updating device %s\n", name);
67 dev->syspath = eina_stringshare_ref(syspath);
68 dev->dev_name = dev_name;
69 dev->type = type;
70 eina_stringshare_del(name);
71 }
72 else
73 {
74 if (_imfos_devices_check_capabilities(syspath, dev_name))
75 {
76 printf("First time\n");
77 dev = calloc(1, sizeof(Imfos_Device));
78 dev->syspath = eina_stringshare_ref(syspath);
79 dev->name = name;
80 dev->type = type;
81 dev->dev_name = dev_name;
82 imfos_config->devices =
83 eina_list_append(imfos_config->devices, dev);
84 }
85 else
86 {
87 eina_stringshare_del(name);
88 eina_stringshare_del(dev_name);
89 }
90 }
91 return dev;
92}
93
94static void
95_imfos_device_remove(Imfos_Device *dev)
96{
97 eina_stringshare_del(dev->syspath);
98 dev->syspath = NULL;
99 if (!dev->dev_name_locked)
100 {
101 eina_stringshare_del(dev->dev_name);
102 dev->dev_name = NULL;
103 }
104 if (dev->thread) ecore_thread_cancel(dev->thread);
105}
106
107static void
108_imfos_devices_eeze_events(const char *syspath, Eeze_Udev_Event ev,
109 void *data EINA_UNUSED,
110 Eeze_Udev_Watch *watch EINA_UNUSED)
111{
112 Imfos_Device *dev;
113 Eina_List *l;
114
115 if (ev == EEZE_UDEV_EVENT_ADD)
116 {
117 dev = _imfos_devices_add(syspath, EEZE_UDEV_TYPE_V4L);
118 }
119 else if (ev == EEZE_UDEV_EVENT_REMOVE)
120 {
121 EINA_LIST_FOREACH(imfos_config->devices, l, dev)
122 {
123 if (dev->syspath == syspath)
124 {
125 _imfos_device_remove(dev);
126 break;
127 }
128 }
129 }
130}
131
132
133void
134imfos_devices_init(void)
135{
136 Eina_List *devices;
137 const char *syspath;
138
139 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL);
140 EINA_LIST_FREE(devices, syspath)
141 {
142 _imfos_devices_add(syspath, EEZE_UDEV_TYPE_V4L);
143 eina_stringshare_del(syspath);
144 }
145 /*
146 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_KEYBOARD, NULL);
147 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_MOUSE, NULL);
148 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NET, NULL);
149 */
150 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_BLUETOOTH, NULL);
151 EINA_LIST_FREE(devices, syspath)
152 {
153 _imfos_devices_add(syspath, EEZE_UDEV_TYPE_BLUETOOTH);
154 eina_stringshare_del(syspath);
155 }
156 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL);
157 EINA_LIST_FREE(devices, syspath)
158 {
159 _imfos_devices_add(syspath, EEZE_UDEV_TYPE_DRIVE_REMOVABLE);
160 eina_stringshare_del(syspath);
161 }
162
163 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL);
164 _eeze_watcher = eeze_udev_watch_add(EEZE_UDEV_TYPE_V4L,
165 (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE),
166 _imfos_devices_eeze_events, NULL);
167}
168
169void
170imfos_devices_shutdown(void)
171{
172 Imfos_Device *dev;
173 eeze_udev_watch_del(_eeze_watcher);
174}
175
176
177Eina_Bool
178imfos_devices_timeout(Imfos_Device *dev)
179{
180 double loop_time;
181
182 if (dev->timeout > 0)
183 {
184 loop_time = ecore_time_get() - dev->time_start;
185 if (loop_time > dev->timeout)
186 {
187 printf("timeout\n");
188 return EINA_TRUE;
189 }
190 }
191
192 return ecore_thread_check(dev->thread);
193}
194
195static void
196_imfos_devices_thread_run(void *data, Ecore_Thread *thread)
197{
198 Imfos_Device *dev;
199
200 dev = data;
201
202 dev->catched = EINA_FALSE;
203 dev->time_start = ecore_time_get();
204 imfos_v4l_run(dev);
205
206}
207
208static void
209_imfos_device_run(void)
210{
211 Eina_List *l;
212 Imfos_Device *dev;
213
214 EINA_LIST_FOREACH(_delayed_jobs, l, dev)
215 {
216 if (!dev->thread)
217 {
218 imfos_devices_run(dev);
219 _delayed_jobs = eina_list_remove_list(_delayed_jobs, l);
220 break;
221 }
222 }
223}
224
225
226static void
227_imfos_devices_thread_clean(void *data, Ecore_Thread *thread)
228{
229 Imfos_Device *dev;
230 double catch_time;
231
232 dev = data;
233
234 printf("Imfos thread End\n");
235 if (dev->catched)
236 {
237 catch_time = dev->time_start - ecore_time_get();
238 dev->catch_time_average =
239 ((dev->catch_time_average * dev->catch_count) + catch_time)
240 / (dev->catch_count + 1);
241 ++dev->catch_count;
242 }
243
244 imfos_v4l_clean(dev);
245 dev->thread = NULL;
246
247 _imfos_device_run();
248}
249
250
251
252static void
253_imfos_devices_thread_cancel(void *data, Ecore_Thread *thread)
254{
255 printf("Imfos thread cancel\n");
256}
257
258Eina_Bool
259imfos_devices_run(Imfos_Device *dev)
260{
261 Ecore_Thread *thread;
262
263
264 if (dev->thread)
265 {
266 ecore_thread_cancel(dev->thread);
267 if (!dev->async)
268 {
269 _delayed_jobs = eina_list_append(_delayed_jobs, dev);
270 return EINA_TRUE;
271 }
272 }
273 dev->thread = ecore_thread_run(_imfos_devices_thread_run,
274 _imfos_devices_thread_clean,
275 _imfos_devices_thread_clean,
276 dev);
277
278 return EINA_FALSE;
279}
280
281Eina_Bool
282imfos_devices_cancel(Imfos_Device *dev)
283{
284 if (dev->thread)
285 {
286 ecore_thread_cancel(dev->thread);
287 return EINA_TRUE;
288 }
289 return EINA_FALSE;
290}
diff --git a/src/modules/imfos/imfos_devices.h b/src/modules/imfos/imfos_devices.h
new file mode 100644
index 000000000..6fe524de8
--- /dev/null
+++ b/src/modules/imfos/imfos_devices.h
@@ -0,0 +1,60 @@
1#ifndef IMFOS_DEVICES_H_
2#define IMFOS_DEVICES_H_
3
4#include <e.h>
5
6typedef struct _Imfos_Device
7{
8 const char *syspath;
9 const char *name;
10 const char *dev_name;
11 int type;
12 Ecore_Thread *thread;
13 int capacities;
14 int poll_interval;
15 int powersave_min_state;
16 int priority;
17 int timeout;
18 double time_start;
19 double last_catch;
20 int catch_count;
21 int catch_time_average;
22 Eina_Bool init_time_fixed;
23 Eina_Bool catched;
24 Eina_Bool async;
25 Eina_Bool auto_screen_on;
26 Eina_Bool auto_screen_off;
27 Eina_Bool auto_logout;
28 Eina_Bool auto_login;
29 Eina_Bool timeout_enabled;
30 Eina_Bool found;
31 Eina_Bool enabled;
32 Eina_Bool dev_name_locked;
33 struct
34 {
35 struct
36 {
37 Evas_Object *cam;
38 Eina_Bool flip;
39 int init_time;
40 int init_time_average;
41 } v4l;
42 struct
43 {
44 const char *ssid;
45 } wifi;
46 struct
47 {
48 const char *id;
49 } bluetooth;
50 } param;
51} Imfos_Device;
52
53void imfos_devices_init(void);
54void imfos_devices_shutdown(void);
55Eina_Bool imfos_devices_run(Imfos_Device *dev);
56Eina_Bool imfos_devices_cancel(Imfos_Device *dev);
57Eina_Bool imfos_devices_timeout(Imfos_Device *dev);
58
59
60#endif /* IMFOS_DEVICES_H_ */
diff --git a/src/modules/imfos/imfos_v4l.c b/src/modules/imfos/imfos_v4l.c
index e53e1f814..6a63b516a 100755
--- a/src/modules/imfos/imfos_v4l.c
+++ b/src/modules/imfos/imfos_v4l.c
@@ -10,26 +10,30 @@
10#include <linux/videodev2.h> 10#include <linux/videodev2.h>
11#include <libv4l2.h> 11#include <libv4l2.h>
12 12
13#include <Eeze.h>
14#include <e.h>
15#include "e_mod_main.h"
16
13#include <Ecore.h> 17#include <Ecore.h>
14#include <Evas.h> 18#include <Evas.h>
15#include "imfos_v4l.h" 19#include "imfos_v4l.h"
16#include "imfos_face.h" 20//#include "imfos_face.h"
17#include <e.h> 21#include <e.h>
18 22
19#define CLEAR(x) memset(&(x), 0, sizeof(x)) 23#define CLEAR(x) memset(&(x), 0, sizeof(x))
20 24
21static int _imfos_xioctl(int fh, int request, void *arg); 25static int _imfos_xioctl(int fh, int request, void *arg);
26static Eina_Bool _imfos_v4l_image_transform(Evas_Object *cam, void *data, size_t size);
22static void _imfos_v4l_takeshot(void *data, Ecore_Thread *thread); 27static void _imfos_v4l_takeshot(void *data, Ecore_Thread *thread);
23static void _imfos_v4l_end(void *data, Ecore_Thread *thread); 28static void _imfos_v4l_end(void *data, Ecore_Thread *thread);
24static void _imfos_v4l_cancel(void *data, Ecore_Thread *thread); 29static void _imfos_v4l_cancel(void *data, Ecore_Thread *thread);
25 30
26static const char *_imfos_v4l_path = NULL; 31static Ecore_Animator *_imfos_v4l_anim = NULL;
27static Ecore_Thread *_imfos_v4l_thread = NULL;
28 32
29static int _width; 33static int _width;
30static int _height; 34static int _height;
31static int _size; 35static int _size;
32//static void *_img = NULL; 36static void *_img = NULL;
33static void *_img_y = NULL; 37static void *_img_y = NULL;
34static int _2126[256]; 38static int _2126[256];
35static int _7152[256]; 39static int _7152[256];
@@ -60,44 +64,72 @@ _imfos_xioctl(int fh, int request, void *arg)
60} 64}
61 65
62static Eina_Bool 66static Eina_Bool
63_imfos_v4l_image_transform(void *data, size_t size) 67_imfos_v4l_frame_anim(void *data)
68{
69 _imfos_v4l_anim = NULL;
70 evas_object_image_pixels_dirty_set(data, 1);
71 return EINA_FALSE;
72}
73
74static Eina_Bool
75_imfos_v4l_image_transform(Evas_Object *cam, void *data, size_t size)
64{ 76{
65 unsigned char *b, *cb, *cyb; 77 unsigned char *b, *cb, *cyb;
66 size_t i; 78 size_t i;
67 unsigned int percent; 79 unsigned int percent;
68 80
69 percent = 0; 81 percent = 0;
70 /* 82 if (cam)
71 if (!_img) 83 {
72 _img = malloc(_width * _height * 4); 84 if (!_img)
73 */ 85 {
74 if (!_img_y) 86 evas_object_image_pixels_get_callback_set(cam, NULL, NULL);
87 evas_object_image_alpha_set(cam, 0);
88
89 evas_object_image_colorspace_set(cam, EVAS_COLORSPACE_ARGB8888);
90 evas_object_image_size_set(cam, _width, _height);
91 _img = evas_object_image_data_get(cam, 1);
92 }
93 }
94
95 if (!_img_y)
75 _img_y = malloc(_width * _height); 96 _img_y = malloc(_width * _height);
76 b = data; 97 b = data;
77// cb = _img; 98 cb = _img;
78 cyb = _img_y; 99 cyb = _img_y;
79 100
80 for (i = 0; i < size; i += 3) 101 for (i = 0; i < size; i += 3)
81 { 102 {
82 /*
83 cb[3] = 255;
84 cb[2] = b[0];
85 cb[1] = b[1];
86 cb[0] = b[2];
87 */
88 *cyb = (char)((_2126[b[2]] + _7152[b[1]] + _0722[b[0]]) >> 8); 103 *cyb = (char)((_2126[b[2]] + _7152[b[1]] + _0722[b[0]]) >> 8);
89 if (*cyb > 16) 104 if (*cyb > 16)
90 ++percent; 105 ++percent;
91 //cb += 4; 106 if (cam)
107 {
108 cb[3] = 255;
109 cb[2] = b[0];
110 cb[1] = b[1];
111 cb[0] = b[2];
112 cb += 4;
113 }
92 b += 3; 114 b += 3;
93 cyb += 1; 115 cyb += 1;
94 } 116 }
95 printf("percent %d%%\n", (percent * 100)/ (_width * _height)); 117
118 if (cam)
119 {
120 if (!_imfos_v4l_anim)
121 _imfos_v4l_anim = ecore_animator_add(_imfos_v4l_frame_anim, cam);
122 evas_object_image_data_set(cam, _img);
123 evas_object_image_data_update_add(cam, 0, 0, _width, _height);
124 evas_object_image_pixels_dirty_set(cam, 0);
125 }
126
127// printf("percent %d%%\n", (percent * 100)/ (_width * _height));
96 return (percent > (size / 10)); 128 return (percent > (size / 10));
97} 129}
98 130
99static void 131void
100_imfos_v4l_takeshot(void *data, Ecore_Thread *thread) 132imfos_v4l_run(Imfos_Device *conf)
101{ 133{
102 struct v4l2_format fmt; 134 struct v4l2_format fmt;
103 struct v4l2_buffer buf; 135 struct v4l2_buffer buf;
@@ -107,7 +139,6 @@ _imfos_v4l_takeshot(void *data, Ecore_Thread *thread)
107 struct timeval tv; 139 struct timeval tv;
108 int r, fd = -1; 140 int r, fd = -1;
109 unsigned int i, n_buffers; 141 unsigned int i, n_buffers;
110 char *dev_name = "/dev/video0";
111 char out_name[256]; 142 char out_name[256];
112 FILE *fout; 143 FILE *fout;
113 struct buffer *buffers; 144 struct buffer *buffers;
@@ -116,15 +147,11 @@ _imfos_v4l_takeshot(void *data, Ecore_Thread *thread)
116 double loop_time_start; 147 double loop_time_start;
117 double loop_time_cur; 148 double loop_time_cur;
118 double loop_time_avg = 0.0; 149 double loop_time_avg = 0.0;
119 Imfos_V4l_Conf *conf;
120
121 conf = data;
122 time_start = ecore_time_get();
123 150
124 stop = EINA_FALSE; 151 stop = EINA_FALSE;
125 fprintf(stderr, "imfos thread\n"); 152 fprintf(stderr, "imfos thread %s\n", conf->dev_name);
126 153
127 fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0); 154 fd = v4l2_open(conf->dev_name, O_RDWR | O_NONBLOCK, 0);
128 if (fd < 0) { 155 if (fd < 0) {
129 perror("Cannot open device"); 156 perror("Cannot open device");
130 return; 157 return;
@@ -178,6 +205,13 @@ _imfos_v4l_takeshot(void *data, Ecore_Thread *thread)
178 printf("Warning: driver is sending image at %dx%d\n", 205 printf("Warning: driver is sending image at %dx%d\n",
179 fmt.fmt.pix.width, fmt.fmt.pix.height); 206 fmt.fmt.pix.width, fmt.fmt.pix.height);
180 207
208 if (conf->param.v4l.cam)
209 {
210 printf("Sizing object %d %d\n", _width, _height);
211 evas_object_image_colorspace_set(conf->param.v4l.cam, EVAS_COLORSPACE_ARGB8888);
212 evas_object_image_size_set(conf->param.v4l.cam, _width, _height);
213 }
214
181 CLEAR(req); 215 CLEAR(req);
182 req.count = 2; 216 req.count = 2;
183 req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 217 req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -217,7 +251,7 @@ _imfos_v4l_takeshot(void *data, Ecore_Thread *thread)
217 _imfos_xioctl(fd, VIDIOC_STREAMON, &type); 251 _imfos_xioctl(fd, VIDIOC_STREAMON, &type);
218 for (i = 0; ; ++i) { 252 for (i = 0; ; ++i) {
219 loop_time_start = ecore_time_get(); 253 loop_time_start = ecore_time_get();
220 fprintf(stderr, "try %d\n", i); 254 //fprintf(stderr, "try %d\n", i);
221 do { 255 do {
222 FD_ZERO(&fds); 256 FD_ZERO(&fds);
223 FD_SET(fd, &fds); 257 FD_SET(fd, &fds);
@@ -238,40 +272,36 @@ _imfos_v4l_takeshot(void *data, Ecore_Thread *thread)
238 buf.memory = V4L2_MEMORY_MMAP; 272 buf.memory = V4L2_MEMORY_MMAP;
239 _imfos_xioctl(fd, VIDIOC_DQBUF, &buf); 273 _imfos_xioctl(fd, VIDIOC_DQBUF, &buf);
240 274
241
242 /* check image is right */
243 /*
244 _imfos_v4l_image_check(buffers[buf.index].start,
245 buf.bytesused);
246 */
247 _width = fmt.fmt.pix.width; 275 _width = fmt.fmt.pix.width;
248 _height = fmt.fmt.pix.height; 276 _height = fmt.fmt.pix.height;
249 _size = buf.bytesused; 277 _size = buf.bytesused;
250 //_img = buffers[buf.index].start; 278// printf("copy %d %d %d - %d\n", buf.bytesused,
251 printf("copy %d %d %d - %d\n", buf.bytesused, 279// _width * _height * 2, _width, _height);
252 _width * _height * 2, _width, _height);
253 280
254 if (_imfos_v4l_image_transform(buffers[buf.index].start, buf.bytesused)) 281 if (_imfos_v4l_image_transform(conf->param.v4l.cam, buffers[buf.index].start,
282 buf.bytesused))
255 { 283 {
284 /*
256 if (imfos_face_search(_img_y, _width, _height, 0)) 285 if (imfos_face_search(_img_y, _width, _height, 0))
257 { 286 {
258 stop = EINA_TRUE; 287 stop = EINA_TRUE;
259 fprintf(stderr, "Found your fucking head guy\n"); 288 e_screensaver_notidle();
289 fprintf(stderr, "I saw you !\n");
260 } 290 }
291 */
261 } 292 }
262 _imfos_xioctl(fd, VIDIOC_QBUF, &buf); 293 _imfos_xioctl(fd, VIDIOC_QBUF, &buf);
294 /*
263 fprintf(stderr, "imfos %.8f %.8f\n", 295 fprintf(stderr, "imfos %.8f %.8f\n",
264 ecore_time_get() - time_start, 296 ecore_time_get() - time_start,
265 loop_time_avg); 297 loop_time_avg);
298 */
266 if (stop) break; 299 if (stop) break;
267 loop_time_cur = ecore_time_get() - loop_time_start; 300 if (imfos_devices_timeout(conf))
268 if (loop_time_cur > loop_time_avg) 301 break;
269 loop_time_avg = loop_time_cur;
270 if ((ecore_time_get() - time_start + loop_time_avg) > conf->timeout)
271 break;
272 } 302 }
273 if (stop) 303 // if (stop)
274 e_screensaver_notidle(); 304 // e_screensaver_notidle();
275v4l_close: 305v4l_close:
276 type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 306 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
277 _imfos_xioctl(fd, VIDIOC_STREAMOFF, &type); 307 _imfos_xioctl(fd, VIDIOC_STREAMOFF, &type);
@@ -281,30 +311,22 @@ v4l_close:
281 fprintf(stderr, "v4l close %d\n", stop); 311 fprintf(stderr, "v4l close %d\n", stop);
282} 312}
283 313
284static void 314void
285_imfos_v4l_end(void *data, Ecore_Thread *thread) 315imfos_v4l_clean(Imfos_Device *conf)
286{ 316{
287 fprintf(stderr, "v4l end\n"); 317 fprintf(stderr, "v4l end\n");
288 free(data);
289
290 /*
291 if (data) {
292 evas_object_image_colorspace_set(data, EVAS_COLORSPACE_ARGB8888);
293 //evas_object_image_colorspace_set(data, EVAS_COLORSPACE_GRY8);
294 evas_object_image_size_set(data, _width, _height);
295 evas_object_image_data_set(data, _img);
296 //evas_object_image_data_set(data, _img_y);
297 }
298 */
299
300 318
301 /* 319 if (_imfos_v4l_anim)
302 free(_img); 320 ecore_animator_del(_imfos_v4l_anim);
303 _img = NULL; 321 _imfos_v4l_anim = NULL;
304 */ 322 if (conf->param.v4l.cam)
323 {
324 evas_object_image_size_set(conf->param.v4l.cam, 1, 1);
325 evas_object_image_data_set(conf->param.v4l.cam, NULL);
326 }
305 free(_img_y); 327 free(_img_y);
306 _img_y = NULL; 328 _img_y = NULL;
307 _imfos_v4l_thread = NULL; 329 _img = NULL;
308} 330}
309 331
310static void 332static void
@@ -314,13 +336,11 @@ _imfos_v4l_cancel(void *data, Ecore_Thread *thread)
314 336
315} 337}
316 338
317
318void 339void
319imfos_v4l_init(void) 340imfos_v4l_init(void)
320{ 341{
321 unsigned int i; 342 unsigned int i;
322 /* list webcams */ 343
323 _imfos_v4l_path = eina_stringshare_add("/dev/video0");
324 for (i = 0; i < 256; i++) 344 for (i = 0; i < 256; i++)
325 { 345 {
326 _2126[i] = 0.2116 * 256 * i; 346 _2126[i] = 0.2116 * 256 * i;
@@ -332,15 +352,4 @@ imfos_v4l_init(void)
332void 352void
333imfos_v4l_shutdown(void) 353imfos_v4l_shutdown(void)
334{ 354{
335 eina_stringshare_del(_imfos_v4l_path);
336}
337
338void
339imfos_v4l_run(Imfos_V4l_Conf *conf)
340{
341 fprintf(stderr, "v4l run\n");
342 _imfos_v4l_thread = ecore_thread_run(_imfos_v4l_takeshot,
343 _imfos_v4l_end,
344 _imfos_v4l_cancel,
345 conf);
346} 355}
diff --git a/src/modules/imfos/imfos_v4l.h b/src/modules/imfos/imfos_v4l.h
index b06fc0cfc..289d85562 100755
--- a/src/modules/imfos/imfos_v4l.h
+++ b/src/modules/imfos/imfos_v4l.h
@@ -1,15 +1,11 @@
1#ifndef IMFOS_V4L_H_ 1#ifndef IMFOS_V4L_H_
2#define IMFOS_V4L_H_ 2#define IMFOS_V4L_H_
3#include "imfos_face.h"
4 3
5typedef struct Imfos_V4l_Conf_ 4#include "e_mod_main.h"
6{
7 double timeout;
8 Eina_Bool invert : 1;
9} Imfos_V4l_Conf;
10 5
11void imfos_v4l_init(void); 6void imfos_v4l_init(void);
12void imfos_v4l_shutdown(void); 7void imfos_v4l_shutdown(void);
13void imfos_v4l_run(Imfos_V4l_Conf *conf); 8void imfos_v4l_run(Imfos_Device *dev);
9void imfos_v4l_clean(Imfos_Device *dev);
14 10
15#endif /* IMFOS_V4L_H_ */ 11#endif /* IMFOS_V4L_H_ */