View Single Post
  #3   Spotlight this post!  
Unread 05-09-2012, 19:05
sergioCorral842's Avatar
sergioCorral842 sergioCorral842 is offline
College Student
FRC #0842 (Falcon Robotics)
Team Role: Alumni
 
Join Date: Aug 2011
Rookie Year: 2012
Location: Phoenix, Arizona
Posts: 161
sergioCorral842 is a splendid one to beholdsergioCorral842 is a splendid one to beholdsergioCorral842 is a splendid one to beholdsergioCorral842 is a splendid one to beholdsergioCorral842 is a splendid one to beholdsergioCorral842 is a splendid one to beholdsergioCorral842 is a splendid one to beholdsergioCorral842 is a splendid one to behold
Re: Reading multiple joysticks on C# using SlimDX.

I will use that for the starting point thank you and here is the code if anyone is interested.

Code:
public Form1()
        {
            InitializeComponent();
            BootGamePort();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            BootGamePort();

        }

Joystick mainScouter; 
        JoystickState state = new JoystickState();

        void BootGamePort()
        {
            DirectInput dinput = new DirectInput();

            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                try
                {
                    if (count == 0)
                    {
                        mainScouter = new Joystick(dinput, device.InstanceGuid);
                    }

                    count = 1;
                    break;
                }

                catch (DirectInputException)
                {
                }

            }
            if (mainScouter == null)
            {
                return;
            }
            

            

            foreach (DeviceObjectInstance deviceObject in mainScouter.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    mainScouter.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100);
            }

            

            mainScouter.Acquire();
        }

        public void timer1_Tick(object sender, EventArgs e)
        {

            if (mainScouter.Acquire().IsFailure)
            {
                return;
            }

            if (mainScouter.Poll().IsFailure)
            {
                return;
            }

           

            state = mainScouter.GetCurrentState();
           

            if (Result.Last.IsFailure)
            {
                return;
            }

            bool[] buttons = state.GetButtons();
           


            String strText = "";
            

            for (int b = 0; b < buttons.Length; b++)
            {
                if (buttons[b])
                {
                    strText += b.ToString("00 ", CultureInfo.CurrentCulture);
                    lblbuttons.Text = strText;
                }

               
            }

Last edited by sergioCorral842 : 06-09-2012 at 10:44.