示例#1
0
        /// <summary>
        /// Returns whether the connecting succeeded or not.
        ///
        /// NOTE! This function does NOT pair the controller by Bluetooth.
        /// If the controller is not already paired, it can only be connected by USB.
        /// See README for more information.
        /// </summary>
        public PSMoveConnectStatus Init(int index)
        {
            _motionController.Handle = PsMoveApi.psmove_connect_by_id(index);

            // Error check the result!
            if (_motionController.Handle == IntPtr.Zero)
            {
                return(_motionController.ConnectStatus = PSMoveConnectStatus.Error);
            }

            // Make sure the connection is actually sending data. If not, this is probably a controller
            // you need to remove manually from the OSX Bluetooth Control Panel, then re-connect.
            if (PsMoveApi.psmove_update_leds(_motionController.Handle) == 0)
            {
                return(_motionController.ConnectStatus = PSMoveConnectStatus.NoData);
            }

            _motionController.Id             = index;
            _motionController.Remote         = PsMoveApi.psmove_is_remote(_motionController.Handle) > 0;
            _motionController.ConnectionType = PsMoveApi.psmove_connection_type(_motionController.Handle);;

            StringBuilder builder = new StringBuilder(64);

            PsMoveApi.get_moved_host(_motionController.Handle, builder);
            _motionController.HostIp = builder.ToString();
            PsMoveApi.get_serial(_motionController.Handle, builder);
            _motionController.Serial = builder.ToString();
            UpdateController();

            return(_motionController.ConnectStatus = PSMoveConnectStatus.OK);
        }