// User-defined Removal/Arival callback Function // When registered, label2 was passed as user-data private void Removal(bool removal, bool first, object userData) { string prt; Label l = userData as Label; int nBtn = joystick.GetVJDButtonNumber(id); int nDPov = joystick.GetVJDDiscPovNumber(id); int nCPov = joystick.GetVJDContPovNumber(id); bool X_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); bool Y_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y); bool Z_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z); bool RX_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); // Final values after the last arival if (!removal && !first) { prt = String.Format("Device[{0}]: Buttons={1}; DiscPOVs:{2}; ContPOVs:{3}", id, nBtn, nDPov, nCPov); label2.Text = prt; } // Temporary message during intermediate states else { prt = String.Format("Device[{0}]: Wait ...", id); label2.Text = prt; } }
public TesterForm() { InitializeComponent(); joystick = new vGen(); position = new vGen.JoystickState(); ///// General driver data short iVer = joystick.GetvJoyVersion(); bool enabled = joystick.vJoyEnabled(); string Prd = joystick.GetvJoyProductString(); string Mnf = joystick.GetvJoyManufacturerString(); string Srl = joystick.GetvJoySerialNumberString(); string prt = String.Format("Product: {0}; Version {1:X}; Manuf: {2}; Serial:{3}", Prd, iVer, Mnf, Srl); label1.Text = prt; Enbld.Checked = enabled; ///// vGen Device properties (vJoy Devices) int nBtn = joystick.GetVJDButtonNumber(id); int nDPov = joystick.GetVJDDiscPovNumber(id); int nCPov = joystick.GetVJDContPovNumber(id); bool X_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); bool Y_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y); bool Z_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z); bool RX_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); prt = String.Format("Device[{0}]: Buttons={1}; DiscPOVs:{2}; ContPOVs:{3}", id, nBtn, nDPov, nCPov); label2.Text = prt; UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (match) { prt = String.Format("Version of Driver Matches DLL Version {0:X}", DllVer); } else { prt = String.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})", DrvVer, DllVer); } label7.Text = prt; // vXbox devices UInt32 UserIndex = 0; bool Exist = false; uint stat = joystick.isVBusExist(); if (stat == 0) { System.Diagnostics.Debug.WriteLine("======== vXbox bus installed"); Byte nSlots = 0; stat = joystick.GetNumEmptyBusSlots(ref nSlots); System.Diagnostics.Debug.WriteLine("======== Number of empty slots: " + nSlots.ToString()); UserIndex = 2; stat = joystick.PlugIn(UserIndex); if (stat == 0) { System.Diagnostics.Debug.WriteLine("======== vXbox device 2 was plugged in"); } joystick.isControllerPluggedIn(UserIndex, ref Exist); System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + " is plugged in: " + Exist.ToString()); joystick.isControllerOwned(UserIndex, ref Exist); System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + " is owned: " + Exist.ToString()); UserIndex = 1; joystick.isControllerPluggedIn(UserIndex, ref Exist); System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + " is plugged in: " + Exist.ToString()); joystick.isControllerOwned(UserIndex, ref Exist); System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + " is owned: " + Exist.ToString()); joystick.PlugInNext(ref UserIndex); joystick.isControllerPluggedIn(UserIndex, ref Exist); System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + " is plugged in: " + Exist.ToString()); joystick.isControllerOwned(UserIndex, ref Exist); System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + " is owned: " + Exist.ToString()); joystick.SetButton(UserIndex, 1, true); joystick.SetButton(UserIndex, 3, true); joystick.ResetAllControllers(); joystick.SetButton(UserIndex, 1, false); joystick.SetButton(UserIndex, 3, false); joystick.SetTriggerL(UserIndex, 255); joystick.SetTriggerR(UserIndex, 128); joystick.SetAxisLx(UserIndex, -32768); joystick.SetAxisLy(UserIndex, 32767); joystick.SetAxisRx(UserIndex, -32000); joystick.SetAxisRy(UserIndex, 32000); joystick.SetDpad(UserIndex, vGen.XINPUT_GAMEPAD_DPAD_UP); joystick.SetDpad(UserIndex, 0); byte Led = 0xFF; vGen.XINPUT_VIBRATION Vib; Vib.wRightMotorSpeed = Vib.wLeftMotorSpeed = 0; joystick.GetLedNumber(UserIndex, ref Led); System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + ": Led=" + Led.ToString()); int x = 0, L = 0, R = 0; while (x < 1000) { x++; stat = joystick.GetVibration(UserIndex, ref Vib); if ((Vib.wLeftMotorSpeed != L) || (Vib.wRightMotorSpeed != R)) { System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + ": Vibration (L/R)=" + Vib.wLeftMotorSpeed.ToString() + "/" + Vib.wRightMotorSpeed.ToString()); } System.Threading.Thread.Sleep(10); } //joystick.UnPlug(2); } // Testing long max = 10, min = 10; bool ok; ok = joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref max); ok = joystick.GetVJDAxisMin(id, HID_USAGES.HID_USAGE_X, ref min); ///// Write access to vGen Device - Basic VjdStat status; status = joystick.GetVJDStatus(id); bool acq = joystick.AcquireVJD(id); status = joystick.GetVJDStatus(id); position.AxisX = 1000; position.AxisY = 5000; position.AxisZ = 10000; position.AxisXRot = 20000; position.Buttons = 0xA5A5A5A5; position.ButtonsEx1 = 0; bool upd = joystick.UpdateVJD(id, ref position); status = joystick.GetVJDStatus(id); //// Reset functions joystick.ResetButtons(id); // Register callback function // Function to register: Removal() // User data to pass: label2 joystick.RegisterRemovalCB(Removal, label2); }
public bool Initialize(uint id) { if (id <= 0 || (id > 15 && id < 1001) || id > 1004) { throw new ArgumentException("Invalid ID!", "id"); } bool xbox = id > 1000; // Test for the driver if (!vJoy.vJoyEnabled()) { Console.Write(Color.Red, "vJoy driver not enabled\n"); return(false); } if (xbox && vJoy.isVBusExist() != 0) { Console.Write(Color.Red, "vXbox driver not enabled\n"); return(false); } // Test if DLL matches the driver uint DllVer = 0, DrvVer = 0; if (!xbox && !vJoy.DriverMatch(ref DllVer, ref DrvVer)) { Console.Write(Color.Red, "Driver version ({0:X}) does NOT match DLL version ({1:X})\n", DrvVer, DllVer); return(false); } // Get the state of the controller VjdStat status = vJoy.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_FREE: Console.Write(Color.White, "Device {0} is free\n", id); break; case VjdStat.VJD_STAT_OWN: Console.Write(Color.Red, "Device {0} is already owned by this feeder\n", id); break; case VjdStat.VJD_STAT_BUSY: Console.Write(Color.Red, "Device {0} is already owned by another feeder\n", id); return(false); case VjdStat.VJD_STAT_MISS: Console.Write(Color.Red, "Device {0} is not installed or disabled\n", id); return(false); default: Console.Write(Color.Red, "Device {0}: UNKNOWN ERROR\n", id); return(false); } // Make sure the controller has the required configuration if (vJoy.GetVJDButtonNumber(id) < 12 || vJoy.GetVJDContPovNumber(id) < 1 || !vJoy.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X) || !vJoy.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y) || !vJoy.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z) || !vJoy.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX)) { Console.Write(Color.Red, "Unsupported controller: Controller does not match required configuration. (12+ buttons, 1+ POV, X, Y, Z and RX axes)\n"); return(false); } // Acquire the controller if (status == VjdStat.VJD_STAT_FREE && !vJoy.AcquireVJD(id)) { Console.Write(Color.Red, String.Format("Failed to acquire vJoy device number {0}\n", id)); return(false); } else { Console.Write(Color.Green, String.Format("Acquired: vJoy device number {0}\n", id)); } // No FFB for now... /*if (vJoy.IsDeviceFfb (id)) { * vJoy.FfbRegisterGenCB (new vGen.FfbCbFunc (FFBCallback), null); * }*/ handle = id; Initialized = true; return(true); }
private bool vJoySetup() { joystick = new vGen(); iReport = new vGen.JoystickState(); if (id <= 0 || id > 16) { consoleOut("Illegal device ID " + id + "!"); } if (!joystick.vJoyEnabled()) { consoleOut("vJoy driver not enabled: Failed Getting vJoy attributes."); return(false); } else { consoleOut("Vendor: " + joystick.GetvJoyManufacturerString() + "\nProduct: " + joystick.GetvJoyProductString() + "\nVersion Number: " + joystick.GetvJoySerialNumberString() + "."); } VjdStat st = joystick.GetVJDStatus(id); switch (st) { case VjdStat.VJD_STAT_OWN: consoleOut("vJoy Device " + id + " is already owned by this feeder."); break; case VjdStat.VJD_STAT_FREE: consoleOut("vJoy Device " + id + " is free."); break; case VjdStat.VJD_STAT_BUSY: joystick.RelinquishVJD(id); consoleOut("vJoy Device " + id + " is already owned by another feeder - Trying to recover."); return(false); case VjdStat.VJD_STAT_MISS: consoleOut("vJoy Device " + id + " is not installed or disabled - Cannot continue."); return(false); default: consoleOut("vJoy Device " + id + " general error - Cannot continue."); return(false); } ; st = joystick.GetVJDStatus(id); if ((st == VjdStat.VJD_STAT_OWN) || ((st == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { consoleOut("Failed to acquire vJoy device number " + id + "."); } else { consoleOut("Acquired vJoy device number " + id + "."); } int nButtons = joystick.GetVJDButtonNumber(id); UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (match) { consoleOut("Version of Driver Matches DLL Version (" + DllVer + ")"); } else { consoleOut("Version of Driver (" + DrvVer + ") does NOT match DLL Version (" + DllVer + ")"); } joystick.ResetVJD(id); for (uint i = 1; i <= nButtons; i++) { consoleOut(i + ") OFF: " + joystick.SetBtn(false, id, i)); } consoleOut("\nvJoy setup completed succesfully!\n"); return(true); }