public void SetDirectionalPov(int pov, VJoyPov direction) { if (pov >= maxDirPov) { throw new Exception(string.Format("Maximum digital POV hats are {0}. You need to increase number of digital POV hats in vJoy config", maxDirPov)); } joystick.SetDiscPov((int)direction, Index, (uint)pov + 1); }
private void Reset(uint player, vJoy playa) { bool code = false; code = playa.SetDiscPov(-1, player, 2); for (uint i = 1; i <= 5; i++) { code = playa.SetBtn(false, player, i); } System.Threading.Thread.Sleep(50); }
/// <summary> /// Set the POV (vJoy DiscretePOV 1..4 - if set..) /// </summary> /// <param name="pov">The POV 1..4</param> /// <param name="value">The POV value</param> public void SetPOV(int pov, POVType value) { if (pov < 1 || pov > m_nPov) { return; } if (m_hasPov[pov].has) { m_hasPov[pov].current = (int)value; // read back storage m_joy.SetDiscPov(m_hasPov[pov].current, Index, (uint)pov); } }
private void ResetAll(uint player) { vJoy playa = player == 1 ? player1 : player2; bool code = false; for (uint i = 1; i <= 2; i++) { code = playa.SetDiscPov(-1, player, i); code = playa.SetBtn(false, player, i); } for (uint i = 3; i <= 5; i++) { code = playa.SetBtn(false, player, i); } System.Threading.Thread.Sleep(50); }
public void SetDirectionalPov(int pov, int direction) { if (pov >= maxDirPov) { throw new Exception( $"Maximum digital POV hats are {maxDirPov}. You need to increase number of digital POV hats in vJoy config"); } if (direction > 3) { throw new Exception($"Different values of direction are -1, 0 to 3. Your value is {direction}."); } if (!modeDiffered) { _joystick.SetDiscPov(direction, Index, (uint)pov + 1); } else { uint b = (uint)0xF << 4 * pov; direction = (direction & 0xF) << 4 * pov; report.bHats = (report.bHats & ~b) | (uint)direction; } }
static void Main(string[] args) { // Create one joystick object and a position structure. joystick = new vJoy(); iReport = new vJoy.JoystickState(); // Device ID can only be in the range 1-16 if (args.Length > 0 && !String.IsNullOrEmpty(args[0])) { id = Convert.ToUInt32(args[0]); } if (id <= 0 || id > 16) { Console.WriteLine("Illegal device ID {0}\nExit!", id); return; } // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return; } else { Console.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString()); } // Get the state of the requested device VjdStat status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", id); break; case VjdStat.VJD_STAT_FREE: Console.WriteLine("vJoy Device {0} is free\n", id); break; case VjdStat.VJD_STAT_BUSY: Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id); return; case VjdStat.VJD_STAT_MISS: Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id); return; default: Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id); return; } ; // Check which axes are supported bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); bool AxisY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y); bool AxisZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z); bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ); // Get the number of buttons and POV Hat switchessupported by this vJoy device int nButtons = joystick.GetVJDButtonNumber(id); int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(id); // Print results Console.WriteLine("\nvJoy Device {0} capabilities:\n", id); Console.WriteLine("Numner of buttons\t\t{0}\n", nButtons); Console.WriteLine("Numner of Continuous POVs\t{0}\n", ContPovNumber); Console.WriteLine("Numner of Descrete POVs\t\t{0}\n", DiscPovNumber); Console.WriteLine("Axis X\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No"); Console.WriteLine("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No"); // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id); return; } else { Console.WriteLine("Acquired: vJoy device number {0}.\n", id); } Console.WriteLine("\npress enter to stat feeding"); Console.ReadKey(true); int X, Y, Z, ZR, XR; uint count = 0; long maxval = 0; X = 20; Y = 30; Z = 40; XR = 60; ZR = 80; joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); #if ROBUST bool res; // Reset this device to default values joystick.ResetVJD(id); // Feed the device in endless loop while (true) { // Set position of 4 axes res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X); res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y); res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z); res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX); res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ); // Press/Release Buttons res = joystick.SetBtn(true, id, count / 50); res = joystick.SetBtn(false, id, 1 + count / 50); // If Continuous POV hat switches installed - make them go round // For high values - put the switches in neutral state if (ContPovNumber > 0) { if ((count * 70) < 30000) { res = joystick.SetContPov(((int)count * 70), id, 1); res = joystick.SetContPov(((int)count * 70) + 2000, id, 2); res = joystick.SetContPov(((int)count * 70) + 4000, id, 3); res = joystick.SetContPov(((int)count * 70) + 6000, id, 4); } else { res = joystick.SetContPov(-1, id, 1); res = joystick.SetContPov(-1, id, 2); res = joystick.SetContPov(-1, id, 3); res = joystick.SetContPov(-1, id, 4); }; } ; // If Discrete POV hat switches installed - make them go round // From time to time - put the switches in neutral state if (DiscPovNumber > 0) { if (count < 550) { joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1); joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2); joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3); joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4); } else { joystick.SetDiscPov(-1, id, 1); joystick.SetDiscPov(-1, id, 2); joystick.SetDiscPov(-1, id, 3); joystick.SetDiscPov(-1, id, 4); }; } ; System.Threading.Thread.Sleep(20); X += 150; if (X > maxval) { X = 0; } Y += 250; if (Y > maxval) { Y = 0; } Z += 350; if (Z > maxval) { Z = 0; } XR += 220; if (XR > maxval) { XR = 0; } ZR += 200; if (ZR > maxval) { ZR = 0; } count++; if (count > 640) { count = 0; } } // While (Robust) #endif // ROBUST #if EFFICIENT byte[] pov = new byte[4]; while (true) { iReport.bDevice = (byte)id; iReport.AxisX = X; iReport.AxisY = Y; iReport.AxisZ = Z; iReport.AxisZRot = ZR; iReport.AxisXRot = XR; // Set buttons one by one iReport.Buttons = (uint)(0x1 << (int)(count / 20)); if (ContPovNumber > 0) { // Make Continuous POV Hat spin iReport.bHats = (count * 70); iReport.bHatsEx1 = (count * 70) + 3000; iReport.bHatsEx2 = (count * 70) + 5000; iReport.bHatsEx3 = 15000 - (count * 70); if ((count * 70) > 36000) { iReport.bHats = 0xFFFFFFFF; // Neutral state iReport.bHatsEx1 = 0xFFFFFFFF; // Neutral state iReport.bHatsEx2 = 0xFFFFFFFF; // Neutral state iReport.bHatsEx3 = 0xFFFFFFFF; // Neutral state } ; } else { // Make 5-position POV Hat spin pov[0] = (byte)(((count / 20) + 0) % 4); pov[1] = (byte)(((count / 20) + 1) % 4); pov[2] = (byte)(((count / 20) + 2) % 4); pov[3] = (byte)(((count / 20) + 3) % 4); iReport.bHats = (uint)(pov[3] << 12) | (uint)(pov[2] << 8) | (uint)(pov[1] << 4) | (uint)pov[0]; if ((count) > 550) { iReport.bHats = 0xFFFFFFFF; // Neutral state } }; /*** Feed the driver with the position packet - is fails then wait for input then try to re-acquire device ***/ if (!joystick.UpdateVJD(id, ref iReport)) { Console.WriteLine("Feeding vJoy device number {0} failed - try to enable device then press enter\n", id); Console.ReadKey(true); joystick.AcquireVJD(id); } System.Threading.Thread.Sleep(20); count++; if (count > 640) { count = 0; } X += 150; if (X > maxval) { X = 0; } Y += 250; if (Y > maxval) { Y = 0; } Z += 350; if (Z > maxval) { Z = 0; } XR += 220; if (XR > maxval) { XR = 0; } ZR += 200; if (ZR > maxval) { ZR = 0; } } ; // While #endif // EFFICIENT } // Main
bool FeedDinputDevice(uint id, out string message) { message = ""; // Create one joystick object and a position structure. joystick = new vJoy(); iReport = new vJoy.JoystickState(); // Device ID can only be in the range 1-16 if (id <= 0 || id > 16) { message += string.Format("Illegal device ID {0}\nExit!", id); return(false); } // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { message += string.Format("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return(false); } else { message += string.Format("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString()); } // Get the state of the requested device VjdStat status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: message += string.Format("vJoy Device {0} is already owned by this feeder\n", id); break; case VjdStat.VJD_STAT_FREE: message += string.Format("vJoy Device {0} is free\n", id); break; case VjdStat.VJD_STAT_BUSY: message += string.Format("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id); return(false); case VjdStat.VJD_STAT_MISS: message += string.Format("vJoy Device {0} is not installed or disabled\nCannot continue\n", id); return(false); default: message += string.Format("vJoy Device {0} general error\nCannot continue\n", id); return(false); } ; // Check which axes are supported bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); bool AxisY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y); bool AxisZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z); bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ); // Get the number of buttons and POV Hat switches supported by this vJoy device int nButtons = joystick.GetVJDButtonNumber(id); int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(id); // Print results message += string.Format("\nvJoy Device {0} capabilities:\n", id); message += string.Format("Number of buttons\t\t{0}\n", nButtons); message += string.Format("Number of Continuous POVs\t{0}\n", ContPovNumber); message += string.Format("Number of Discrete POVs\t\t{0}\n", DiscPovNumber); message += string.Format("Axis X\t\t{0}\n", AxisX ? "Yes" : "No"); message += string.Format("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No"); message += string.Format("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No"); message += string.Format("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No"); message += string.Format("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No"); // Test if DLL matches the driver UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (match) { message += string.Format("Version of Driver Matches DLL Version ({0:X})\n", DllVer); } else { message += string.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer); } // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { message += string.Format("Failed to acquire vJoy device number {0}.\n", id); return(false); } else { message += string.Format("Acquired: vJoy device number {0}.\n", id); } int X, Y, Z, ZR, XR; uint count = 0; long maxval = 0; X = 20; Y = 30; Z = 40; XR = 60; ZR = 80; joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); bool res; // Reset this device to default values joystick.ResetVJD(id); // Feed the device in endless loop while (!Program.IsClosing && FeedingEnabled) { // Set position of 4 axes res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X); res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y); res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z); res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX); res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ); // Press/Release Buttons res = joystick.SetBtn(true, id, count / 50); res = joystick.SetBtn(false, id, 1 + count / 50); // If Continuous POV hat switches installed - make them go round // For high values - put the switches in neutral state if (ContPovNumber > 0) { if ((count * 70) < 30000) { res = joystick.SetContPov(((int)count * 70), id, 1); res = joystick.SetContPov(((int)count * 70) + 2000, id, 2); res = joystick.SetContPov(((int)count * 70) + 4000, id, 3); res = joystick.SetContPov(((int)count * 70) + 6000, id, 4); } else { res = joystick.SetContPov(-1, id, 1); res = joystick.SetContPov(-1, id, 2); res = joystick.SetContPov(-1, id, 3); res = joystick.SetContPov(-1, id, 4); }; } ; // If Discrete POV hat switches installed - make them go round // From time to time - put the switches in neutral state if (DiscPovNumber > 0) { if (count < 550) { joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1); joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2); joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3); joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4); } else { joystick.SetDiscPov(-1, id, 1); joystick.SetDiscPov(-1, id, 2); joystick.SetDiscPov(-1, id, 3); joystick.SetDiscPov(-1, id, 4); }; } ; System.Threading.Thread.Sleep(20); X += 150; if (X > maxval) { X = 0; } Y += 250; if (Y > maxval) { Y = 0; } Z += 350; if (Z > maxval) { Z = 0; } XR += 220; if (XR > maxval) { XR = 0; } ZR += 200; if (ZR > maxval) { ZR = 0; } count++; if (count > 640) { count = 0; } } // While (Robust) return(true); } // Main
} // Main public static IEnumerator TestCoroutine() { int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(id); int X, Y, Z, ZR, XR; uint count = 0; long maxval = 0; X = 20; Y = 30; Z = 40; XR = 60; ZR = 80; joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); bool res; // Reset this device to default values joystick.ResetVJD(id); // Feed the device in endless loop Debug.Log("start"); while (true) { // Set position of 4 axes res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X); res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y); res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z); res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX); res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ); // Press/Release Buttons res = joystick.SetBtn(true, id, count / 50); res = joystick.SetBtn(false, id, 1 + count / 50); // If Continuous POV hat switches installed - make them go round // For high values - put the switches in neutral state if (ContPovNumber > 0) { if ((count * 70) < 30000) { res = joystick.SetContPov(((int)count * 70), id, 1); res = joystick.SetContPov(((int)count * 70) + 2000, id, 2); res = joystick.SetContPov(((int)count * 70) + 4000, id, 3); res = joystick.SetContPov(((int)count * 70) + 6000, id, 4); } else { res = joystick.SetContPov(-1, id, 1); res = joystick.SetContPov(-1, id, 2); res = joystick.SetContPov(-1, id, 3); res = joystick.SetContPov(-1, id, 4); }; } ; // If Discrete POV hat switches installed - make them go round // From time to time - put the switches in neutral state if (DiscPovNumber > 0) { if (count < 550) { joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1); joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2); joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3); joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4); } else { joystick.SetDiscPov(-1, id, 1); joystick.SetDiscPov(-1, id, 2); joystick.SetDiscPov(-1, id, 3); joystick.SetDiscPov(-1, id, 4); }; } ; System.Threading.Thread.Sleep(20); X += 150; if (X > maxval) { X = 0; } Y += 250; if (Y > maxval) { Y = 0; } Z += 350; if (Z > maxval) { Z = 0; } XR += 220; if (XR > maxval) { XR = 0; } ZR += 200; if (ZR > maxval) { ZR = 0; } count++; if (count > 640) { count = 0; } yield return(new WaitForFixedUpdate()); } // While (Robust) }
/// <summary> /// 方向キー /// </summary> /// <param name="n">0:上 1:右 2:下 3:左</param> public void PushCross(uint n) // 0 ~ 3 { joystick.SetDiscPov((Int32)n, rID, 1); }
public static void Initialize(uint id) //(string[] args) { // Create one joystick object and a position structure. joystick = new vJoy(); iReport = new vJoy.JoystickState(); string buffer; // Device ID can only be in the range 1-16 if (id < 1 || id > 16) { buffer = string.Format("Illegal device ID {0}\nExit!", id); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); return; } // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { BalanceWalker.FormMain.consoleBoxWriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return; } else { buffer = string.Format("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString()); //BalanceWalker.FormMain.consoleBoxWriteLine($"Vendor: {joystick.GetvJoyManufacturerString()}\nProduct :{joystick.GetvJoyProductString()}\nVersion Number:{joystick.GetvJoySerialNumberString()}\n"); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); } // Get the state of the requested device VjdStat status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: buffer = string.Format("vJoy Device {0} is already owned by this feeder\n", id); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); break; case VjdStat.VJD_STAT_FREE: buffer = string.Format("vJoy Device {0} is free\n", id); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); break; case VjdStat.VJD_STAT_BUSY: buffer = string.Format("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); return; case VjdStat.VJD_STAT_MISS: buffer = string.Format("vJoy Device {0} is not installed or disabled. \nCannot continue\n", id); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); return; default: buffer = string.Format("vJoy Device {0} general error\nCannot continue\n", id); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); return; } ; // Check which axes are supported bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); bool AxisY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y); bool AxisZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z); bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ); bool AxisRY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RY); // Get the number of buttons and POV Hat switches supported by this vJoy device int nButtons = joystick.GetVJDButtonNumber(id); int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(id); // Print results buffer = string.Format("\nvJoy Device {0} capabilities:\n", id); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); buffer = string.Format("Number of buttons\t\t{0}\n", nButtons); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); buffer = string.Format("Number of Continuous POVs\t{0}\n", ContPovNumber); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); buffer = string.Format("Number of Descrete POVs\t\t{0}\n", DiscPovNumber); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); buffer = string.Format("Axis X\t\t{0}\n", AxisX ? "Yes" : "No"); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); buffer = string.Format("Axis Y\t\t{0}\n", AxisY ? "Yes" : "No"); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); buffer = string.Format("Axis Z\t\t{0}\n", AxisZ ? "Yes" : "No"); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); buffer = string.Format("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No"); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); buffer = string.Format("Axis Ry\t\t{0}\n", AxisRY ? "Yes" : "No"); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); buffer = string.Format("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No"); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); if (!(AxisX && AxisY && AxisZ && AxisRX && AxisRZ && AxisRY)) { buffer = string.Format("Please enable Axes X,Y,Z,RX,RY,RZ in vJoyConf for device number", id, " in order to use all functions", id); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); } if (nButtons < 1) { buffer = string.Format("Please enable at least 1 button in vJoyConf for device ", id, " in order to use the only button on the wii balance board"); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); } // Test if DLL matches the driver UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (match) { buffer = string.Format("Version of Driver Matches DLL Version ({0:X})\n", DllVer); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); } else { buffer = string.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); } // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { buffer = string.Format("Failed to acquire vJoy device number {0}.\n", id); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); return; } else { buffer = string.Format("Acquired: vJoy device number {0}.\n", id); BalanceWalker.FormMain.consoleBoxWriteLine(buffer); } int X, Y, Z, XR, ZR; uint count = 0; long maxval = 0; // maxval is -32767 +32767 X = 20; Y = 30; Z = 40; XR = 60; ZR = 80; joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); #if ROBUST bool res; // Reset this device to default values joystick.ResetVJD(id); // set this to true to test if the vJoy driver is working. This will feed vjoy with an endless loop of joystick commands. while (false) { // Set position of 4 axes res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X); res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y); res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z); res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX); res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ); // Press/Release Buttons res = joystick.SetBtn(true, id, count / 50); res = joystick.SetBtn(false, id, 1 + count / 50); // If Continuous POV hat switches installed - make them go round // For high values - put the switches in neutral state if (ContPovNumber > 0) { if ((count * 70) < 30000) { res = joystick.SetContPov(((int)count * 70), id, 1); res = joystick.SetContPov(((int)count * 70) + 2000, id, 2); res = joystick.SetContPov(((int)count * 70) + 4000, id, 3); res = joystick.SetContPov(((int)count * 70) + 6000, id, 4); } else { res = joystick.SetContPov(-1, id, 1); res = joystick.SetContPov(-1, id, 2); res = joystick.SetContPov(-1, id, 3); res = joystick.SetContPov(-1, id, 4); }; } ; // If Discrete POV hat switches installed - make them go round // From time to time - put the switches in neutral state if (DiscPovNumber > 0) { if (count < 550) { joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1); joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2); joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3); joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4); } else { joystick.SetDiscPov(-1, id, 1); joystick.SetDiscPov(-1, id, 2); joystick.SetDiscPov(-1, id, 3); joystick.SetDiscPov(-1, id, 4); }; } ; System.Threading.Thread.Sleep(20); X += 150; if (X > maxval) { X = 0; } Y += 250; if (Y > maxval) { Y = 0; } Z += 350; if (Z > maxval) { Z = 0; } XR += 220; if (XR > maxval) { XR = 0; } ZR += 200; if (ZR > maxval) { ZR = 0; } count++; if (count > 640) { count = 0; } } // While (Robust) #endif // ROBUST #if EFFICIENT // todo: unused, from the original vjoy feeder demo code. byte[] pov = new byte[4]; while (true) { iReport.bDevice = (byte)id; iReport.AxisX = X; iReport.AxisY = Y; iReport.AxisZ = Z; iReport.AxisZRot = ZR; iReport.AxisXRot = XR; // Set buttons one by one iReport.Buttons = (uint)(0x1 << (int)(count / 20)); if (ContPovNumber > 0) { // Make Continuous POV Hat spin iReport.bHats = (count * 70); iReport.bHatsEx1 = (count * 70) + 3000; iReport.bHatsEx2 = (count * 70) + 5000; iReport.bHatsEx3 = 15000 - (count * 70); if ((count * 70) > 36000) { iReport.bHats = 0xFFFFFFFF; // Neutral state iReport.bHatsEx1 = 0xFFFFFFFF; // Neutral state iReport.bHatsEx2 = 0xFFFFFFFF; // Neutral state iReport.bHatsEx3 = 0xFFFFFFFF; // Neutral state } ; } else { // Make 5-position POV Hat spin pov[0] = (byte)(((count / 20) + 0) % 4); pov[1] = (byte)(((count / 20) + 1) % 4); pov[2] = (byte)(((count / 20) + 2) % 4); pov[3] = (byte)(((count / 20) + 3) % 4); iReport.bHats = (uint)(pov[3] << 12) | (uint)(pov[2] << 8) | (uint)(pov[1] << 4) | (uint)pov[0]; if ((count) > 550) { iReport.bHats = 0xFFFFFFFF; // Neutral state } }; /*** Feed the driver with the position packet - is fails then wait for input then try to re-acquire device ***/ if (!joystick.UpdateVJD(id, ref iReport)) { Console.WriteLine("Feeding vJoy device number {0} failed - try to enable device then press enter\n", id); Console.ReadKey(true); joystick.AcquireVJD(id); } System.Threading.Thread.Sleep(20); count++; if (count > 640) { count = 0; } X += 150; if (X > maxval) { X = 0; } Y += 250; if (Y > maxval) { Y = 0; } Z += 350; if (Z > maxval) { Z = 0; } XR += 220; if (XR > maxval) { XR = 0; } ZR += 200; if (ZR > maxval) { ZR = 0; } } ; // While #endif // EFFICIENT }
private bool C4(uint player, vJoy playa) { return(playa.SetDiscPov(2, player, 2)); }
private bool None(uint player, vJoy playa) { return(playa.SetDiscPov(-1, player, 1)); }
static void Main(string[] args) { // Create one joystick object and a position structure. joystick = new vJoy(); iReport = new vJoy.JoystickState(); // Device ID can only be in the range 1-16 if (args.Length > 0 && !String.IsNullOrEmpty(args[0])) { id = Convert.ToUInt32(args[0]); } if (id <= 0 || id > 16) { Console.WriteLine("Illegal device ID {0}\nExit!", id); return; } // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return; } else { Console.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString()); } // Get the state of the requested device VjdStat status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", id); break; case VjdStat.VJD_STAT_FREE: Console.WriteLine("vJoy Device {0} is free\n", id); break; case VjdStat.VJD_STAT_BUSY: Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id); return; case VjdStat.VJD_STAT_MISS: Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id); return; default: Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id); return; } ; // Check which axes are supported bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); bool AxisY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y); bool AxisZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z); bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ); // Get the number of buttons and POV Hat switchessupported by this vJoy device int nButtons = joystick.GetVJDButtonNumber(id); int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(id); // Print results Console.WriteLine("\nvJoy Device {0} capabilities:\n", id); Console.WriteLine("Numner of buttons\t\t{0}\n", nButtons); Console.WriteLine("Numner of Continuous POVs\t{0}\n", ContPovNumber); Console.WriteLine("Numner of Descrete POVs\t\t{0}\n", DiscPovNumber); Console.WriteLine("Axis X\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No"); Console.WriteLine("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No"); // Test if DLL matches the driver UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (match) { Console.WriteLine("Version of Driver Matches DLL Version ({0:X})\n", DllVer); } else { Console.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer); } // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id); return; } else { Console.WriteLine("Acquired: vJoy device number {0}.\n", id); } // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(2)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", 2); return; } else { Console.WriteLine("Acquired: vJoy device number {0}.\n", 2); } // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(3)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", 3); return; } else { Console.WriteLine("Acquired: vJoy device number {0}.\n", 3); } // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(4)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", 4); return; } else { Console.WriteLine("Acquired: vJoy device number {0}.\n", 4); } int X, Y, Z, ZR, XR; uint count = 0; long maxval = 0; X = 20; Y = 30; Z = 40; XR = 60; ZR = 80; joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); #if LMAONEITHER bool res; // Reset this device to default values joystick.ResetVJD(id); // Connecting to socket.io server (make sure the server is up first!) var socket = IO.Socket("http://localhost:14178"); socket.On(Socket.EVENT_CONNECT, () => { socket.Emit("clientconnect", "iamclient"); Console.WriteLine("Thanks for using LocalLink! This is a controller log; feel free to minimize it, but DO NOT CLOSE IT unless you're finished using our program."); }); socket.On("buttondown", (data) => { JObject a = (JObject)data; joystick.SetBtn(true, Convert.ToUInt32((string)a["controllerid"]), Convert.ToUInt32((string)a["buttonid"])); Console.WriteLine("\ngot button " + (string)a["buttonid"] + " down on controller " + (string)a["controllerid"]); }); socket.On("buttonup", (data) => { JObject a = (JObject)data; joystick.SetBtn(false, Convert.ToUInt32((string)a["controllerid"]), Convert.ToUInt32((string)a["buttonid"])); Console.WriteLine("\ngot button " + (string)a["buttonid"] + " up on controller " + (string)a["controllerid"]); }); socket.On("setaxis", (data) => { JObject a = (JObject)data; switch (a["axis"].ToString().ToLower()) { case "x": joystick.SetAxis((int)a["value"], Convert.ToUInt32((string)a["controllerid"]), HID_USAGES.HID_USAGE_X); Console.WriteLine("got x " + (int)a["value"]); break; case "y": joystick.SetAxis((int)a["value"], Convert.ToUInt32((string)a["controllerid"]), HID_USAGES.HID_USAGE_Y); break; case "z": joystick.SetAxis((int)a["value"], Convert.ToUInt32((string)a["controllerid"]), HID_USAGES.HID_USAGE_Z); break; case "rx": joystick.SetAxis((int)a["value"], Convert.ToUInt32((string)a["controllerid"]), HID_USAGES.HID_USAGE_RX); break; case "ry": joystick.SetAxis((int)a["value"], Convert.ToUInt32((string)a["controllerid"]), HID_USAGES.HID_USAGE_RY); break; case "rz": joystick.SetAxis((int)a["value"], Convert.ToUInt32((string)a["controllerid"]), HID_USAGES.HID_USAGE_RZ); break; } }); Console.ReadLine(); #endif // LMAONEITHER #if ROBUST bool res; // Reset this device to default values joystick.ResetVJD(id); // Feed the device in endless loop while (true) { // Set position of 4 axes res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X); res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y); res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z); res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX); res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ); // Press/Release Buttons res = joystick.SetBtn(true, id, count / 50); res = joystick.SetBtn(false, id, 1 + count / 50); // If Continuous POV hat switches installed - make them go round // For high values - put the switches in neutral state if (ContPovNumber > 0) { if ((count * 70) < 30000) { res = joystick.SetContPov(((int)count * 70), id, 1); res = joystick.SetContPov(((int)count * 70) + 2000, id, 2); res = joystick.SetContPov(((int)count * 70) + 4000, id, 3); res = joystick.SetContPov(((int)count * 70) + 6000, id, 4); } else { res = joystick.SetContPov(-1, id, 1); res = joystick.SetContPov(-1, id, 2); res = joystick.SetContPov(-1, id, 3); res = joystick.SetContPov(-1, id, 4); }; } ; // If Discrete POV hat switches installed - make them go round // From time to time - put the switches in neutral state if (DiscPovNumber > 0) { if (count < 550) { joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1); joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2); joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3); joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4); } else { joystick.SetDiscPov(-1, id, 1); joystick.SetDiscPov(-1, id, 2); joystick.SetDiscPov(-1, id, 3); joystick.SetDiscPov(-1, id, 4); }; } ; System.Threading.Thread.Sleep(20); X += 150; if (X > maxval) { X = 0; } Y += 250; if (Y > maxval) { Y = 0; } Z += 350; if (Z > maxval) { Z = 0; } XR += 220; if (XR > maxval) { XR = 0; } ZR += 200; if (ZR > maxval) { ZR = 0; } count++; if (count > 640) { count = 0; } } // While (Robust) #endif // ROBUST #if EFFICIENT byte[] pov = new byte[4]; while (true) { iReport.bDevice = (byte)id; iReport.AxisX = X; iReport.AxisY = Y; iReport.AxisZ = Z; iReport.AxisZRot = ZR; iReport.AxisXRot = XR; // Set buttons one by one iReport.Buttons = (uint)(0x1 << (int)(count / 20)); if (ContPovNumber > 0) { // Make Continuous POV Hat spin iReport.bHats = (count * 70); iReport.bHatsEx1 = (count * 70) + 3000; iReport.bHatsEx2 = (count * 70) + 5000; iReport.bHatsEx3 = 15000 - (count * 70); if ((count * 70) > 36000) { iReport.bHats = 0xFFFFFFFF; // Neutral state iReport.bHatsEx1 = 0xFFFFFFFF; // Neutral state iReport.bHatsEx2 = 0xFFFFFFFF; // Neutral state iReport.bHatsEx3 = 0xFFFFFFFF; // Neutral state } ; } else { // Make 5-position POV Hat spin pov[0] = (byte)(((count / 20) + 0) % 4); pov[1] = (byte)(((count / 20) + 1) % 4); pov[2] = (byte)(((count / 20) + 2) % 4); pov[3] = (byte)(((count / 20) + 3) % 4); iReport.bHats = (uint)(pov[3] << 12) | (uint)(pov[2] << 8) | (uint)(pov[1] << 4) | (uint)pov[0]; if ((count) > 550) { iReport.bHats = 0xFFFFFFFF; // Neutral state } }; /*** Feed the driver with the position packet - is fails then wait for input then try to re-acquire device ***/ if (!joystick.UpdateVJD(id, ref iReport)) { Console.WriteLine("Feeding vJoy device number {0} failed - try to enable device then press enter\n", id); Console.ReadKey(true); joystick.AcquireVJD(id); } System.Threading.Thread.Sleep(20); count++; if (count > 640) { count = 0; } X += 150; if (X > maxval) { X = 0; } Y += 250; if (Y > maxval) { Y = 0; } Z += 350; if (Z > maxval) { Z = 0; } XR += 220; if (XR > maxval) { XR = 0; } ZR += 200; if (ZR > maxval) { ZR = 0; } } ; // While #endif // EFFICIENT } // Main
private bool Down(uint player, vJoy playa) { return(playa.SetDiscPov(2, player, 1)); }
private bool Up(uint player, vJoy playa) { return(playa.SetDiscPov(0, player, 1)); }
private bool Left(uint player, vJoy playa) { return(playa.SetDiscPov(3, player, 1)); }
private bool Right(uint player, vJoy playa) { return(playa.SetDiscPov(1, player, 1)); }