WorkerRead() публичный Метод

public WorkerRead ( ) : void
Результат void
Пример #1
0
    public void ThreadUpdate()
    {
        using (new PSMoveHitchWatchdog("FPSMoveWorker_ThreadUpdate", 34 * PSMoveHitchWatchdog.MICROSECONDS_PER_MILLISECOND))
        {
            int AcquiredContextCounter_TLS;

            lock (this)
            {
                AcquiredContextCounter_TLS = this.AcquiredContextCounter;
            }

            // If there are component contexts active, make sure the tracking context is setup
            if (!WorkerSettings.DisableTracking)
            {
                if (AcquiredContextCounter_TLS > 0 && !WorkerContextIsTrackingSetup(Context))
                {
                    WorkerContextSetupTracking(WorkerSettings, Context);
                }
                // If there are no component contexts active, make sure the tracking context is torn-down
                else if (AcquiredContextCounter_TLS <= 0 && WorkerContextIsTrackingSetup(Context))
                {
                    WorkerContextTeardown(Context);
                }
            }

            // Update controller state while tracking is active (or if we don't care about tracking)
            if (WorkerSettings.DisableTracking || WorkerContextIsTrackingSetup(Context))
            {
                // Setup or tear down controller connections based on the number of active controllers
                WorkerContextUpdateControllerConnections(Context);

                // Renew the image on camera
                using (new PSMoveHitchWatchdog("FPSMoveWorker_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
                for (int psmove_id = 0; psmove_id < Context.PSMoveCount; psmove_id++)
                {
                    PSMoveRawControllerData_TLS localControllerData = WorkerControllerDataArray[psmove_id];

                    if (!Context.WorkerSettings.DisableTracking)
                    {
                        ControllerUpdatePositions(
                            WorkerSettings,
                            Context.PSMoveTracker,
                            Context.PSMoveFusion,
                            Context.PSMoves[psmove_id],
                            localControllerData);
                    }
                    else
                    {
                        localControllerData.IsTracking = 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 (!Context.WorkerSettings.DisableTracking)
                            {
                                UnityEngine.Debug.Log("PSMoveWorker:: CYCLE COLOUR");
                                PSMoveAPI.psmove_tracker_cycle_color(Context.PSMoveTracker, Context.PSMoves[psmove_id]);
                            }
                            else
                            {
                                UnityEngine.Debug.LogWarning("PSMoveWorker:: CYCLE COLOUR ignored! Tracking is disabled!");
                            }

                            localControllerData.CycleColourRequest = false;
                        }

                        // Publish the worker data to the component. e.g., Position, Orientation, Buttons
                        // This also publishes updated CycleColourRequest.
                        localControllerData.WorkerPost();
                    }
                }
            }
        }
    }
Пример #2
0
    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))
                {
                    for (int tracker_index = 0; tracker_index < Context.TrackerCount; ++tracker_index)
                    {
                        PSMoveAPI.psmove_tracker_update_image(Context.PSMoveTrackers[tracker_index]); // 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.PSMoveTrackers,
                            Context.PSMoveFusions,
                            Context.TrackerCount,
                            Context.PSMovePositionFilter,
                            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 sensor data
                    ControllerUpdateSensors(Context.PSMoves[psmove_id], localControllerData);

                    // 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)
                        {
                            UnityEngine.Debug.Log("PSMoveWorker:: CYCLE COLOUR");

                            // Attempt to cycle the color for each tracker and re-acquire tracking
                            int happyTrackerCount = 0;
                            for (int tracker_index = 0; tracker_index < Context.TrackerCount; ++tracker_index)
                            {
                                PSMoveAPI.psmove_tracker_cycle_color(
                                    Context.PSMoveTrackers[tracker_index], Context.PSMoves[psmove_id]);

                                PSMoveTracker_Status tracker_status =
                                    PSMoveAPI.psmove_tracker_get_status(
                                        Context.PSMoveTrackers[tracker_index],
                                        Context.PSMoves[psmove_id]);

                                if (tracker_status == PSMoveTracker_Status.Tracker_CALIBRATED ||
                                    tracker_status == PSMoveTracker_Status.Tracker_TRACKING)
                                {
                                    ++happyTrackerCount;
                                }
                            }

                            // If not all trackers re-acquired,
                            // mark the controller as no having tracking enabled,
                            // and let WorkerContextUpdateControllerConnections() try
                            // and reacquire next update.
                            if (happyTrackerCount < Context.TrackerCount)
                            {
                                Context.WorkerControllerDataArray[psmove_id].IsTrackingEnabled = false;
                            }
                        }
                        else
                        {
                            UnityEngine.Debug.LogWarning("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();
                }
            }
        }
    }