public PSMoveDataContext( int moveID, PSMoveRawControllerData_Concurrent controllerConcurrentData) { PSMoveID = moveID; Pose = new PSMovePose(); RawControllerData = new PSMoveRawControllerData_TLS(controllerConcurrentData); }
private PSMoveWorker() { WorkerSettings = new PSMoveWorkerSettings(); HaltThreadSignal = new ManualResetEvent(false); ThreadExitedSignal = new ManualResetEvent(false); WorkerThread = new Thread(() => { this.ThreadProc(); }); WorkerThread.Priority = System.Threading.ThreadPriority.AboveNormal; WorkerControllerDataArray_Concurrent = new PSMoveRawControllerData_Concurrent[MAX_CONTROLLERS]; WorkerControllerDataArray = new PSMoveRawControllerData_TLS[MAX_CONTROLLERS]; for (int i = 0; i < WorkerControllerDataArray_Concurrent.Length; i++) { WorkerControllerDataArray_Concurrent[i] = new PSMoveRawControllerData_Concurrent(); WorkerControllerDataArray[i] = new PSMoveRawControllerData_TLS(WorkerControllerDataArray_Concurrent[i]); } psmoveapiHandle = IntPtr.Zero; psmoveapiTrackerHandle = IntPtr.Zero; }
public void ThreadUpdate() { using (new PSMoveHitchWatchdog("PSMoveWorker_ThreadUpdate", 34 * PSMoveHitchWatchdog.MICROSECONDS_PER_MILLISECOND)) { // Setup or teardown tracking based on the updated tracking state if (WorkerSettings.bTrackerEnabled && !WorkerContextIsTrackingSetup(Context)) { WorkerContextSetupTracking(WorkerSettings, Context); } else if (!WorkerSettings.bTrackerEnabled && WorkerContextIsTrackingSetup(Context)) { WorkerContextTeardownTracking(Context); } // Setup or tear down controller connections based on the number of active controllers WorkerContextUpdateControllerConnections(Context); // Renew the image on camera, if tracking is enabled if (WorkerContextIsTrackingSetup(Context)) { using ( new PSMoveHitchWatchdog("PSMoveWorker_UpdateImage", 33 * PSMoveHitchWatchdog.MICROSECONDS_PER_MILLISECOND)) { PSMoveAPI.psmove_tracker_update_image(Context.PSMoveTracker); // Sometimes libusb crashes here. } } // Update the raw positions on the local controller data if (WorkerContextIsTrackingSetup(Context)) { for (int psmove_id = 0; psmove_id < Context.PSMoveCount; psmove_id++) { PSMoveRawControllerData_TLS localControllerData = WorkerControllerDataArray[psmove_id]; if (WorkerSettings.bTrackerEnabled) { ControllerUpdatePositions( WorkerSettings, Context.PSMoveTracker, Context.PSMoveFusion, Context.PSMoves[psmove_id], localControllerData); } else { localControllerData.IsSeenByTracker = false; } } } // Do bluetooth IO: Orientation, Buttons, Rumble for (int psmove_id = 0; psmove_id < Context.PSMoveCount; psmove_id++) { //TODO: Is it necessary to keep polling until no frames are left? while (PSMoveAPI.psmove_poll(Context.PSMoves[psmove_id]) > 0) { PSMoveRawControllerData_TLS localControllerData = WorkerControllerDataArray[psmove_id]; // Update the controller status (via bluetooth) PSMoveAPI.psmove_poll(Context.PSMoves[psmove_id]); // Necessary to poll yet again? // Store the controller orientation ControllerUpdateOrientations(Context.PSMoves[psmove_id], localControllerData); // Store the button state ControllerUpdateButtonState(Context.PSMoves[psmove_id], localControllerData); // Now read in requested changes from Component. e.g., RumbleRequest, CycleColourRequest localControllerData.WorkerRead(); // Set the controller rumble (uint8; 0-255) PSMoveAPI.psmove_set_rumble(Context.PSMoves[psmove_id], localControllerData.RumbleRequest); // Push the updated rumble state to the controller PSMoveAPI.psmove_update_leds(Context.PSMoves[psmove_id]); if (localControllerData.CycleColourRequest) { if (WorkerSettings.bTrackerEnabled) { Debug.WriteLine("PSMoveWorker:: CYCLE COLOUR"); PSMoveAPI.psmove_tracker_cycle_color(Context.PSMoveTracker, Context.PSMoves[psmove_id]); } else { Debug.WriteLine("PSMoveWorker:: CYCLE COLOUR ignored! Tracking is disabled!"); } localControllerData.CycleColourRequest = false; } // Publish Position, Orientation, and Button state to the concurrent data // This also publishes updated CycleColourRequest. localControllerData.WorkerPost(); } } } }