void CMUCamera::getCameraControls(C1394Camera* pCamera, CameraInfo* pCamInfo) { //Iterate over amount of possible Features (up to 24 in CMU1394 DCD 6.4.5.240) for (int indexFeature = 0; indexFeature <= 23; indexFeature++) { C1394CameraControl* feature = pCamera->GetCameraControl((CAMERA_FEATURE)indexFeature); if (feature == NULL) { continue; } bool hasFeature = pCamera->HasFeature((CAMERA_FEATURE)indexFeature); if (!hasFeature) { continue; } //FrameRate (also known as TransferRate) is not supported if (feature->GetFeatureID() == FEATURE_FRAME_RATE) { continue; } std::string featureName = feature->GetName(); unsigned short min = -1; unsigned short max = -1; feature->GetRange(&min, &max); unsigned short value_low = -1; unsigned short value_high = -1; //TODO: For Whitebalance or Temperature etc. feature->GetValue(&value_low, &value_high); CameraControl camControl = CameraControl(featureName, (int)min, (int)max, (int)value_low); pCamInfo->addControl(camControl); } }
void Update() { AGE_CameraUpdate(); CameraControl(); snprintf(buffer, sizeof(buffer), "FPS: %d", CURRENT_FPS); AGE_SpriteLoadFromText(&fpsSprite, buffer, fpsTextColor, gFont); BattleUpdate(); HandleMainInput(); }
//GET THREAD //Gets Files over USB. Camera -> Memory void * GetEvents(void*aaa){ CameraFile* my_File; CameraEventType my_Type; void* retevent; struct timespec time; char filename[40]; while(1){ CameraControl(); do{ //Wait for camera to fire an event. Most are useless/not used by us //When a picture is taken (triggered on camera), FILE_ADDED event fired //retevent will contain a CameraFilePath object with name/loc on camera of file //Timeout is 100 <units, probably ms> gp_camera_wait_for_event(getMyCamera(), 100, &my_Type, &retevent, getMyContext()); if(my_Type == GP_EVENT_FILE_ADDED){ CameraFilePath* my_FP = (CameraFilePath*)retevent; gp_file_new(&my_File); //Get the file from the given location to memory gp_camera_file_get(getMyCamera(), my_FP->folder, my_FP->name, GP_FILE_TYPE_NORMAL, my_File, getMyContext()); //Get time in ms since Epoch -> used for filename for Skynet purposes clock_gettime(CLOCK_REALTIME, &time); long long time_millis = time.tv_sec * 1000 + time.tv_nsec / 1000000; sprintf(filename, "%s/%llu.jpg", ImagesFolder.c_str(), time_millis); AddFile(my_File, filename); //Save the last obtained Telemetry/GPS to disk, with the same filename we just used saveLast(time_millis); //Tell the Save Thread that there is a new CameraFile enqueued sem_post(&NewFileSem); free(my_FP); } } while(decrementWaitCounter() > 0); //WaitCounter is a variable used to cycle through images possibly still on the camera //Used to cycle out images before switching quality, see CameraControl.c setWaitCounter(0); } return NULL; }
/*------------------------------------------------------------- 30fps timer callback in fixed frame rate for major game loop --------------------------------------------------------------*/ void GameAI(int skip) { FnCharacter actor; // play character pose actor.ID(actorID); actor.Play(LOOP, (float)skip, FALSE, TRUE); // Homework #01 part 1 if (FyCheckHotKeyStatus(FY_UP)) actor.MoveForward(20); if (FyCheckHotKeyStatus(FY_LEFT)) actor.TurnRight(-5); if (FyCheckHotKeyStatus(FY_RIGHT)) actor.TurnRight(5); //else {} // .... if (IsCameraFollow) { CameraControl(actorID); } }
/*Test Recplayer UDP Demo*/ static int RecPlayProcess(int *puserIndex) { int nLen; MsgHeader header, *pheader, sd_header; unsigned char szData[1280]; int fileflags; int userIndex = *puserIndex; if(userIndex >= gLiveMaxUserNum || userIndex < 0) { printf("Exit RecPlayProcess Thread!!!!\n"); pthread_detach(pthread_self()); return 0; } LIVE_SOCKET socket = getRecuserTcpSocket(userIndex); printf("enter live RecPlayProcess() function!!\n"); SetSendTimeOut(socket, 10); SetRecvTimeOut(socket, 10); memset(&header, 0, sizeof(header)); pheader = &header; sd_header.sLen = htons(sizeof(MsgHeader)); sd_header.sVer = MSG_VER; sd_header.sMsgType = MSG_TYPE_PASSWORD; if((fileflags = fcntl(socket, F_GETFL, 0)) == -1) { printf("fcntl F_GETFL error:%d,error msg: = %s\n", errno, strerror(errno)); return -1; } if(fcntl(socket, F_SETFL, fileflags & (~O_NONBLOCK)) == -1) { printf("fcntl F_SETFL error:%d,error msg: = %s\n", errno, strerror(errno)); return -1; } // fcntl(socket, F_SETFL, O_NONBLOCK); // 是否为阻塞版本的socket while(liveplayTaskStatus == RUNNING) { memset(szData, 0, 1280); nLen = recv(socket, szData, HEAD_LEN, 0); if(nLen < HEAD_LEN || nLen == -1) { printf("nLen < HEAD_LEN errno = %d nLen = %d\n", errno, nLen); goto EXITTHREAD; } memcpy(&header, szData, HEAD_LEN); pheader->sLen = ntohs(pheader->sLen); if(pheader->sLen - HEAD_LEN > 0) { nLen = recv(socket, szData + HEAD_LEN, pheader->sLen - HEAD_LEN, 0); if(nLen < pheader->sLen - HEAD_LEN) { fprintf(stderr, "nLen < nMsgLen -HEAD_LEN\n"); goto EXITTHREAD; } } switch(pheader->sMsgType) { case MSG_TYPE_PASSWORD: // 判断密码 if(!(strncmp(LIVE_CONNECT_KEY_1, (char *)(szData + HEAD_LEN), pheader->sLen - HEAD_LEN)) || !(strncmp(LIVE_CONNECT_KEY_2, (char *)(szData + HEAD_LEN), pheader->sLen - HEAD_LEN))) { int ln = strlen(LIVE_SERVER_VERSION) + strlen(LIVE_MINPLAYER_VERSION) + 4; char bver[40], buffer[100]; int userID = 0; time_t timep; sprintf(bver, "%s %s", LIVE_SERVER_VERSION, LIVE_MINPLAYER_VERSION); sd_header.sData = 0; //密码正确 sd_header.sLen = htons(sizeof(MsgHeader) + ln - 2); send(socket, &sd_header, sizeof(MsgHeader), 0); send(socket, bver, ln - 2, 0); sd_header.sLen = htons(sizeof(MsgHeader) + 4); sd_header.sVer = MSG_VER; sd_header.sMsgType = MSG_TYPE_ID; time(&timep); userID = (int)timep; fprintf(stderr, "------ userId = %x\n", userID); recplayEnv.recUser[userIndex].userID = userID; memcpy(buffer, &sd_header, sizeof(MsgHeader)); memcpy(buffer + sizeof(MsgHeader), &userID, 4); send(socket, buffer, sizeof(MsgHeader) + 4, 0); } else { sd_header.sData = 1; //密码错误 printf("passwd error!!!\n"); send(socket, &sd_header, sizeof(MsgHeader), 0); goto EXITTHREAD; } break; case MSG_TYPE_HEART: DEBUG(DL_DEBUG, gLiveDebug_Level, "liveplay Heat OK!!\n"); break; case MSG_TYPE_USEINFO: DEBUG(DL_DEBUG, gLiveDebug_Level, "MSG_TYPE_USEINFO\n"); break; case MSG_TYPE_ID: DEBUG(DL_DEBUG, gLiveDebug_Level, "MSG_TYPE_ID \n"); break; case MSG_TYPE_BDPROXY: DEBUG(DL_DEBUG, gLiveDebug_Level, "MSG_TYPE_BDPROXY \n"); break; case MSG_TYPE_CTRL: { #if 0 printf("MSG_TYPE_CTRL"); unsigned char type, speed, num; type = *(szData + HEAD_LEN); speed = *(szData + HEAD_LEN + 1); num = *(szData + HEAD_LEN + 2); CameraControl((int)type, (int)speed); #endif } break; default: DEBUG(DL_DEBUG, gLiveDebug_Level, "default Exit !!! pheader->sMsgType = %d \n", pheader->sMsgType); break; } } EXITTHREAD: close(socket); setUserLogout(userIndex); removeRecuserIndex(userIndex); clearRecuserNum(); printf("(((((((((((((((((((((((((((((Exit RecPlayProcess Thread!!!!))))))))))))))))))))))))))))\n"); pthread_detach(pthread_self()); return 0; }
void FWCamera::getCameraControls(dc1394camera_t* pCamera, CameraInfo* camInfo) { dc1394featureset_t featureSet; int err = dc1394_feature_get_all(pCamera, &featureSet); if (err != DC1394_SUCCESS) { AVG_ASSERT(false); return; } for (int i = DC1394_FEATURE_MIN; i <= DC1394_FEATURE_MAX; i++) { dc1394feature_info_t featureInfo = featureSet.feature[i - DC1394_FEATURE_MIN]; dc1394bool_t bool_t; dc1394_feature_is_present(pCamera,featureInfo.id, &bool_t); if (bool_t != DC1394_TRUE) { continue; } uint32_t min = -1; uint32_t max = -1; uint32_t actValue = -1; //TODO: 428 (TRIGGER) doesnt have min max err = dc1394_feature_get_boundaries(pCamera, featureInfo.id, &min, &max); if (err != DC1394_SUCCESS) { continue; } switch(featureInfo.id) { case DC1394_FEATURE_TEMPERATURE: { uint32_t targetTemp = -1; uint32_t currentTemp = -1; err = dc1394_feature_temperature_get_value(pCamera,&targetTemp,¤tTemp); if (err != DC1394_SUCCESS) { continue; } actValue = currentTemp; break; } //TODO: Think about a way to get this information into CameraInfo case DC1394_FEATURE_WHITE_BALANCE: { uint32_t ubValue = -1; uint32_t vrValue = -1; err = dc1394_feature_whitebalance_get_value(pCamera,&ubValue,&vrValue); if (err != DC1394_SUCCESS) { continue; } //actValue = ubValue; //vrValue; //cout <<"UBlue Value: " << ubValue << " VRed Value: " << vrValue << endl; break; } default: { err = dc1394_feature_get_value(pCamera,featureInfo.id, &actValue); if (err != DC1394_SUCCESS) { continue; } break; } } CameraFeature enumFeature = featureIDToEnum(featureInfo.id); if (enumFeature == CAM_FEATURE_UNSUPPORTED) { continue; } std::string controlName = cameraFeatureToString(enumFeature); CameraControl control = CameraControl(controlName, (int) min, (int) max, (int) actValue ); //TODO: isnt really a default value!? camInfo->addControl(control); } }