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 AcquireDevice(uint id) { bool res = vjoy.AcquireVJD(id); vjoy.ResetVJD(id); Console.WriteLine("Res: " + res); }
private void Initialize_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()) { MessageBox.Show("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); Program._shouldExit = true; System.Environment.Exit(0); } // Get the state of the requested device VjdStat status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: break; case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_BUSY: MessageBox.Show("vJoy Device is already owned by another feeder\nInput feeding will not occur."); //System.Environment.Exit(0); return; case VjdStat.VJD_STAT_MISS: MessageBox.Show("vJoy Device is not installed or disabled\nInput feeding will not occur."); //System.Environment.Exit(0); return; default: MessageBox.Show("vJoy Device general error\nInput feeding will not occur."); //System.Environment.Exit(0); return; } ; // 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); // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { MessageBox.Show("Failed to acquire vJoy device number"); Program._shouldExit = true; System.Environment.Exit(0); } joystick.ResetVJD(id); }
public IWriter Create(Identifier id) { var device = new vJoy(); device.AcquireVJD(id.Id); device.ResetVJD(id.Id); return(new Writer(id, device)); }
public void ReleaseDevice() { if (bDeviceAcquired) { m_joystick.ResetVJD(m_vJoyID); m_joystick.RelinquishVJD(m_vJoyID); bDeviceAcquired = false; } }
string Joystick(dynamic input) { id = (uint)input.pid; joystick = new vJoy(); iReport = new vJoy.JoystickState(); if (!joystick.vJoyEnabled()) { return("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); } if (started == 0) { status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_MISS: case VjdStat.VJD_STAT_BUSY: default: return("vJoy error\n" + status); } ; if (!joystick.AcquireVJD(id)) { return("Cannot acquire!"); } joystick.ResetVJD(id); } started = 1; bool btnStatus = false; uint btnId = 0; string teste = ""; foreach (dynamic btn in input.buttons) { foreach (dynamic btnP in btn.Value) { if (btnP.Key == "bid") { btnId = (uint)btnP.Value; } if (btnP.Key == "status") { btnStatus = (bool)btnP.Value; } } joystick.SetBtn(btnStatus, id, btnId); teste += " " + btnId + ":(" + btnStatus + ")"; } joystick.SetAxis(((int)input.axis.X), id, HID_USAGES.HID_USAGE_X); joystick.SetAxis(((int)input.axis.Y), id, HID_USAGES.HID_USAGE_Y); return("vJoy Enabled! " + id + teste); }
public MainWindow() { InitializeComponent(); this.Leap_Controller = new Controller(); this.Leap_Listener = new LeapEventListener(this); Leap_Controller.AddListener(Leap_Listener); Leap_Controller.SetPolicyFlags(Controller.PolicyFlag.POLICYBACKGROUNDFRAMES); vJoy_Joystick = new vJoy(); if (!vJoy_Joystick.vJoyEnabled()) { return; } UInt32 DllVer = 0, DrvVer = 0; vJoy_Joystick.DriverMatch(ref DllVer, ref DrvVer); vJoy_Joystick.AcquireVJD(vJoy_id); vJoy_Joystick.ResetVJD(vJoy_id); Trig_En = new SolidColorBrush(Colors.LightGreen); Trig_Dis = Text_Trig_Max_Up.Background; try { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("LeapJoySets.bin", FileMode.Open, FileAccess.Read, FileShare.Read); Data_Set = (DataSet)formatter.Deserialize(stream); stream.Close(); } catch { Data_Set = new DataSet(); } Text_Max_Up.Text = Data_Set.Axis_Max_Up.ToString(); Text_Max_Pitch.Text = Data_Set.Axis_Max_Pitch.ToString(); Text_Max_Roll.Text = Data_Set.Axis_Max_Roll.ToString(); Text_Max_Yaw.Text = Data_Set.Axis_Max_Yaw.ToString(); Text_Min_Up.Text = Data_Set.Axis_Min_Up.ToString(); Text_Min_Pitch.Text = Data_Set.Axis_Min_Pitch.ToString(); Text_Min_Roll.Text = Data_Set.Axis_Min_Roll.ToString(); Text_Min_Yaw.Text = Data_Set.Axis_Min_Yaw.ToString(); Text_Trig_Max_Up.Text = Data_Set.Axis_Trig_Max_Up.ToString(); Text_Trig_Max_Pitch.Text = Data_Set.Axis_Trig_Max_Pitch.ToString(); Text_Trig_Max_Roll.Text = Data_Set.Axis_Trig_Max_Roll.ToString(); Text_Trig_Max_Yaw.Text = Data_Set.Axis_Trig_Max_Yaw.ToString(); Text_Trig_Min_Up.Text = Data_Set.Axis_Trig_Min_Up.ToString(); Text_Trig_Min_Pitch.Text = Data_Set.Axis_Trig_Min_Pitch.ToString(); Text_Trig_Min_Roll.Text = Data_Set.Axis_Trig_Min_Roll.ToString(); Text_Trig_Min_Yaw.Text = Data_Set.Axis_Trig_Min_Yaw.ToString(); rdy = true; }
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); }
// Demo callback function // Called with every FFB packet that is sent to a vJoy device // Must be registered using function FfbRegisterGenCB() private void TesterForm_FormClosed(object sender, FormClosedEventArgs e) { VjdStat status; // Don't use (Too slow) - joystick.ResetAll(); joystick.ResetVJD(id); status = joystick.GetVJDStatus(id); joystick.RelinquishVJD(id); status = joystick.GetVJDStatus(id); }
private bool FreeVJoy() { if (!_joystick.ResetVJD(1)) { return(false); } _isAcquired = false; return(true); }
static void Main(string[] args) { uint index = 1; var joystick = new vJoy(); if (!joystick.vJoyEnabled()) { throw new Exception("vJoy driver not enabled: Failed Getting vJoy attributes"); } var status = joystick.GetVJDStatus(index); string error = null; switch (status) { case VjdStat.VJD_STAT_BUSY: error = "vJoy Device {0} is already owned by another feeder"; break; case VjdStat.VJD_STAT_MISS: error = "vJoy Device {0} is not installed or disabled"; break; case VjdStat.VJD_STAT_UNKN: error = ("vJoy Device {0} general error"); break; } if (error == null && !joystick.AcquireVJD(index)) { error = "Failed to acquire vJoy device number {0}"; } if (error != null) { throw new Exception(string.Format(error, index)); } joystick.ResetVJD(index); if (!FfbStart(index)) { throw new Exception(string.Format("Failed to start Forcefeedback on device {0}", index)); } FfbRegisterGenCB(OnEffect, IntPtr.Zero); Console.ReadLine(); FfbStop(index); joystick.RelinquishVJD(index); }
/// <summary> /// Last one close the door... /// /// Disconnect the Joystick system /// </summary> public void Disconnect() { if (Connected) { m_joystick.ResetVJD(m_jsId); m_joystick.RelinquishVJD(m_jsId); } Connected = false; m_jsId = 0; m_joystick = null; }
private void ResetGamepad(uint id) { _vJoy.ResetVJD(id); var zeroState = new byte[_config.ConfigItems.Count]; for (var i = 0; i < _config.ConfigItems.Count; i++) { zeroState[i] = 0; } UpdateState(zeroState); }
private void ConnectToVirtualJoystick() { joystick = new vJoy(); if (!joystick.vJoyEnabled()) throw new Exception("Unable to connect to virtual joystick"); VjdStat joystickStatus = joystick.GetVJDStatus(JoystickId); if (joystickStatus != VjdStat.VJD_STAT_FREE) throw new Exception("State of Joystick is not free"); if (!joystick.AcquireVJD(JoystickId)) throw new Exception("Unable to acquire joystick"); joystick.GetVJDAxisMax(JoystickId, HID_USAGES.HID_USAGE_X, ref maxValue); joystick.ResetVJD(JoystickId); inputMultiplyer = maxValue / (maxDirectionVectorValue * 2d); // Max direction value }
/// <summary> /// Connect to a Joystick instance /// </summary> /// <param name="n">The joystick ID 1..16</param> /// <returns>True if successfull</returns> public bool Connect(int n) { if (Connected) { return(true); // already connected } try { if (!vJoy.isDllLoaded) { return(false); // ERROR exit DLL not loaded } if (n <= 0 || n > 16) { return(false); // ERROR exit invalid Joystick ID } m_jsId = (uint)n; m_joystick = new vJoy( ); if (!m_joystick.vJoyEnabled( )) { Disconnect( ); // cleanup return(false); // ERROR exit } // try to control.. Connected = m_joystick.isVJDExists(m_jsId); // exists? if (Connected) { Connected = m_joystick.AcquireVJD(m_jsId); // to use? } if (Connected) { bool r = m_joystick.ResetVJD(m_jsId); m_vJoystick = new vJoystick(m_joystick, m_jsId); // the one to use.. } else { m_jsId = 0; m_joystick = null; return(false); // ERROR exit } } catch { // wrong ... m_jsId = 0; m_joystick = null; } return(Connected); }
/*private void FfbCB(IntPtr data, object userData) { * FFBPType type = new FFBPType(); * if(joystick.Ffb_h_Type(data, ref type) == 0) { * Debug.WriteLine(type); * } * //Debug.WriteLine(userData); * }*/ private byte AcquireDevice(byte _id) { VjdStat status = joystick.GetVJDStatus(_id); switch (status) { case VjdStat.VJD_STAT_OWN: //Debug.WriteLine("vJoy Device {0} is already owned by this feeder\n", _id); joystick.ResetVJD(_id); // Reset this device to default values return(0); case VjdStat.VJD_STAT_FREE: //Debug.WriteLine("vJoy Device {0} is free\n", _id); if (joystick.AcquireVJD(_id)) { //Debug.WriteLine(string.Format("Acquired: vJoy device number {0}.", _id)); joystick.ResetVJD(_id); return(1); } //Debug.WriteLine(string.Format("Failed to acquire vJoy device number {0}.", _id)); return(5); case VjdStat.VJD_STAT_BUSY: //Debug.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", _id); return(2); case VjdStat.VJD_STAT_MISS: //Debug.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", _id); return(3); default: //Debug.WriteLine("vJoy Device {0} general error\nCannot continue\n", _id); return(4); } ; }
public VJoyHandler(BongoManager manager, BongoInputMapping mapping, int id, int mic) : base(manager, mapping) { joystick = new vJoy(); uint _id = (uint)id; micSensitivity = mic; if (id <= 0 | id > 16) { Program.WriteErrorToConsoleAndExit("Invalid vJoy id"); } if (!joystick.vJoyEnabled()) { Program.WriteErrorToConsoleAndExit("vJoy not enabled"); } if (!joystick.AcquireVJD(_id)) { Program.WriteErrorToConsoleAndExit("Failed to acquire vJoy device"); } TranslateMapping(mapping); joystick.ResetVJD(_id); manager.TopRightPressed += () => joystick.SetBtn(true, _id, topRight); manager.BotRightPressed += () => joystick.SetBtn(true, _id, botRight); manager.TopLeftPressed += () => joystick.SetBtn(true, _id, topLeft); manager.BotLeftPressed += () => joystick.SetBtn(true, _id, botLeft); manager.StartPressed += () => joystick.SetBtn(true, _id, start); manager.TopRightReleased += () => joystick.SetBtn(false, _id, topRight); manager.BotRightReleased += () => joystick.SetBtn(false, _id, botRight); manager.TopLeftReleased += () => joystick.SetBtn(false, _id, topLeft); manager.BotLeftReleased += () => joystick.SetBtn(false, _id, botLeft); manager.StartReleased += () => joystick.SetBtn(false, _id, start); if (micButton == 255) { manager.MicUpdate += (int update) => joystick.SetAxis(update * micSensitivity, _id, micAxis); } else { manager.MicStarted += () => joystick.SetBtn(true, _id, micButton); manager.MicReleased += () => joystick.SetBtn(false, _id, micButton); } }
public static bool InitJoy() { joyStick = new vJoy(); VjdStat status = joyStick.GetVJDStatus(joyId); if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joyStick.AcquireVJD(joyId)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", joyId); return(false); } else { Console.WriteLine("Acquired: vJoy device number {0}.\n", joyId); joyStick.ResetVJD(joyId); return(true); } }
public vJoyHelper(USBHelper usb) { _joystick = new vJoy(); bool tmp = _joystick.vJoyEnabled(); _jState = new vJoy.JoystickState(); _joystick.AcquireVJD(1); _joystick.ResetVJD(1); _maxVal = 0; _axisAry = new Dictionary <HID_USAGES, bool>(); foreach (HID_USAGES hidUsage in Enum.GetValues(typeof(HID_USAGES))) { _axisAry.Add(hidUsage, _joystick.GetVJDAxisExist(1, hidUsage)); } _joystick.GetVJDAxisMax(1, HID_USAGES.HID_USAGE_X, ref _maxVal); _usb = usb; usb.Polled += new EventHandler(OnUSBPolled); }
public static string setup(vJoy joystick, uint id) { if (!joystick.vJoyEnabled()) { return("Not enabled"); } UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (!match) { return("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})"); } VjdStat status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_BUSY: return("vJoy Device " + id + " is already owned by another feeder\nCannot continue"); case VjdStat.VJD_STAT_MISS: return("vJoy Device " + id + " is not installed or disabled\nCannot continue"); default: return("vJoy Device " + id + " general error. Cannot continue"); } ; if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { return("Failed to acquire vJoy device number " + id); } joystick.ResetVJD(id); return(null); }
public static bool InitJoy(IFfbListener listener) { joyStick = new vJoy(); ffbListener = listener; VjdStat status = joyStick.GetVJDStatus(joyId); if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joyStick.AcquireVJD(joyId)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", joyId); return(false); } else { Console.WriteLine("Acquired: vJoy device number {0}.\n", joyId); joyStick.ResetVJD(joyId); joyStick.FfbRegisterGenCB(OnFFBEvent, joyId); return(true); } }
void Start() { joystick = new vJoy(); iReport = new vJoy.JoystickState(); if (joystick.vJoyEnabled()) { VjdStat status = joystick.GetVJDStatus(1); bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); int nButtons = joystick.GetVJDButtonNumber(id); int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(id); joystick.AcquireVJD(id); joystick.ResetVJD(id); } fpsMonitor = GetComponent <FpsMonitor> (); displayFacePointsToggle.isOn = displayFacePoints; displayAxesToggle.isOn = displayAxes; displayHeadToggle.isOn = displayHead; displayEffectsToggle.isOn = displayEffects; enableLowPassFilterToggle.isOn = enableLowPassFilter; webCamTextureToMatHelper = gameObject.GetComponent <WebCamTextureToMatHelper> (); dlibShapePredictorFileName = DlibFaceLandmarkDetectorExample.dlibShapePredictorFileName; #if UNITY_WEBGL && !UNITY_EDITOR getFilePath_Coroutine = DlibFaceLandmarkDetector.UnityUtils.Utils.getFilePathAsync(dlibShapePredictorFileName, (result) => { getFilePath_Coroutine = null; dlibShapePredictorFilePath = result; Run(); }); StartCoroutine(getFilePath_Coroutine); #else dlibShapePredictorFilePath = DlibFaceLandmarkDetector.UnityUtils.Utils.getFilePath(dlibShapePredictorFileName); Run(); #endif }
private static bool InitVJoyById(vJoy vJoy, uint id) { // Get the state of the requested device VjdStat status = vJoy.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_BUSY: Console.Error.WriteLine("vJoy {0} busy", id); return(false); case VjdStat.VJD_STAT_MISS: Console.Error.WriteLine("vJoy {0} missing", id); return(false); default: Console.Error.WriteLine("vJoy {0} error {1}", id, status); return(false); } // Acquire joystick if (!vJoy.AcquireVJD(id)) { Console.Error.WriteLine("Failed to acquire vJoy {0}", id); return(false); } else { Console.WriteLine("Acquired: vJoy {0}", id); } // Reset this joy vJoy.ResetVJD(id); return(true); }
public static void vJoyLoop() { joystick.ResetVJD(vjd); Console.WriteLine("Starting update loop..."); JoystickState iReport; while (true) { iReport = new JoystickState(); // make all of them -1 (no angle) // also aren't these all uints? wouldn't it just underflow? // it works tho iReport.bHatsEx1--; iReport.bHatsEx2--; iReport.bHatsEx3--; controllers.ForEach((c) => c.Poll()); //buttons iReport.Buttons = controller.GetButtonData(); //pov iReport.bHats = (uint)(GetPOVMultiplier(controller.GetPov(0)) * 4487.5); //sticks Position leftPos = controller.GetStick(0); Position rightPos = controller.GetStick(1); iReport.AxisX = leftPos.x; iReport.AxisY = leftPos.y; iReport.AxisXRot = rightPos.x; iReport.AxisYRot = rightPos.y; joystick.UpdateVJD(vjd, ref iReport); //Thread.Sleep((1 / 60) * 1000); // joycons update @ 60hz } }
private void FeederForm_Load(object sender, EventArgs e) { r = new Random(DateTime.Now.Millisecond); DiscPovNumber = joystick.GetVJDDiscPovNumber(id); ContPovNumber = joystick.GetVJDContPovNumber(id); joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); // Reset this device to default values joystick.ResetVJD(id); X = 20; Y = 30; Z = 40; XR = 60; ZR = 80; cPitch = cRoll = cYaw = 0.5; desPitch = desRoll = desYaw = 0.5; cThr = 0; desThr = 0; cConv = 0; state = ERAState.Disarmed; label2.Text = "НЕ ВЗВЕДЕНО"; joystick.SetBtn(false, id, 1); pParam = 2; waitTime = 1.5; }
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 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); }
public VJoyGlobalHolder(uint index) { Index = index; Global = new VJoyGlobal(this); setPressedStrategy = new SetPressedStrategy(b => SetButton(b, true), b => SetButton(b, false)); joystick = new vJoy(); if (index < 1 || index > 16) { throw new ArgumentException(string.Format("Illegal joystick device id: {0}", index)); } if (!joystick.vJoyEnabled()) { throw new Exception("vJoy driver not enabled: Failed Getting vJoy attributes"); } uint apiVersion = 0; uint driverVersion = 0; bool match = joystick.DriverMatch(ref apiVersion, ref driverVersion); if (!match) { Console.WriteLine("vJoy version of Driver ({0:X}) does NOT match DLL Version ({1:X})", driverVersion, apiVersion); } Version = new VjoyVersionGlobal(apiVersion, driverVersion); var status = joystick.GetVJDStatus(index); string error = null; switch (status) { case VjdStat.VJD_STAT_BUSY: error = "vJoy Device {0} is already owned by another feeder"; break; case VjdStat.VJD_STAT_MISS: error = "vJoy Device {0} is not installed or disabled"; break; case VjdStat.VJD_STAT_UNKN: error = ("vJoy Device {0} general error"); break; } if (error == null && !joystick.AcquireVJD(index)) { error = "Failed to acquire vJoy device number {0}"; } if (error != null) { throw new Exception(string.Format(error, index)); } long max = 0; joystick.GetVJDAxisMax(index, HID_USAGES.HID_USAGE_X, ref max); AxisMax = (int)max / 2 - 1; enabledAxis = new Dictionary <HID_USAGES, bool>(); foreach (HID_USAGES axis in Enum.GetValues(typeof(HID_USAGES))) { enabledAxis[axis] = joystick.GetVJDAxisExist(index, axis); } maxButtons = joystick.GetVJDButtonNumber(index); maxDirPov = joystick.GetVJDDiscPovNumber(index); maxContinuousPov = joystick.GetVJDContPovNumber(index); currentAxisValue = new Dictionary <HID_USAGES, int>(); joystick.ResetVJD(index); }
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
} // 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) }