예제 #1
0
        public static bool checkJoystick(ref vJoy joystick, uint id)
        {
            bool checker = false;

            if (joystick.vJoyEnabled())
            {
                VjdStat status = joystick.GetVJDStatus(id);
                switch (status)
                {
                case VjdStat.VJD_STAT_OWN:
                    Log(null, new Driver.LogEventArgs(string.Format("Port {0} is already owned by this feeder (OK).", id)));
                    checker = true;
                    break;

                case VjdStat.VJD_STAT_FREE:
                    Log(null, new Driver.LogEventArgs(string.Format("Port {0} is detected (OK).", id)));
                    checker = true;
                    break;

                case VjdStat.VJD_STAT_BUSY:
                    Log(null, new Driver.LogEventArgs(string.Format("Port {0} is already owned by another feeder, cannot continue.", id)));
                    checker = false;
                    return(checker);

                case VjdStat.VJD_STAT_MISS:
                    Log(null, new Driver.LogEventArgs(string.Format("Port {0} is not detected.", id)));
                    checker = false;
                    return(checker);

                default:
                    Log(null, new Driver.LogEventArgs(string.Format("Port {0} general error, cannot continue.", id)));
                    checker = false;
                    return(checker);
                }

                //fix missing buttons, if the count is off.
                if (joystick.GetVJDButtonNumber(id) != 12 || FfbSetup(ref joystick, id) == false)
                {
                    SystemHelper.CreateJoystick(id);
                }
            }
            return(checker);
        }
예제 #2
0
        public void Start()
        {
            //WUP-028
            //VENDORID 0x57E
            //PRODUCT ID 0x337

            var USBFinder = new UsbDeviceFinder(0x057E, 0x0337);

            GCNAdapter = UsbDevice.OpenUsbDevice(USBFinder);

            if (GCNAdapter != null)
            {
                int transferLength;

                reader = GCNAdapter.OpenEndpointReader(ReadEndpointID.Ep01);
                writer = GCNAdapter.OpenEndpointWriter(WriteEndpointID.Ep02);

                //prompt controller to start sending
                writer.Write(Convert.ToByte((char)19), 10, out transferLength);

                try
                {
                    if (gcn1Enabled && !JoystickHelper.checkJoystick(ref vjoy, 1))
                    {
                        SystemHelper.CreateJoystick(1);
                    }
                    if (gcn2Enabled && !JoystickHelper.checkJoystick(ref vjoy, 2))
                    {
                        SystemHelper.CreateJoystick(2);
                    }
                    if (gcn3Enabled && !JoystickHelper.checkJoystick(ref vjoy, 3))
                    {
                        SystemHelper.CreateJoystick(3);
                    }
                    if (gcn4Enabled && !JoystickHelper.checkJoystick(ref vjoy, 4))
                    {
                        SystemHelper.CreateJoystick(4);
                    }

                    if (gcn1Enabled && vjoy.AcquireVJD(1))
                    {
                        gcn1ok = true;
                    }
                    if (gcn2Enabled && vjoy.AcquireVJD(2))
                    {
                        gcn2ok = true;
                    }
                    if (gcn3Enabled && vjoy.AcquireVJD(3))
                    {
                        gcn3ok = true;
                    }
                    if (gcn4Enabled && vjoy.AcquireVJD(4))
                    {
                        gcn4ok = true;
                    }

                    vjoy.ResetAll();
                    vjoy.FfbRegisterGenCB(FfbRecieved, IntPtr.Zero);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("HRESULT: 0x8007000B"))
                    {
                        Log(null, new LogEventArgs("Error: vJoy driver mismatch. Did you install the wrong version (x86/x64)?"));
                        Driver.run = false;
                        return;
                    }
                }

                if (noEventMode)
                {
                    // PORT 1: bytes 02-09
                    // PORT 2: bytes 11-17
                    // PORT 3: bytes 20-27
                    // PORT 4: bytes 29-36l
                    byte[] ReadBuffer  = new byte[37]; // 32 (4 players x 8) bytes for input, 5 bytes for formatting
                    byte[] WriteBuffer = new byte[5];  // 1 for command, 4 for rumble state
                    WriteBuffer[0] = 0x11;
                    WriteBuffer[1] = 0;
                    Log(null, new LogEventArgs("Driver successfully started, entering input loop."));
                    run = true;
                    Stopwatch sw = Stopwatch.StartNew();
                    while (run)
                    {
                        var ec     = reader.Read(ReadBuffer, 10, out transferLength);
                        var input1 = GCNState.GetState(getFastInput1(ref ReadBuffer));
                        var input2 = GCNState.GetState(getFastInput2(ref ReadBuffer));
                        var input3 = GCNState.GetState(getFastInput3(ref ReadBuffer));
                        var input4 = GCNState.GetState(getFastInput4(ref ReadBuffer));

                        if (gcn1ok)
                        {
                            JoystickHelper.setJoystick(ref vjoy, input1, 1, gcn1DZ);
                        }
                        if (gcn2ok)
                        {
                            JoystickHelper.setJoystick(ref vjoy, input2, 2, gcn2DZ);
                        }
                        if (gcn3ok)
                        {
                            JoystickHelper.setJoystick(ref vjoy, input3, 3, gcn3DZ);
                        }
                        if (gcn4ok)
                        {
                            JoystickHelper.setJoystick(ref vjoy, input4, 4, gcn4DZ);
                        }

                        long elapsed = sw.ElapsedMilliseconds;
                        sw.Reset(); sw.Start();

                        if (Interlocked.Read(ref gcn1Ffb) > 0)
                        {
                            if (gcn1FfbInf == false)
                            {
                                Interlocked.Add(ref gcn1Ffb, -elapsed);
                            }
                            WriteBuffer[1] = (byte)(gcn1FfbActive ? 1 : 0);
                        }
                        else
                        {
                            WriteBuffer[1] = 0;
                        }
                        if (Interlocked.Read(ref gcn2Ffb) > 0)
                        {
                            if (gcn2FfbInf == false)
                            {
                                Interlocked.Add(ref gcn2Ffb, -elapsed);
                            }
                            WriteBuffer[2] = (byte)(gcn2FfbActive ? 1 : 0);
                        }
                        else
                        {
                            WriteBuffer[2] = 0;
                        }
                        if (Interlocked.Read(ref gcn3Ffb) > 0)
                        {
                            if (gcn3FfbInf == false)
                            {
                                Interlocked.Add(ref gcn3Ffb, -elapsed);
                            }
                            WriteBuffer[3] = (byte)(gcn3FfbActive ? 1 : 0);
                        }
                        else
                        {
                            WriteBuffer[3] = 0;
                        }
                        if (Interlocked.Read(ref gcn4Ffb) > 0)
                        {
                            if (gcn4FfbInf == false)
                            {
                                Interlocked.Add(ref gcn4Ffb, -elapsed);
                            }
                            WriteBuffer[4] = (byte)(gcn4FfbActive ? 1 : 0);
                        }
                        else
                        {
                            WriteBuffer[4] = 0;
                        }
                        writer.Write(WriteBuffer, 10, out transferLength);
                        System.Threading.Thread.Sleep(5);
                    }

                    WriteBuffer[1] = 0; WriteBuffer[2] = 0; WriteBuffer[3] = 0; WriteBuffer[4] = 0;
                    writer.Write(WriteBuffer, 10, out transferLength);

                    if (GCNAdapter != null)
                    {
                        if (GCNAdapter.IsOpen)
                        {
                            if (!ReferenceEquals(wholeGCNAdapter, null))
                            {
                                wholeGCNAdapter.ReleaseInterface(0);
                            }
                            GCNAdapter.Close();
                        }
                        GCNAdapter = null;
                        UsbDevice.Exit();
                        Log(null, new LogEventArgs("Closing driver thread..."));
                    }
                    Log(null, new LogEventArgs("Driver thread has been stopped."));
                }
                else
                {
                    Log(null, new LogEventArgs("Driver successfully started, entering input loop."));
                    //using  Interrupt request instead of looping behavior.
                    reader.DataReceivedEnabled = true;
                    reader.DataReceived       += reader_DataReceived;
                    reader.ReadBufferSize      = 37;
                    reader.ReadThreadPriority  = System.Threading.ThreadPriority.Highest;
                    run = true;
                }
            }
            else
            {
                Log(null, new LogEventArgs("GCN Adapter not detected."));
                Driver.run = false;
            }
        }
예제 #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            txtSaving.Location = new Point(350, 205);
            txtSaving.Visible  = true;
            txtSaving.Update();

            if (Settings.Default.currentVersion)
            {
                Settings.Default.Upgrade();
                Settings.Default.currentVersion = false;
            }

            Settings.Default["autoStart"]          = cbAutoStart.Checked;
            Settings.Default["startWithWindows"]   = cbStartWithWindows.Checked;
            Settings.Default["startInTray"]        = cbStartInTray.Checked;
            Settings.Default["autoUpdate"]         = cbAutoUpdates.Checked;
            Settings.Default["disablePortsOnExit"] = cbDisablevJoyOnExit.Checked;

            Settings.Default["noEventMode"] = cbNoEventMode.Checked;

            //disable joysticks we don't want, but only when a change has occured.
            if ((bool)Settings.Default["port1Enabled"] != port1Enabled.Checked)
            {
                if (!port1Enabled.Checked)
                {
                    SystemHelper.DestroyJoystick(1);
                }
                else
                {
                    SystemHelper.CreateJoystick(1);
                }
            }
            if ((bool)Settings.Default["port2Enabled"] != port2Enabled.Checked)
            {
                if (!port2Enabled.Checked)
                {
                    SystemHelper.DestroyJoystick(2);
                }
                else
                {
                    SystemHelper.CreateJoystick(2);
                }
            }
            if ((bool)Settings.Default["port3Enabled"] != port3Enabled.Checked)
            {
                if (!port3Enabled.Checked)
                {
                    SystemHelper.DestroyJoystick(3);
                }
                else
                {
                    SystemHelper.CreateJoystick(3);
                }
            }
            if ((bool)Settings.Default["port4Enabled"] != port4Enabled.Checked)
            {
                if (!port4Enabled.Checked)
                {
                    SystemHelper.DestroyJoystick(4);
                }
                else
                {
                    SystemHelper.CreateJoystick(4);
                }
            }

            Settings.Default["port1Enabled"] = port1Enabled.Checked;
            Settings.Default["port2Enabled"] = port2Enabled.Checked;
            Settings.Default["port3Enabled"] = port3Enabled.Checked;
            Settings.Default["port4Enabled"] = port4Enabled.Checked;

            Settings.Default["port1AX"] = Convert.ToInt32(port1AX.Value);
            Settings.Default["port1AY"] = Convert.ToInt32(port1AY.Value);
            Settings.Default["port1CX"] = Convert.ToInt32(port1CX.Value);
            Settings.Default["port1CY"] = Convert.ToInt32(port1CY.Value);
            Settings.Default["port1LT"] = Convert.ToInt32(port1LT.Value);
            Settings.Default["port1RT"] = Convert.ToInt32(port1RT.Value);

            Settings.Default["port2AX"] = Convert.ToInt32(port2AX.Value);
            Settings.Default["port2AY"] = Convert.ToInt32(port2AY.Value);
            Settings.Default["port2CX"] = Convert.ToInt32(port2CX.Value);
            Settings.Default["port2CY"] = Convert.ToInt32(port2CY.Value);
            Settings.Default["port2LT"] = Convert.ToInt32(port2LT.Value);
            Settings.Default["port2RT"] = Convert.ToInt32(port2RT.Value);

            Settings.Default["port3AX"] = Convert.ToInt32(port3AX.Value);
            Settings.Default["port3AY"] = Convert.ToInt32(port3AY.Value);
            Settings.Default["port3CX"] = Convert.ToInt32(port3CX.Value);
            Settings.Default["port3CY"] = Convert.ToInt32(port3CY.Value);
            Settings.Default["port3LT"] = Convert.ToInt32(port3LT.Value);
            Settings.Default["port3RT"] = Convert.ToInt32(port3RT.Value);

            Settings.Default["port4AX"] = Convert.ToInt32(port4AX.Value);
            Settings.Default["port4AY"] = Convert.ToInt32(port4AY.Value);
            Settings.Default["port4CX"] = Convert.ToInt32(port4CX.Value);
            Settings.Default["port4CY"] = Convert.ToInt32(port4CY.Value);
            Settings.Default["port4LT"] = Convert.ToInt32(port4LT.Value);
            Settings.Default["port4RT"] = Convert.ToInt32(port4RT.Value);

            Settings.Default.Save();
            PropogateSettings();

            Log(null, new Driver.LogEventArgs("Settings saved, configuration has been updated."));

            txtSaving.Visible = false;
        }