From 1aa9c2def8ff694a6ad80135ba65779d4312aa2c Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Sat, 5 Nov 2011 17:49:55 +0000 Subject: [PATCH] Ecore: Add ecore-psl1ght library SVN revision: 64782 --- legacy/ecore/AUTHORS | 1 + legacy/ecore/Makefile.am | 5 + legacy/ecore/configure.ac | 13 + legacy/ecore/ecore-psl1ght.pc.in | 12 + legacy/ecore/src/lib/Makefile.am | 4 + .../src/lib/ecore_psl1ght/Ecore_Psl1ght.h | 124 +++ .../lib/ecore_psl1ght/Ecore_Psl1ght_Keys.h | 78 ++ .../ecore/src/lib/ecore_psl1ght/Makefile.am | 30 + .../src/lib/ecore_psl1ght/ecore_psl1ght.c | 804 ++++++++++++++++++ .../lib/ecore_psl1ght/ecore_psl1ght_private.h | 36 + legacy/ecore/src/lib/ecore_psl1ght/gemutil.c | 281 ++++++ legacy/ecore/src/lib/ecore_psl1ght/gemutil.h | 19 + legacy/ecore/src/lib/ecore_psl1ght/moveutil.c | 245 ++++++ legacy/ecore/src/lib/ecore_psl1ght/moveutil.h | 43 + .../ecore/src/lib/ecore_psl1ght/spursutil.c | 62 ++ .../ecore/src/lib/ecore_psl1ght/spursutil.h | 24 + 16 files changed, 1781 insertions(+) create mode 100644 legacy/ecore/ecore-psl1ght.pc.in create mode 100644 legacy/ecore/src/lib/ecore_psl1ght/Ecore_Psl1ght.h create mode 100644 legacy/ecore/src/lib/ecore_psl1ght/Ecore_Psl1ght_Keys.h create mode 100644 legacy/ecore/src/lib/ecore_psl1ght/Makefile.am create mode 100644 legacy/ecore/src/lib/ecore_psl1ght/ecore_psl1ght.c create mode 100644 legacy/ecore/src/lib/ecore_psl1ght/ecore_psl1ght_private.h create mode 100644 legacy/ecore/src/lib/ecore_psl1ght/gemutil.c create mode 100644 legacy/ecore/src/lib/ecore_psl1ght/gemutil.h create mode 100644 legacy/ecore/src/lib/ecore_psl1ght/moveutil.c create mode 100644 legacy/ecore/src/lib/ecore_psl1ght/moveutil.h create mode 100644 legacy/ecore/src/lib/ecore_psl1ght/spursutil.c create mode 100644 legacy/ecore/src/lib/ecore_psl1ght/spursutil.h diff --git a/legacy/ecore/AUTHORS b/legacy/ecore/AUTHORS index 0ab54f12bf..1a0e372795 100644 --- a/legacy/ecore/AUTHORS +++ b/legacy/ecore/AUTHORS @@ -45,3 +45,4 @@ ChunEon Park xlopez@igalia.com Rafael Antognolli Kim Yunhan +Youness Alaoui diff --git a/legacy/ecore/Makefile.am b/legacy/ecore/Makefile.am index 1e482f0d3f..3de767395c 100644 --- a/legacy/ecore/Makefile.am +++ b/legacy/ecore/Makefile.am @@ -103,6 +103,7 @@ ecore-x.pc.in \ ecore-win32.pc.in \ ecore-sdl.pc.in \ ecore-cocoa.pc.in \ +ecore-psl1ght.pc.in \ ecore-input.pc.in \ ecore-wince.pc.in \ ecore.spec.in \ @@ -185,6 +186,10 @@ if BUILD_ECORE_COCOA pkgconfig_DATA += ecore-cocoa.pc endif +if BUILD_ECORE_PSL1GHT +pkgconfig_DATA += ecore-psl1ght.pc +endif + .PHONY: doc # Documentation diff --git a/legacy/ecore/configure.ac b/legacy/ecore/configure.ac index 69a1a70545..67664db19e 100644 --- a/legacy/ecore/configure.ac +++ b/legacy/ecore/configure.ac @@ -129,6 +129,7 @@ want_ecore_x="no" want_ecore_win32="no" want_ecore_cocoa="no" want_ecore_sdl="no" +want_ecore_psl1ght="no" want_ecore_fb="no" want_ecore_directfb="no" want_ecore_wince="no" @@ -255,6 +256,7 @@ requirements_ecore_input_evas="" requirements_ecore_ipc="" requirements_ecore_cocoa="" requirements_ecore_sdl="" +requirements_ecore_psl1ght="" requirements_ecore_x="" requirements_ecore_win32="" requirements_ecore_wince="" @@ -475,12 +477,14 @@ case "$host_vendor" in PKG_CHECK_MODULES([ESCAPE], [escape]) CFLAGS="$CFLAGS $ESCAPE_CFLAGS" AC_DEFINE(HAVE_ESCAPE, 1, [Set to 1 if Escape library is installed]) + EFL_ECORE_PSL1GHT_BUILD="-DEFL_ECORE_PSL1GHT_BUILD" requirements_ecore="escape ${requirements_ecore}" requirements_ecore_evas="escape ${requirements_ecore_evas}" requirements_ecore_file="escape ${requirements_ecore_file}" requirements_ecore_imf="escape ${requirements_ecore_imf}" requirements_ecore_imf_evas="escape ${requirements_ecore_imf_evas}" requirements_ecore_sdl="escape ${requirements_ecore_sdl}" + want_ecore_psl1ght="yes" ;; esac @@ -496,6 +500,7 @@ AC_SUBST(EFL_ECORE_IPC_BUILD) AC_SUBST(EFL_ECORE_WINCE_BUILD) AC_SUBST(EFL_ECORE_WIN32_BUILD) AC_SUBST(EFL_ECORE_SDL_BUILD) +AC_SUBST(EFL_ECORE_PSL1GHT_BUILD) AM_CONDITIONAL(ECORE_HAVE_WINCE, test "x${have_wince}" = "xyes") AM_CONDITIONAL(ECORE_HAVE_WIN32, test "x${have_win32}" = "xyes") @@ -549,6 +554,7 @@ requirements_ecore_input_evas="ecore >= 1.0.0 eina >= 1.0.0 ${requirements_ecore requirements_ecore_ipc="ecore >= 1.0.0 eina >= 1.0.0 ${requirements_ecore_ipc}" requirements_ecore_cocoa="ecore >= 1.0.0 eina >= 1.0.0 ${requirements_ecore_cocoa}" requirements_ecore_sdl="ecore >= 1.0.0 eina >= 1.0.0 ${requirements_ecore_sdl}" +requirements_ecore_psl1ght="ecore >= 1.0.0 eina >= 1.0.0 ${requirements_ecore_sdl}" requirements_ecore_win32="ecore >= 1.0.0 eina >= 1.0.0 ${requirements_ecore_win32}" requirements_ecore_wince="ecore >= 1.0.0 eina >= 1.0.0 ${requirements_ecore_wince}" requirements_ecore_x="ecore >= 1.0.0 eina >= 1.0.0 ${requirements_ecore_x}" @@ -1579,6 +1585,9 @@ fi ECORE_CHECK_MODULE([sdl], [${want_ecore_sdl}], [Sdl], [${ecore_sdl_deps}], [requirements_ecore_sdl="ecore-input >= 1.0.0 ${requirements_ecore_sdl}"]) +ECORE_CHECK_MODULE([psl1ght], [${want_ecore_psl1ght}], [psl1ght], [${ecore_psl1ght_deps}], + [requirements_ecore_psl1ght="ecore-input >= 1.0.0 ${requirements_ecore_psl1ght}"]) + # ecore_fb ECORE_CHECK_MODULE([fb], [${want_ecore_fb}], [FB], [$have_fb]) @@ -1816,6 +1825,7 @@ AC_SUBST(requirements_ecore_input_evas) AC_SUBST(requirements_ecore_ipc) AC_SUBST(requirements_ecore_cocoa) AC_SUBST(requirements_ecore_sdl) +AC_SUBST(requirements_ecore_psl1ght) AC_SUBST(requirements_ecore_x) AC_SUBST(requirements_ecore_win32) AC_SUBST(requirements_ecore_wince) @@ -1838,6 +1848,7 @@ ecore-input-evas.pc ecore-win32.pc ecore-sdl.pc ecore-cocoa.pc +ecore-psl1ght.pc ecore-wince.pc ecore.pc doc/ecore.dox @@ -1856,6 +1867,7 @@ src/lib/ecore_fb/Makefile src/lib/ecore_file/Makefile src/lib/ecore_cocoa/Makefile src/lib/ecore_sdl/Makefile +src/lib/ecore_psl1ght/Makefile src/lib/ecore_imf/Makefile src/lib/ecore_imf_evas/Makefile src/lib/ecore_input/Makefile @@ -1984,6 +1996,7 @@ if test "x${have_ecore_fb}" = "xyes" ; then fi echo " Ecore_DirectFB...............: $have_ecore_directfb" echo " Ecore_WinCE..................: $have_ecore_wince" +echo " Ecore_PSL1GHT................: $have_ecore_psl1ght" echo echo " Ecore Evas:" diff --git a/legacy/ecore/ecore-psl1ght.pc.in b/legacy/ecore/ecore-psl1ght.pc.in new file mode 100644 index 0000000000..e81f4e8366 --- /dev/null +++ b/legacy/ecore/ecore-psl1ght.pc.in @@ -0,0 +1,12 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: ecore-psl1ght +Description: E core library, PSL1GHT module +@pkgconfig_requires_private@: @requirements_ecore_psl1ght@ +Version: @VERSION@ +Libs: -L${libdir} -lecore_psl1ght +Libs.private: -lio -lsysutil -lgem -lcamera -lspurs +Cflags: -I${includedir}/ecore-@VMAJ@ diff --git a/legacy/ecore/src/lib/Makefile.am b/legacy/ecore/src/lib/Makefile.am index aeee3d8732..b13bc183e9 100644 --- a/legacy/ecore/src/lib/Makefile.am +++ b/legacy/ecore/src/lib/Makefile.am @@ -38,6 +38,10 @@ if BUILD_ECORE_SDL SUBDIRS += ecore_sdl endif +if BUILD_ECORE_PSL1GHT +SUBDIRS += ecore_psl1ght +endif + if BUILD_ECORE_COCOA SUBDIRS += ecore_cocoa endif diff --git a/legacy/ecore/src/lib/ecore_psl1ght/Ecore_Psl1ght.h b/legacy/ecore/src/lib/ecore_psl1ght/Ecore_Psl1ght.h new file mode 100644 index 0000000000..39331f738b --- /dev/null +++ b/legacy/ecore/src/lib/ecore_psl1ght/Ecore_Psl1ght.h @@ -0,0 +1,124 @@ +#ifndef _ECORE_PSL1GHT_H +#define _ECORE_PSL1GHT_H + +#ifdef EAPI +# undef EAPI +#endif + +#ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EAPI __attribute__ ((visibility("default"))) +# else +# define EAPI +# endif +#else +# define EAPI +#endif + +/** + * @file + * @brief Ecore PSL1GHT system functions. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +EAPI extern int ECORE_PSL1GHT_EVENT_KEY_MODIFIERS; +EAPI extern int ECORE_PSL1GHT_EVENT_GOT_FOCUS; +EAPI extern int ECORE_PSL1GHT_EVENT_LOST_FOCUS; +EAPI extern int ECORE_PSL1GHT_EVENT_EXPOSE; + +typedef struct _Ecore_Psl1ght_Event_Key_Modifiers Ecore_Psl1ght_Event_Key_Modifiers; +struct _Ecore_Psl1ght_Event_Key_Modifiers /** PSL1GHT Key Modifier event */ +{ + unsigned int timestamp; + unsigned int modifiers; + int shift_changed : 1; + int shift : 1; + int alt_changed : 1; + int alt : 1; + int ctrl_changed : 1; + int ctrl : 1; + int win_changed : 1; + int win : 1; + int num_lock_changed : 1; + int num_lock : 1; + int caps_lock_changed : 1; + int caps_lock : 1; + int scroll_lock_changed : 1; + int scroll_lock : 1; +}; + +typedef struct _Ecore_Psl1ght_Event_Key_Down Ecore_Psl1ght_Event_Key_Down; +struct _Ecore_Psl1ght_Event_Key_Down /** PSL1GHT Key Down event */ +{ + const char *keyname; /**< The name of the key that was pressed */ + const char *keycompose; /**< The UTF-8 string conversion if any */ + unsigned int time; +}; + +typedef struct _Ecore_Psl1ght_Event_Key_Up Ecore_Psl1ght_Event_Key_Up; +struct _Ecore_Psl1ght_Event_Key_Up /** PSL1GHT Key Up event */ +{ + const char *keyname; /**< The name of the key that was released */ + const char *keycompose; /**< The UTF-8 string conversion if any */ + unsigned int time; +}; + +typedef struct _Ecore_Psl1ght_Event_Mouse_Button_Down Ecore_Psl1ght_Event_Mouse_Button_Down; +struct _Ecore_Psl1ght_Event_Mouse_Button_Down /** PSL1GHT Mouse Down event */ +{ + int button; /**< Mouse button that was pressed (1 - 32) */ + int x; /**< Mouse co-ordinates when mouse button was pressed */ + int y; /**< Mouse co-ordinates when mouse button was pressed */ + int double_click : 1; /**< Set if click was a double click */ + int triple_click : 1; /**< Set if click was a triple click */ + unsigned int time; +}; + +typedef struct _Ecore_Psl1ght_Event_Mouse_Button_Up Ecore_Psl1ght_Event_Mouse_Button_Up; +struct _Ecore_Psl1ght_Event_Mouse_Button_Up /** PSL1GHT Mouse Up event */ +{ + int button; /**< Mouse button that was released (1 - 32) */ + int x; /**< Mouse co-ordinates when mouse button was raised */ + int y; /**< Mouse co-ordinates when mouse button was raised */ + int double_click : 1; /**< Set if click was a double click */ + int triple_click : 1; /**< Set if click was a triple click */ + unsigned int time; +}; + +typedef struct _Ecore_Psl1ght_Event_Mouse_Move Ecore_Psl1ght_Event_Mouse_Move; +struct _Ecore_Psl1ght_Event_Mouse_Move /** PSL1GHT Mouse Move event */ +{ + int x; /**< Mouse co-ordinates where the mouse cursor moved to */ + int y; /**< Mouse co-ordinates where the mouse cursor moved to */ + unsigned int time; +}; + +typedef struct _Ecore_Psl1ght_Event_Mouse_Wheel Ecore_Psl1ght_Event_Mouse_Wheel; +struct _Ecore_Psl1ght_Event_Mouse_Wheel /** PSL1GHT Mouse Wheel event */ +{ + int x, y; + int direction; /* 0 = vertical, 1 = horizontal */ + int wheel; /* value 1 (left/up), -1 (right/down) */ + unsigned int time; +}; + +EAPI int + ecore_psl1ght_init(const char *name); +EAPI int + ecore_psl1ght_shutdown(void); +EAPI void + ecore_psl1ght_resolution_set(int width, int height); +EAPI void + ecore_psl1ght_poll_events(void); + +EAPI void ecore_psl1ght_screen_resolution_get(int *w, int *h); +EAPI void ecore_psl1ght_optimal_screen_resolution_get(int *w, int *h); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/legacy/ecore/src/lib/ecore_psl1ght/Ecore_Psl1ght_Keys.h b/legacy/ecore/src/lib/ecore_psl1ght/Ecore_Psl1ght_Keys.h new file mode 100644 index 0000000000..e385af8a4d --- /dev/null +++ b/legacy/ecore/src/lib/ecore_psl1ght/Ecore_Psl1ght_Keys.h @@ -0,0 +1,78 @@ +#ifndef ECORE_PSL1GHT_KEYS_H__ +# define ECORE_PSL1GHT_KEYS_H__ + +struct _ecore_psl1ght_keys_s +{ + int code; + const char *name; + const char *compose; +}; + +static const struct _ecore_psl1ght_keys_s keystable[] = +{ + { KB_RAWKEY_NO_EVENT, "0x00", "" }, + { KB_RAWKEY_BS, "BackSpace", "\010" }, + { KB_RAWKEY_TAB, "Tab", "\011" }, + { KB_RAWKEY_ENTER, "Return", "\015" }, + { KB_RAWKEY_PAUSE, "Pause", "Pause" }, + { KB_RAWKEY_ESCAPE, "Escape", "\033" }, + { KB_RAWKEY_SPACE, "space", " " }, + + /* Skip uppercase letters */ + { KB_RAWKEY_LEFT_BRACKET_101, "bracketleft", "[" }, + { KB_RAWKEY_BACKSLASH_101, "backslash", "\\" }, + { KB_RAWKEY_RIGHT_BRACKET_101, "bracketright", "]" }, + { KB_RAWKEY_ACCENT_CIRCONFLEX_106, "asciicircumm", "^" }, + { KB_RAWKEY_DELETE, "Delete", "\177" }, + /* End of ASCII mapped keysyms */ + + /* Numeric keypad */ + { KB_RAWKEY_KPAD_0, "KP0", "0" }, + { KB_RAWKEY_KPAD_1, "KP1", "1" }, + { KB_RAWKEY_KPAD_2, "KP2", "2" }, + { KB_RAWKEY_KPAD_3, "KP3", "3" }, + { KB_RAWKEY_KPAD_4, "KP4", "4" }, + { KB_RAWKEY_KPAD_5, "KP5", "5" }, + { KB_RAWKEY_KPAD_6, "KP6", "6" }, + { KB_RAWKEY_KPAD_7, "KP7", "7" }, + { KB_RAWKEY_KPAD_8, "KP8", "8" }, + { KB_RAWKEY_KPAD_9, "KP9", "9" }, + { KB_RAWKEY_KPAD_PERIOD, "period", "." }, + { KB_RAWKEY_KPAD_SLASH, "KP_Divide", "/" }, + { KB_RAWKEY_KPAD_ASTERISK, "KP_Multiply", "*" }, + { KB_RAWKEY_KPAD_MINUS, "KP_Minus", "-" }, + { KB_RAWKEY_KPAD_PLUS, "KP_Plus", "+" }, + { KB_RAWKEY_KPAD_ENTER, "KP_Enter", "\015" }, + + /* Arrows + Home/End pad */ + { KB_RAWKEY_UP_ARROW, "Up", "Up" }, + { KB_RAWKEY_DOWN_ARROW, "Down", "Down" }, + { KB_RAWKEY_RIGHT_ARROW, "Right", "Right" }, + { KB_RAWKEY_LEFT_ARROW, "Left", "Left" }, + { KB_RAWKEY_INSERT, "Insert", "Insert" }, + { KB_RAWKEY_HOME, "Home", "Home" }, + { KB_RAWKEY_END, "End", "End" }, + { KB_RAWKEY_PAGE_UP, "Page_Up", "Page_Up" }, + { KB_RAWKEY_PAGE_DOWN, "Page_Down", "Page_Down" }, + + /* Function keys */ + { KB_RAWKEY_F1, "F1", "F1" }, + { KB_RAWKEY_F2, "F2", "F2" }, + { KB_RAWKEY_F3, "F3", "F3" }, + { KB_RAWKEY_F4, "F4", "F4" }, + { KB_RAWKEY_F5, "F5", "F5" }, + { KB_RAWKEY_F6, "F6", "F6" }, + { KB_RAWKEY_F7, "F7", "F7" }, + { KB_RAWKEY_F8, "F8", "F8" }, + { KB_RAWKEY_F9, "F9", "F9" }, + { KB_RAWKEY_F10, "F10", "F10" }, + { KB_RAWKEY_F11, "F11", "F11" }, + { KB_RAWKEY_F12, "F12", "F12" }, + + /* Key state modifier keys */ + { KB_RAWKEY_KPAD_NUMLOCK, "Num_Lock", "Num_Lock" }, + { KB_RAWKEY_CAPS_LOCK, "Caps_Lock", "Caps_Lock" }, + { KB_RAWKEY_SCROLL_LOCK, "Scroll_Lock", "Scroll_Lock" }, +}; + +#endif /* ECORE_PSL1GHT_KEYS_H__ */ diff --git a/legacy/ecore/src/lib/ecore_psl1ght/Makefile.am b/legacy/ecore/src/lib/ecore_psl1ght/Makefile.am new file mode 100644 index 0000000000..8e7328a544 --- /dev/null +++ b/legacy/ecore/src/lib/ecore_psl1ght/Makefile.am @@ -0,0 +1,30 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CPPFLAGS = \ +-I$(top_srcdir)/src/lib/ecore \ +-I$(top_srcdir)/src/lib/ecore_evas \ +-I$(top_srcdir)/src/lib/ecore_input \ +-I$(top_builddir)/src/lib/ecore \ +-I$(top_builddir)/src/lib/ecore_evas \ +-I$(top_builddir)/src/lib/ecore_input \ +@EFL_ECORE_PSL1GHT_BUILD@ \ +@EVAS_CFLAGS@ \ +@EINA_CFLAGS@ + +lib_LTLIBRARIES = libecore_psl1ght.la +includes_HEADERS = Ecore_Psl1ght.h +includesdir = $(includedir)/ecore-@VMAJ@ + +libecore_psl1ght_la_SOURCES = \ +ecore_psl1ght.c \ +moveutil.c \ +spursutil.c + +libecore_psl1ght_la_LIBADD = \ +$(top_builddir)/src/lib/ecore/libecore.la \ +$(top_builddir)/src/lib/ecore_input/libecore_input.la \ +@EINA_LIBS@ + +libecore_psl1ght_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @release_info@ + +EXTRA_DIST = Ecore_Psl1ght_Keys.h ecore_psl1ght_private.h diff --git a/legacy/ecore/src/lib/ecore_psl1ght/ecore_psl1ght.c b/legacy/ecore/src/lib/ecore_psl1ght/ecore_psl1ght.c new file mode 100644 index 0000000000..64cef9f350 --- /dev/null +++ b/legacy/ecore/src/lib/ecore_psl1ght/ecore_psl1ght.c @@ -0,0 +1,804 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "moveutil.h" + +#include "Eina.h" +#include "Ecore_Psl1ght.h" +#include "Ecore_Input.h" +#include "Ecore.h" +#include "ecore_psl1ght_private.h" +#include "ecore_private.h" +#include "Ecore_Psl1ght_Keys.h" + +/* Allocate 1MB stack to avoid overflows */ +SYS_PROCESS_PARAM(1001, 0x100000); + +int _ecore_psl1ght_log_dom = -1; + +EAPI int ECORE_PSL1GHT_EVENT_KEY_MODIFIERS = 0; +EAPI int ECORE_PSL1GHT_EVENT_GOT_FOCUS = 0; +EAPI int ECORE_PSL1GHT_EVENT_LOST_FOCUS = 0; +EAPI int ECORE_PSL1GHT_EVENT_EXPOSE = 0; + +static int _ecore_psl1ght_init_count = 0; +static int window_width = 0; +static int window_height = 0; +/* Mouse support */ +static int mouse_connected = FALSE; +static u8 mouse_buttons = 0; +static int mouse_x = 0; +static int mouse_y = 0; +/* Keyboard support */ +static int keyboard_connected = FALSE; +static KbLed keyboard_leds = {{0}}; +static KbMkey keyboard_mods = {{0}}; +static u16 keyboard_old_key = 0; +/* Pad support */ +static padData pad_data; +static int pad_old_x = 0; +static int pad_old_o = 0; +/* Move support */ +static int move_connected = FALSE; +static moveContext *move_context = NULL; +u16 move_buttons = 0; + +static void xmb_event_handler(u64 status, u64 param, void *user_data); + +/** + * @defgroup Ecore_Psl1ght_Library_Group PSL1GHT Library Functions + * + * Functions used to set up and shut down the Ecore_Psl1ght functions. + */ + +/** + * Sets up the Ecore_Psl1ght library. + * @param name device target name + * @return @c 0 on failure. Otherwise, the number of times the library has + * been initialised without being shut down. + * @ingroup Ecore_PSL1GHT_Library_Group + */ +EAPI int +ecore_psl1ght_init(const char *name __UNUSED__) +{ + videoState state; + videoResolution resolution; + int ret, camera_loaded, gem_loaded; + + if (++_ecore_psl1ght_init_count != 1) + return _ecore_psl1ght_init_count; + _ecore_psl1ght_log_dom = eina_log_domain_register + ("ecore_psl1ght", ECORE_PSL1GHT_DEFAULT_LOG_COLOR); + if (_ecore_psl1ght_log_dom < 0) + { + EINA_LOG_ERR("Impossible to create a log domain for the Ecore PSL1GHT module."); + return --_ecore_psl1ght_init_count; + } + if (!ecore_event_init()) + { + eina_log_domain_unregister(_ecore_psl1ght_log_dom); + _ecore_psl1ght_log_dom = -1; + return --_ecore_psl1ght_init_count; + } + + if (videoGetState (0, 0, &state) == 0 && + videoGetResolution (state.displayMode.resolution, &resolution) == 0) + { + ecore_psl1ght_resolution_set (resolution.width, resolution.height); + } + else + { + ecore_event_shutdown(); + eina_log_domain_unregister(_ecore_psl1ght_log_dom); + _ecore_psl1ght_log_dom = -1; + return --_ecore_psl1ght_init_count; + } + + /* Pad support */ + ioPadInit (7); + /* Mouse support */ + ioMouseInit(2); + mouse_buttons = 0; + mouse_x = 0; + mouse_y = 0; + + /* Keyboard support */ + ioKbInit(2); + keyboard_leds._KbLedU.leds = 0; + keyboard_mods._KbMkeyU.mkeys = 0; + + /* Initialize Move */ + move_context = NULL; + move_buttons = 0; + + camera_loaded = !sysModuleIsLoaded (SYSMODULE_CAMERA); + if (!camera_loaded) + ret = sysModuleLoad (SYSMODULE_CAMERA); + else + ret = 0; + if (ret == 0) + { + gem_loaded = !sysModuleIsLoaded (SYSMODULE_GEM); + if (!gem_loaded) + ret = sysModuleLoad (SYSMODULE_GEM); + if (ret == 0) + { + move_context = initMove (); + } + else { + if (gem_loaded) + sysModuleUnload (SYSMODULE_CAMERA); + } + } + + sysUtilRegisterCallback (SYSUTIL_EVENT_SLOT0, xmb_event_handler, NULL); + + ECORE_PSL1GHT_EVENT_GOT_FOCUS = ecore_event_type_new(); + ECORE_PSL1GHT_EVENT_LOST_FOCUS = ecore_event_type_new(); + ECORE_PSL1GHT_EVENT_EXPOSE = ecore_event_type_new(); + ECORE_PSL1GHT_EVENT_KEY_MODIFIERS = ecore_event_type_new(); + + mouse_x = 0; + mouse_y = 0; + + return _ecore_psl1ght_init_count; +} + +/** + * Shuts down the Ecore_Psl1ght library. + * @return @c The number of times the system has been initialised without + * being shut down. + * @ingroup Ecore_PSL1GHT_Library_Group + */ +EAPI int +ecore_psl1ght_shutdown(void) +{ + if (--_ecore_psl1ght_init_count != 0) + return _ecore_psl1ght_init_count; + + ecore_event_shutdown(); + eina_log_domain_unregister(_ecore_psl1ght_log_dom); + _ecore_psl1ght_log_dom = -1; + + ECORE_PSL1GHT_EVENT_GOT_FOCUS = 0; + ECORE_PSL1GHT_EVENT_LOST_FOCUS = 0; + ECORE_PSL1GHT_EVENT_EXPOSE = 0; + ECORE_PSL1GHT_EVENT_KEY_MODIFIERS = 0; + + ioPadEnd(); + ioMouseEnd(); + ioKbEnd(); + + if (move_context) + { + endMove (move_context); + move_context = NULL; + sysModuleUnload (SYSMODULE_CAMERA); + sysModuleUnload (SYSMODULE_GEM); + } + + sysUtilUnregisterCallback(SYSUTIL_EVENT_SLOT0); + + return _ecore_psl1ght_init_count; +} + +static unsigned int +_ecore_psl1ght_get_time(void) +{ + return (unsigned int)((unsigned long long) + (ecore_time_get() * 1000.0) & 0xffffffff); +} + +static unsigned int +_ecore_psl1ght_get_modifiers(void) +{ + unsigned int modifiers = 0; + + if (keyboard_mods._KbMkeyU._KbMkeyS.r_shift || + keyboard_mods._KbMkeyU._KbMkeyS.l_shift) + modifiers |= ECORE_EVENT_MODIFIER_SHIFT; + if (keyboard_mods._KbMkeyU._KbMkeyS.r_ctrl || + keyboard_mods._KbMkeyU._KbMkeyS.l_ctrl) + modifiers |= ECORE_EVENT_MODIFIER_CTRL; + if (keyboard_mods._KbMkeyU._KbMkeyS.r_alt || + keyboard_mods._KbMkeyU._KbMkeyS.l_alt) + modifiers |= ECORE_EVENT_MODIFIER_ALT; + if (keyboard_mods._KbMkeyU._KbMkeyS.r_win || + keyboard_mods._KbMkeyU._KbMkeyS.l_win) + modifiers |= ECORE_EVENT_MODIFIER_WIN; + + if (keyboard_leds._KbLedU._KbLedS.num_lock) + modifiers |= ECORE_EVENT_LOCK_NUM; + if (keyboard_leds._KbLedU._KbLedS.caps_lock) + modifiers |= ECORE_EVENT_LOCK_CAPS; + if (keyboard_leds._KbLedU._KbLedS.scroll_lock) + modifiers |= ECORE_EVENT_LOCK_SCROLL; + + return modifiers; +} + +static void +_ecore_psl1ght_key_modifiers(KbMkey *mods, KbLed *leds) +{ + Ecore_Psl1ght_Event_Key_Modifiers *ev; + Eina_Bool emit = EINA_FALSE; + + ev = malloc(sizeof(Ecore_Psl1ght_Event_Key_Modifiers)); + if (!ev) return; + + if (mods->_KbMkeyU._KbMkeyS.l_shift != + keyboard_mods._KbMkeyU._KbMkeyS.l_shift || + mods->_KbMkeyU._KbMkeyS.r_shift != + keyboard_mods._KbMkeyU._KbMkeyS.r_shift) + { + emit = EINA_TRUE; + ev->shift_changed = EINA_TRUE; + ev->shift = mods->_KbMkeyU._KbMkeyS.r_shift | + mods->_KbMkeyU._KbMkeyS.l_shift; + } + if (mods->_KbMkeyU._KbMkeyS.l_ctrl != + keyboard_mods._KbMkeyU._KbMkeyS.l_ctrl || + mods->_KbMkeyU._KbMkeyS.r_ctrl != + keyboard_mods._KbMkeyU._KbMkeyS.r_ctrl) + { + emit = EINA_TRUE; + ev->ctrl_changed = EINA_TRUE; + ev->ctrl = mods->_KbMkeyU._KbMkeyS.r_ctrl | + mods->_KbMkeyU._KbMkeyS.l_ctrl; + } + if (mods->_KbMkeyU._KbMkeyS.l_alt != + keyboard_mods._KbMkeyU._KbMkeyS.l_alt || + mods->_KbMkeyU._KbMkeyS.r_alt != + keyboard_mods._KbMkeyU._KbMkeyS.r_alt) + { + emit = EINA_TRUE; + ev->alt_changed = EINA_TRUE; + ev->alt = mods->_KbMkeyU._KbMkeyS.r_alt | + mods->_KbMkeyU._KbMkeyS.l_alt; + } + if (mods->_KbMkeyU._KbMkeyS.l_win != + keyboard_mods._KbMkeyU._KbMkeyS.l_win || + mods->_KbMkeyU._KbMkeyS.r_win != + keyboard_mods._KbMkeyU._KbMkeyS.r_win) + { + emit = EINA_TRUE; + ev->win_changed = EINA_TRUE; + ev->win = mods->_KbMkeyU._KbMkeyS.r_win | + mods->_KbMkeyU._KbMkeyS.l_win; + } + keyboard_mods = *mods; + + if (leds->_KbLedU._KbLedS.num_lock != + keyboard_leds._KbLedU._KbLedS.num_lock) + { + emit = EINA_TRUE; + ev->num_lock_changed = EINA_TRUE; + ev->num_lock = leds->_KbLedU._KbLedS.num_lock; + } + if (leds->_KbLedU._KbLedS.caps_lock != + keyboard_leds._KbLedU._KbLedS.caps_lock) + { + emit = EINA_TRUE; + ev->caps_lock_changed = EINA_TRUE; + ev->caps_lock = leds->_KbLedU._KbLedS.caps_lock; + } + if (leds->_KbLedU._KbLedS.scroll_lock != + keyboard_leds._KbLedU._KbLedS.scroll_lock) + { + emit = EINA_TRUE; + ev->scroll_lock_changed = EINA_TRUE; + ev->scroll_lock = leds->_KbLedU._KbLedS.scroll_lock; + } + keyboard_leds = *leds; + + if (emit) + { + ev->timestamp = _ecore_psl1ght_get_time (); + ev->modifiers = _ecore_psl1ght_get_modifiers(); + ecore_event_add(ECORE_PSL1GHT_EVENT_KEY_MODIFIERS, ev, NULL, NULL); + } + else + { + free(ev); + } +} + +static void +unicodeToUtf8(u16 w, char *utf8buf) +{ + unsigned char *utf8s = (unsigned char *)utf8buf; + + if ( w < 0x0080 ) + { + utf8s[0] = ( unsigned char )w; + utf8s[1] = 0; + } + else if ( w < 0x0800 ) + { + utf8s[0] = 0xc0 | ((w) >> 6); + utf8s[1] = 0x80 | ((w) & 0x3f); + utf8s[2] = 0; + } + else { + utf8s[0] = 0xe0 | ((w) >> 12); + utf8s[1] = 0x80 | (((w) >> 6) & 0x3f); + utf8s[2] = 0x80 | ((w) & 0x3f); + utf8s[3] = 0; + } +} + +static Ecore_Event_Key * +_ecore_psl1ght_event_key(u16 key) +{ + Ecore_Event_Key *ev; + char utf8[4]; + u16 utf16; + unsigned int i; + + ev = malloc(sizeof(Ecore_Event_Key)); + if (!ev) return NULL; + + ev->timestamp = _ecore_psl1ght_get_time (); + ev->window = 0; + ev->event_window = 0; + ev->modifiers = _ecore_psl1ght_get_modifiers(); + + printf ("Key is %X\n", key); + key &= ~KB_KEYPAD; + for (i = 0; i < sizeof(keystable) / sizeof(struct _ecore_psl1ght_keys_s); ++i) + if (keystable[i].code == key) + { + ev->keyname = keystable[i].name; + ev->key = keystable[i].name; + ev->string = keystable[i].compose; + ev->compose = keystable[i].compose; + + printf ("Found key '%s' in the table\n", ev->keyname); + return ev; + } + + utf16 = ioKbCnvRawCode (KB_MAPPING_101, keyboard_mods, keyboard_leds, key); + unicodeToUtf8(utf16, utf8); + printf ("Converting to utf16 : %X - utf8 : %s\n", utf16, utf8); + ev->keyname = ev->key = ev->string = ev->compose = strdup (utf8); + + return ev; +} + +static void +_ecore_psl1ght_mouse_move(s32 x_axis, s32 y_axis) +{ + Ecore_Event_Mouse_Move *ev; + + ev = malloc(sizeof(Ecore_Event_Mouse_Move)); + if (!ev) return; + + mouse_x += x_axis; + mouse_y += y_axis; + if (mouse_x < 0) mouse_x = 0; + if (mouse_y < 0) mouse_y = 0; + if (mouse_x > window_width) mouse_x = window_width; + if (mouse_y > window_height) mouse_y = window_height; + + ev->window = 0; + ev->root_window = 0; + ev->event_window = 0; + ev->same_screen = 0; + ev->timestamp = _ecore_psl1ght_get_time (); + ev->modifiers = _ecore_psl1ght_get_modifiers (); + ev->x = ev->root.x = mouse_x; + ev->y = ev->root.x = mouse_y; + + ev->multi.device = 0; + ev->multi.radius = ev->multi.radius_x = ev->multi.radius_y = 0; + ev->multi.pressure = ev->multi.angle = 0; + ev->multi.x = ev->multi.y = ev->multi.root.x = ev->multi.root.y = 0; + + ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL); +} + +static void +_ecore_psl1ght_mouse_button(int button, int pressed) +{ + Ecore_Event_Mouse_Button *ev; + static unsigned int previous_timestamp = 0; + + ev = malloc(sizeof(Ecore_Event_Mouse_Button)); + if (!ev) return; + + ev->window = 0; + ev->root_window = 0; + ev->event_window = 0; + ev->same_screen = 0; + ev->timestamp = _ecore_psl1ght_get_time (); + ev->modifiers = _ecore_psl1ght_get_modifiers (); + ev->buttons = button; + if (ev->timestamp - previous_timestamp <= 500) + ev->double_click = 1; + ev->triple_click = 0; + previous_timestamp = ev->timestamp; + + ev->x = ev->root.x = mouse_x; + ev->y = ev->root.y = mouse_y; + ev->multi.device = 0; + ev->multi.radius = ev->multi.radius_x = ev->multi.radius_y = 0; + ev->multi.pressure = ev->multi.angle = 0; + ev->multi.x = ev->multi.y = ev->multi.root.x = ev->multi.root.y = 0; + + if (pressed) + ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL); + else + ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL); +} + +static void +_ecore_psl1ght_mouse_wheel(s8 wheel, s8 tilt) +{ + Ecore_Event_Mouse_Wheel *ev; + + ev = malloc(sizeof(Ecore_Event_Mouse_Wheel)); + if (!ev) return; + + ev->timestamp = _ecore_psl1ght_get_time (); + ev->window = 0; + ev->event_window = 0; + ev->modifiers = _ecore_psl1ght_get_modifiers (); + ev->direction = 0; + ev->z = wheel; + + ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL); +} + +#define PAD_STICK_DEADZONE 0x20 + +static void +_ecore_psl1ght_poll_joypad(void) +{ + padInfo padinfo; + int i; + + /**/ + /* Check mouse events */ + ioPadGetInfo (&padinfo); + + for (i = 0; i < 4; i++) /* Ignore the move */ + { + if (padinfo.status[i]) + { + int analog_h, analog_v; + + if (ioPadGetData (i, &pad_data) != 0) + continue; + analog_h = pad_data.ANA_L_H - 0x80; + analog_v = pad_data.ANA_L_V - 0x80; + + if (analog_h > PAD_STICK_DEADZONE) + analog_h -= PAD_STICK_DEADZONE; + else if (analog_h < -PAD_STICK_DEADZONE) + analog_h += PAD_STICK_DEADZONE; + else + analog_h = 0; + analog_h /= 10; + + if (analog_v > PAD_STICK_DEADZONE) + analog_v -= PAD_STICK_DEADZONE; + else if (analog_v < -PAD_STICK_DEADZONE) + analog_v += PAD_STICK_DEADZONE; + else + analog_v = 0; + analog_v /= 10; + + if (analog_h != 0 || analog_v != 0) + _ecore_psl1ght_mouse_move (analog_h, analog_v); + + if (pad_old_x != pad_data.BTN_CROSS) + _ecore_psl1ght_mouse_button (1, pad_data.BTN_CROSS); + if (pad_old_o != pad_data.BTN_CIRCLE) + _ecore_psl1ght_mouse_button (3, pad_data.BTN_CIRCLE); + + pad_old_x = pad_data.BTN_CROSS; + pad_old_o = pad_data.BTN_CIRCLE; + + //pad_buttons = paddata.buttons; + } + } +} + +static void +_ecore_psl1ght_poll_mouse(void) +{ + mouseInfo mouseinfo; + u32 i; + + /**/ + /* Check mouse events */ + ioMouseGetInfo(&mouseinfo); + + if (mouseinfo.status[0] == 1 && !mouse_connected) // Connected + { + mouse_connected = TRUE; + mouse_buttons = 0; + + // Old events in the queue are discarded + ioMouseClearBuf(0); + } + else if (mouseinfo.status[0] != 1 && mouse_connected) // Disconnected + { + mouse_connected = FALSE; + mouse_buttons = 0; + } + + if (mouse_connected) + { + mouseDataList datalist; + + ioMouseGetDataList(0, &datalist); + + for (i = 0; i < datalist.count; i++) + { + u8 old_left = mouse_buttons & 1; + u8 new_left = datalist.list[i].buttons & 1; + u8 old_right = mouse_buttons & 2; + u8 new_right = datalist.list[i].buttons & 2; + u8 old_middle = mouse_buttons & 4; + u8 new_middle = datalist.list[i].buttons & 4; + + if (datalist.list[i].x_axis != 0 || + datalist.list[i].y_axis != 0) + _ecore_psl1ght_mouse_move (datalist.list[i].x_axis, + datalist.list[i].y_axis); + + if (old_left != new_left) + _ecore_psl1ght_mouse_button (1, new_left); + if (old_middle != new_middle) + _ecore_psl1ght_mouse_button (2, new_middle); + if (old_right != new_right) + _ecore_psl1ght_mouse_button (3, new_right); + + if (datalist.list[i].wheel != 0) + _ecore_psl1ght_mouse_wheel (datalist.list[i].wheel, + datalist.list[i].tilt); + + mouse_buttons = datalist.list[i].buttons; + } + } +} + +static void +_ecore_psl1ght_poll_move(void) +{ + int i; + u16 new_buttons; + static int t_pressed = 0; + static int calibrated = 0; + static float prev_x = 0; + static float prev_y = 0; + static int gyro = 0; + float x, y, z; + + /* Check move events */ + processMove (move_context); + new_buttons = move_context->state.paddata.buttons & (~move_buttons); + move_buttons = move_context->state.paddata.buttons; + + moveGet3DPosition (move_context, &x, &y, &z); + //printf ("Move 3D position is : %f, %f, %f\n", x,y,z); + + switch (new_buttons) { + case 1: + gyro = !gyro; + break; + + case 4: + // Move button + printf ("Calibrating\n"); + gemCalibrate (0); + calibrated = 1; + break; + + case 8: + // start button + _ecore_psl1ght_mouse_move ((window_width / 2) - mouse_x, (window_height / 2) - mouse_y); + break; + } + + if (calibrated) + { + float x_axis, y_axis; + + if (gyro) + { + gemInertialState gem_inert; + + gemGetInertialState (0, 0, 0, &gem_inert); + x_axis = -vec_array (gem_inert.gyro, 1) * 25; + y_axis = -vec_array (gem_inert.gyro, 0) * 25; + if (abs (x_axis) > 2 || abs (y_axis) > 2) + _ecore_psl1ght_mouse_move (x_axis, y_axis); + } + else { + x_axis = (x - prev_x) * 2.5; + y_axis = -(y - prev_y) * 2.5; + prev_x = x; + prev_y = y; + _ecore_psl1ght_mouse_move (x_axis, y_axis); + } + + if (!t_pressed && (move_buttons & 0x2)) + _ecore_psl1ght_mouse_button (1, 1); + else if (t_pressed && (move_buttons & 0x2) == 0) + _ecore_psl1ght_mouse_button (1, 0); + t_pressed = move_buttons & 0x2; + } +} + +static void +_ecore_psl1ght_poll_keyboard(void) +{ + KbInfo kbInfo; + int i; + + /* Check keyboard events */ + ioKbGetInfo(&kbInfo); + + if (kbInfo.status[0] == 1 && !keyboard_connected) + { + /* Connected */ + keyboard_connected = true; + + // Old events in the queue are discarded + ioKbClearBuf(0); + keyboard_leds._KbLedU.leds = 0; + keyboard_mods._KbMkeyU.mkeys = 0; + keyboard_old_key = 0; + + // Set raw keyboard code types to get scan codes + ioKbSetCodeType(0, KB_CODETYPE_RAW); + ioKbSetReadMode(0, KB_RMODE_INPUTCHAR); + } + else if (kbInfo.status[0] != 1 && keyboard_connected) + { + /* Disconnected keyboard */ + keyboard_connected = FALSE; + } + + if (keyboard_connected) + { + KbData Keys; + + // Read data from the keyboard buffer + if (ioKbRead(0, &Keys) == 0 && Keys.nb_keycode > 0) + { + Ecore_Event_Key *ev = NULL; + + _ecore_psl1ght_key_modifiers (&Keys.mkey, &Keys.led); + + if (Keys.nb_keycode == 0 && keyboard_old_key != 0) + { + ev = _ecore_psl1ght_event_key (keyboard_old_key); + if (ev) ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL); + } + for (i = 0; i < Keys.nb_keycode; i++) + { + if (Keys.keycode[i] != keyboard_old_key) + { + if (Keys.keycode[i] != 0) + { + ev = _ecore_psl1ght_event_key (Keys.keycode[i]); + if (ev) + ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, + NULL, NULL); + } + else + { + ev = _ecore_psl1ght_event_key (keyboard_old_key); + if (ev) + ecore_event_add(ECORE_EVENT_KEY_UP, ev, + NULL, NULL); + } + keyboard_old_key = Keys.keycode[0]; + } + } + } + } +} + +static void +xmb_event_handler(u64 status, u64 param, void *user_data) +{ + printf ("Received event %lX\n", status); + if (status == SYSUTIL_EXIT_GAME) + { + ecore_main_loop_quit(); + } + else if (status == SYSUTIL_MENU_OPEN) + { + } + else if (status == SYSUTIL_MENU_CLOSE) + { + } + else if (status == SYSUTIL_DRAW_BEGIN) + { + } + else if (status == SYSUTIL_DRAW_END) + { + } +} + +EAPI void +ecore_psl1ght_poll_events(void) +{ + _ecore_psl1ght_poll_joypad (); + _ecore_psl1ght_poll_mouse (); + if (move_context) + _ecore_psl1ght_poll_move (); + _ecore_psl1ght_poll_keyboard (); + + sysUtilCheckCallback (); +} + +EAPI void +ecore_psl1ght_resolution_set(int width, int height) +{ + window_width = width; + window_height = height; + if (mouse_x > window_width) mouse_x = window_width; + if (mouse_y > window_height) mouse_y = window_height; +} + +EAPI void +ecore_psl1ght_screen_resolution_get(int *w, int *h) +{ + videoState state; + videoResolution resolution; + + /* Get the state of the display */ + if (videoGetState (0, 0, &state) == 0 && + videoGetResolution (state.displayMode.resolution, &resolution) == 0) + { + if (w) *w = resolution.width; + if (h) *h = resolution.height; + } + else { + if (w) *w = 0; + if (h) *h = 0; + } +} + +EAPI void +ecore_psl1ght_optimal_screen_resolution_get(int *w, int *h) +{ + videoDeviceInfo info; + videoResolution res; + int area = 720 * 480; + int mode_area; + int i; + + if (w) *w = 720; + if (h) *h = 480; + + videoGetDeviceInfo(0, 0, &info); + + for (i = 0; i < info.availableModeCount; i++) { + videoGetResolution (info.availableModes[i].resolution, &res); + mode_area = res.width * res.height; + if (mode_area > area) + { + area = mode_area; + if (w) *w = res.width; + if (h) *h = res.height; + } + } +} + diff --git a/legacy/ecore/src/lib/ecore_psl1ght/ecore_psl1ght_private.h b/legacy/ecore/src/lib/ecore_psl1ght/ecore_psl1ght_private.h new file mode 100644 index 0000000000..bd5a86e2bb --- /dev/null +++ b/legacy/ecore/src/lib/ecore_psl1ght/ecore_psl1ght_private.h @@ -0,0 +1,36 @@ +#ifndef _ECORE_PSL1GHT_PRIVATE_H +# define _ECORE_PSL1GHT_PRIVATE_H + +extern int _ecore_psl1ght_log_dom; + +# ifdef ECORE_PSL1GHT_DEFAULT_LOG_COLOR +# undef ECORE_PSL1GHT_DEFAULT_LOG_COLOR +# endif +# define ECORE_PSL1GHT_DEFAULT_LOG_COLOR EINA_COLOR_BLUE + +# ifdef ERR +# undef ERR +# endif +# define ERR(...) EINA_LOG_DOM_ERR(_ecore_psl1ght_log_dom, __VA_ARGS__) + +# ifdef DBG +# undef DBG +# endif +# define DBG(...) EINA_LOG_DOM_DBG(_ecore_psl1ght_log_dom, __VA_ARGS__) + +# ifdef INF +# undef INF +# endif +# define INF(...) EINA_LOG_DOM_INFO(_ecore_psl1ght_log_dom, __VA_ARGS__) + +# ifdef WRN +# undef WRN +# endif +# define WRN(...) EINA_LOG_DOM_WARN(_ecore_psl1ght_log_dom, __VA_ARGS__) + +# ifdef CRIT +# undef CRIT +# endif +# define CRIT(...) EINA_LOG_DOM_CRIT(_ecore_psl1ght_log_dom, __VA_ARGS__) + +#endif diff --git a/legacy/ecore/src/lib/ecore_psl1ght/gemutil.c b/legacy/ecore/src/lib/ecore_psl1ght/gemutil.c new file mode 100644 index 0000000000..9ccfc1c861 --- /dev/null +++ b/legacy/ecore/src/lib/ecore_psl1ght/gemutil.c @@ -0,0 +1,281 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SPURS_DEFAULT_PREFIX_NAME "gem_spurs" + +u16 oldGemPad = 0; +u16 newGemPad = 0; +u16 newGemAnalogT = 0; +extern cameraReadInfo camread; + +static inline float +vec_array(vec_float4 vec, unsigned int idx) +{ + union { + vec_float4 vec; + float array[4]; + } v; + + v.vec = vec; + + if (idx > 3) + return -1; + return v.array[idx]; +} + +int +initMove() +{ + Spurs *spurs; + gemAttribute gem_attr; + u8 gem_spu_priorities[8] = { 1, 0, 0, 0, 0, 0, 0, 0 }; + int ret; + int i; + + spurs = initSpurs (NULL); + + if (spurs == NULL) + goto error; + + printf ("preparing GemAttribute structure with spurs\n"); + + initAttributeGem (&gem_attr, 1, NULL, spurs, gem_spu_priorities); + gem_attr->version = 2; + gem_attr->max = 1; + gem_attr->spurs = spurs; + gem_attr->memory = NULL; + gem_attr->spu_priorities[0] = 1; + for (i = 1; i < 8; ++i) + gem_attr->spu_priorities[i] = 0; + + printf ("calling GemInit with GemAttribute structure version=%d max_connect=%d spurs=%X\n", + gem_attr.version, gem_attr.max, gem_attr.spurs); + ret = gemInit (&gem_attr); + printf ("return from GemInit %X \n", ret); + if (ret) + goto error; + + ret = gemPrepareCamera (128, 0.5); + printf ("GemPrepareCamera return %d exposure set to 128 and quality to 0.5\n", + ret); + if (ret) + goto error; + ret = gemReset (0); + printf ("GemReset return %X \n", ret); + if (ret) + goto error; + return ret; + +error: + if (spurs) + endSpurs (spurs); + return NULL; +} + +int +endMove() +{ + endSpurs (spurs); + gemEnd (); + return 0; +} + +int +proccessGem(int t) +{ + int ret; + + switch (t) { + case 0: + + ret = gemUpdateStart (camread.buffer, camread.timestamp); + + if (ret != 0) + { + printf ("Return from gemUpdateStart %X\n", ret); + } + break; + + case 2: + + ret = gemUpdateFinish (); + if (ret != 0) + { + printf ("Return from gemUpdateFinish %X\n", ret); + } + break; + + case 3: + ret = gemConvertVideoFinish (); + if (ret != 0) + { + printf ("Return from gemConvertVideoFinish %X\n", ret); + } + break; + + default: + ret = -1; + break; + } + return ret; +} + +void +readGemPad(int num_gem) +{ + gemState gem_state; + int ret; + unsigned int hues[] = { 4 << 24, 4 << 24, 4 << 24, 4 << 24 }; + ret = gemGetState (0, 0, -22000, &gem_state); + + newGemPad = gem_state.paddata.buttons & (~oldGemPad); + newGemAnalogT = gem_state.paddata.ANA_T; + oldGemPad = gem_state.paddata.buttons; + + switch (ret) { + case 2: + gemForceRGB (num_gem, 0.5, 0.5, 0.5); + break; + + case 5: + + gemTrackHues (hues, NULL); + break; + + default: + break; + } +} + +void +readGemAccPosition(int num_gem) +{ + vec_float4 position; + + gemGetAccelerometerPositionInDevice (num_gem, &position); + + printf (" accelerometer device coordinates [%f,%f,%f,%f]\n", + vec_array (position, 0), vec_array (position, 1), vec_array (position, 2), + vec_array (position, 3)); +} + +void +readGemInertial(int num_gem) +{ + gemInertialState gem_inertial_state; + int ret; + + ret = gemGetInertialState (num_gem, 0, -22000, &gem_inertial_state); + printf ("gemGetInertialState return %X\n", ret); + printf ("counter %d temperature %f\n", gem_inertial_state.counter, + gem_inertial_state.temperature); + + printf (" accelerometer sensor [%f,%f,%f,%f]\n", + vec_array (gem_inertial_state.accelerometer, 0), + vec_array (gem_inertial_state.accelerometer, 1), + vec_array (gem_inertial_state.accelerometer, 2), + vec_array (gem_inertial_state.accelerometer, 3)); + + printf (" accelerometer_bias sensor [%f,%f,%f,%f]\n", + vec_array (gem_inertial_state.accelerometer_bias, 0), + vec_array (gem_inertial_state.accelerometer_bias, 1), + vec_array (gem_inertial_state.accelerometer_bias, 2), + vec_array (gem_inertial_state.accelerometer_bias, 3)); + + printf (" gyro sensor [%f,%f,%f,%f]\n", vec_array (gem_inertial_state.gyro, + 0), vec_array (gem_inertial_state.gyro, 1), + vec_array (gem_inertial_state.gyro, 2), + vec_array (gem_inertial_state.gyro, 3)); + + printf (" gyro_bias sensor [%f,%f,%f,%f]\n", + vec_array (gem_inertial_state.gyro_bias, 0), + vec_array (gem_inertial_state.gyro_bias, 1), + vec_array (gem_inertial_state.gyro_bias, 2), + vec_array (gem_inertial_state.gyro_bias, 3)); +} + +void +readGem() +{ + gemState gem_state; + proccessGem (0); + + proccessGem (2); + + readGemPad (0); // This will read buttons from Move + switch (newGemPad) { + case 1: + printf ("Select pressed \n"); + break; + + case 2: + printf ("T pressed value %d\n", newGemAnalogT); + printf + ("Frame %d center of the sphere in world coordinates %f %f %f %f \n", + camread.frame, vec_array (gem_state.pos, 0), vec_array (gem_state.pos, + 1), vec_array (gem_state.pos, 2), vec_array (gem_state.pos, 3)); + break; + + case 4: + printf ("Move pressed \n"); + gemCalibrate (0); + break; + + case 8: + printf ("Start pressed \n"); + pos_x = 0; + pos_y = 0; + break; + + case 16: + printf ("Triangle pressed \n"); + getImageState (); + break; + + case 32: + printf ("Circle pressed \n"); + break; + + case 64: + printf ("Cross pressed \n"); + printf ("X,Y,Z position (mm) %f %f %f\n", vec_array (gem_state.pos, 0), + vec_array (gem_state.pos, 1), vec_array (gem_state.pos, 2)); + readGemAccPosition (0); + break; + + case 128: + printf ("Square pressed \n"); + readGemInertial (0); + break; + + default: + break; + } +} + +void +getImageState() +{ + int ret; + + gemImageState imgState; + + gemGetImageState (0, &imgState); + printf (" u [%f]\n", imgState.u); + printf (" v [%f]\n", imgState.v); + printf (" r [%f]\n", imgState.r); + printf (" projectionx [%f]\n", imgState.projectionx); + printf (" projectiony [%f]\n", imgState.projectiony); + printf (" distance [%f]\n", imgState.distance); + printf ("visible=%d r_valid=%d\n", imgState.visible, imgState.r_valid); + printf ("tiemestamp=%Ld\n", imgState.frame_time); +} + diff --git a/legacy/ecore/src/lib/ecore_psl1ght/gemutil.h b/legacy/ecore/src/lib/ecore_psl1ght/gemutil.h new file mode 100644 index 0000000000..ce4b544589 --- /dev/null +++ b/legacy/ecore/src/lib/ecore_psl1ght/gemutil.h @@ -0,0 +1,19 @@ +/* + * Copyright (C) Antonio José Ramos Márquez (bigboss) + * Copyright (C) Youness Alaoui (KaKaRoTo) + */ + +#ifndef __GEMUTIL_H__ +#define __GEMUTIL_H__ + +#include +#include +#include +#include + +typedef struct +{ + Spurs *spurs; +} moveContext; + +#endif /* __GEMUTIL_H__ */ diff --git a/legacy/ecore/src/lib/ecore_psl1ght/moveutil.c b/legacy/ecore/src/lib/ecore_psl1ght/moveutil.c new file mode 100644 index 0000000000..1dadfbc4b9 --- /dev/null +++ b/legacy/ecore/src/lib/ecore_psl1ght/moveutil.c @@ -0,0 +1,245 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "spursutil.h" +#include "moveutil.h" + +u16 oldGemPad = 0; +u16 newGemPad = 0; +u16 newGemAnalogT = 0; + +static void +endCamera(moveContext *context) +{ + cameraStop (0); + + cameraClose (0); + cameraEnd (); + + sysMemContainerDestroy (context->camInfo.container); +} + +static int +initCamera(moveContext *context) +{ + int ret; + + context->camInfo.container = NULL; + + ret = cameraInit (); + printf ("cameraInit() returned %d\n", ret); + if (ret == 0) + { + cameraType type = CAM_TYPE_UNKNOWN; + + ret = cameraGetType (0, &type); + if (ret == 0 && type == CAM_TYPE_PLAYSTATION_EYE) + { + context->camInfo.format = CAM_FORM_RAW8; + context->camInfo.framerate = 60; + context->camInfo.resolution = CAM_RESO_VGA; + context->camInfo.info_ver = 0x0101; + ret = sysMemContainerCreate (&context->camInfo.container, 0x200000); + printf ("sysMemContainerCreate() for camera container returned %d\n", ret); + + ret = cameraOpenEx (0, &context->camInfo); + switch (ret) { + case 0: + printf ("Found me an eye, arrr!\n"); + printf ("cameraOpenEx returned %08X\n", ret); + printf ("Video dimensions: %dx%d\n", context->camInfo.width, context->camInfo.height); + printf ("Buffer at %08X\n", context->camInfo.buffer); + printf ("pbuf0 Buffer at %08X\n", context->camInfo.pbuf[0]); + printf ("pbuf0 Buffer at %08X\n", context->camInfo.pbuf[1]); + printf ("context->camInfo.info_ver %X\n", context->camInfo.info_ver); + + context->camRead.buffer = context->camInfo.buffer; + context->camRead.version = 0x0100; + printf ("Setting CameraReadEx %08X buffer to cameraInfoex buffer \n", + context->camRead.buffer); + break; + + default: + printf ("Error %X detected opening PlayStation Eye\n", ret); + goto error; + } + } + else { + printf ("Device detected is not a PlayStation Eye and this sample need it\n"); + goto error; + } + } + else { + goto error; + } + return ret; + +error: + if (context->camInfo.container) + sysMemContainerDestroy (context->camInfo.container); + return ret; +} + +static int +readCamera(moveContext *context) +{ + int ret; + + ret = cameraReadEx (0, &context->camRead); + switch (ret) { + case CAMERA_ERRO_NEED_START: + cameraReset (0); + ret = gemPrepareCamera (128, 0.5); + printf ("GemPrepareCamera return %d exposure set to 128 and quality to 0.5 before cameraStart\n", + ret); + printf ("lets go!! It's time to look your face in Sony Bravia :P\n"); + ret = cameraStart (0); + printf ("cameraStart return %d \n", ret); + printf ("*******************************************\n"); + printf ("* Now make sure you have a Move connected\n"); + printf ("* and point it towards the camera and press\n"); + printf ("* the action button to calibrate\n"); + printf ("*******************************************\n"); + break; + + case 0: + break; + + default: + printf ("error %08X ", ret); + ret = 1; + break; + } + // printf("despues de start return %d \n",ret); + if (ret == 0 && context->camRead.readcount != 0) + { + return context->camRead.readcount; + } + else { + return 0; + } +} + +moveContext * +initMove() +{ + moveContext *context = NULL; + Spurs *spurs; + gemAttribute gem_attr; + int ret; + int i; + + spurs = initSpurs ("gem_spurs"); + + if (spurs == NULL) + goto error; + + printf ("preparing GemAttribute structure with spurs\n"); + + gem_attr.version = 2; + gem_attr.max = 1; + gem_attr.spurs = spurs; + gem_attr.memory = NULL; + gem_attr.spu_priorities[0] = 1; + for (i = 1; i < 8; ++i) + gem_attr.spu_priorities[i] = 0; + + printf ("calling GemInit with GemAttribute structure version=%d max_connect=%d spurs=%X\n", + gem_attr.version, gem_attr.max, gem_attr.spurs); + ret = gemInit (&gem_attr); + printf ("return from GemInit %X \n", ret); + if (ret) + goto error; + + ret = gemPrepareCamera (128, 0.5); + printf ("GemPrepareCamera return %d exposure set to 128 and quality to 0.5\n", + ret); + if (ret) + goto error; + ret = gemReset (0); + printf ("GemReset return %X \n", ret); + if (ret) + goto error; + + context = (moveContext *)malloc (sizeof (moveContext)); + context->spurs = spurs; + ret = initCamera (context); + + if (ret == 0) + return context; + +error: + if (spurs) + endSpurs (spurs); + if (context) + free (context); + return NULL; +} + +void +endMove(moveContext *context) +{ + /* Stop Move */ + gemEnd (); + /* Stop Camera */ + endCamera (context); + /* Stop Spurs */ + endSpurs (context->spurs); + + free (context); +} + +int +processMove(moveContext *context) +{ + const unsigned int hues[] = { 4 << 24, 4 << 24, 4 << 24, 4 << 24 }; + int ret = -1; + + if (readCamera (context) > 0) + { + ret = gemUpdateStart (context->camRead.buffer, context->camRead.timestamp); + //printf ("Return from gemUpdateStart %X\n", ret); + if (ret == 0) + { + ret = gemUpdateFinish (); + //printf ("Return from gemUpdateFinish %X\n", ret); + if (ret == 0) + { + ret = gemGetState (0, STATE_LATEST_IMAGE_TIME, 0, &context->state); + switch (ret) { + case 2: + gemForceRGB (0, 0.5, 0.5, 0.5); + break; + + case 5: + gemTrackHues (hues, NULL); + break; + + default: + break; + } + } + } + } + + return ret; +} + +void +moveGet3DPosition(moveContext *context, float *x, float *y, float *z) +{ + if (x) + *x = vec_array (context->state.pos, 0); + if (y) + *y = vec_array (context->state.pos, 1); + if (z) + *z = vec_array (context->state.pos, 2); +} + diff --git a/legacy/ecore/src/lib/ecore_psl1ght/moveutil.h b/legacy/ecore/src/lib/ecore_psl1ght/moveutil.h new file mode 100644 index 0000000000..bb4b22c09d --- /dev/null +++ b/legacy/ecore/src/lib/ecore_psl1ght/moveutil.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) Antonio José Ramos Márquez (bigboss) + * Copyright (C) Youness Alaoui (KaKaRoTo) + */ + +#ifndef __MOVEUTIL_H__ +#define __MOVEUTIL_H__ + +#include +#include +#include +#include + +typedef struct +{ + Spurs *spurs; + cameraInfoEx camInfo; + cameraReadInfo camRead; + gemState state; +} moveContext; + +static inline float +vec_array(vec_float4 vec, unsigned int idx) +{ + union { + vec_float4 vec; + float array[4]; + } v; + + v.vec = vec; + + if (idx > 3) + return -1; + return v.array[idx]; +} + +moveContext *initMove(); +void endMove(moveContext *context); +void readGemState(moveContext *context); +int processMove(moveContext *context); +void moveGet3DPosition(moveContext *context, float *x, float *y, float *z); + +#endif /* __MOVEUTIL_H__ */ diff --git a/legacy/ecore/src/lib/ecore_psl1ght/spursutil.c b/legacy/ecore/src/lib/ecore_psl1ght/spursutil.c new file mode 100644 index 0000000000..27b5c1d635 --- /dev/null +++ b/legacy/ecore/src/lib/ecore_psl1ght/spursutil.c @@ -0,0 +1,62 @@ +#include "spursutil.h" +#include + +#define SPURS_DEFAULT_PREFIX_NAME "spursutil" + +Spurs * +initSpurs(const char *prefix_name) +{ + Spurs *spurs = NULL; + SpursAttribute attributeSpurs; + int ret; + int i; + + ret = sysSpuInitialize (6, 0); + printf ("sysSpuInitialize return %d\n", ret); + + /* initialize spurs */ + printf ("Initializing spurs\n"); + spurs = (void *)memalign (SPURS_ALIGN, sizeof (Spurs)); + printf ("Initializing spurs attribute\n"); + + ret = spursAttributeInitialize (&attributeSpurs, 5, 250, 1000, true); + if (ret) + { + printf ("error : spursAttributeInitialize failed %x\n", ret); + goto error; + } + + printf ("Setting name prefix\n"); + if (!prefix_name) + prefix_name = SPURS_DEFAULT_PREFIX_NAME; + ret = spursAttributeSetNamePrefix (&attributeSpurs, + prefix_name, strlen (prefix_name)); + if (ret) + { + printf ("error : spursAttributeInitialize failed %x\n", ret); + goto error; + } + + printf ("Initializing with attribute\n"); + ret = spursInitializeWithAttribute (spurs, &attributeSpurs); + if (ret) + { + printf ("error: spursInitializeWithAttribute failed %x\n", ret); + goto error; + } + + return spurs; + +error: + if (spurs) + free (spurs); + return NULL; +} + +void +endSpurs(Spurs *spurs) +{ + spursFinalize (spurs); + free (spurs); +} + diff --git a/legacy/ecore/src/lib/ecore_psl1ght/spursutil.h b/legacy/ecore/src/lib/ecore_psl1ght/spursutil.h new file mode 100644 index 0000000000..0b35030be3 --- /dev/null +++ b/legacy/ecore/src/lib/ecore_psl1ght/spursutil.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) Antonio José Ramos Márquez (bigboss) + * Copyright (C) Youness Alaoui (KaKaRoTo) + */ + +#ifndef __SPURSUTIL_H__ +#define __SPURSUTIL_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Initialize spurs with a given name prefix (*/ +Spurs *initSpurs(const char *prefix_name); +void endSpurs(Spurs *spurs); + +#ifdef __cplusplus +} +#endif + +#endif /* __SPURSUTIL_H__ */