public MainForm() { mainDriver = new Driver(); InitializeComponent(); Driver.Log += Driver_Log; JoystickHelper.Log += Driver_Log; SystemHelper.Log += Driver_Log; Configuration.Log += Driver_Log; Configuration.StopProc += btnStop_Click; this.FormClosing += MainForm_FormClosing; this.FormClosed += MainForm_FormClosed; Configuration.PropogateSettings(); JoystickHelper.DestroyAll(); //quietly finish the constructor if we're updating. SystemHelper.checkForMissingDrivers(); if (disablePortsOnExit) { } if (startInTray) { this.Hide(); } else { this.Show(); } if (autoStart) { btnStart_Click(null, EventArgs.Empty); } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (!exit && Driver.run) { this.Hide(); e.Cancel = true; } if (disablePortsOnExit) { JoystickHelper.DestroyAll(); } }
public void reader_DataReceived(object sender, EndpointDataEventArgs e) { if (run) { var data = e.Buffer; var input1 = GCNState.GetState(getFastInput1(ref data)); var input2 = GCNState.GetState(getFastInput2(ref data)); var input3 = GCNState.GetState(getFastInput3(ref data)); var input4 = GCNState.GetState(getFastInput4(ref data)); if (gcn1ok) { JoystickHelper.setJoystick(input1, 1, gcn1DZ); } if (gcn2ok) { JoystickHelper.setJoystick(input2, 2, gcn2DZ); } if (gcn3ok) { JoystickHelper.setJoystick(input3, 3, gcn3DZ); } if (gcn4ok) { JoystickHelper.setJoystick(input4, 4, gcn4DZ); } } else { reader.DataReceivedEnabled = false; 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.")); } }
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(1)) { JoystickHelper.CreateJoystick(1); } if (gcn2Enabled && !JoystickHelper.checkJoystick(2)) { JoystickHelper.CreateJoystick(2); } if (gcn3Enabled && !JoystickHelper.checkJoystick(3)) { JoystickHelper.CreateJoystick(3); } if (gcn4Enabled && !JoystickHelper.checkJoystick(4)) { JoystickHelper.CreateJoystick(4); } if (gcn1Enabled && JoystickHelper.Acquire(1)) { gcn1ok = true; } if (gcn2Enabled && JoystickHelper.Acquire(2)) { gcn2ok = true; } if (gcn3Enabled && JoystickHelper.Acquire(3)) { gcn3ok = true; } if (gcn4Enabled && JoystickHelper.Acquire(4)) { gcn4ok = true; } } 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(input1, 1, gcn1DZ); } if (gcn2ok) { JoystickHelper.setJoystick(input2, 2, gcn2DZ); } if (gcn3ok) { JoystickHelper.setJoystick(input3, 3, gcn3DZ); } if (gcn4ok) { JoystickHelper.setJoystick(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; } }
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) { JoystickHelper.DestroyJoystick(1); } else { JoystickHelper.CreateJoystick(1); } } if ((bool)Settings.Default["port2Enabled"] != port2Enabled.Checked) { if (!port2Enabled.Checked) { JoystickHelper.DestroyJoystick(2); } else { JoystickHelper.CreateJoystick(2); } } if ((bool)Settings.Default["port3Enabled"] != port3Enabled.Checked) { if (!port3Enabled.Checked) { JoystickHelper.DestroyJoystick(3); } else { JoystickHelper.CreateJoystick(3); } } if ((bool)Settings.Default["port4Enabled"] != port4Enabled.Checked) { if (!port4Enabled.Checked) { JoystickHelper.DestroyJoystick(4); } else { JoystickHelper.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; }