Example #1
0
        public DeviceInformationCollection GetDevices(VjdStat[] status)
        {
            using (var input = new DirectInput())
            {
                var deviceInstances = input.GetDevices().Where(w => w.ProductGuid.Equals(VJoyProductGuid)).ToList();

                var result = new DeviceInformationCollection();
                for (short i = 0; i < 16; i++)
                {
                    var deviceId = Convert.ToUInt32(i);

                    try
                    {
                        var joystick = new vJoy();

                        if (!joystick.isVJDExists(deviceId))
                        {
                            continue;
                        }

                        var joyStatus = joystick.GetVJDStatus(deviceId);

                        if (!status.Contains(joyStatus))
                        {
                            continue;
                        }

                        foreach (var device in deviceInstances.Select(s => new Joystick(input, s.InstanceGuid)))
                        {
                            var objects = device.GetObjects(DeviceObjectTypeFlags.All);

                            var first = objects.FirstOrDefault(fd => fd.ReportId.Equals(i));

                            if (first == null)
                            {
                                continue;
                            }

                            result.Add(first.ReportId, device.Information.ProductName.TrimEnd('\0'),
                                       device.Information.InstanceGuid,
                                       joyStatus);

                            break;
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                return(result);
            }
        }
Example #2
0
        public override List <string> GetJoysticks()
        {
            var list = new List <string>();

            for (uint i = 1; i <= 16; i++)
            {
                if (joystick.isVJDExists(i))
                {
                    list.Add(i.ToString());
                }
            }
            return(list);
        }
Example #3
0
        public object[] GetJoysticks()
        {
            ArrayList list = new ArrayList();

            for (uint i = 1; i <= 16; i++)
            {
                if (joystick.isVJDExists(i))
                {
                    list.Add(i.ToString());
                }
            }
            return(list.ToArray());
        }
Example #4
0
        /// <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);
        }
Example #5
0
        public VJoyDirector()
        {
            _interface        = new vJoy();
            _devices          = new List <JoyDevice>();
            _states           = new Dictionary <uint, vJoy.JoystickState>();
            _activeDirections = new Dictionary <uint, Dictionary <POVDirection, bool> >();

            if (Available)
            {
                for (uint i = 1; i <= 16; i++)
                {
                    if (_interface.isVJDExists(i))
                    {
                        var status = _interface.GetVJDStatus(i);

                        if (status == VjdStat.VJD_STAT_FREE || status == VjdStat.VJD_STAT_OWN)
                        {
                            _devices.Add(new JoyDevice(i));
                        }
                    }
                }
            }
        }
Example #6
0
        public bool AcquireDevice(uint deviceID)
        {
            if (!joystick.isVJDExists(deviceID))
            {
                return(false);
            }

            VjdStat status = joystick.GetVJDStatus(deviceID);

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                Console.WriteLine("vJoy Device {0} is already owned by this feeder", deviceID);
                return(true);

            case VjdStat.VJD_STAT_FREE:
                Console.WriteLine("vJoy Device {0} is free", deviceID);
                break;

            case VjdStat.VJD_STAT_BUSY:
                Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue", deviceID);
                return(false);

            case VjdStat.VJD_STAT_MISS:
                Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue", deviceID);
                return(false);

            default:
                Console.WriteLine("vJoy Device {0} general error\nCannot continue", deviceID);
                return(false);
            }
            ;

            if ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(deviceID)))
            {
                Console.WriteLine("Failed to acquire vJoy device number {0}.", deviceID);
                return(false);
            }
            else
            {
                Console.WriteLine("Acquired: vJoy device number {0}.", deviceID);
            }

            ResetDeviceAxes(deviceID);

            return(true);

            // joystick.RegisterRemovalCB(ChangedCB, label2);

            // void CALLBACK ChangedCB(bool Removed, bool First, object userData)

            /*
             *      This function is called when a process of vJoy device removal starts or ends and when a process of vJoy device
             *      arrival starts or ends. The function must return as soon as possible.
             *      • When a process of vJoy device removal starts, Parameter Removed = TRUE and parameter First = TRUE.
             *      • When a process of vJoy device removal ends, Parameter Removed = TRUE and parameter First = FALSE.
             *      • When a process of vJoy device arrival starts, Parameter Removed = FALSE and parameter First = TRUE.
             *      • When a process of vJoy device arrival ends, Parameter Removed = FALSE and parameter First = FALSE.
             *      Parameter userData is always an object registered as second parameter of function RegisterRemovalCB.
             */

            // register device-client allocation
        }