3 #include <sys/memory.h>
7 #include <spurs/spurs.h>
8 #include <sys/thread.h>
9 #include <sys/systime.h>
11 #include "spursutil.h"
16 u16 newGemAnalogT = 0;
19 endCamera(moveContext *context)
26 sysMemContainerDestroy (context->camInfo.container);
30 initCamera(moveContext *context)
34 context->camInfo.container = NULL;
37 printf ("cameraInit() returned %d\n", ret);
40 cameraType type = CAM_TYPE_UNKNOWN;
42 ret = cameraGetType (0, &type);
43 if (ret == 0 && type == CAM_TYPE_PLAYSTATION_EYE)
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);
52 ret = cameraOpenEx (0, &context->camInfo);
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);
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);
70 printf ("Error %X detected opening PlayStation Eye\n", ret);
75 printf ("Device detected is not a PlayStation Eye and this sample need it\n");
85 if (context->camInfo.container)
86 sysMemContainerDestroy (context->camInfo.container);
91 readCamera(moveContext *context)
95 ret = cameraReadEx (0, &context->camRead);
97 case CAMERA_ERRO_NEED_START:
99 ret = gemPrepareCamera (128, 0.5);
100 printf ("GemPrepareCamera return %d exposure set to 128 and quality to 0.5 before cameraStart\n",
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");
116 printf ("error %08X ", ret);
120 // printf("despues de start return %d \n",ret);
121 if (ret == 0 && context->camRead.readcount != 0)
123 return context->camRead.readcount;
133 moveContext *context = NULL;
135 gemAttribute gem_attr;
139 spurs = initSpurs ("gem_spurs");
144 printf ("preparing GemAttribute structure with spurs\n");
146 gem_attr.version = 2;
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;
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);
161 ret = gemPrepareCamera (128, 0.5);
162 printf ("GemPrepareCamera return %d exposure set to 128 and quality to 0.5\n",
167 printf ("GemReset return %X \n", ret);
171 context = (moveContext *)malloc (sizeof (moveContext));
172 context->spurs = spurs;
173 ret = initCamera (context);
187 endMove(moveContext *context)
194 endSpurs (context->spurs);
200 processMove(moveContext *context)
202 const unsigned int hues[] = { 4 << 24, 4 << 24, 4 << 24, 4 << 24 };
205 if (readCamera (context) > 0)
207 ret = gemUpdateStart (context->camRead.buffer, context->camRead.timestamp);
208 //printf ("Return from gemUpdateStart %X\n", ret);
211 ret = gemUpdateFinish ();
212 //printf ("Return from gemUpdateFinish %X\n", ret);
215 ret = gemGetState (0, STATE_LATEST_IMAGE_TIME, 0, &context->state);
218 gemForceRGB (0, 0.5, 0.5, 0.5);
222 gemTrackHues (hues, NULL);
236 moveGet3DPosition(moveContext *context, float *x, float *y, float *z)
239 *x = vec_array (context->state.pos, 0);
241 *y = vec_array (context->state.pos, 1);
243 *z = vec_array (context->state.pos, 2);