Beispiel #1
0
        public void UpdateController()
        {
            uint buttons = 0;

            prevButtons = currentButtons;
            // NOTE! There is potentially data waiting in queue.
            // We need to poll *all* of it by calling psmove_poll() until the queue is empty. Otherwise, data might begin to build up.
            while (PsMoveApi.psmove_poll(_motionController.Handle) > 0)
            {
                // We are interested in every button press between the last update and this one:
                buttons = buttons | PsMoveApi.psmove_get_buttons(_motionController.Handle);

                // The events are not really working from the PS Move Api. So we do our own with the prevButtons
                //psmove_get_button_events(handle, ref pressed, ref released);
            }
            currentButtons = buttons;

            // For acceleration, gyroscope, and magnetometer values, we look at only the last value in the queue.
            // We could in theory average all the acceleration (and other) values in the queue for a "smoothing" effect, but we've chosen not to.
            ProcessData();

            // Send a report to the controller to update the LEDs and rumble.
            if (PsMoveApi.psmove_update_leds(_motionController.Handle) == 0)
            {
                //			Debug.Log ("led set");
                // If it returns zero, the controller must have disconnected (i.e. out of battery or out of range),
                // so we should fire off any events and disconnect it.
                if (this != null)
                {
                    OnControllerDisconnected(this, new EventArgs());
                }
                Disconnect();
            }
        }