コード例 #1
0
ファイル: ComponentStructs.cs プロジェクト: zw5/WiinUPro
        /// <summary>
        /// Normalizes raw values to calculate X and Y
        /// </summary>
        public void Normalize()
        {
            // This is a square deadzone
            if ((rawX - centerX < deadXp && rawX - centerX > deadXn) && (rawY - centerY < deadYp && rawY - centerY > deadYn))
            {
                X = 0;
                Y = 0;
                return;
            }

            X = Nintroller.Normalize(rawX, minX, centerX, maxX, deadXp, deadXn);
            Y = Nintroller.Normalize(rawY, minY, centerY, maxY, deadYp, deadYn);

            if (antiDeadzone != 0)
            {
                if (X != 0)
                {
                    X = X * (1f - antiDeadzone) + antiDeadzone * Math.Sign(X);
                }

                if (Y != 0)
                {
                    Y = Y * (1f - antiDeadzone) + antiDeadzone * Math.Sign(Y);
                }
            }
        }
コード例 #2
0
ファイル: DeviceControl.xaml.cs プロジェクト: zw5/WiinUPro
        public DeviceControl(Nintroller nintroller, string path)
            : this()
        {
            Device     = nintroller;
            devicePath = path;

            Device.Disconnected += device_Disconnected;
        }
コード例 #3
0
        public bool Connect()
        {
            bool success = false;

            if (_info.DevicePath == "Dummy")
            {
                _dummy = new Shared.DummyDevice(Calibrations.Defaults.ProControllerDefault);
                var dumWin = new Windows.DummyWindow(_dummy);
                dumWin.Show();
                _nintroller   = new Nintroller(_dummy);
                OnDisconnect += () =>
                {
                    dumWin.Close();
                };
            }
            else
            {
                _stream     = new WinBtStream(_info.DevicePath);
                _nintroller = new Nintroller(_stream);//, deviceInfo.Type);
            }
            _nintroller.StateUpdate     += _nintroller_StateUpdate;
            _nintroller.ExtensionChange += _nintroller_ExtensionChange;
            _nintroller.LowBattery      += _nintroller_LowBattery;

            // TODO: Seems OpenConnection() can still succeed on toshiba w/o device connected
            if (_dummy != null || _stream.OpenConnection())
            {
                _nintroller.BeginReading();
                _nintroller.GetStatus();
                _nintroller.SetPlayerLED(1);

                // We need a function we can await for the type to come back
                // But the hint type may be present
                CreateController(_nintroller.Type);

                if (_controller != null)
                {
                    SetupController();

                    success = true;
                    _nintroller.SetReportType(InputReport.ExtOnly, true);
                }
                else
                {
                    // Controller type not supported or unknown, teardown?
                    //success = false;
                    success = true;
                }

                _nintroller.Disconnected += _nintroller_Disconnected;
            }
#if DEBUGz
            else
            {
                _controller = new ProControl(Calibrations.Defaults.ProControllerDefault);
                SetupController();
                success = true;
            }
コード例 #4
0
        private void _btnFind_Click(object sender, RoutedEventArgs e)
        {
            //var controllers = Nintroller.FindControllers();
            var controllers = Nintroller.GetControllerPaths();

            DeviceList = new List <string>();

            foreach (string id in controllers)
            {
                DeviceList.Add(id);
            }

            _comboBoxDeviceList.ItemsSource = DeviceList;
        }
コード例 #5
0
ファイル: ComponentStructs.cs プロジェクト: zw5/WiinUPro
        /// <summary>
        /// Calculates the normalized values.
        /// </summary>
        public void Normalize()
        {
            // Cubic deadzone
            if (Math.Abs(rawX) < deadX && Math.Abs(rawY) < deadY && Math.Abs(rawZ) < deadZ)
            {
                X = 0;
                Y = 0;
                Z = 0;
                return;
            }

            X = Nintroller.Normalize(rawX, minX, centerX, maxX, deadX);
            Y = Nintroller.Normalize(rawY, minY, centerY, maxY, deadY);
            Z = Nintroller.Normalize(rawZ, minZ, centerZ, maxZ, deadZ);
        }
コード例 #6
0
        private void _btnConnect_Click(object sender, RoutedEventArgs e)
        {
            if (_nintroller != null)
            {
                _nintroller.ExtensionChange -= ExtensionChange;
                //_nintroller.StateChange -= StateChange;
                _nintroller.StateUpdate -= StateUpdate;
                _nintroller.Disconnect();
                _nintroller = null;
                _stackDigitalInputs.Children.Clear();
                _stackAnalogInputs.Children.Clear();
                _btnConnect.Content = "Connect";
            }
            else if (_comboBoxDeviceList.SelectedItem != null)
            {
                _nintroller = new Nintroller((string)_comboBoxDeviceList.SelectedItem);

                bool success = _nintroller.Connect();

                if (!success)
                {
                    Debug.WriteLine("Failed to connect");
                    _nintroller = null;
                }
                else
                {
                    _btnConnect.Content = "Disconnect";

                    _nintroller.ExtensionChange += ExtensionChange;
                    _nintroller.StateUpdate     += StateUpdate;
                    _nintroller.BeginReading();
                    _nintroller.GetStatus();
                    _nintroller.SetPlayerLED(1);
                }
            }
        }
コード例 #7
0
        public bool Connect()
        {
            bool success = false;

            if (_info.DevicePath != null && _info.DevicePath.StartsWith("Dummy"))
            {
                if (_info.DevicePath.Contains("GCN"))
                {
                    var dummyGameCubeAdapter = new GameCubeAdapter();
                    dummyGameCubeAdapter.SetCalibration(Calibrations.CalibrationPreset.Default);
                    _dummy      = new DummyDevice(dummyGameCubeAdapter);
                    _nintroller = new Nintroller(_dummy, 0x0337);
                }
                else
                {
                    if (_info.DevicePath.Contains("Wiimote"))
                    {
                        _dummy = new DummyDevice(Calibrations.Defaults.WiimoteDefault);
                    }
                    else
                    {
                        _dummy = new DummyDevice(Calibrations.Defaults.ProControllerDefault);
                    }

                    _nintroller = new Nintroller(_dummy, _dummy.DeviceType);
                }

                var dumWin = new Windows.DummyWindow(_dummy);
                dumWin.Show();

                OnDisconnect += () =>
                {
                    dumWin.Close();
                };
            }
            else
            {
                if (_stream == null)
                {
                    _stream = new WinBtStream(_info.DevicePath);
                }

                _nintroller = new Nintroller(_stream, _info.PID);
            }

            _nintroller.StateUpdate     += _nintroller_StateUpdate;
            _nintroller.ExtensionChange += _nintroller_ExtensionChange;
            _nintroller.LowBattery      += _nintroller_LowBattery;

            // TODO: Seems OpenConnection() can still succeed on toshiba w/o device connected
            if (_dummy != null || _stream.OpenConnection())
            {
                _nintroller.BeginReading();

                if (_nintroller.Type != ControllerType.Other)
                {
                    _nintroller.GetStatus();
                    _nintroller.SetPlayerLED(1);
                }

                // We need a function we can await for the type to come back
                // But the hint type may be present
                CreateController(_nintroller.Type);

                if (_controller != null)
                {
                    UpdateAlignment();

                    success = true;
                    _nintroller.SetReportType(InputReport.ExtOnly, true);
                }
                else
                {
                    // Controller type not supported or unknown, teardown?
                    //success = false;
                    success = true;
                }

                _nintroller.Disconnected += _nintroller_Disconnected;
            }
#if DEBUGz
            else
            {
                _controller = new ProControl(Calibrations.Defaults.ProControllerDefault);
                SetupController();
                success = true;
            }
コード例 #8
0
        private void Refresh()
        {
            hidList = WinBtStream.GetPaths();
            List <KeyValuePair <int, DeviceControl> > connectSeq = new List <KeyValuePair <int, DeviceControl> >();

            foreach (var hid in hidList)
            {
                DeviceControl existingDevice = null;

                foreach (DeviceControl d in deviceList)
                {
                    if (d.DevicePath == hid.DevicePath)
                    {
                        existingDevice = d;
                        break;
                    }
                }

                if (existingDevice != null)
                {
                    if (!existingDevice.Connected)
                    {
                        existingDevice.RefreshState();
                        if (existingDevice.properties.autoConnect && existingDevice.ConnectionState == DeviceState.Discovered)
                        {
                            connectSeq.Add(new KeyValuePair <int, DeviceControl>(existingDevice.properties.autoNum, existingDevice));
                        }
                    }
                }
                else
                {
                    var stream = new WinBtStream(
                        hid.DevicePath,
                        UserPrefs.Instance.toshibaMode ? WinBtStream.BtStack.Toshiba : WinBtStream.BtStack.Microsoft,
                        UserPrefs.Instance.greedyMode ? FileShare.None : FileShare.ReadWrite);
                    Nintroller n = new Nintroller(stream, hid.Type);

                    if (stream.OpenConnection() && stream.CanRead)
                    {
                        deviceList.Add(new DeviceControl(n, hid.DevicePath));
                        deviceList[deviceList.Count - 1].OnConnectStateChange += DeviceControl_OnConnectStateChange;
                        deviceList[deviceList.Count - 1].OnConnectionLost     += DeviceControl_OnConnectionLost;
                        deviceList[deviceList.Count - 1].RefreshState();
                        if (deviceList[deviceList.Count - 1].properties.autoConnect)
                        {
                            connectSeq.Add(new KeyValuePair <int, DeviceControl>(deviceList[deviceList.Count - 1].properties.autoNum, deviceList[deviceList.Count - 1]));
                        }
                    }
                }
            }

            int target = -1;

            for (int i = 0; i < 4; i++)
            {
                if (Holders.XInputHolder.availabe.Length > i)
                {
                    if (Holders.XInputHolder.availabe[i])
                    {
                        target = i;
                        break;
                    }
                }
            }

            if (target < 0)
            {
                return;
            }

            //while (!Holders.XInputHolder.availabe[target] && target < 4)
            //{
            //    target++;
            //}

            // Auto Connect First Available devices
            for (int a = 0; a < connectSeq.Count; a++)
            {
                var thingy = connectSeq[a];

                if (thingy.Key == 5)
                {
                    if (Holders.XInputHolder.availabe[target] && target < 4)
                    {
                        if (thingy.Value.Device.Connected || (thingy.Value.Device.DataStream as WinBtStream).OpenConnection())
                        {
                            thingy.Value.targetXDevice   = target + 1;
                            thingy.Value.ConnectionState = DeviceState.Connected_XInput;
                            thingy.Value.Device.BeginReading();
                            thingy.Value.Device.GetStatus();
                            thingy.Value.Device.SetPlayerLED(target + 1);
                            target++;
                        }
                    }

                    connectSeq.Remove(thingy);
                }
            }

            // Auto connect in preferred order
            for (int i = 1; i < connectSeq.Count; i++)
            {
                if (connectSeq[i].Key < connectSeq[i - 1].Key)
                {
                    var tmp = connectSeq[i];
                    connectSeq[i]     = connectSeq[i - 1];
                    connectSeq[i - 1] = tmp;
                    i = 0;
                }
            }

            foreach (KeyValuePair <int, DeviceControl> d in connectSeq)
            {
                if (Holders.XInputHolder.availabe[target] && target < 4)
                {
                    if (d.Value.Device.Connected || (d.Value.Device.DataStream as WinBtStream).OpenConnection())
                    {
                        d.Value.targetXDevice   = target + 1;
                        d.Value.ConnectionState = DeviceState.Connected_XInput;
                        d.Value.Device.BeginReading();
                        d.Value.Device.GetStatus();
                        d.Value.Device.SetPlayerLED(target + 1);
                        target++;
                    }
                }
            }
        }
コード例 #9
0
ファイル: MainWindow.xaml.cs プロジェクト: FreshJR07/WiinUPro
        private void Refresh()
        {
            hidList = WinBtStream.GetPaths();
            List <KeyValuePair <int, DeviceControl> > connectSeq = new List <KeyValuePair <int, DeviceControl> >();

            //for each Nintendo (HID) device in device manager
            foreach (var hid in hidList)                        //will create new DeviceControl if not already present and execute actions
            {                                                   //if DeviceControl is already present will execute actions
                DeviceControl existingDevice = null;

                foreach (DeviceControl d in deviceList)
                {
                    if (d.DevicePath == hid.DevicePath)
                    {
                        existingDevice = d;
                        break;
                    }
                }

                if (existingDevice != null)                     // follow this procedure for devices that already have DeviceControl
                {                                               // Refreshstate and check for AutoConnect
                    if (!existingDevice.Connected)
                    {
                        existingDevice.RefreshState();
                    }

                    if (UserPrefs.Instance.autoXInput && existingDevice.properties.autoNum != 0 && existingDevice.ConnectionState == DeviceState.Discovered)
                    {
                        connectSeq.Add(new KeyValuePair <int, DeviceControl>(existingDevice.properties.autoNum, existingDevice));
                    }
                }
                else                                           // or follow this prodcedure that do not have DeviceControl
                {                                              // create DeviceControl, subscribes to DeviceControl's events, RefreshState, and check for AutoConnect
                    var stream = new WinBtStream(
                        hid.DevicePath,
                        UserPrefs.Instance.toshibaMode ? WinBtStream.BtStack.Toshiba : WinBtStream.BtStack.Microsoft,
                        UserPrefs.Instance.greedyMode ? FileShare.None : FileShare.ReadWrite);
                    Nintroller n = new Nintroller(stream, hid.Type);

                    if (stream.OpenConnection() && stream.CanRead)
                    {
                        deviceList.Add(new DeviceControl(n, hid.DevicePath, hid.Mac));
                        deviceList[deviceList.Count - 1].OnConnectStateChange += DeviceControl_OnConnectStateChange;
                        deviceList[deviceList.Count - 1].OnConnectionLost     += DeviceControl_OnConnectionLost;
                        deviceList[deviceList.Count - 1].RefreshState();
                        if (UserPrefs.Instance.autoXInput && deviceList[deviceList.Count - 1].properties.autoNum != 0)
                        {
                            connectSeq.Add(new KeyValuePair <int, DeviceControl>(deviceList[deviceList.Count - 1].properties.autoNum, deviceList[deviceList.Count - 1]));
                        }
                    }
                }
            }

            //for each existing DeviceControl
            foreach (DeviceControl dc in deviceList)                    //check if existing Device Control has its corresponding HID device still present
            {
                bool hidPresent = false;
                foreach (var hid in hidList)
                {
                    if (dc.DevicePath == hid.DevicePath)
                    {
                        hidPresent = true;
                        break;
                    }
                }
                if (hidPresent == false)                                // dispose of DeviceControl on if corresponding HID device is not present
                {
                    dc.setDisconnected();
                }
            }

            int target = 0;

            while (!Holders.XInputHolder.availabe[target] && target < 4)
            {
                target++;
            }

            // Auto Connect First Available devices
            for (int a = 0; a < connectSeq.Count; a++)
            {
                var thingy = connectSeq[a];

                if (thingy.Key == 5)
                {
                    if (Holders.XInputHolder.availabe[target] && target < 4)
                    {
                        if (thingy.Value.Device.Connected || (thingy.Value.Device.DataStream as WinBtStream).OpenConnection())
                        {
                            thingy.Value.targetXDevice   = target + 1;
                            thingy.Value.ConnectionState = DeviceState.Connected_XInput;
                            thingy.Value.Device.BeginReading();
                            thingy.Value.Device.GetStatus();
                            thingy.Value.Device.SetPlayerLED(target + 1);
                            target++;
                        }
                    }

                    connectSeq.Remove(thingy);
                }
            }

            // Auto connect in preferred order
            for (int i = 1; i < connectSeq.Count; i++)
            {
                if (connectSeq[i].Key < connectSeq[i - 1].Key)
                {
                    var tmp = connectSeq[i];
                    connectSeq[i]     = connectSeq[i - 1];
                    connectSeq[i - 1] = tmp;
                    i = 0;
                }
            }

            foreach (KeyValuePair <int, DeviceControl> d in connectSeq)
            {
                if (Holders.XInputHolder.availabe[target] && target < 4)
                {
                    if (d.Value.Device.Connected || (d.Value.Device.DataStream as WinBtStream).OpenConnection())
                    {
                        d.Value.targetXDevice   = target + 1;
                        d.Value.ConnectionState = DeviceState.Connected_XInput;
                        d.Value.Device.BeginReading();
                        d.Value.Device.GetStatus();
                        d.Value.Device.SetPlayerLED(target + 1);
                        target++;
                    }
                }
            }
        }