XBMCMove 1.0
Controlar o XBMC com gestos

callbacks.h

Go to the documentation of this file.
00001 
00013 #include "variaveis.h"
00014 
00018 void pSessao(int msg, int tipo) {
00019     if (tipo == FILME) {
00020         /*Ação para Filmes*/
00021         if (msg != amsg) {
00022             switch (msg) {
00023                 case PAUSE:
00024                     g_pSessionManager->RemoveListener(g_pCircle);
00025                     g_pSessionManager->AddListener(g_pTrackPad);
00026                     break;
00027                 case PLAY:
00028                     printf("case PLAY!\n");
00029                     g_pSessionManager->RemoveListener(g_pSwipeD);
00030                     g_pSessionManager->RemoveListener(g_pTrackPad);
00031                     g_pSessionManager->AddListener(g_pCircle);
00032                     break;
00033                 case END:
00034                 case STOP:
00035                     g_pSessionManager->AddListener(g_pSwipeD);
00036                     g_pSessionManager->AddListener(g_pTrackPad);
00037                     g_pSessionManager->RemoveListener(g_pCircle);
00038                     break;
00039                     //default:
00040                     //    printf("DEFAULT!\n");
00041             }
00042             amsg = msg;
00043         }
00044     }
00045     //-------------------------------------------------
00046     //if (tipo == SPEED) {
00047     /*Ação para quando retroceder ou avançar*/
00048     //    g_pSessionManager->AddListener(g_pTrackPad);
00049     // }
00050 }
00051 
00055 void * retro(void* tid) {
00056     teclar->simular(XK_Down);
00057     sleep(1);
00058     //teclar->simular(XK_p);
00059     pthread_exit(NULL);
00060 }
00061 
00065 void * fast(void* tid) {
00066     teclar->simular(XK_Up);
00067     sleep(1);
00068     //teclar->simular(XK_p);
00069     pthread_exit(NULL);
00070 }
00071 
00075 void XN_CALLBACK_TYPE SessionStart(const XnPoint3D& ptFocus, void *pUserCxt) {
00076     printf("Seção iniciada!\n");
00077     pSessao(msg, tipo);
00078 }
00079 
00083 void XN_CALLBACK_TYPE SessionEnd(void *pUserCxt) {
00084     printf("Seção encerrada!\n");
00085 }
00086 
00091 void XN_CALLBACK_TYPE CircleCB(XnFloat fTimes, XnBool bConfident, const XnVCircle* pCircle, void* pUserCxt) {
00092     if (!gCirculo) {
00093         if (msg != PAUSE) {
00094 
00095             circuloDirecaoAtual = fmod((double) fTimes, 1.0) * 2 * XnVMathCommon::PI;
00096             if (circuloDirecaoAtual < -4) {
00097                 printf("Circulo para esquerda %f\n", circuloDirecaoAtual);
00098                 pthread_create(&threadC, NULL, retro, (void *) tC);
00099                 pthread_join(threadC, NULL); //Aguarda thread ser finalizada corretamente!
00100                 gCirculo = false;
00101 
00102             } else {
00103                 if (circuloDirecaoAtual > 4) {
00104                     printf("Circulo para Direita %f\n", circuloDirecaoAtual);
00105                     pthread_create(&threadC, NULL, fast, (void *) tC);
00106                     pthread_join(threadC, NULL); //Aguarda thread ser finalizada corretamente!
00107                     gCirculo = false;
00108                 }
00109             }
00110             circuloDirecaoAntiga = circuloDirecaoAtual;
00111             //sleep(1);
00112         }
00113     }
00114 }
00115 
00119 void XN_CALLBACK_TYPE NoCircleCB(XnFloat fLastValue, XnVCircleDetector::XnVNoCircleReason reason, void * pUserCxt) {
00120     //printf("Sem Circulo!\n");
00121 }
00122 
00126 void XN_CALLBACK_TYPE Circle_PrimaryCreate(const XnVHandPointContext *cxt, const XnPoint3D& ptFocus, void * pUserCxt) {
00127     //printf("Circulo criado!\n");
00128 }
00129 
00133 void XN_CALLBACK_TYPE Circle_PrimaryDestroy(XnUInt32 nID, void * pUserCxt) {
00134     //printf("Circulo destruido!\n");
00135 }
00136 
00140 void XN_CALLBACK_TYPE OnWaveCB(void* cxt) {
00141     //printf("Tchau!\n");
00142     switch (msg) {
00143         case PAUSE:
00144             teclar->simular(XK_X);
00145             break;
00146         case PLAY:
00147             teclar->simular(XK_space);
00148             break;
00149         default:
00150             teclar->simular(XK_Escape);
00151     }
00152 }
00153 
00157 void XN_CALLBACK_TYPE SwipeLeftCB(XnFloat fVelocity, XnFloat fAngle, void *pUserCxt) {
00158     if ((msg != PAUSE) && (msg != PLAY) && (msg != RESUME)) {
00159         teclar->simular(XK_Left);
00160         sleep(0.5);
00161     }
00162 }
00163 
00167 void XN_CALLBACK_TYPE SwipeRightCB(XnFloat fVelocity, XnFloat fAngle, void *pUserCxt) {
00168     if ((msg != PAUSE) && (msg != PLAY) && (msg != RESUME)) {
00169         teclar->simular(XK_Right);
00170         sleep(0.5);
00171     }
00172 }
00173 
00177 void XN_CALLBACK_TYPE SwipeUpCB(XnFloat fVelocity, XnFloat fAngle, void *pUserCxt) {
00178     if ((msg != PAUSE) && (msg != PLAY) && (msg != RESUME)) {
00179         teclar->simular(XK_Up);
00180         sleep(0.5);
00181     }
00182 
00183 }
00184 
00188 void XN_CALLBACK_TYPE SwipeDownCB(XnFloat fVelocity, XnFloat fAngle, void *pUserCxt) {
00189     if ((msg != PAUSE) && (msg != PLAY) && (msg != RESUME)) {
00190         teclar->simular(XK_Down);
00191         sleep(0.5);
00192     }
00193 }
00194 
00198 void XN_CALLBACK_TYPE Gesture_Recognized(xn::GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pIDPosition, const XnPoint3D* pEndPosition, void* pCookie) {
00199     //printf("Gesto Reconhecido: %s\n", strGesture);
00200 
00201     //if (!strcmp(strGesture, "Click")) {
00202     //    teclar.simular(XK_Return);
00203     //}
00204     //g_GestureGenerator.RemoveGesture(strGesture);
00205     //g_HandsGenerator.StartTracking(*pEndPosition);
00206 }
00207 
00211 void XN_CALLBACK_TYPE Gesture_Process(xn::GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, XnFloat fProgress, void* pCookie) {
00212 }
00213 
00214 
00218 void XN_CALLBACK_TYPE Hand_Create(xn::HandsGenerator& generator, XnUserID nId, const XnPoint3D* pPosition, XnFloat fTime, void* pCookie) {
00219     //printf("New Hand: %d @ (%f,%f,%f)\n", nId, pPosition->X, pPosition->Y, pPosition->Z);
00220 }
00221 
00225 void XN_CALLBACK_TYPE Hand_Update(xn::HandsGenerator& generator, XnUserID nId, const XnPoint3D* pPosition, XnFloat fTime, void* pCookie) {
00226 }
00227 
00231 void XN_CALLBACK_TYPE Hand_Destroy(xn::HandsGenerator& generator, XnUserID nId, XnFloat fTime, void* pCookie) {
00232     //printf("Lost Hand: %d\n", nId);
00233     //g_GestureGenerator.AddGesture(GESTURE_TO_USE, NULL);
00234 }
00235 
00239 void XN_CALLBACK_TYPE TrackPad_ValueChange(XnFloat fXValue, XnFloat fYValue, void* cxt) {
00240     //if(TRUE == g_isPrintValueChange)
00241     //    printf("Value changed: %f, %f\n", fXValue, fYValue);
00242     //g_fXValue = fXValue;
00243     //g_fYValue = fYValue;
00244 }
00245 
00249 void XN_CALLBACK_TYPE TrackPad_ItemHover(XnInt32 nXItem, XnInt32 nYItem, void* cxt) {
00250     //if(TRUE == g_isPrintItemHover)
00251     //  printf("Hover: %d,%d\n", nXItem, nYItem);
00252     //if((TRUE == g_bIsPushed) && (CurrentItem.X != nXItem || CurrentItem.Y != nYItem))
00253     //{
00254     //  g_bIsPushed = FALSE;
00255     //  g_nCurrentFrame = 0;
00256     //}
00257     //CurrentItem.X = nXItem;
00258     //CurrentItem.Y = nYItem;
00259 }
00260 
00264 void XN_CALLBACK_TYPE TrackPad_ItemSelect(XnInt32 nXItem, XnInt32 nYItem, XnVDirection eDir, void* cxt) {
00265     //printf("Select: %d,%d (%s)\n", nXItem, nYItem, XnVDirectionAsString(eDir));
00266     //g_bIsPushed = TRUE;
00267     if (!strcmp(XnVDirectionAsString(eDir), "Forward")) { //Backward
00268         if (msg != PLAY) {
00269             if (msg == PAUSE) {
00270                 printf("[INFO] Retornar a reprodução!\n");
00271                 teclar->simular(XK_p);
00272                 //teclar->simular(XK_Escape);
00273             } else {
00274                 if (tipo == SPEED) {
00275                     teclar->simular(XK_p);
00276                     teclar->simular(XK_Escape);
00277                     gCirculo = false;
00278                 } else {
00279                     printf("[INFO] Enter!\n");
00280                     teclar->simular(XK_Return);
00281                     sleep(0.5);
00282                 }
00283             }
00284         }
00285     }
00286 }
00287 
00291 void XN_CALLBACK_TYPE TrackPad_PrimaryCreate(const XnVHandPointContext* cxt, const XnPoint3D& ptFocus, void* UserCxt) {
00292     //printf("TrackPad input has started!!!, point ID: [%d] ", cxt->nID);
00293     //printf("Starting point position: [%f],[%f],[%f]\n", cxt->ptPosition.X, cxt->ptPosition.Y, cxt->ptPosition.Z);
00294     g_isInputStarted = TRUE;
00295 }
00296 
00300 void XN_CALLBACK_TYPE TrackPad_PrimaryDestroy(XnUInt32 nID, void* UserCxt) {
00301     // printf("TrackPad input has stopped!!!\n");
00302     g_isInputStarted = FALSE;
00303 }
00304 
00308 void XN_CALLBACK_TYPE User_NewUser(xn::UserGenerator& generator, XnUserID nId, void* pCookie) {
00309     printf("[INFO] Novo usuario, ID=%d\n", nId);
00310     // New user found
00311     if (g_bNeedPose) {
00312         g_UserGenerator.GetPoseDetectionCap().StartPoseDetection(g_strPose, nId);
00313     } else {
00314         g_UserGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
00315     }
00316 }
00317 // Callback: An existing user was lost
00318 
00322 void XN_CALLBACK_TYPE User_LostUser(xn::UserGenerator& generator, XnUserID nId, void* pCookie) {
00323     //printf("[INFO] Usuario %d perdido!\n", nId);
00324 }
00325 // Callback: Detected a pose
00326 
00330 void XN_CALLBACK_TYPE UserPose_PoseDetected(xn::PoseDetectionCapability& capability, const XnChar* strPose, XnUserID nId, void* pCookie) {
00331     printf("Pose %s detected for user %d\n", strPose, nId);
00332     g_UserGenerator.GetPoseDetectionCap().StopPoseDetection(nId);
00333     g_UserGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
00334 }
00335 // Callback: Started calibration
00336 
00340 void XN_CALLBACK_TYPE UserCalibration_CalibrationStart(xn::SkeletonCapability& capability, XnUserID nId, void* pCookie) {
00341     //printf("[INFO] Calibração iniciada para o usuario %d!\n", nId);
00342 }
00343 // Callback: Finished calibration
00344 
00348 void XN_CALLBACK_TYPE UserCalibration_CalibrationEnd(xn::SkeletonCapability& capability, XnUserID nId, XnBool bSuccess, void* pCookie) {
00349     if (bSuccess) {
00350         // Calibration succeeded
00351         printf("[INFO] Calibração completa, restreando usuario %d!\n", nId);
00352         g_UserGenerator.GetSkeletonCap().StartTracking(nId);
00353         gestoTrack = true;
00354     } else {
00355         // Calibration failed
00356         gestoTrack = false;
00357         printf("[INFO]Calibração do usuario %d falhou!\n", nId);
00358         if (g_bNeedPose) {
00359             g_UserGenerator.GetPoseDetectionCap().StartPoseDetection(g_strPose, nId);
00360         } else {
00361             g_UserGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
00362         }
00363     }
00364 }
00365 
00369 void XN_CALLBACK_TYPE UserCalibration_CalibrationComplete(xn::SkeletonCapability& capability, XnUserID nId, XnCalibrationStatus eStatus, void* pCookie) {
00370     if (eStatus == XN_CALIBRATION_STATUS_OK) {
00371         // Calibration succeeded
00372         printf("[INFO] Calibração completa, restreando usuario %d!\n", nId);
00373         g_UserGenerator.GetSkeletonCap().StartTracking(nId);
00374         gestoTrack = true;
00375     } else {
00376         // Calibration failed
00377         gestoTrack = false;
00378         printf("[INFO]Calibração do usuario %d falhou!\n", nId);
00379         if (g_bNeedPose) {
00380             g_UserGenerator.GetPoseDetectionCap().StartPoseDetection(g_strPose, nId);
00381         } else {
00382             g_UserGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
00383         }
00384     }
00385 }
 All Classes Files Functions Variables Defines