diff options
Diffstat (limited to 'libraries/ecore/src/lib/ecore_psl1ght/moveutil.c')
-rw-r--r-- | libraries/ecore/src/lib/ecore_psl1ght/moveutil.c | 245 |
1 files changed, 245 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_psl1ght/moveutil.c b/libraries/ecore/src/lib/ecore_psl1ght/moveutil.c new file mode 100644 index 0000000..1dadfbc --- /dev/null +++ b/libraries/ecore/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 | |||
14 | u16 oldGemPad = 0; | ||
15 | u16 newGemPad = 0; | ||
16 | u16 newGemAnalogT = 0; | ||
17 | |||
18 | static void | ||
19 | endCamera(moveContext *context) | ||
20 | { | ||
21 | cameraStop (0); | ||
22 | |||
23 | cameraClose (0); | ||
24 | cameraEnd (); | ||
25 | |||
26 | sysMemContainerDestroy (context->camInfo.container); | ||
27 | } | ||
28 | |||
29 | static int | ||
30 | initCamera(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 | |||
84 | error: | ||
85 | if (context->camInfo.container) | ||
86 | sysMemContainerDestroy (context->camInfo.container); | ||
87 | return ret; | ||
88 | } | ||
89 | |||
90 | static int | ||
91 | readCamera(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 | |||
130 | moveContext * | ||
131 | initMove() | ||
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 | |||
178 | error: | ||
179 | if (spurs) | ||
180 | endSpurs (spurs); | ||
181 | if (context) | ||
182 | free (context); | ||
183 | return NULL; | ||
184 | } | ||
185 | |||
186 | void | ||
187 | endMove(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 | |||
199 | int | ||
200 | processMove(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 | |||
235 | void | ||
236 | moveGet3DPosition(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 | |||