Exemplo n.º 1
0
        // --- functions ---

        /// <returns>Call this function to refresh the list of available joysticks and thier capabilities</returns>
        internal void RefreshJoysticks()
        {
            for (int i = 0; i < 10; i++)
            {
                //Load the list of attached openTK joysticks
                var state       = OpenTK.Input.Joystick.GetState(i);
                var description = OpenTK.Input.Joystick.GetCapabilities(i).ToString();
                if (description == "{Axes: 0; Buttons: 0; Hats: 0; IsConnected: True}")
                {
                    break;
                }
                //A joystick with 56 buttons and zero axis is likely the RailDriver, which is bugged in openTK
                if (state.IsConnected && description != "{Axes: 0; Buttons: 56; Hats: 0; IsConnected: True}")
                {
                    StandardJoystick newJoystick = new StandardJoystick
                    {
                        Name   = "Joystick" + i,
                        Handle = i,
                        Guid   = OpenTK.Input.Joystick.GetGuid(i)
                    };

                    bool alreadyFound = false;
                    for (int j = 0; j < AttachedJoysticks.Length; j++)
                    {
                        if (AttachedJoysticks[j] is StandardJoystick && AttachedJoysticks[j].Handle == newJoystick.Handle)
                        {
                            alreadyFound = true;
                        }
                    }
                    if (!alreadyFound)
                    {
                        int l = AttachedJoysticks.Length;
                        Array.Resize(ref AttachedJoysticks, AttachedJoysticks.Length + 1);
                        AttachedJoysticks[l] = newJoystick;
                    }
                }
            }
        }
Exemplo n.º 2
0
        // --- functions ---

        /// <returns>Call this function to refresh the list of available joysticks and thier capabilities</returns>
        internal void RefreshJoysticks()
        {
            for (int i = 0; i < 100; i++)
            {
                //Load the list of attached openTK joysticks
                var  state       = OpenTK.Input.Joystick.GetState(i);
                Guid foundGuid   = OpenTK.Input.Joystick.GetGuid(i);
                var  description = OpenTK.Input.Joystick.GetCapabilities(i);
                if (description.ToString() == "{Axes: 0; Buttons: 0; Hats: 0; IsConnected: True}")
                {
                    break;
                }
                //A joystick with 56 buttons and zero axis is likely the RailDriver, which is bugged in openTK
                if (description.ToString() != "{Axes: 0; Buttons: 56; Hats: 0; IsConnected: True}")
                {
                    if (Program.CurrentHost.MonoRuntime)
                    {
                        if (description.AxisCount == 0 && description.ButtonCount == 0 && description.HatCount == 0)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (!state.IsConnected)
                        {
                            continue;
                        }
                    }

                    StandardJoystick newJoystick = new StandardJoystick(i);

                    if (AttachedJoysticks.ContainsKey(newJoystick.GetGuid()))
                    {
                        AttachedJoysticks[newJoystick.GetGuid()].Handle       = i;
                        AttachedJoysticks[newJoystick.GetGuid()].Disconnected = false;
                    }
                    else
                    {
                        AttachedJoysticks.Add(newJoystick.GetGuid(), newJoystick);
                    }
                }
            }
            if (Program.CurrentHost.Platform != HostPlatform.MicrosoftWindows || devices == null || RailDriverInit == true)
            {
                return;
            }
            //Enumerate all PI Engineering devices
            RailDriverInit = true;
            for (int i = 0; i < devices.Length; i++)
            {
                if (devices[i].HidUsagePage == 0xc)
                {
                    switch (devices[i].Pid)
                    {
                    case 210:
                        //Raildriver controller
                        Raildriver newJoystick = new Raildriver
                        {
                            Name   = "RailDriver Desktop Cab Controller",
                            Handle = i,
                            wData  = new byte[]
                            {
                                0, 134, 0, 0, 0, 0, 0, 0, 0
                            }
                        };
                        if (!AttachedJoysticks.ContainsKey(new Guid()))
                        {
                            AttachedJoysticks.Add(new Guid(), newJoystick);
                            devices[i].SetupInterface();
                            devices[i].SetDataCallback(this);
                            devices[i].SetErrorCallback(this);
                        }
                        break;
                    }
                }
            }
        }
Exemplo n.º 3
0
        // --- functions ---

        /// <returns>Call this function to refresh the list of available joysticks and thier capabilities</returns>
        internal void RefreshJoysticks()
        {
            for (int i = 0; i < 10; i++)
            {
                //Load the list of attached openTK joysticks
                var state       = OpenTK.Input.Joystick.GetState(i);
                var description = OpenTK.Input.Joystick.GetCapabilities(i);
                if (description.ToString() == "{Axes: 0; Buttons: 0; Hats: 0; IsConnected: True}")
                {
                    break;
                }
                //A joystick with 56 buttons and zero axis is likely the RailDriver, which is bugged in openTK
                if (description.ToString() != "{Axes: 0; Buttons: 56; Hats: 0; IsConnected: True}")
                {
                    if (Program.CurrentlyRunningOnMono)
                    {
                        if (description.AxisCount == 0 && description.ButtonCount == 0 && description.HatCount == 0)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (!state.IsConnected)
                        {
                            continue;
                        }
                    }
                    StandardJoystick newJoystick = new StandardJoystick
                    {
                        Name   = "Joystick" + i,
                        Handle = i,
                    };

                    bool alreadyFound = false;
                    for (int j = 0; j < AttachedJoysticks.Length; j++)
                    {
                        if (AttachedJoysticks[j] is StandardJoystick && AttachedJoysticks[j].Handle == newJoystick.Handle)
                        {
                            alreadyFound = true;
                        }
                    }
                    if (!alreadyFound)
                    {
                        int l = AttachedJoysticks.Length;
                        Array.Resize(ref AttachedJoysticks, AttachedJoysticks.Length + 1);
                        AttachedJoysticks[l] = newJoystick;
                    }
                }
            }
            if (!Program.CurrentlyRunningOnWindows || devices == null || RailDriverInit == true)
            {
                return;
            }
            //Enumerate all PI Engineering devices
            RailDriverInit = true;
            for (int i = 0; i < devices.Length; i++)
            {
                if (devices[i].HidUsagePage == 0xc)
                {
                    switch (devices[i].Pid)
                    {
                    case 210:
                        //Raildriver controller
                        Raildriver newJoystick = new Raildriver
                        {
                            Name   = "RailDriver Desktop Cab Controller",
                            Handle = i,
                            wData  = new byte[]
                            {
                                0, 134, 0, 0, 0, 0, 0, 0, 0
                            }
                        };
                        bool alreadyFound = false;
                        for (int j = 0; j < AttachedJoysticks.Length; j++)
                        {
                            if (AttachedJoysticks[j] is Raildriver && AttachedJoysticks[j].Handle == newJoystick.Handle)
                            {
                                alreadyFound = true;
                            }
                        }
                        if (!alreadyFound)
                        {
                            int l = AttachedJoysticks.Length;
                            Array.Resize(ref AttachedJoysticks, AttachedJoysticks.Length + 1);
                            AttachedJoysticks[l] = newJoystick;
                            devices[i].SetupInterface();
                            devices[i].SetDataCallback(this);
                            devices[i].SetErrorCallback(this);
                            RailDriverIndex = l;
                        }
                        break;
                    }
                }
            }
        }