Inheritance: PSMoveRawControllerData_Base
Ejemplo n.º 1
0
 public PSMoveDataContext(
     int moveID,
     PSMoveRawControllerData_Concurrent controllerConcurrentData)
 {
     PSMoveID = moveID;
     Pose = new PSMovePose();
     RawControllerData = new PSMoveRawControllerData_TLS(controllerConcurrentData);
 }
Ejemplo n.º 2
0
 public PSMoveDataContext(
     int moveID,
     PSMoveRawControllerData_Concurrent controllerConcurrentData)
 {
     PSMoveID          = moveID;
     Pose              = new PSMovePose();
     RawControllerData = new PSMoveRawControllerData_TLS(controllerConcurrentData);
 }
Ejemplo n.º 3
0
    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;
    }
Ejemplo n.º 4
0
    private PSMoveWorker(PSMoveWorkerSettings workerSettings)
    {
        WorkerInstance = this;

        this.WorkerSettings = workerSettings;

        if (workerSettings.Multithreaded)
        {
            StopSignal            = new ManualResetEvent(false);
            ExitedSignal          = new ManualResetEvent(false);
            WorkerThread          = new Thread(() => { this.Run(); });
            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]);
        }
    }
Ejemplo n.º 5
0
    private PSMoveWorker(PSMoveWorkerSettings workerSettings)
    {
        WorkerInstance= this;

        this.WorkerSettings = workerSettings;

        if (workerSettings.Multithreaded)
        {
            StopSignal = new ManualResetEvent(false);
            ExitedSignal = new ManualResetEvent(false);
            WorkerThread = new Thread(() => { this.Run(); });
            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]);
        }
    }
Ejemplo n.º 6
0
    public IntPtr PSMoveFusion; // PSMoveFusion*
    
    // Constructor
    public WorkerContext(PSMoveRawControllerData_TLS[] controllerDataArray, PSMoveWorkerSettings settings)
    {
        WorkerSettings= settings;
        WorkerControllerDataArray= controllerDataArray;
        
        // This timestamp is used to throttle how frequently we poll for controller count changes
        moveCountCheckTimer = new Stopwatch();

        Reset();
    }
Ejemplo n.º 7
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();
                    }
                }
            }
        }
    }
Ejemplo n.º 8
0
    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]);
        }

        psmoveapiSharedLibHandle = IntPtr.Zero;
        psmoveapiTrackerSharedLibHandle = IntPtr.Zero;
    }
Ejemplo n.º 9
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();
                }
            }
        }
    }