private void ConnectClient() { try { VJoy = new vJoy(); if (!VJoy.vJoyEnabled()) { Connection.LogSDMessage("vJoy driver not enabled: Failed Getting vJoy attributes."); Logger.Instance.LogMessage(TracingLevel.ERROR, "vJoy driver not enabled: Failed Getting vJoy attributes."); } else { Connection.LogSDMessage($"Vendor: {VJoy.GetvJoyManufacturerString()}\nProduct :{VJoy.GetvJoyProductString()}\nVersion Number:{VJoy.GetvJoySerialNumberString()}\n"); Logger.Instance.LogMessage(TracingLevel.INFO, $"Vendor: {VJoy.GetvJoyManufacturerString()}\nProduct :{VJoy.GetvJoyProductString()}\nVersion Number:{VJoy.GetvJoySerialNumberString()}\n"); } if (!VJoy.AcquireVJD(JoystickId)) { Connection.ShowAlert().Start(); } else { VJoy.ResetAll(); } } catch (ArgumentException ex) { Connection.LogSDMessage($"{ex.Message}"); Logger.Instance.LogMessage(TracingLevel.ERROR, $"{ex.Message}"); } }
public VirtualController(uint ID) { this.ID = ID; this.joystick = new vJoy(); if (!ControllerCache.VCCheck) { if (!joystick.vJoyEnabled()) { logger.Fatal("vJoy driver not enabled: Failed Getting vJoy attributes."); return; } else { logger.Info("Vendor: {0}; Product :{1}; Version Number:{2}", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString() ); } // check driver version against local DLL version uint DllVer = 0, DrvVer = 0; if (!this.joystick.DriverMatch(ref DllVer, ref DrvVer)) { logger.Error("Version of vJoy Driver ({0:X}) NOT MATCH NOT MATCH vJoy DLL Version ({1:X})", DrvVer, DllVer); } else { logger.Info("Version of vJoy Driver ({0:X}), vJoy DLL Version ({1:X})", DrvVer, DllVer); } ControllerCache.VCCheck = true; } }
const int PULSE_LENGTH = 60; //ms public ButtonProcessor(int multiplier, int holdThresholdStart, int holdThresholdStop, OutputButton outputButton) { _multiplier = multiplier; _holdThresholdStart = holdThresholdStart; _holdThresholdStop = holdThresholdStop; _vJoyId = outputButton.VJoyDevice; _vJoyButtonNumber = outputButton.VJoyItem; _joystick = new vJoy(); if (!_joystick.vJoyEnabled()) { Debug.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); } else { Debug.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", _joystick.GetvJoyManufacturerString(), _joystick.GetvJoyProductString(), _joystick.GetvJoySerialNumberString()); } // Acquire the target VjdStat status = _joystick.GetVJDStatus(_vJoyId); if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!_joystick.AcquireVJD(_vJoyId)))) { Debug.WriteLine("Failed to acquire vJoy device number {0}.", _vJoyId); return; } else { Debug.WriteLine("Acquired: vJoy device number {0}.", _vJoyId); } _joystick.ResetVJD(_vJoyId); }
public void ValidateHost() { // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!vjoy.vJoyEnabled()) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return; } else { Console.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", vjoy.GetvJoyManufacturerString(), vjoy.GetvJoyProductString(), vjoy.GetvJoySerialNumberString()); } // Test if DLL matches the driver UInt32 DllVer = 0, DrvVer = 0; bool match = vjoy.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); } }
public void Initialize() { if (Initialized == true) { return; } VJoyInstance = new vJoy(); if (VJoyInstance.vJoyEnabled() == false) { TRBotLogger.Logger.Error("vJoy driver not enabled!"); return; } //The data object passed in here will be returned in the callback //This can be used to update the object's data when a vJoy device is connected or disconnected from the computer //This does not get fired when the vJoy device is acquired or relinquished VJoyInstance.RegisterRemovalCB(OnDeviceRemoved, null); string vendor = VJoyInstance.GetvJoyManufacturerString(); string product = VJoyInstance.GetvJoyProductString(); string serialNum = VJoyInstance.GetvJoySerialNumberString(); TRBotLogger.Logger.Information($"vJoy driver found - Vendor: {vendor} | Product: {product} | Version: {serialNum}"); uint dllver = 0; uint drvver = 0; bool match = VJoyInstance.DriverMatch(ref dllver, ref drvver); TRBotLogger.Logger.Information($"Using vJoy DLL version {dllver} and vJoy driver version {drvver} | Version Match: {match}"); }
public void Initialize() { if (Initialized == true) { return; } VJoyInstance = new vJoy(); if (VJoyInstance.vJoyEnabled() == false) { Console.WriteLine("vJoy driver not enabled!"); return; } //Kimimaru: The data object passed in here will be returned in the callback //This can be used to update the object's data when a vJoy device is connected or disconnected from the computer //This does not get fired when the vJoy device is acquired or relinquished VJoyInstance.RegisterRemovalCB(OnDeviceRemoved, null); string vendor = VJoyInstance.GetvJoyManufacturerString(); string product = VJoyInstance.GetvJoyProductString(); string serialNum = VJoyInstance.GetvJoySerialNumberString(); Console.WriteLine($"vJoy driver found - Vendor: {vendor} | Product: {product} | Version: {serialNum}"); uint dllver = 0; uint drvver = 0; bool match = VJoyInstance.DriverMatch(ref dllver, ref drvver); Console.WriteLine($"Using vJoy DLL version {dllver} and vJoy driver version {drvver} | Version Match: {match}"); //int acquiredCount = InitControllers(BotProgram.BotData.JoystickCount); //Console.WriteLine($"Acquired {acquiredCount} controllers!"); }
readonly long BUTTON_FILTER = 0; // Ignore new button presses less than this (ms) public AxisProcessor(int axisSensitivity, OutputAxis outputAxis) { Debug.WriteLine("Multiplier is {0}", axisSensitivity); _sensitivity = axisSensitivity; _vJoyId = outputAxis.VJoyDevice; _vJoyAxisNumber = outputAxis.VJoyItem; _joystick = new vJoy(); if (!_joystick.vJoyEnabled()) { Debug.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); } else { Debug.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", _joystick.GetvJoyManufacturerString(), _joystick.GetvJoyProductString(), _joystick.GetvJoySerialNumberString()); } // Acquire the target (Not currently used really...) VjdStat status = _joystick.GetVJDStatus(_vJoyId); Debug.WriteLine("vJoy Status: " + status.ToString()); if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!_joystick.AcquireVJD(_vJoyId)))) { Debug.WriteLine("Failed to acquire vJoy device number {0}.", _vJoyId); } _joystick.GetVJDAxisMax(_vJoyId, (HID_USAGES)_vJoyAxisNumber, ref _maxAxisValue); Debug.WriteLine("Max value of VJID {0} axis {1} is {2}", _vJoyId, (HID_USAGES)_vJoyAxisNumber, _maxAxisValue); Centre(); }
public VJoyFeeder() { _joystick = new vJoy(); _joystickState = new vJoy.JoystickState(); _id = 1; _joystick.ResetVJD(_id); if (!_joystick.vJoyEnabled()) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return; } 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; } ; // 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); } _joystick.AcquireVJD(_id); }
// functions ................... public void check() //check if virual joystick is enabled { if (!joystick1.vJoyEnabled()) { Debug.WriteLine("not enabled"); } else { Debug.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick1.GetvJoyManufacturerString(), joystick1.GetvJoyProductString(), joystick1.GetvJoySerialNumberString());; } }
public static void EnablevJoy() { Console.WriteLine("Getting vJoy controller..."); joystick = new vJoy(); if (joystick.vJoyEnabled()) { Console.WriteLine("vJoy enabled!"); Console.WriteLine("vJoy ver: " + joystick.GetvJoyVersion()); Console.WriteLine("Manufacturer: " + joystick.GetvJoyManufacturerString()); Console.WriteLine("Product: " + joystick.GetvJoyProductString()); Console.WriteLine("Serial No. : " + joystick.GetvJoySerialNumberString()); Console.WriteLine("Searching for available joystick..."); for (uint i = 1; i < 16; i++) { Console.WriteLine($"Trying joystick {i}..."); var status = joystick.GetVJDStatus(i); Console.WriteLine($"Joystick status: {status}"); if (new VjdStat[] { VjdStat.VJD_STAT_OWN, VjdStat.VJD_STAT_FREE }.Contains(status))// is it owned already or ready to own? { vjd = i; break; } } if (vjd != 0) // joystick id can never be 0, not using -1 to avoid casting { Console.WriteLine("Attempting to acquire joystick..."); if (joystick.AcquireVJD(vjd)) { Console.WriteLine("Success!"); } else { Console.WriteLine("Failed to acquire joystick!"); } } else { Console.WriteLine("No joysticks available!"); } } else { Console.WriteLine("vJoy not enabled!"); } }
private void Form1_Load(object sender, EventArgs e) { // Initialize vJoy ujoyStick = new vJoy(); // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!ujoyStick.vJoyEnabled()) { vjoy_status.Text = "vJoy driver not enabled"; Application.Exit(); Console.WriteLine(vjoy_status.Text); } vjoy_status.Text = ujoyStick.GetVJDStatus(uJoyId).ToString(); vjoy_vendor.Text = ujoyStick.GetvJoyManufacturerString(); vjoy_product.Text = ujoyStick.GetvJoyProductString(); vjoy_version.Text = ujoyStick.GetvJoySerialNumberString(); UInt32 DllVer = 0, DrvVer = 0; bool match = ujoyStick.DriverMatch(ref DllVer, ref DrvVer); if (match) { vjoy_dllver.Text = DllVer.ToString(); vjoy_drvver.Text = DrvVer.ToString(); Console.WriteLine("DLL: " + vjoy_dllver.Text); Console.WriteLine("DRV: " + vjoy_drvver.Text); } else { vjoy_status.Text = "DLL MISMATCH"; Console.WriteLine(vjoy_status.Text); } comRefresh(); fillListView(new string[] { "Throttle", "Rudder", "Aileron", "Elevator", "Gear", "Aux 1" }, new int[] { 0, 0, 1, 1, 0, 0 }); }
public EncoderAxisProcessor(int encoderPPR, float revsInPerRevsOut, OutputAxis outputAxis) { _vJoyId = outputAxis.VJoyDevice; _vJoyAxisNumber = outputAxis.VJoyItem; _joystick = new vJoy(); if (!_joystick.vJoyEnabled()) { Debug.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); } else { Debug.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", _joystick.GetvJoyManufacturerString(), _joystick.GetvJoyProductString(), _joystick.GetvJoySerialNumberString()); } // Acquire the target (Not currently used really...) VjdStat status = _joystick.GetVJDStatus(_vJoyId); Debug.WriteLine("vJoy Status: " + status.ToString()); if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!_joystick.AcquireVJD(_vJoyId)))) { Debug.WriteLine("Failed to acquire vJoy device number {0}.", _vJoyId); } _joystick.GetVJDAxisMax(_vJoyId, (HID_USAGES)_vJoyAxisNumber, ref _maxAxisValue); Debug.WriteLine("Max value of VJID {0} axis {1} is {2}", _vJoyId, (HID_USAGES)_vJoyAxisNumber, _maxAxisValue); Centre(); // Calculate how much to move the output by for each input pulse Debug.WriteLine("Encoder PPR is {0} and Revs In per Out is {1}", encoderPPR, revsInPerRevsOut); float outputRevolutionSize = _maxAxisValue / revsInPerRevsOut; encoderPPR *= 4; // I think I can get 4x the resolution out of the encoder using the tranistions between pulses Debug.WriteLine("Modifying Encoder PPR to {0}", encoderPPR); _outputIncrement = (int)(outputRevolutionSize / encoderPPR); Debug.WriteLine("Output Increment calculated as {0}", _outputIncrement); }
public static bool VjoyStart() { //string[] args = Environment.GetCommandLineArgs(); //Create one joystick object and a position structure. joystick = new vJoy(); iReport = new vJoy.JoystickState(); joystick.ResetVJD(id); // 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) { Debug.Log(string.Format("Illegal device ID {0}\nExit!", id)); return(false); } // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { Debug.Log(string.Format("vJoy driver not enabled: Failed Getting vJoy attributes.\n")); return(false); } else { Debug.Log(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: Debug.Log(string.Format("vJoy Device {0} is already owned by this feeder\n", id)); break; case VjdStat.VJD_STAT_FREE: Debug.Log(string.Format("vJoy Device {0} is free\n", id)); break; case VjdStat.VJD_STAT_BUSY: Debug.Log(string.Format("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id)); return(false); case VjdStat.VJD_STAT_MISS: Debug.Log(string.Format("vJoy Device {0} is not installed or disabled\nCannot continue\n", id)); return(false); default: Debug.Log(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 switchessupported by this vJoy device int nButtons = joystick.GetVJDButtonNumber(id); int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(id); // Print results Debug.Log(string.Format("\nvJoy Device {0} capabilities:\n", id)); Debug.Log(string.Format("Numner of buttons\t\t{0}\n", nButtons)); Debug.Log(string.Format("Numner of Continuous POVs\t{0}\n", ContPovNumber)); Debug.Log(string.Format("Numner of Descrete POVs\t\t{0}\n", DiscPovNumber)); Debug.Log(string.Format("Axis X\t\t{0}\n", AxisX ? "Yes" : "No")); Debug.Log(string.Format("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No")); Debug.Log(string.Format("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No")); Debug.Log(string.Format("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No")); Debug.Log(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) { Debug.Log(string.Format("Version of Driver Matches DLL Version ({0:X})\n", DllVer)); } else { Debug.Log(string.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer)); } // Acquire the target bool stat = ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE))); bool acq = (!joystick.AcquireVJD(id)); if (stat && acq) { Debug.Log(string.Format("Failed to acquire vJoy device number {0}.\n", id)); return(false); } else { Debug.Log(string.Format("Acquired: vJoy device number {0}.\n", id)); } //Debug.Log(string.Format("\npress enter to stat feeding"); //Console.ReadKey(true); return(true); } // Main
/// <summary> /// Tries to connect to the current instance of JoyControl which manages a specific virtual joystick /// </summary> /// <returns>Struct containing information about engaged joystick or (in case of error) /// information describing eventual problems with request</returns> public JoyCapabilities TryConnect() { if (IsBusy) { throw new Exception("Cannot connect to a joystick already connected."); } /* Creating a new instance every time when we start a new connection * because we have to refresh the access token to preserve the uniqueness * among all connection attempts */ Capabilities = new JoyCapabilities(); /* Checking if the vJoy driver is enabled */ if (!_joystick.vJoyEnabled()) { Capabilities.ErrorInfo = "vJoy driver not enabled."; return(Capabilities); } /* For information purposes only */ Capabilities.JoyInfo = String.Format("Vendor: {0}, Product :{1}, Version Number:{2}.", _joystick.GetvJoyManufacturerString(), _joystick.GetvJoyProductString(), _joystick.GetvJoySerialNumberString()); /* Checking eventual problems with occupied or not installed joystick */ var status = _joystick.GetVJDStatus(_joyId); switch (status) { case VjdStat.VJD_STAT_OWN: case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_BUSY: Capabilities.ErrorInfo = String.Format("vJoy Device {0} is already owned by another feeder. Cannot continue.", _joyId); return(Capabilities); case VjdStat.VJD_STAT_MISS: Capabilities.ErrorInfo = String.Format("vJoy Device {0} is not installed or disabled. Cannot continue.", _joyId); return(Capabilities); default: Capabilities.ErrorInfo = String.Format("vJoy Device {0} general error. Cannot continue.", _joyId); return(Capabilities); } /* ##### Remark ##### * Generally a situation that in this moment the joystick is in state VJD_STAT_OWN shouldn't be possible * and we can consider to throw an exception when the situation occurs. */ /* Engaging joystick with specified id with the current instance of JoyControl */ if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!_joystick.AcquireVJD(_joyId)))) { Capabilities.ErrorInfo = String.Format("Failed to acquire vJoy device number {0}.", _joyId); return(Capabilities); } IsBusy = true; _joystick.ResetVJD(_joyId); Capabilities.JoyId = _joyId; Capabilities.AxisXExists = _joystick.GetVJDAxisExist(_joyId, HID_USAGES.HID_USAGE_X); Capabilities.AxisXExists = _joystick.GetVJDAxisExist(_joyId, HID_USAGES.HID_USAGE_Y); Capabilities.ButtonsCount = _joystick.GetVJDButtonNumber(_joyId); long max = 0; _joystick.GetVJDAxisMax(_joyId, HID_USAGES.HID_USAGE_X, ref max); Capabilities.AxisXMax = max; _joystick.GetVJDAxisMax(_joyId, HID_USAGES.HID_USAGE_X, ref max); Capabilities.AxisYMax = max; return(Capabilities); }
/** * Code is just reference from vJoy. */ public void setupVjoy() { // 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()) { writeMessage(String.Format("vJoy driver not enabled: Failed Getting vJoy attributes.")); return; } else { writeMessage(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: writeMessage(String.Format("vJoy Device {0} is already owned by this feeder\n", id)); break; case VjdStat.VJD_STAT_FREE: writeMessage(String.Format("vJoy Device {0} is free\n", id)); break; case VjdStat.VJD_STAT_BUSY: writeMessage(String.Format("vJoy Device {0} is already owned by another feeder\nCannot continue", id)); return; case VjdStat.VJD_STAT_MISS: writeMessage(String.Format("vJoy Device {0} is not installed or disabled\nCannot continue", id)); return; default: writeMessage(String.Format("vJoy Device {0} general error\nCannot continue", 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 nButtons = joystick.GetVJDButtonNumber(id); ContPovNumber = joystick.GetVJDContPovNumber(id); DiscPovNumber = joystick.GetVJDDiscPovNumber(id); // Print results /* * writeMessage(String.Format("vJoy Device {0} capabilities:", id)); * writeMessage(String.Format("Numner of buttons\t\t{0}", nButtons)); * writeMessage(String.Format("Numner of Continuous POVs\t{0}", ContPovNumber)); * writeMessage(String.Format("Numner of Descrete POVs\t\t{0}", DiscPovNumber)); * writeMessage(String.Format("Axis X\t\t{0}", AxisX ? "Yes" : "No")); * writeMessage(String.Format("Axis Y\t\t{0}", AxisX ? "Yes" : "No")); * writeMessage(String.Format("Axis Z\t\t{0}", AxisX ? "Yes" : "No")); * writeMessage(String.Format("Axis Rx\t\t{0}", AxisRX ? "Yes" : "No")); * writeMessage(String.Format("Axis Rz\t\t{0}", 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); } maxval = 0; joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); joystick.ResetAll(); }
/// <summary> /// Enable vJoy /// </summary> /// <returns></returns> public int EnablevJoy() { // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!Joystick.vJoyEnabled()) { Log("vJoy driver not enabled: Failed Getting vJoy attributes.", LogLevels.ERROR); return(-2); } else { LogFormat(LogLevels.DEBUG, "Vendor: {0}\tProduct :{1}\tVersion Number:{2}", Joystick.GetvJoyManufacturerString(), Joystick.GetvJoyProductString(), Joystick.GetvJoySerialNumberString()); } // Test if DLL matches the driver this.vJoyVersionMatch = Joystick.DriverMatch(ref this.vJoyVersionDll, ref this.vJoyVersionDriver); if (this.vJoyVersionMatch) { LogFormat(LogLevels.DEBUG, "Version of Driver Matches DLL Version ({0:X})", this.vJoyVersionDll); return(1); } else { LogFormat(LogLevels.ERROR, "Version of Driver ({0:X}) does NOT match DLL Version ({1:X})", this.vJoyVersionDriver, this.vJoyVersionDll); return(-1); } }
public void StartInjector() { // Create one joystick object and a position structure. var joystick = new vJoy(); var joystick2 = new vJoy(); uint id = 1; uint id2 = 2; 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() || !joystick2.vJoyEnabled()) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return; } Console.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString()); Console.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick2.GetvJoyManufacturerString(), joystick2.GetvJoyProductString(), joystick2.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; } ; // Get the state of the requested device var status2 = joystick2.GetVJDStatus(id2); switch (status2) { case VjdStat.VJD_STAT_OWN: Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", id2); break; case VjdStat.VJD_STAT_FREE: Console.WriteLine("vJoy Device {0} is free\n", id2); break; case VjdStat.VJD_STAT_BUSY: Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id2); return; case VjdStat.VJD_STAT_MISS: Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id2); return; default: Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id2); 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); // Check which axes are supported bool AxisX2 = joystick2.GetVJDAxisExist(id2, HID_USAGES.HID_USAGE_X); bool AxisY2 = joystick2.GetVJDAxisExist(id2, HID_USAGES.HID_USAGE_Y); bool AxisZ2 = joystick2.GetVJDAxisExist(id2, HID_USAGES.HID_USAGE_Z); bool AxisRX2 = joystick2.GetVJDAxisExist(id2, HID_USAGES.HID_USAGE_RX); bool AxisRZ2 = joystick2.GetVJDAxisExist(id2, HID_USAGES.HID_USAGE_RZ); // Get the number of buttons and POV Hat switchessupported by this vJoy device int nButtons = joystick.GetVJDButtonNumber(id); int nButtons2 = joystick2.GetVJDButtonNumber(id2); // 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); } bool match2 = joystick2.DriverMatch(ref DllVer, ref DrvVer); if (match2) { 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; } // Acquire the target if ((status2 == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && !joystick2.AcquireVJD(id2))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id2); return; } Console.WriteLine("Acquired: vJoy device number {0}.\n", id2); long maxval = 0; joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); joystick2.GetVJDAxisMax(id2, HID_USAGES.HID_USAGE_X, ref maxval); // Reset this device to default values joystick.ResetVJD(id); joystick2.ResetVJD(id2); // Feed the device in endless loop joystick2.SetBtn(false, 2, 10); while (!KillMe) { if (Digitals != null && Digitals.Length != 0) { for (int i = 0; i < Digitals.Length; i++) { //if(i >= Digitals.Length / 2) //{ // joystick2.SetBtn(Digitals[i], id + 1, (uint)(i - (Digitals.Length / 2))); //} //else //{ if (Digitals[i]) { // Start SetButton(joystick, joystick2, true, i); } else { SetButton(joystick, joystick2, false, i); } //} } //for (var i = 0; i < Digitals.Length; i++) //{ // joystick.SetBtn(Digitals[i], id, (uint) i); //} } //if (AnalogChannels != null && AnalogChannels.Length != 0) //{ // int ptr = 48; // for (int i = 0; i < AnalogChannels.Length; i++) // { // if (i == 1) // { // joystick.SetAxis(CalculateDiFromJvs((byte)AnalogChannels[i], _gasMinimum, _gasMaximum), id, (HID_USAGES)ptr); // } // else if (i == 2) // { // joystick.SetAxis(CalculateDiFromJvs((byte)AnalogChannels[i], _brakeMinimum, _brakeMaximum), id, (HID_USAGES)ptr); // } // else if (i == 0) // { // joystick.SetAxis(CalculateDiFromJvs((byte)AnalogChannels[i], _wheelMinimum, _wheelMaximum), id, (HID_USAGES)ptr); // } // ptr++; // } //} Thread.Sleep(10); } }
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
public bool Start(bool[] parSelectedPads, PadSettings config, DeviceManagement devManLevel) { //Setup vJoy //Perform device enable/disable based on dll version //EnableVJoy needs to know which version of vJoy we are running joystick = new vJoy(); UInt32 DllVer = 0, DrvVer = 0; joystick.DriverMatch(ref DllVer, ref DrvVer); //MIN Version Check 1 vJoyVersion = DllVer; if (vJoyVersion < vJoyConstants.MIN_VER) { Trace.WriteLine("vJoy version less than required: Aborting\n"); Stop(parSelectedPads, devManLevel); return(false); } if ((devManLevel & DeviceManagement.vJoy_Config) == DeviceManagement.vJoy_Config) { EnableVJoy(false); SetupVjoy(parSelectedPads, config); vJoyInstall.RefreshvJoy(); //do it like vJConfig does (needed in 2.1.6) EnableVJoy(true); } else if ((devManLevel & DeviceManagement.vJoy_Device) == DeviceManagement.vJoy_Device) { EnableVJoy(true); } if (!joystick.vJoyEnabled()) { Trace.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return(false); } else { Trace.WriteLine(string.Format("Vendor : {0}\nProduct: {1}\nVersion: {2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString())); // Test if DLL matches the driver bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (match) { Trace.WriteLine(string.Format("Version of Driver Matches DLL Version ({0:X})", DllVer)); Trace.WriteLine(string.Format("Version of vJoyInterfaceWrap.dll is ({0})", typeof(vJoy).Assembly.GetName().Version)); Trace.WriteLine(string.Format("Version of ScpControl.dll is ({0})\n", typeof(ScpControl.ScpProxy).Assembly.GetName().Version)); } else { Trace.WriteLine(string.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer)); Stop(parSelectedPads, devManLevel); return(false); } //MinVersion Check vJoyVersion = DrvVer; if (vJoyVersion < vJoyConstants.MIN_VER) { Trace.WriteLine("vJoy version less than required: Aborting\n"); Stop(parSelectedPads, devManLevel); return(false); } } for (uint dsID = 1; dsID <= SCPConstants.MAX_XINPUT_DEVICES; dsID++) { if (parSelectedPads[dsID - 1]) { uint id = GetvjFromDS(dsID); // Acquire the target VjdStat status = joystick.GetVJDStatus(id); if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { Trace.WriteLine(string.Format("Failed to acquire vJoy device number {0}.", id)); Stop(parSelectedPads, devManLevel); return(false); } else { Trace.WriteLine(string.Format("Acquired vJoy device number {0}.", id)); } Trace.WriteLine(string.Format("Buttons : {0}.", joystick.GetVJDButtonNumber(id))); Trace.WriteLine(string.Format("DiscPov : {0}.", joystick.GetVJDDiscPovNumber(id))); Trace.WriteLine(string.Format("ContPov : {0}.", joystick.GetVJDContPovNumber(id))); //FFB if (config.ffb) { vibrationCore = new vJoyVibrate(joystick); vibrationCore.FfbInterface(dsID); vibrationCore.VibrationCommand += VibEventProxy; } // Reset this device to default values joystick.ResetVJD(id); //Set Axis to mid value joyReport[dsID - 1].AxisX = vJoyConstants.HALF_AXIS_VALUE; joyReport[dsID - 1].AxisY = vJoyConstants.HALF_AXIS_VALUE; joyReport[dsID - 1].AxisZ = vJoyConstants.HALF_AXIS_VALUE; joyReport[dsID - 1].AxisXRot = vJoyConstants.HALF_AXIS_VALUE; joyReport[dsID - 1].AxisYRot = vJoyConstants.HALF_AXIS_VALUE; joyReport[dsID - 1].AxisZRot = vJoyConstants.HALF_AXIS_VALUE; joyReport[dsID - 1].Slider = vJoyConstants.HALF_AXIS_VALUE; joyReport[dsID - 1].Dial = vJoyConstants.HALF_AXIS_VALUE; } } return(true); }
private void init(uint id) { this.id = id; joystick = new vJoy(); iReport = new vJoy.JoystickState(); // Device ID can only be in the range 1-16 if (id <= 0 || id > 16) { err(String.Format("Illegal device ID {0} (1-16)", id)); } // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { err("vJoy driver not enabled: Failed Getting vJoy attributes."); } else { Console.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString()); } VjdStat status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: Console.WriteLine("vJoy Device {0} is already owned by this feeder.", id); break; case VjdStat.VJD_STAT_FREE: Console.WriteLine("vJoy Device {0} is free.", id); break; case VjdStat.VJD_STAT_BUSY: err(String.Format("vJoy Device {0} is already owned by another feeder.", id)); return; case VjdStat.VJD_STAT_MISS: err(String.Format("vJoy Device {0} is not installed or disabled.", id)); return; default: err(String.Format("vJoy Device {0} general error.", 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:", id); * Console.WriteLine("Numner of buttons\t\t{0}", nButtons); * Console.WriteLine("Numner of Continuous POVs\t{0}", ContPovNumber); * Console.WriteLine("Numner of Descrete POVs\t\t{0}", DiscPovNumber); * Console.WriteLine("Axis X\t\t{0}", AxisX ? "Yes" : "No"); * Console.WriteLine("Axis Y\t\t{0}", AxisX ? "Yes" : "No"); * Console.WriteLine("Axis Z\t\t{0}", AxisX ? "Yes" : "No"); * Console.WriteLine("Axis Rx\t\t{0}", AxisRX ? "Yes" : "No"); * Console.WriteLine("Axis Rz\t\t{0}", 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})", DllVer); } else { Console.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})", DrvVer, DllVer); } // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { err(String.Format("Failed to acquire vJoy device number {0}.", id)); return; } else { Console.WriteLine("Acquired: vJoy device number {0}.", id); } initAxes(); }
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]); for (int i = 0; i < args.Length; i++) { if (args[i] != null && args[i] != "") { switch (args[i][0]) { case 'i': if (!UInt32.TryParse(args[i].Substring(1, args[i].Length - 1), out id)) { id = 1; } break; case 's': try { portname = args[i].Substring(1, args[i].Length - 1); } catch (Exception ex) { portname = "COM1"; } break; default: break; } } } Console.WriteLine("Command line arguments parsed."); //Console.ReadLine(); if (id <= 0 || id > 16) { Console.WriteLine("Illegal device ID {0}\nExit!", id); Console.ReadLine(); return; } string[] ports = System.IO.Ports.SerialPort.GetPortNames(); bool portfound = false; for (int i = 0; i < ports.Length; i++) { Console.WriteLine(ports[i]); if (portname == ports[i]) { portfound = true; } } if (!portfound) { Console.WriteLine("Port {0} not found\nExit!", id); Console.ReadLine(); } Console.WriteLine("Device ID and port name checked."); //Console.ReadLine(); // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); Console.ReadLine(); 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); Console.ReadLine(); return; case VjdStat.VJD_STAT_MISS: Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id); Console.ReadLine(); return; default: Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id); Console.ReadLine(); 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); Console.ReadLine(); return; } else { Console.WriteLine("Acquired: vJoy device number {0}.\n", id); } //Console.WriteLine("\npress enter to stat feeding"); //Console.ReadKey(true); Console.WriteLine("Feeding controller inputs..."); //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); using (Process p = Process.GetCurrentProcess()) { try { p.PriorityClass = ProcessPriorityClass.RealTime; } catch (Exception ex1) { Console.WriteLine("Failed to set realtime priority."); try { p.PriorityClass = ProcessPriorityClass.High; } catch (Exception ex2) { Console.WriteLine("Failed to set high priority. Running at normal priority."); } } p.ProcessorAffinity = (IntPtr)(1 << (Environment.ProcessorCount - 1)); } byte[] oldinputs = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] cosinputs = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; using (System.IO.Ports.SerialPort port = new System.IO.Ports.SerialPort(portname, 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One)) { port.WriteTimeout = 1000; port.ReadTimeout = 1000; port.Open(); // Feed the device in endless loop while (true) { byte[] inputs = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; try { byte[] test = new byte[1]; do { port.Read(test, 0, 1); } while (test[0] != 0xFF); for (int i = 0; i < 16; i++) { int inbyte; do { inbyte = port.ReadByte(); }while (inbyte < 0); inputs[i] = (byte)inbyte; } } catch (Exception ex) { Console.WriteLine("Exception reading joystick port: " + ex.Message); } //16 byte packet - supports 8 SNES-style controllers simultaneously //2 byte - player 1 //2 byte - player 2 //2 byte - player 3 //2 byte - player 4 //2 byte - player 5 //2 byte - player 6 //2 byte - player 7 //2 byte - player 8 for (int i = 0; i < inputs.Length; i++) { cosinputs[i] = (byte)(inputs[i] ^ oldinputs[i]); for (int j = 0; j < 8; j++) { //change: try to only send new status on change-of-state to reduce input events if ((cosinputs[i] & (1 << j)) != 0) { res = joystick.SetBtn((inputs[i] & (1 << j)) != 0, id, (uint)(((i * 8) + j) + 1)); } } } //copy current over old oldinputs = inputs; } // While (Robust) } } // Main
public Form1() { InitializeComponent(); // ******************************************* **** ********************************************* // **************************************** start_Vjoy ****************************************** // ******************************************* **** ********************************************* // Create one joystick object and a position structure. joystick = new vJoy(); iReport = new vJoy.JoystickState(); // 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 AxisRY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RY); 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("Number of buttons\t\t{0}\n", nButtons); Console.WriteLine("Number of Continuous POVs\t{0}\n", ContPovNumber); Console.WriteLine("Number 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", AxisY ? "Yes" : "No"); Console.WriteLine("Axis Z\t\t{0}\n", AxisZ ? "Yes" : "No"); Console.WriteLine("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No"); Console.WriteLine("Axis Rx\t\t{0}\n", AxisRY ? "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); } joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxvalue); Console.WriteLine("Max value X: {0}.\n", maxvalue); joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_Y, ref maxvalue); Console.WriteLine("Max value Y: {0}.\n", maxvalue); joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_RX, ref maxvalue); Console.WriteLine("Max value RX: {0}.\n", maxvalue); joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_RY, ref maxvalue); Console.WriteLine("Max value RY: {0}.\n", maxvalue); joystick.GetVJDAxisMin(id, HID_USAGES.HID_USAGE_X, ref minvalue); Console.WriteLine("Min value X: {0}.\n", minvalue); joystick.GetVJDAxisMin(id, HID_USAGES.HID_USAGE_Y, ref minvalue); Console.WriteLine("Min value Y: {0}.\n", minvalue); joystick.GetVJDAxisMin(id, HID_USAGES.HID_USAGE_RX, ref minvalue); Console.WriteLine("Min value RX: {0}.\n", minvalue); joystick.GetVJDAxisMin(id, HID_USAGES.HID_USAGE_RY, ref minvalue); Console.WriteLine("Min value RY: {0}.\n", minvalue); this.minValJOY.Text = minvalue.ToString(); this.maxValJOY.Text = maxvalue.ToString(); // Reset this device to default values joystick.ResetVJD(id); yawProg.Minimum = (int)minvalue; yawProg.Maximum = (int)maxvalue; rollProg.Minimum = (int)minvalue; rollProg.Maximum = (int)maxvalue; pitchProg.Minimum = (int)minvalue; pitchProg.Maximum = (int)maxvalue; heightProg.Minimum = (int)minvalue; heightProg.Maximum = (int)maxvalue; rollChart.ChartAreas[0].AxisY.Maximum = maxvalue; rollChart.ChartAreas[0].AxisY.Minimum = minvalue; pitchChart.ChartAreas[0].AxisY.Maximum = maxvalue; pitchChart.ChartAreas[0].AxisY.Minimum = minvalue; heightChart.ChartAreas[0].AxisY.Maximum = maxvalue; heightChart.ChartAreas[0].AxisY.Minimum = minvalue; yawChart.ChartAreas[0].AxisY.Maximum = maxvalue; yawChart.ChartAreas[0].AxisY.Minimum = minvalue; myCircularBuff = new CircularBuffer <HandValue>(2000); myLog = new Logger(); t = new Thread(joyThread); t.Start(); tS = new Thread(serialThread); tS.Start(); // ******************************************* **** ********************************************* // ***************************************** end_Vjoy ******************************************* // ******************************************* **** ********************************************* controller.EventContext = WindowsFormsSynchronizationContext.Current; controller.FrameReady += newFrameHandler; controller.ImageReady += onImageReady; controller.ImageRequestFailed += onImageRequestFailed; //set greyscale palette for image Bitmap object ColorPalette grayscale = bitmap.Palette; for (int i = 0; i < 256; i++) { grayscale.Entries[i] = Color.FromArgb((int)255, i, i, i); } bitmap.Palette = grayscale; }
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
public TesterForm() { InitializeComponent(); joystick = new vJoy(); position = new vJoy.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; ///// vJoy Device properties 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; 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 vJoy 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 void SetUpJoystick() { joystick = new vJoy(); iReport = new vJoy.JoystickState(); 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; } ; int nButtons = joystick.GetVJDButtonNumber(id); // 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); } joystick.ResetVJD(id); }
/// <summary> /// バージョン文字列作成 /// </summary> /// <returns></returns> public override string ToString() { string format = "{0} version {1}\nCopyright © {2}."; return(string.Format(format, joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString(), joystick.GetvJoyManufacturerString())); }
static void VJoyActivation() { //Check ID Console.WriteLine("Joystick Number : "); id = UInt32.Parse(Console.ReadLine()); if (id <= 0 || id > 16) { Console.WriteLine("Illegal device ID {0}\nExit!", id); return; } //Check Activaton 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; } ; // 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); } Console.WriteLine("\npress enter to stat feeding"); Console.ReadLine(); }
public void initializeJoystick() { if (joystick == null) { joystick = new vJoy(); } // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { NotifyStatusMessage("vJoy driver not enabled: Failed Getting vJoy attributes."); return; } else { NotifyStatusMessage(String.Format("Vendor: {0} Product :{1} Version Number:{2}", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString())); } // Get the state of the requested device VjdStat status = joystick.GetVJDStatus(jID); switch (status) { case VjdStat.VJD_STAT_OWN: NotifyStatusMessage(String.Format("vJoy Device {0} is already owned by this feeder", jID)); break; case VjdStat.VJD_STAT_FREE: NotifyStatusMessage(String.Format("vJoy Device {0} is free", jID)); break; case VjdStat.VJD_STAT_BUSY: NotifyStatusMessage(String.Format("vJoy Device {0} is already owned by another feeder. Cannot continue", jID)); return; case VjdStat.VJD_STAT_MISS: NotifyStatusMessage(String.Format("vJoy Device {0} is not installed or disabled. Cannot continue", jID)); return; default: NotifyStatusMessage(String.Format("vJoy Device {0} general error. Cannot continue", jID)); return; } ; // Check which axes are supported bool AxisX = joystick.GetVJDAxisExist(jID, HID_USAGES.HID_USAGE_X); bool AxisY = joystick.GetVJDAxisExist(jID, HID_USAGES.HID_USAGE_Y); bool AxisZ = joystick.GetVJDAxisExist(jID, HID_USAGES.HID_USAGE_Z); bool AxisRX = joystick.GetVJDAxisExist(jID, HID_USAGES.HID_USAGE_RX); bool AxisRZ = joystick.GetVJDAxisExist(jID, HID_USAGES.HID_USAGE_RZ); // Get the number of buttons and POV Hat switchessupported by this vJoy device int nButtons = joystick.GetVJDButtonNumber(jID); int ContPovNumber = joystick.GetVJDContPovNumber(jID); int DiscPovNumber = joystick.GetVJDDiscPovNumber(jID); // Print results NotifyStatusMessage(String.Format("vJoy Device {0} capabilities:", jID)); NotifyStatusMessage(String.Format("Numner of buttons\t{0}", nButtons)); NotifyStatusMessage(String.Format("Numner of Continuous POVs\t{0}", ContPovNumber)); NotifyStatusMessage(String.Format("Numner of Descrete POVs\t{0}", DiscPovNumber)); NotifyStatusMessage(String.Format("Axis X\t\t{0}", AxisX ? "Yes" : "No")); NotifyStatusMessage(String.Format("Axis Y\t\t{0}", AxisX ? "Yes" : "No")); NotifyStatusMessage(String.Format("Axis Z\t\t{0}", AxisX ? "Yes" : "No")); NotifyStatusMessage(String.Format("Axis Rx\t\t{0}", AxisRX ? "Yes" : "No")); NotifyStatusMessage(String.Format("Axis Rz\t\t{0}", AxisRZ ? "Yes" : "No")); // Test if DLL matches the driver UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (match) { NotifyStatusMessage(String.Format("Version of Driver Matches DLL Version ({0:X})", DllVer)); } else { NotifyStatusMessage(String.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})", DrvVer, DllVer)); } // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || (status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(jID))) { NotifyStatusMessage(String.Format("Failed to acquire vJoy device number {0}.", jID)); return; } else { NotifyStatusMessage(String.Format("Acquired: vJoy device number {0}.", jID)); } }
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 }
static void Main(string[] args) { // Create one joystick object and a position structure. joystick = new vJoy(); iReport = new vJoy.JoystickState(); Verbose = args.Any(l => l.ToLower().Equals("v")); SerialStates.CenterInsensibility = args.Any(l => l.ToLower().Equals("i")); // Device ID can only be in the range 1-16 if (args.Length > 1 && !String.IsNullOrEmpty(args[0]) && !String.IsNullOrEmpty(args[1])) { id = Convert.ToUInt32(args[0]); serialLink = new SerialLink(Convert.ToInt32(args[1])); } else { Console.WriteLine($"Input parameter vJoy id and com port!"); return; } 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 AxisRY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RY); 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", AxisY ? "Yes" : "No"); Console.WriteLine("Axis Z\t\t{0}\n", AxisZ ? "Yes" : "No"); Console.WriteLine("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No"); Console.WriteLine("Axis Ry\t\t{0}\n", AxisRY ? "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); } joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref SerialStates.AxeMaxVal); serialLink.OpenPortAndRead(); }