summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-12-03 08:16:27 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-12-03 08:16:27 +0000
commit2f4b741ccdb08bf29d27d985ea1b4500079381fe (patch)
tree61faf737febcd23c755b0aebe2541b31fd6e482f /src
parenta3562c0173f6d39d7cc5f79a78f5b3fba9ee4d41 (diff)
ecore: missing files...
SVN revision: 80022
Diffstat (limited to 'src')
-rw-r--r--src/lib/ecore_psl1ght/Ecore_Psl1ght.h121
-rw-r--r--src/lib/ecore_psl1ght/Ecore_Psl1ght_Keys.h78
-rw-r--r--src/lib/ecore_psl1ght/ecore_psl1ght.c859
-rw-r--r--src/lib/ecore_psl1ght/ecore_psl1ght_private.h36
-rw-r--r--src/lib/ecore_psl1ght/gemutil.c281
-rw-r--r--src/lib/ecore_psl1ght/gemutil.h19
-rw-r--r--src/lib/ecore_psl1ght/moveutil.c245
-rw-r--r--src/lib/ecore_psl1ght/moveutil.h43
-rw-r--r--src/lib/ecore_psl1ght/spursutil.c62
-rw-r--r--src/lib/ecore_psl1ght/spursutil.h24
10 files changed, 1768 insertions, 0 deletions
diff --git a/src/lib/ecore_psl1ght/Ecore_Psl1ght.h b/src/lib/ecore_psl1ght/Ecore_Psl1ght.h
new file mode 100644
index 0000000000..c6300fda73
--- /dev/null
+++ b/src/lib/ecore_psl1ght/Ecore_Psl1ght.h
@@ -0,0 +1,121 @@
1#ifndef _ECORE_PSL1GHT_H
2#define _ECORE_PSL1GHT_H
3
4#ifdef EAPI
5# undef EAPI
6#endif
7
8#ifdef __GNUC__
9# if __GNUC__ >= 4
10# define EAPI __attribute__ ((visibility("default")))
11# else
12# define EAPI
13# endif
14#else
15# define EAPI
16#endif
17
18/**
19 * @file
20 * @brief Ecore PSL1GHT system functions.
21 */
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27EAPI extern int ECORE_PSL1GHT_EVENT_KEY_MODIFIERS;
28EAPI extern int ECORE_PSL1GHT_EVENT_GOT_FOCUS;
29EAPI extern int ECORE_PSL1GHT_EVENT_LOST_FOCUS;
30EAPI extern int ECORE_PSL1GHT_EVENT_EXPOSE;
31EAPI extern int ECORE_PSL1GHT_EVENT_QUIT;
32
33typedef struct _Ecore_Psl1ght_Event_Key_Modifiers Ecore_Psl1ght_Event_Key_Modifiers;
34struct _Ecore_Psl1ght_Event_Key_Modifiers /** PSL1GHT Key Modifier event */
35{
36 unsigned int timestamp;
37 unsigned int modifiers;
38 int shift_changed : 1;
39 int shift : 1;
40 int alt_changed : 1;
41 int alt : 1;
42 int ctrl_changed : 1;
43 int ctrl : 1;
44 int win_changed : 1;
45 int win : 1;
46 int num_lock_changed : 1;
47 int num_lock : 1;
48 int caps_lock_changed : 1;
49 int caps_lock : 1;
50 int scroll_lock_changed : 1;
51 int scroll_lock : 1;
52};
53
54typedef struct _Ecore_Psl1ght_Event_Key_Down Ecore_Psl1ght_Event_Key_Down;
55struct _Ecore_Psl1ght_Event_Key_Down /** PSL1GHT Key Down event */
56{
57 const char *keyname; /**< The name of the key that was pressed */
58 const char *keycompose; /**< The UTF-8 string conversion if any */
59 unsigned int time;
60};
61
62typedef struct _Ecore_Psl1ght_Event_Key_Up Ecore_Psl1ght_Event_Key_Up;
63struct _Ecore_Psl1ght_Event_Key_Up /** PSL1GHT Key Up event */
64{
65 const char *keyname; /**< The name of the key that was released */
66 const char *keycompose; /**< The UTF-8 string conversion if any */
67 unsigned int time;
68};
69
70typedef struct _Ecore_Psl1ght_Event_Mouse_Button_Down Ecore_Psl1ght_Event_Mouse_Button_Down;
71struct _Ecore_Psl1ght_Event_Mouse_Button_Down /** PSL1GHT Mouse Down event */
72{
73 int button; /**< Mouse button that was pressed (1 - 32) */
74 int x; /**< Mouse co-ordinates when mouse button was pressed */
75 int y; /**< Mouse co-ordinates when mouse button was pressed */
76 int double_click : 1; /**< Set if click was a double click */
77 int triple_click : 1; /**< Set if click was a triple click */
78 unsigned int time;
79};
80
81typedef struct _Ecore_Psl1ght_Event_Mouse_Button_Up Ecore_Psl1ght_Event_Mouse_Button_Up;
82struct _Ecore_Psl1ght_Event_Mouse_Button_Up /** PSL1GHT Mouse Up event */
83{
84 int button; /**< Mouse button that was released (1 - 32) */
85 int x; /**< Mouse co-ordinates when mouse button was raised */
86 int y; /**< Mouse co-ordinates when mouse button was raised */
87 int double_click : 1; /**< Set if click was a double click */
88 int triple_click : 1; /**< Set if click was a triple click */
89 unsigned int time;
90};
91
92typedef struct _Ecore_Psl1ght_Event_Mouse_Move Ecore_Psl1ght_Event_Mouse_Move;
93struct _Ecore_Psl1ght_Event_Mouse_Move /** PSL1GHT Mouse Move event */
94{
95 int x; /**< Mouse co-ordinates where the mouse cursor moved to */
96 int y; /**< Mouse co-ordinates where the mouse cursor moved to */
97 unsigned int time;
98};
99
100typedef struct _Ecore_Psl1ght_Event_Mouse_Wheel Ecore_Psl1ght_Event_Mouse_Wheel;
101struct _Ecore_Psl1ght_Event_Mouse_Wheel /** PSL1GHT Mouse Wheel event */
102{
103 int x, y;
104 int direction; /* 0 = vertical, 1 = horizontal */
105 int wheel; /* value 1 (left/up), -1 (right/down) */
106 unsigned int time;
107};
108
109EAPI int ecore_psl1ght_init(const char *name);
110EAPI int ecore_psl1ght_shutdown(void);
111EAPI void ecore_psl1ght_resolution_set(int width, int height);
112EAPI void ecore_psl1ght_poll_events(void);
113
114EAPI void ecore_psl1ght_screen_resolution_get(int *w, int *h);
115EAPI void ecore_psl1ght_optimal_screen_resolution_get(int *w, int *h);
116
117#ifdef __cplusplus
118}
119#endif
120
121#endif
diff --git a/src/lib/ecore_psl1ght/Ecore_Psl1ght_Keys.h b/src/lib/ecore_psl1ght/Ecore_Psl1ght_Keys.h
new file mode 100644
index 0000000000..e385af8a4d
--- /dev/null
+++ b/src/lib/ecore_psl1ght/Ecore_Psl1ght_Keys.h
@@ -0,0 +1,78 @@
1#ifndef ECORE_PSL1GHT_KEYS_H__
2# define ECORE_PSL1GHT_KEYS_H__
3
4struct _ecore_psl1ght_keys_s
5{
6 int code;
7 const char *name;
8 const char *compose;
9};
10
11static const struct _ecore_psl1ght_keys_s keystable[] =
12{
13 { KB_RAWKEY_NO_EVENT, "0x00", "" },
14 { KB_RAWKEY_BS, "BackSpace", "\010" },
15 { KB_RAWKEY_TAB, "Tab", "\011" },
16 { KB_RAWKEY_ENTER, "Return", "\015" },
17 { KB_RAWKEY_PAUSE, "Pause", "Pause" },
18 { KB_RAWKEY_ESCAPE, "Escape", "\033" },
19 { KB_RAWKEY_SPACE, "space", " " },
20
21 /* Skip uppercase letters */
22 { KB_RAWKEY_LEFT_BRACKET_101, "bracketleft", "[" },
23 { KB_RAWKEY_BACKSLASH_101, "backslash", "\\" },
24 { KB_RAWKEY_RIGHT_BRACKET_101, "bracketright", "]" },
25 { KB_RAWKEY_ACCENT_CIRCONFLEX_106, "asciicircumm", "^" },
26 { KB_RAWKEY_DELETE, "Delete", "\177" },
27 /* End of ASCII mapped keysyms */
28
29 /* Numeric keypad */
30 { KB_RAWKEY_KPAD_0, "KP0", "0" },
31 { KB_RAWKEY_KPAD_1, "KP1", "1" },
32 { KB_RAWKEY_KPAD_2, "KP2", "2" },
33 { KB_RAWKEY_KPAD_3, "KP3", "3" },
34 { KB_RAWKEY_KPAD_4, "KP4", "4" },
35 { KB_RAWKEY_KPAD_5, "KP5", "5" },
36 { KB_RAWKEY_KPAD_6, "KP6", "6" },
37 { KB_RAWKEY_KPAD_7, "KP7", "7" },
38 { KB_RAWKEY_KPAD_8, "KP8", "8" },
39 { KB_RAWKEY_KPAD_9, "KP9", "9" },
40 { KB_RAWKEY_KPAD_PERIOD, "period", "." },
41 { KB_RAWKEY_KPAD_SLASH, "KP_Divide", "/" },
42 { KB_RAWKEY_KPAD_ASTERISK, "KP_Multiply", "*" },
43 { KB_RAWKEY_KPAD_MINUS, "KP_Minus", "-" },
44 { KB_RAWKEY_KPAD_PLUS, "KP_Plus", "+" },
45 { KB_RAWKEY_KPAD_ENTER, "KP_Enter", "\015" },
46
47 /* Arrows + Home/End pad */
48 { KB_RAWKEY_UP_ARROW, "Up", "Up" },
49 { KB_RAWKEY_DOWN_ARROW, "Down", "Down" },
50 { KB_RAWKEY_RIGHT_ARROW, "Right", "Right" },
51 { KB_RAWKEY_LEFT_ARROW, "Left", "Left" },
52 { KB_RAWKEY_INSERT, "Insert", "Insert" },
53 { KB_RAWKEY_HOME, "Home", "Home" },
54 { KB_RAWKEY_END, "End", "End" },
55 { KB_RAWKEY_PAGE_UP, "Page_Up", "Page_Up" },
56 { KB_RAWKEY_PAGE_DOWN, "Page_Down", "Page_Down" },
57
58 /* Function keys */
59 { KB_RAWKEY_F1, "F1", "F1" },
60 { KB_RAWKEY_F2, "F2", "F2" },
61 { KB_RAWKEY_F3, "F3", "F3" },
62 { KB_RAWKEY_F4, "F4", "F4" },
63 { KB_RAWKEY_F5, "F5", "F5" },
64 { KB_RAWKEY_F6, "F6", "F6" },
65 { KB_RAWKEY_F7, "F7", "F7" },
66 { KB_RAWKEY_F8, "F8", "F8" },
67 { KB_RAWKEY_F9, "F9", "F9" },
68 { KB_RAWKEY_F10, "F10", "F10" },
69 { KB_RAWKEY_F11, "F11", "F11" },
70 { KB_RAWKEY_F12, "F12", "F12" },
71
72 /* Key state modifier keys */
73 { KB_RAWKEY_KPAD_NUMLOCK, "Num_Lock", "Num_Lock" },
74 { KB_RAWKEY_CAPS_LOCK, "Caps_Lock", "Caps_Lock" },
75 { KB_RAWKEY_SCROLL_LOCK, "Scroll_Lock", "Scroll_Lock" },
76};
77
78#endif /* ECORE_PSL1GHT_KEYS_H__ */
diff --git a/src/lib/ecore_psl1ght/ecore_psl1ght.c b/src/lib/ecore_psl1ght/ecore_psl1ght.c
new file mode 100644
index 0000000000..80efca1b64
--- /dev/null
+++ b/src/lib/ecore_psl1ght/ecore_psl1ght.c
@@ -0,0 +1,859 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <sysutil/video.h>
6#include <sysutil/sysutil.h>
7#include <sysmodule/sysmodule.h>
8#include <io/pad.h>
9#include <io/mouse.h>
10#include <io/kb.h>
11#include <io/camera.h>
12#include <io/move.h>
13#include <sys/process.h>
14
15#include "moveutil.h"
16
17#include "Eina.h"
18#include "Ecore_Psl1ght.h"
19#include "Ecore_Input.h"
20#include "Ecore.h"
21#include "ecore_psl1ght_private.h"
22#include "ecore_private.h"
23#include "Ecore_Psl1ght_Keys.h"
24
25/* Allocate 1MB stack to avoid overflows */
26SYS_PROCESS_PARAM(1001, 0x100000);
27
28int _ecore_psl1ght_log_dom = -1;
29
30EAPI int ECORE_PSL1GHT_EVENT_KEY_MODIFIERS = 0;
31EAPI int ECORE_PSL1GHT_EVENT_GOT_FOCUS = 0;
32EAPI int ECORE_PSL1GHT_EVENT_LOST_FOCUS = 0;
33EAPI int ECORE_PSL1GHT_EVENT_EXPOSE = 0;
34EAPI int ECORE_PSL1GHT_EVENT_QUIT = 0;
35
36static int _ecore_psl1ght_init_count = 0;
37static int window_width = 0;
38static int window_height = 0;
39/* Mouse support */
40static int mouse_connected = FALSE;
41static u8 mouse_buttons = 0;
42static int mouse_x = 0;
43static int mouse_y = 0;
44/* Keyboard support */
45static int keyboard_connected = FALSE;
46static KbLed keyboard_leds = {{0}};
47static KbMkey keyboard_mods = {{0}};
48static u16 keyboard_old_key = 0;
49/* Pad support */
50static padData pad_data;
51static padData old_pad_data = {0};
52static int pad_old_x = 0;
53static int pad_old_o = 0;
54/* Move support */
55static int move_connected = FALSE;
56static moveContext *move_context = NULL;
57u16 move_buttons = 0;
58
59static void xmb_event_handler(u64 status, u64 param, void *user_data);
60
61/**
62 * @defgroup Ecore_Psl1ght_Library_Group PSL1GHT Library Functions
63 *
64 * Functions used to set up and shut down the Ecore_Psl1ght functions.
65 */
66
67/**
68 * Sets up the Ecore_Psl1ght library.
69 * @param name device target name
70 * @return @c 0 on failure. Otherwise, the number of times the library has
71 * been initialised without being shut down.
72 * @ingroup Ecore_PSL1GHT_Library_Group
73 */
74EAPI int
75ecore_psl1ght_init(const char *name EINA_UNUSED)
76{
77 videoState state;
78 videoResolution resolution;
79 int ret, camera_loaded, gem_loaded;
80
81 if (++_ecore_psl1ght_init_count != 1)
82 return _ecore_psl1ght_init_count;
83 _ecore_psl1ght_log_dom = eina_log_domain_register
84 ("ecore_psl1ght", ECORE_PSL1GHT_DEFAULT_LOG_COLOR);
85 if (_ecore_psl1ght_log_dom < 0)
86 {
87 EINA_LOG_ERR("Impossible to create a log domain for the Ecore PSL1GHT module.");
88 return --_ecore_psl1ght_init_count;
89 }
90 if (!ecore_event_init())
91 {
92 eina_log_domain_unregister(_ecore_psl1ght_log_dom);
93 _ecore_psl1ght_log_dom = -1;
94 return --_ecore_psl1ght_init_count;
95 }
96
97 if (videoGetState (0, 0, &state) == 0 &&
98 videoGetResolution (state.displayMode.resolution, &resolution) == 0)
99 {
100 ecore_psl1ght_resolution_set (resolution.width, resolution.height);
101 }
102 else
103 {
104 ecore_event_shutdown();
105 eina_log_domain_unregister(_ecore_psl1ght_log_dom);
106 _ecore_psl1ght_log_dom = -1;
107 return --_ecore_psl1ght_init_count;
108 }
109
110 /* Pad support */
111 ioPadInit (7);
112 /* Mouse support */
113 ioMouseInit(2);
114 mouse_buttons = 0;
115 mouse_x = 0;
116 mouse_y = 0;
117
118 /* Keyboard support */
119 ioKbInit(2);
120 keyboard_leds._KbLedU.leds = 0;
121 keyboard_mods._KbMkeyU.mkeys = 0;
122
123 /* Initialize Move */
124 move_context = NULL;
125 move_buttons = 0;
126
127 camera_loaded = !sysModuleIsLoaded (SYSMODULE_CAMERA);
128 if (!camera_loaded)
129 ret = sysModuleLoad (SYSMODULE_CAMERA);
130 else
131 ret = 0;
132 if (ret == 0)
133 {
134 gem_loaded = !sysModuleIsLoaded (SYSMODULE_GEM);
135 if (!gem_loaded)
136 ret = sysModuleLoad (SYSMODULE_GEM);
137 if (ret == 0)
138 {
139 move_context = initMove ();
140 }
141 else {
142 if (gem_loaded)
143 sysModuleUnload (SYSMODULE_CAMERA);
144 }
145 }
146
147 sysUtilRegisterCallback (SYSUTIL_EVENT_SLOT0, xmb_event_handler, NULL);
148
149 ECORE_PSL1GHT_EVENT_GOT_FOCUS = ecore_event_type_new();
150 ECORE_PSL1GHT_EVENT_LOST_FOCUS = ecore_event_type_new();
151 ECORE_PSL1GHT_EVENT_EXPOSE = ecore_event_type_new();
152 ECORE_PSL1GHT_EVENT_KEY_MODIFIERS = ecore_event_type_new();
153 ECORE_PSL1GHT_EVENT_QUIT = ecore_event_type_new();
154
155 mouse_x = 0;
156 mouse_y = 0;
157
158 return _ecore_psl1ght_init_count;
159}
160
161/**
162 * Shuts down the Ecore_Psl1ght library.
163 * @return @c The number of times the system has been initialised without
164 * being shut down.
165 * @ingroup Ecore_PSL1GHT_Library_Group
166 */
167EAPI int
168ecore_psl1ght_shutdown(void)
169{
170 if (--_ecore_psl1ght_init_count != 0)
171 return _ecore_psl1ght_init_count;
172
173 ecore_event_shutdown();
174 eina_log_domain_unregister(_ecore_psl1ght_log_dom);
175 _ecore_psl1ght_log_dom = -1;
176
177 ECORE_PSL1GHT_EVENT_GOT_FOCUS = 0;
178 ECORE_PSL1GHT_EVENT_LOST_FOCUS = 0;
179 ECORE_PSL1GHT_EVENT_EXPOSE = 0;
180 ECORE_PSL1GHT_EVENT_KEY_MODIFIERS = 0;
181 ECORE_PSL1GHT_EVENT_QUIT = 0;
182
183 ioPadEnd();
184 ioMouseEnd();
185 ioKbEnd();
186
187 if (move_context)
188 {
189 endMove (move_context);
190 move_context = NULL;
191 sysModuleUnload (SYSMODULE_CAMERA);
192 sysModuleUnload (SYSMODULE_GEM);
193 }
194
195 sysUtilUnregisterCallback(SYSUTIL_EVENT_SLOT0);
196
197 return _ecore_psl1ght_init_count;
198}
199
200static unsigned int
201_ecore_psl1ght_get_time(void)
202{
203 return (unsigned int)((unsigned long long)
204 (ecore_time_get() * 1000.0) & 0xffffffff);
205}
206
207static unsigned int
208_ecore_psl1ght_get_modifiers(void)
209{
210 unsigned int modifiers = 0;
211
212 if (keyboard_mods._KbMkeyU._KbMkeyS.r_shift ||
213 keyboard_mods._KbMkeyU._KbMkeyS.l_shift)
214 modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
215 if (keyboard_mods._KbMkeyU._KbMkeyS.r_ctrl ||
216 keyboard_mods._KbMkeyU._KbMkeyS.l_ctrl)
217 modifiers |= ECORE_EVENT_MODIFIER_CTRL;
218 if (keyboard_mods._KbMkeyU._KbMkeyS.r_alt ||
219 keyboard_mods._KbMkeyU._KbMkeyS.l_alt)
220 modifiers |= ECORE_EVENT_MODIFIER_ALT;
221 if (keyboard_mods._KbMkeyU._KbMkeyS.r_win ||
222 keyboard_mods._KbMkeyU._KbMkeyS.l_win)
223 modifiers |= ECORE_EVENT_MODIFIER_WIN;
224
225 if (keyboard_leds._KbLedU._KbLedS.num_lock)
226 modifiers |= ECORE_EVENT_LOCK_NUM;
227 if (keyboard_leds._KbLedU._KbLedS.caps_lock)
228 modifiers |= ECORE_EVENT_LOCK_CAPS;
229 if (keyboard_leds._KbLedU._KbLedS.scroll_lock)
230 modifiers |= ECORE_EVENT_LOCK_SCROLL;
231
232 return modifiers;
233}
234
235static void
236_ecore_psl1ght_key_modifiers(KbMkey *mods, KbLed *leds)
237{
238 Ecore_Psl1ght_Event_Key_Modifiers *ev;
239 Eina_Bool emit = EINA_FALSE;
240
241 ev = malloc(sizeof(Ecore_Psl1ght_Event_Key_Modifiers));
242 if (!ev) return;
243
244 if (mods->_KbMkeyU._KbMkeyS.l_shift !=
245 keyboard_mods._KbMkeyU._KbMkeyS.l_shift ||
246 mods->_KbMkeyU._KbMkeyS.r_shift !=
247 keyboard_mods._KbMkeyU._KbMkeyS.r_shift)
248 {
249 emit = EINA_TRUE;
250 ev->shift_changed = EINA_TRUE;
251 ev->shift = mods->_KbMkeyU._KbMkeyS.r_shift |
252 mods->_KbMkeyU._KbMkeyS.l_shift;
253 }
254 if (mods->_KbMkeyU._KbMkeyS.l_ctrl !=
255 keyboard_mods._KbMkeyU._KbMkeyS.l_ctrl ||
256 mods->_KbMkeyU._KbMkeyS.r_ctrl !=
257 keyboard_mods._KbMkeyU._KbMkeyS.r_ctrl)
258 {
259 emit = EINA_TRUE;
260 ev->ctrl_changed = EINA_TRUE;
261 ev->ctrl = mods->_KbMkeyU._KbMkeyS.r_ctrl |
262 mods->_KbMkeyU._KbMkeyS.l_ctrl;
263 }
264 if (mods->_KbMkeyU._KbMkeyS.l_alt !=
265 keyboard_mods._KbMkeyU._KbMkeyS.l_alt ||
266 mods->_KbMkeyU._KbMkeyS.r_alt !=
267 keyboard_mods._KbMkeyU._KbMkeyS.r_alt)
268 {
269 emit = EINA_TRUE;
270 ev->alt_changed = EINA_TRUE;
271 ev->alt = mods->_KbMkeyU._KbMkeyS.r_alt |
272 mods->_KbMkeyU._KbMkeyS.l_alt;
273 }
274 if (mods->_KbMkeyU._KbMkeyS.l_win !=
275 keyboard_mods._KbMkeyU._KbMkeyS.l_win ||
276 mods->_KbMkeyU._KbMkeyS.r_win !=
277 keyboard_mods._KbMkeyU._KbMkeyS.r_win)
278 {
279 emit = EINA_TRUE;
280 ev->win_changed = EINA_TRUE;
281 ev->win = mods->_KbMkeyU._KbMkeyS.r_win |
282 mods->_KbMkeyU._KbMkeyS.l_win;
283 }
284 keyboard_mods = *mods;
285
286 if (leds->_KbLedU._KbLedS.num_lock !=
287 keyboard_leds._KbLedU._KbLedS.num_lock)
288 {
289 emit = EINA_TRUE;
290 ev->num_lock_changed = EINA_TRUE;
291 ev->num_lock = leds->_KbLedU._KbLedS.num_lock;
292 }
293 if (leds->_KbLedU._KbLedS.caps_lock !=
294 keyboard_leds._KbLedU._KbLedS.caps_lock)
295 {
296 emit = EINA_TRUE;
297 ev->caps_lock_changed = EINA_TRUE;
298 ev->caps_lock = leds->_KbLedU._KbLedS.caps_lock;
299 }
300 if (leds->_KbLedU._KbLedS.scroll_lock !=
301 keyboard_leds._KbLedU._KbLedS.scroll_lock)
302 {
303 emit = EINA_TRUE;
304 ev->scroll_lock_changed = EINA_TRUE;
305 ev->scroll_lock = leds->_KbLedU._KbLedS.scroll_lock;
306 }
307 keyboard_leds = *leds;
308
309 if (emit)
310 {
311 ev->timestamp = _ecore_psl1ght_get_time ();
312 ev->modifiers = _ecore_psl1ght_get_modifiers();
313 ecore_event_add(ECORE_PSL1GHT_EVENT_KEY_MODIFIERS, ev, NULL, NULL);
314 }
315 else
316 {
317 free(ev);
318 }
319}
320
321static void
322unicodeToUtf8(u16 w, char *utf8buf)
323{
324 unsigned char *utf8s = (unsigned char *)utf8buf;
325
326 if ( w < 0x0080 )
327 {
328 utf8s[0] = ( unsigned char )w;
329 utf8s[1] = 0;
330 }
331 else if ( w < 0x0800 )
332 {
333 utf8s[0] = 0xc0 | ((w) >> 6);
334 utf8s[1] = 0x80 | ((w) & 0x3f);
335 utf8s[2] = 0;
336 }
337 else {
338 utf8s[0] = 0xe0 | ((w) >> 12);
339 utf8s[1] = 0x80 | (((w) >> 6) & 0x3f);
340 utf8s[2] = 0x80 | ((w) & 0x3f);
341 utf8s[3] = 0;
342 }
343}
344
345static Ecore_Event_Key *
346_ecore_psl1ght_event_key(u16 key)
347{
348 Ecore_Event_Key *ev;
349 char utf8[4];
350 u16 utf16;
351 unsigned int i;
352
353 ev = malloc(sizeof(Ecore_Event_Key));
354 if (!ev) return NULL;
355
356 ev->timestamp = _ecore_psl1ght_get_time ();
357 ev->window = 0;
358 ev->event_window = 0;
359 ev->modifiers = _ecore_psl1ght_get_modifiers();
360
361 key &= ~KB_KEYPAD;
362 for (i = 0; i < sizeof(keystable) / sizeof(struct _ecore_psl1ght_keys_s); ++i)
363 if (keystable[i].code == key)
364 {
365 ev->keyname = keystable[i].name;
366 ev->key = keystable[i].name;
367 ev->string = keystable[i].compose;
368 ev->compose = keystable[i].compose;
369
370 return ev;
371 }
372
373 utf16 = ioKbCnvRawCode (KB_MAPPING_101, keyboard_mods, keyboard_leds, key);
374 unicodeToUtf8(utf16, utf8);
375 ev->keyname = ev->key = ev->string = ev->compose = strdup (utf8);
376
377 return ev;
378}
379
380static void
381_ecore_psl1ght_mouse_move(s32 x_axis, s32 y_axis)
382{
383 Ecore_Event_Mouse_Move *ev;
384
385 ev = malloc(sizeof(Ecore_Event_Mouse_Move));
386 if (!ev) return;
387
388 mouse_x += x_axis;
389 mouse_y += y_axis;
390 if (mouse_x < 0) mouse_x = 0;
391 if (mouse_y < 0) mouse_y = 0;
392 if (mouse_x > window_width) mouse_x = window_width;
393 if (mouse_y > window_height) mouse_y = window_height;
394
395 ev->window = 0;
396 ev->root_window = 0;
397 ev->event_window = 0;
398 ev->same_screen = 0;
399 ev->timestamp = _ecore_psl1ght_get_time ();
400 ev->modifiers = _ecore_psl1ght_get_modifiers ();
401 ev->x = ev->root.x = mouse_x;
402 ev->y = ev->root.x = mouse_y;
403
404 ev->multi.device = 0;
405 ev->multi.radius = ev->multi.radius_x = ev->multi.radius_y = 0;
406 ev->multi.pressure = ev->multi.angle = 0;
407 ev->multi.x = ev->multi.y = ev->multi.root.x = ev->multi.root.y = 0;
408
409 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
410}
411
412static void
413_ecore_psl1ght_mouse_button(int button, int pressed)
414{
415 Ecore_Event_Mouse_Button *ev;
416 static unsigned int previous_timestamp = 0;
417
418 ev = malloc(sizeof(Ecore_Event_Mouse_Button));
419 if (!ev) return;
420
421 ev->window = 0;
422 ev->root_window = 0;
423 ev->event_window = 0;
424 ev->same_screen = 0;
425 ev->timestamp = _ecore_psl1ght_get_time ();
426 ev->modifiers = _ecore_psl1ght_get_modifiers ();
427 ev->buttons = button;
428 if (ev->timestamp - previous_timestamp <= 500)
429 ev->double_click = 1;
430 ev->triple_click = 0;
431 previous_timestamp = ev->timestamp;
432
433 ev->x = ev->root.x = mouse_x;
434 ev->y = ev->root.y = mouse_y;
435 ev->multi.device = 0;
436 ev->multi.radius = ev->multi.radius_x = ev->multi.radius_y = 0;
437 ev->multi.pressure = ev->multi.angle = 0;
438 ev->multi.x = ev->multi.y = ev->multi.root.x = ev->multi.root.y = 0;
439
440 if (pressed)
441 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
442 else
443 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
444}
445
446static void
447_ecore_psl1ght_mouse_wheel(s8 wheel, s8 tilt)
448{
449 Ecore_Event_Mouse_Wheel *ev;
450
451 ev = malloc(sizeof(Ecore_Event_Mouse_Wheel));
452 if (!ev) return;
453
454 ev->timestamp = _ecore_psl1ght_get_time ();
455 ev->window = 0;
456 ev->event_window = 0;
457 ev->modifiers = _ecore_psl1ght_get_modifiers ();
458 ev->direction = 0;
459 ev->z = wheel;
460
461 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
462}
463
464static void
465_ecore_psl1ght_pad_button (const char *name, int pressed)
466{
467 Ecore_Event_Key *ev = NULL;
468
469 ev = malloc(sizeof(Ecore_Event_Key));
470 if (!ev) return;
471
472 ev->timestamp = _ecore_psl1ght_get_time ();
473 ev->window = 0;
474 ev->event_window = 0;
475 ev->modifiers = 0;
476
477 ev->keyname = name;
478 ev->key = name;
479 ev->string = "";
480 ev->compose = "";
481
482 if (pressed)
483 ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, NULL, NULL);
484 else
485 ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL);
486}
487
488#define PAD_STICK_DEADZONE 0x20
489
490static void
491_ecore_psl1ght_poll_joypad(void)
492{
493 padInfo padinfo;
494 int i;
495
496 /**/
497 /* Check mouse events */
498 ioPadGetInfo (&padinfo);
499
500 for (i = 0; i < 4; i++) /* Ignore the move */
501 {
502 if (padinfo.status[i])
503 {
504 int analog_h, analog_v;
505
506 if (ioPadGetData (i, &pad_data) != 0)
507 continue;
508 analog_h = pad_data.ANA_L_H - 0x80;
509 analog_v = pad_data.ANA_L_V - 0x80;
510
511 if (analog_h > PAD_STICK_DEADZONE)
512 analog_h -= PAD_STICK_DEADZONE;
513 else if (analog_h < -PAD_STICK_DEADZONE)
514 analog_h += PAD_STICK_DEADZONE;
515 else
516 analog_h = 0;
517 analog_h /= 10;
518
519 if (analog_v > PAD_STICK_DEADZONE)
520 analog_v -= PAD_STICK_DEADZONE;
521 else if (analog_v < -PAD_STICK_DEADZONE)
522 analog_v += PAD_STICK_DEADZONE;
523 else
524 analog_v = 0;
525 analog_v /= 10;
526
527 if (analog_h != 0 || analog_v != 0)
528 _ecore_psl1ght_mouse_move (analog_h, analog_v);
529
530 if (old_pad_data.BTN_CROSS ^ pad_data.BTN_CROSS) {
531 _ecore_psl1ght_pad_button ("Cross", pad_data.BTN_CROSS);
532 _ecore_psl1ght_mouse_button (1, pad_data.BTN_CROSS);
533 }
534 if (old_pad_data.BTN_CIRCLE ^ pad_data.BTN_CIRCLE) {
535 _ecore_psl1ght_pad_button ("Circle", pad_data.BTN_CIRCLE);
536 _ecore_psl1ght_mouse_button (3, pad_data.BTN_CIRCLE);
537 }
538 if (old_pad_data.BTN_SQUARE ^ pad_data.BTN_SQUARE)
539 _ecore_psl1ght_pad_button ("Square", pad_data.BTN_SQUARE);
540 if (old_pad_data.BTN_TRIANGLE ^ pad_data.BTN_TRIANGLE)
541 _ecore_psl1ght_pad_button ("Triangle", pad_data.BTN_TRIANGLE);
542 if (old_pad_data.BTN_UP ^ pad_data.BTN_UP)
543 _ecore_psl1ght_pad_button ("Up", pad_data.BTN_UP);
544 if (old_pad_data.BTN_DOWN ^ pad_data.BTN_DOWN)
545 _ecore_psl1ght_pad_button ("Down", pad_data.BTN_DOWN);
546 if (old_pad_data.BTN_LEFT ^ pad_data.BTN_LEFT)
547 _ecore_psl1ght_pad_button ("Left", pad_data.BTN_LEFT);
548 if (old_pad_data.BTN_RIGHT ^ pad_data.BTN_RIGHT)
549 _ecore_psl1ght_pad_button ("Right", pad_data.BTN_RIGHT);
550 if (old_pad_data.BTN_L1 ^ pad_data.BTN_L1)
551 _ecore_psl1ght_pad_button ("L1", pad_data.BTN_L1);
552 if (old_pad_data.BTN_L2 ^ pad_data.BTN_L2)
553 _ecore_psl1ght_pad_button ("L2", pad_data.BTN_L2);
554 if (old_pad_data.BTN_L3 ^ pad_data.BTN_L3)
555 _ecore_psl1ght_pad_button ("L3", pad_data.BTN_L3);
556 if (old_pad_data.BTN_R1 ^ pad_data.BTN_R1)
557 _ecore_psl1ght_pad_button ("R1", pad_data.BTN_R1);
558 if (old_pad_data.BTN_R2 ^ pad_data.BTN_R2)
559 _ecore_psl1ght_pad_button ("R2", pad_data.BTN_R2);
560 if (old_pad_data.BTN_R3 ^ pad_data.BTN_R3)
561 _ecore_psl1ght_pad_button ("R3", pad_data.BTN_R3);
562 if (old_pad_data.BTN_START ^ pad_data.BTN_START)
563 _ecore_psl1ght_pad_button ("Start", pad_data.BTN_START);
564 if (old_pad_data.BTN_SELECT ^ pad_data.BTN_SELECT)
565 _ecore_psl1ght_pad_button ("Select", pad_data.BTN_SELECT);
566
567 old_pad_data = pad_data;
568 }
569 }
570}
571
572static void
573_ecore_psl1ght_poll_mouse(void)
574{
575 mouseInfo mouseinfo;
576 u32 i;
577
578 /**/
579 /* Check mouse events */
580 ioMouseGetInfo(&mouseinfo);
581
582 if (mouseinfo.status[0] == 1 && !mouse_connected) // Connected
583 {
584 mouse_connected = TRUE;
585 mouse_buttons = 0;
586
587 // Old events in the queue are discarded
588 ioMouseClearBuf(0);
589 }
590 else if (mouseinfo.status[0] != 1 && mouse_connected) // Disconnected
591 {
592 mouse_connected = FALSE;
593 mouse_buttons = 0;
594 }
595
596 if (mouse_connected)
597 {
598 mouseDataList datalist;
599
600 ioMouseGetDataList(0, &datalist);
601
602 for (i = 0; i < datalist.count; i++)
603 {
604 u8 old_left = mouse_buttons & 1;
605 u8 new_left = datalist.list[i].buttons & 1;
606 u8 old_right = mouse_buttons & 2;
607 u8 new_right = datalist.list[i].buttons & 2;
608 u8 old_middle = mouse_buttons & 4;
609 u8 new_middle = datalist.list[i].buttons & 4;
610
611 if (datalist.list[i].x_axis != 0 ||
612 datalist.list[i].y_axis != 0)
613 _ecore_psl1ght_mouse_move (datalist.list[i].x_axis,
614 datalist.list[i].y_axis);
615
616 if (old_left != new_left)
617 _ecore_psl1ght_mouse_button (1, new_left);
618 if (old_middle != new_middle)
619 _ecore_psl1ght_mouse_button (2, new_middle);
620 if (old_right != new_right)
621 _ecore_psl1ght_mouse_button (3, new_right);
622
623 if (datalist.list[i].wheel != 0)
624 _ecore_psl1ght_mouse_wheel (datalist.list[i].wheel,
625 datalist.list[i].tilt);
626
627 mouse_buttons = datalist.list[i].buttons;
628 }
629 }
630}
631
632static void
633_ecore_psl1ght_poll_move(void)
634{
635 int i;
636 u16 new_buttons;
637 static int t_pressed = 0;
638 static int calibrated = 0;
639 static float prev_x = 0;
640 static float prev_y = 0;
641 static int gyro = 0;
642 float x, y, z;
643
644 /* Check move events */
645 processMove (move_context);
646 new_buttons = move_context->state.paddata.buttons & (~move_buttons);
647 move_buttons = move_context->state.paddata.buttons;
648
649 moveGet3DPosition (move_context, &x, &y, &z);
650 //printf ("Move 3D position is : %f, %f, %f\n", x,y,z);
651
652 switch (new_buttons) {
653 case 1:
654 gyro = !gyro;
655 break;
656
657 case 4:
658 // Move button
659 //printf ("Calibrating\n");
660 gemCalibrate (0);
661 calibrated = 1;
662 break;
663
664 case 8:
665 // start button
666 _ecore_psl1ght_mouse_move ((window_width / 2) - mouse_x, (window_height / 2) - mouse_y);
667 break;
668 }
669
670 if (calibrated)
671 {
672 float x_axis, y_axis;
673
674 if (gyro)
675 {
676 gemInertialState gem_inert;
677
678 gemGetInertialState (0, 0, 0, &gem_inert);
679 x_axis = -vec_array (gem_inert.gyro, 1) * 25;
680 y_axis = -vec_array (gem_inert.gyro, 0) * 25;
681 if (abs (x_axis) > 2 || abs (y_axis) > 2)
682 _ecore_psl1ght_mouse_move (x_axis, y_axis);
683 }
684 else {
685 x_axis = (x - prev_x) * 2.5;
686 y_axis = -(y - prev_y) * 2.5;
687 prev_x = x;
688 prev_y = y;
689 _ecore_psl1ght_mouse_move (x_axis, y_axis);
690 }
691
692 if (!t_pressed && (move_buttons & 0x2))
693 _ecore_psl1ght_mouse_button (1, 1);
694 else if (t_pressed && (move_buttons & 0x2) == 0)
695 _ecore_psl1ght_mouse_button (1, 0);
696 t_pressed = move_buttons & 0x2;
697 }
698}
699
700static void
701_ecore_psl1ght_poll_keyboard(void)
702{
703 KbInfo kbInfo;
704 int i;
705
706 /* Check keyboard events */
707 ioKbGetInfo(&kbInfo);
708
709 if (kbInfo.status[0] == 1 && !keyboard_connected)
710 {
711 /* Connected */
712 keyboard_connected = true;
713
714 // Old events in the queue are discarded
715 ioKbClearBuf(0);
716 keyboard_leds._KbLedU.leds = 0;
717 keyboard_mods._KbMkeyU.mkeys = 0;
718 keyboard_old_key = 0;
719
720 // Set raw keyboard code types to get scan codes
721 ioKbSetCodeType(0, KB_CODETYPE_RAW);
722 ioKbSetReadMode(0, KB_RMODE_INPUTCHAR);
723 }
724 else if (kbInfo.status[0] != 1 && keyboard_connected)
725 {
726 /* Disconnected keyboard */
727 keyboard_connected = FALSE;
728 }
729
730 if (keyboard_connected)
731 {
732 KbData Keys;
733
734 // Read data from the keyboard buffer
735 if (ioKbRead(0, &Keys) == 0 && Keys.nb_keycode > 0)
736 {
737 Ecore_Event_Key *ev = NULL;
738
739 _ecore_psl1ght_key_modifiers (&Keys.mkey, &Keys.led);
740
741 if (Keys.nb_keycode == 0 && keyboard_old_key != 0)
742 {
743 ev = _ecore_psl1ght_event_key (keyboard_old_key);
744 if (ev) ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL);
745 }
746 for (i = 0; i < Keys.nb_keycode; i++)
747 {
748 if (Keys.keycode[i] != keyboard_old_key)
749 {
750 if (Keys.keycode[i] != 0)
751 {
752 ev = _ecore_psl1ght_event_key (Keys.keycode[i]);
753 if (ev)
754 ecore_event_add(ECORE_EVENT_KEY_DOWN, ev,
755 NULL, NULL);
756 }
757 else
758 {
759 ev = _ecore_psl1ght_event_key (keyboard_old_key);
760 if (ev)
761 ecore_event_add(ECORE_EVENT_KEY_UP, ev,
762 NULL, NULL);
763 }
764 keyboard_old_key = Keys.keycode[0];
765 }
766 }
767 }
768 }
769}
770
771static void
772xmb_event_handler(u64 status, u64 param, void *user_data)
773{
774 //printf ("Received event %lX\n", status);
775 switch (status) {
776 case SYSUTIL_EXIT_GAME:
777 ecore_event_add(ECORE_PSL1GHT_EVENT_QUIT, NULL, NULL, NULL);
778 break;
779 case SYSUTIL_DRAW_BEGIN:
780 ecore_event_add(ECORE_PSL1GHT_EVENT_EXPOSE, NULL, NULL, NULL);
781 case SYSUTIL_MENU_OPEN:
782 ecore_event_add(ECORE_PSL1GHT_EVENT_LOST_FOCUS, NULL, NULL, NULL);
783 break;
784 case SYSUTIL_DRAW_END:
785 ecore_event_add(ECORE_PSL1GHT_EVENT_EXPOSE, NULL, NULL, NULL);
786 case SYSUTIL_MENU_CLOSE:
787 ecore_event_add(ECORE_PSL1GHT_EVENT_GOT_FOCUS, NULL, NULL, NULL);
788 break;
789 default:
790 break;
791 }
792}
793
794EAPI void
795ecore_psl1ght_poll_events(void)
796{
797 _ecore_psl1ght_poll_joypad ();
798 _ecore_psl1ght_poll_mouse ();
799 if (move_context)
800 _ecore_psl1ght_poll_move ();
801 _ecore_psl1ght_poll_keyboard ();
802
803 sysUtilCheckCallback ();
804}
805
806EAPI void
807ecore_psl1ght_resolution_set(int width, int height)
808{
809 window_width = width;
810 window_height = height;
811 if (mouse_x > window_width) mouse_x = window_width;
812 if (mouse_y > window_height) mouse_y = window_height;
813}
814
815EAPI void
816ecore_psl1ght_screen_resolution_get(int *w, int *h)
817{
818 videoState state;
819 videoResolution resolution;
820
821 /* Get the state of the display */
822 if (videoGetState (0, 0, &state) == 0 &&
823 videoGetResolution (state.displayMode.resolution, &resolution) == 0)
824 {
825 if (w) *w = resolution.width;
826 if (h) *h = resolution.height;
827 }
828 else {
829 if (w) *w = 0;
830 if (h) *h = 0;
831 }
832}
833
834EAPI void
835ecore_psl1ght_optimal_screen_resolution_get(int *w, int *h)
836{
837 videoDeviceInfo info;
838 videoResolution res;
839 int area = 720 * 480;
840 int mode_area;
841 int i;
842
843 if (w) *w = 720;
844 if (h) *h = 480;
845
846 videoGetDeviceInfo(0, 0, &info);
847
848 for (i = 0; i < info.availableModeCount; i++) {
849 videoGetResolution (info.availableModes[i].resolution, &res);
850 mode_area = res.width * res.height;
851 if (mode_area > area)
852 {
853 area = mode_area;
854 if (w) *w = res.width;
855 if (h) *h = res.height;
856 }
857 }
858}
859
diff --git a/src/lib/ecore_psl1ght/ecore_psl1ght_private.h b/src/lib/ecore_psl1ght/ecore_psl1ght_private.h
new file mode 100644
index 0000000000..bd5a86e2bb
--- /dev/null
+++ b/src/lib/ecore_psl1ght/ecore_psl1ght_private.h
@@ -0,0 +1,36 @@
1#ifndef _ECORE_PSL1GHT_PRIVATE_H
2# define _ECORE_PSL1GHT_PRIVATE_H
3
4extern int _ecore_psl1ght_log_dom;
5
6# ifdef ECORE_PSL1GHT_DEFAULT_LOG_COLOR
7# undef ECORE_PSL1GHT_DEFAULT_LOG_COLOR
8# endif
9# define ECORE_PSL1GHT_DEFAULT_LOG_COLOR EINA_COLOR_BLUE
10
11# ifdef ERR
12# undef ERR
13# endif
14# define ERR(...) EINA_LOG_DOM_ERR(_ecore_psl1ght_log_dom, __VA_ARGS__)
15
16# ifdef DBG
17# undef DBG
18# endif
19# define DBG(...) EINA_LOG_DOM_DBG(_ecore_psl1ght_log_dom, __VA_ARGS__)
20
21# ifdef INF
22# undef INF
23# endif
24# define INF(...) EINA_LOG_DOM_INFO(_ecore_psl1ght_log_dom, __VA_ARGS__)
25
26# ifdef WRN
27# undef WRN
28# endif
29# define WRN(...) EINA_LOG_DOM_WARN(_ecore_psl1ght_log_dom, __VA_ARGS__)
30
31# ifdef CRIT
32# undef CRIT
33# endif
34# define CRIT(...) EINA_LOG_DOM_CRIT(_ecore_psl1ght_log_dom, __VA_ARGS__)
35
36#endif
diff --git a/src/lib/ecore_psl1ght/gemutil.c b/src/lib/ecore_psl1ght/gemutil.c
new file mode 100644
index 0000000000..9ccfc1c861
--- /dev/null
+++ b/src/lib/ecore_psl1ght/gemutil.c
@@ -0,0 +1,281 @@
1#include <stdio.h>
2#include <io/move.h>
3#include <sys/memory.h>
4#include <ppu-types.h>
5#include <io/camera.h>
6#include <ppu-types.h>
7#include <spurs/spurs.h>
8#include <sys/spu.h>
9#include <sys/thread.h>
10#include <sys/systime.h>
11
12#define SPURS_DEFAULT_PREFIX_NAME "gem_spurs"
13
14u16 oldGemPad = 0;
15u16 newGemPad = 0;
16u16 newGemAnalogT = 0;
17extern cameraReadInfo camread;
18
19static inline float
20vec_array(vec_float4 vec, unsigned int idx)
21{
22 union {
23 vec_float4 vec;
24 float array[4];
25 } v;
26
27 v.vec = vec;
28
29 if (idx > 3)
30 return -1;
31 return v.array[idx];
32}
33
34int
35initMove()
36{
37 Spurs *spurs;
38 gemAttribute gem_attr;
39 u8 gem_spu_priorities[8] = { 1, 0, 0, 0, 0, 0, 0, 0 };
40 int ret;
41 int i;
42
43 spurs = initSpurs (NULL);
44
45 if (spurs == NULL)
46 goto error;
47
48 printf ("preparing GemAttribute structure with spurs\n");
49
50 initAttributeGem (&gem_attr, 1, NULL, spurs, gem_spu_priorities);
51 gem_attr->version = 2;
52 gem_attr->max = 1;
53 gem_attr->spurs = spurs;
54 gem_attr->memory = NULL;
55 gem_attr->spu_priorities[0] = 1;
56 for (i = 1; i < 8; ++i)
57 gem_attr->spu_priorities[i] = 0;
58
59 printf ("calling GemInit with GemAttribute structure version=%d max_connect=%d spurs=%X\n",
60 gem_attr.version, gem_attr.max, gem_attr.spurs);
61 ret = gemInit (&gem_attr);
62 printf ("return from GemInit %X \n", ret);
63 if (ret)
64 goto error;
65
66 ret = gemPrepareCamera (128, 0.5);
67 printf ("GemPrepareCamera return %d exposure set to 128 and quality to 0.5\n",
68 ret);
69 if (ret)
70 goto error;
71 ret = gemReset (0);
72 printf ("GemReset return %X \n", ret);
73 if (ret)
74 goto error;
75 return ret;
76
77error:
78 if (spurs)
79 endSpurs (spurs);
80 return NULL;
81}
82
83int
84endMove()
85{
86 endSpurs (spurs);
87 gemEnd ();
88 return 0;
89}
90
91int
92proccessGem(int t)
93{
94 int ret;
95
96 switch (t) {
97 case 0:
98
99 ret = gemUpdateStart (camread.buffer, camread.timestamp);
100
101 if (ret != 0)
102 {
103 printf ("Return from gemUpdateStart %X\n", ret);
104 }
105 break;
106
107 case 2:
108
109 ret = gemUpdateFinish ();
110 if (ret != 0)
111 {
112 printf ("Return from gemUpdateFinish %X\n", ret);
113 }
114 break;
115
116 case 3:
117 ret = gemConvertVideoFinish ();
118 if (ret != 0)
119 {
120 printf ("Return from gemConvertVideoFinish %X\n", ret);
121 }
122 break;
123
124 default:
125 ret = -1;
126 break;
127 }
128 return ret;
129}
130
131void
132readGemPad(int num_gem)
133{
134 gemState gem_state;
135 int ret;
136 unsigned int hues[] = { 4 << 24, 4 << 24, 4 << 24, 4 << 24 };
137 ret = gemGetState (0, 0, -22000, &gem_state);
138
139 newGemPad = gem_state.paddata.buttons & (~oldGemPad);
140 newGemAnalogT = gem_state.paddata.ANA_T;
141 oldGemPad = gem_state.paddata.buttons;
142
143 switch (ret) {
144 case 2:
145 gemForceRGB (num_gem, 0.5, 0.5, 0.5);
146 break;
147
148 case 5:
149
150 gemTrackHues (hues, NULL);
151 break;
152
153 default:
154 break;
155 }
156}
157
158void
159readGemAccPosition(int num_gem)
160{
161 vec_float4 position;
162
163 gemGetAccelerometerPositionInDevice (num_gem, &position);
164
165 printf (" accelerometer device coordinates [%f,%f,%f,%f]\n",
166 vec_array (position, 0), vec_array (position, 1), vec_array (position, 2),
167 vec_array (position, 3));
168}
169
170void
171readGemInertial(int num_gem)
172{
173 gemInertialState gem_inertial_state;
174 int ret;
175
176 ret = gemGetInertialState (num_gem, 0, -22000, &gem_inertial_state);
177 printf ("gemGetInertialState return %X\n", ret);
178 printf ("counter %d temperature %f\n", gem_inertial_state.counter,
179 gem_inertial_state.temperature);
180
181 printf (" accelerometer sensor [%f,%f,%f,%f]\n",
182 vec_array (gem_inertial_state.accelerometer, 0),
183 vec_array (gem_inertial_state.accelerometer, 1),
184 vec_array (gem_inertial_state.accelerometer, 2),
185 vec_array (gem_inertial_state.accelerometer, 3));
186
187 printf (" accelerometer_bias sensor [%f,%f,%f,%f]\n",
188 vec_array (gem_inertial_state.accelerometer_bias, 0),
189 vec_array (gem_inertial_state.accelerometer_bias, 1),
190 vec_array (gem_inertial_state.accelerometer_bias, 2),
191 vec_array (gem_inertial_state.accelerometer_bias, 3));
192
193 printf (" gyro sensor [%f,%f,%f,%f]\n", vec_array (gem_inertial_state.gyro,
194 0), vec_array (gem_inertial_state.gyro, 1),
195 vec_array (gem_inertial_state.gyro, 2),
196 vec_array (gem_inertial_state.gyro, 3));
197
198 printf (" gyro_bias sensor [%f,%f,%f,%f]\n",
199 vec_array (gem_inertial_state.gyro_bias, 0),
200 vec_array (gem_inertial_state.gyro_bias, 1),
201 vec_array (gem_inertial_state.gyro_bias, 2),
202 vec_array (gem_inertial_state.gyro_bias, 3));
203}
204
205void
206readGem()
207{
208 gemState gem_state;
209 proccessGem (0);
210
211 proccessGem (2);
212
213 readGemPad (0); // This will read buttons from Move
214 switch (newGemPad) {
215 case 1:
216 printf ("Select pressed \n");
217 break;
218
219 case 2:
220 printf ("T pressed value %d\n", newGemAnalogT);
221 printf
222 ("Frame %d center of the sphere in world coordinates %f %f %f %f \n",
223 camread.frame, vec_array (gem_state.pos, 0), vec_array (gem_state.pos,
224 1), vec_array (gem_state.pos, 2), vec_array (gem_state.pos, 3));
225 break;
226
227 case 4:
228 printf ("Move pressed \n");
229 gemCalibrate (0);
230 break;
231
232 case 8:
233 printf ("Start pressed \n");
234 pos_x = 0;
235 pos_y = 0;
236 break;
237
238 case 16:
239 printf ("Triangle pressed \n");
240 getImageState ();
241 break;
242
243 case 32:
244 printf ("Circle pressed \n");
245 break;
246
247 case 64:
248 printf ("Cross pressed \n");
249 printf ("X,Y,Z position (mm) %f %f %f\n", vec_array (gem_state.pos, 0),
250 vec_array (gem_state.pos, 1), vec_array (gem_state.pos, 2));
251 readGemAccPosition (0);
252 break;
253
254 case 128:
255 printf ("Square pressed \n");
256 readGemInertial (0);
257 break;
258
259 default:
260 break;
261 }
262}
263
264void
265getImageState()
266{
267 int ret;
268
269 gemImageState imgState;
270
271 gemGetImageState (0, &imgState);
272 printf (" u [%f]\n", imgState.u);
273 printf (" v [%f]\n", imgState.v);
274 printf (" r [%f]\n", imgState.r);
275 printf (" projectionx [%f]\n", imgState.projectionx);
276 printf (" projectiony [%f]\n", imgState.projectiony);
277 printf (" distance [%f]\n", imgState.distance);
278 printf ("visible=%d r_valid=%d\n", imgState.visible, imgState.r_valid);
279 printf ("tiemestamp=%Ld\n", imgState.frame_time);
280}
281
diff --git a/src/lib/ecore_psl1ght/gemutil.h b/src/lib/ecore_psl1ght/gemutil.h
new file mode 100644
index 0000000000..ce4b544589
--- /dev/null
+++ b/src/lib/ecore_psl1ght/gemutil.h
@@ -0,0 +1,19 @@
1/*
2 * Copyright (C) Antonio José Ramos Márquez (bigboss)
3 * Copyright (C) Youness Alaoui (KaKaRoTo)
4 */
5
6#ifndef __GEMUTIL_H__
7#define __GEMUTIL_H__
8
9#include <ppu-types.h>
10#include <spurs/spurs.h>
11#include <io/camera.h>
12#include <io/move.h>
13
14typedef struct
15{
16 Spurs *spurs;
17} moveContext;
18
19#endif /* __GEMUTIL_H__ */
diff --git a/src/lib/ecore_psl1ght/moveutil.c b/src/lib/ecore_psl1ght/moveutil.c
new file mode 100644
index 0000000000..1dadfbc4b9
--- /dev/null
+++ b/src/lib/ecore_psl1ght/moveutil.c
@@ -0,0 +1,245 @@
1#include <stdio.h>
2#include <io/move.h>
3#include <sys/memory.h>
4#include <ppu-types.h>
5#include <io/camera.h>
6#include <ppu-types.h>
7#include <spurs/spurs.h>
8#include <sys/thread.h>
9#include <sys/systime.h>
10
11#include "spursutil.h"
12#include "moveutil.h"
13
14u16 oldGemPad = 0;
15u16 newGemPad = 0;
16u16 newGemAnalogT = 0;
17
18static void
19endCamera(moveContext *context)
20{
21 cameraStop (0);
22
23 cameraClose (0);
24 cameraEnd ();
25
26 sysMemContainerDestroy (context->camInfo.container);
27}
28
29static int
30initCamera(moveContext *context)
31{
32 int ret;
33
34 context->camInfo.container = NULL;
35
36 ret = cameraInit ();
37 printf ("cameraInit() returned %d\n", ret);
38 if (ret == 0)
39 {
40 cameraType type = CAM_TYPE_UNKNOWN;
41
42 ret = cameraGetType (0, &type);
43 if (ret == 0 && type == CAM_TYPE_PLAYSTATION_EYE)
44 {
45 context->camInfo.format = CAM_FORM_RAW8;
46 context->camInfo.framerate = 60;
47 context->camInfo.resolution = CAM_RESO_VGA;
48 context->camInfo.info_ver = 0x0101;
49 ret = sysMemContainerCreate (&context->camInfo.container, 0x200000);
50 printf ("sysMemContainerCreate() for camera container returned %d\n", ret);
51
52 ret = cameraOpenEx (0, &context->camInfo);
53 switch (ret) {
54 case 0:
55 printf ("Found me an eye, arrr!\n");
56 printf ("cameraOpenEx returned %08X\n", ret);
57 printf ("Video dimensions: %dx%d\n", context->camInfo.width, context->camInfo.height);
58 printf ("Buffer at %08X\n", context->camInfo.buffer);
59 printf ("pbuf0 Buffer at %08X\n", context->camInfo.pbuf[0]);
60 printf ("pbuf0 Buffer at %08X\n", context->camInfo.pbuf[1]);
61 printf ("context->camInfo.info_ver %X\n", context->camInfo.info_ver);
62
63 context->camRead.buffer = context->camInfo.buffer;
64 context->camRead.version = 0x0100;
65 printf ("Setting CameraReadEx %08X buffer to cameraInfoex buffer \n",
66 context->camRead.buffer);
67 break;
68
69 default:
70 printf ("Error %X detected opening PlayStation Eye\n", ret);
71 goto error;
72 }
73 }
74 else {
75 printf ("Device detected is not a PlayStation Eye and this sample need it\n");
76 goto error;
77 }
78 }
79 else {
80 goto error;
81 }
82 return ret;
83
84error:
85 if (context->camInfo.container)
86 sysMemContainerDestroy (context->camInfo.container);
87 return ret;
88}
89
90static int
91readCamera(moveContext *context)
92{
93 int ret;
94
95 ret = cameraReadEx (0, &context->camRead);
96 switch (ret) {
97 case CAMERA_ERRO_NEED_START:
98 cameraReset (0);
99 ret = gemPrepareCamera (128, 0.5);
100 printf ("GemPrepareCamera return %d exposure set to 128 and quality to 0.5 before cameraStart\n",
101 ret);
102 printf ("lets go!! It's time to look your face in Sony Bravia :P\n");
103 ret = cameraStart (0);
104 printf ("cameraStart return %d \n", ret);
105 printf ("*******************************************\n");
106 printf ("* Now make sure you have a Move connected\n");
107 printf ("* and point it towards the camera and press\n");
108 printf ("* the action button to calibrate\n");
109 printf ("*******************************************\n");
110 break;
111
112 case 0:
113 break;
114
115 default:
116 printf ("error %08X ", ret);
117 ret = 1;
118 break;
119 }
120 // printf("despues de start return %d \n",ret);
121 if (ret == 0 && context->camRead.readcount != 0)
122 {
123 return context->camRead.readcount;
124 }
125 else {
126 return 0;
127 }
128}
129
130moveContext *
131initMove()
132{
133 moveContext *context = NULL;
134 Spurs *spurs;
135 gemAttribute gem_attr;
136 int ret;
137 int i;
138
139 spurs = initSpurs ("gem_spurs");
140
141 if (spurs == NULL)
142 goto error;
143
144 printf ("preparing GemAttribute structure with spurs\n");
145
146 gem_attr.version = 2;
147 gem_attr.max = 1;
148 gem_attr.spurs = spurs;
149 gem_attr.memory = NULL;
150 gem_attr.spu_priorities[0] = 1;
151 for (i = 1; i < 8; ++i)
152 gem_attr.spu_priorities[i] = 0;
153
154 printf ("calling GemInit with GemAttribute structure version=%d max_connect=%d spurs=%X\n",
155 gem_attr.version, gem_attr.max, gem_attr.spurs);
156 ret = gemInit (&gem_attr);
157 printf ("return from GemInit %X \n", ret);
158 if (ret)
159 goto error;
160
161 ret = gemPrepareCamera (128, 0.5);
162 printf ("GemPrepareCamera return %d exposure set to 128 and quality to 0.5\n",
163 ret);
164 if (ret)
165 goto error;
166 ret = gemReset (0);
167 printf ("GemReset return %X \n", ret);
168 if (ret)
169 goto error;
170
171 context = (moveContext *)malloc (sizeof (moveContext));
172 context->spurs = spurs;
173 ret = initCamera (context);
174
175 if (ret == 0)
176 return context;
177
178error:
179 if (spurs)
180 endSpurs (spurs);
181 if (context)
182 free (context);
183 return NULL;
184}
185
186void
187endMove(moveContext *context)
188{
189 /* Stop Move */
190 gemEnd ();
191 /* Stop Camera */
192 endCamera (context);
193 /* Stop Spurs */
194 endSpurs (context->spurs);
195
196 free (context);
197}
198
199int
200processMove(moveContext *context)
201{
202 const unsigned int hues[] = { 4 << 24, 4 << 24, 4 << 24, 4 << 24 };
203 int ret = -1;
204
205 if (readCamera (context) > 0)
206 {
207 ret = gemUpdateStart (context->camRead.buffer, context->camRead.timestamp);
208 //printf ("Return from gemUpdateStart %X\n", ret);
209 if (ret == 0)
210 {
211 ret = gemUpdateFinish ();
212 //printf ("Return from gemUpdateFinish %X\n", ret);
213 if (ret == 0)
214 {
215 ret = gemGetState (0, STATE_LATEST_IMAGE_TIME, 0, &context->state);
216 switch (ret) {
217 case 2:
218 gemForceRGB (0, 0.5, 0.5, 0.5);
219 break;
220
221 case 5:
222 gemTrackHues (hues, NULL);
223 break;
224
225 default:
226 break;
227 }
228 }
229 }
230 }
231
232 return ret;
233}
234
235void
236moveGet3DPosition(moveContext *context, float *x, float *y, float *z)
237{
238 if (x)
239 *x = vec_array (context->state.pos, 0);
240 if (y)
241 *y = vec_array (context->state.pos, 1);
242 if (z)
243 *z = vec_array (context->state.pos, 2);
244}
245
diff --git a/src/lib/ecore_psl1ght/moveutil.h b/src/lib/ecore_psl1ght/moveutil.h
new file mode 100644
index 0000000000..bb4b22c09d
--- /dev/null
+++ b/src/lib/ecore_psl1ght/moveutil.h
@@ -0,0 +1,43 @@
1/*
2 * Copyright (C) Antonio José Ramos Márquez (bigboss)
3 * Copyright (C) Youness Alaoui (KaKaRoTo)
4 */
5
6#ifndef __MOVEUTIL_H__
7#define __MOVEUTIL_H__
8
9#include <ppu-types.h>
10#include <spurs/spurs.h>
11#include <io/camera.h>
12#include <io/move.h>
13
14typedef struct
15{
16 Spurs *spurs;
17 cameraInfoEx camInfo;
18 cameraReadInfo camRead;
19 gemState state;
20} moveContext;
21
22static inline float
23vec_array(vec_float4 vec, unsigned int idx)
24{
25 union {
26 vec_float4 vec;
27 float array[4];
28 } v;
29
30 v.vec = vec;
31
32 if (idx > 3)
33 return -1;
34 return v.array[idx];
35}
36
37moveContext *initMove();
38void endMove(moveContext *context);
39void readGemState(moveContext *context);
40int processMove(moveContext *context);
41void moveGet3DPosition(moveContext *context, float *x, float *y, float *z);
42
43#endif /* __MOVEUTIL_H__ */
diff --git a/src/lib/ecore_psl1ght/spursutil.c b/src/lib/ecore_psl1ght/spursutil.c
new file mode 100644
index 0000000000..27b5c1d635
--- /dev/null
+++ b/src/lib/ecore_psl1ght/spursutil.c
@@ -0,0 +1,62 @@
1#include "spursutil.h"
2#include <sys/spu.h>
3
4#define SPURS_DEFAULT_PREFIX_NAME "spursutil"
5
6Spurs *
7initSpurs(const char *prefix_name)
8{
9 Spurs *spurs = NULL;
10 SpursAttribute attributeSpurs;
11 int ret;
12 int i;
13
14 ret = sysSpuInitialize (6, 0);
15 printf ("sysSpuInitialize return %d\n", ret);
16
17 /* initialize spurs */
18 printf ("Initializing spurs\n");
19 spurs = (void *)memalign (SPURS_ALIGN, sizeof (Spurs));
20 printf ("Initializing spurs attribute\n");
21
22 ret = spursAttributeInitialize (&attributeSpurs, 5, 250, 1000, true);
23 if (ret)
24 {
25 printf ("error : spursAttributeInitialize failed %x\n", ret);
26 goto error;
27 }
28
29 printf ("Setting name prefix\n");
30 if (!prefix_name)
31 prefix_name = SPURS_DEFAULT_PREFIX_NAME;
32 ret = spursAttributeSetNamePrefix (&attributeSpurs,
33 prefix_name, strlen (prefix_name));
34 if (ret)
35 {
36 printf ("error : spursAttributeInitialize failed %x\n", ret);
37 goto error;
38 }
39
40 printf ("Initializing with attribute\n");
41 ret = spursInitializeWithAttribute (spurs, &attributeSpurs);
42 if (ret)
43 {
44 printf ("error: spursInitializeWithAttribute failed %x\n", ret);
45 goto error;
46 }
47
48 return spurs;
49
50error:
51 if (spurs)
52 free (spurs);
53 return NULL;
54}
55
56void
57endSpurs(Spurs *spurs)
58{
59 spursFinalize (spurs);
60 free (spurs);
61}
62
diff --git a/src/lib/ecore_psl1ght/spursutil.h b/src/lib/ecore_psl1ght/spursutil.h
new file mode 100644
index 0000000000..0b35030be3
--- /dev/null
+++ b/src/lib/ecore_psl1ght/spursutil.h
@@ -0,0 +1,24 @@
1/*
2 * Copyright (C) Antonio José Ramos Márquez (bigboss)
3 * Copyright (C) Youness Alaoui (KaKaRoTo)
4 */
5
6#ifndef __SPURSUTIL_H__
7#define __SPURSUTIL_H__
8
9#include <ppu-types.h>
10#include <spurs/spurs.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16/* Initialize spurs with a given name prefix (*/
17Spurs *initSpurs(const char *prefix_name);
18void endSpurs(Spurs *spurs);
19
20#ifdef __cplusplus
21}
22#endif
23
24#endif /* __SPURSUTIL_H__ */