private void frmMain_Load(object sender, EventArgs e)
        {
            // grab the joystick
            jst = new JoystickInterface.Joystick(this.Handle);
            string[] sticks = jst.FindJoysticks();
            jst.AcquireJoystick(sticks[0]);

            // add the axis controls to the axis container
            for (int i = 0; i < jst.AxisCount; i++)
            {
                Axis ax = new Axis();
                ax.AxisId = i + 1;
                flpAxes.Controls.Add(ax);
            }

            // add the button controls to the button container
            for (int i = 0; i < jst.Buttons.Length; i++)
            {
                JoystickSample.Button btn = new Button();
                btn.ButtonId     = i + 1;
                btn.ButtonStatus = jst.Buttons[i];
                flpButtons.Controls.Add(btn);
            }

            // start updating positions
            tmrUpdateStick.Enabled = true;
        }
Exemplo n.º 2
0
        // Placeholder test code for joystick:

        // Need to work out some issues with joystick code
        // I'm developing on Win7 X64, but I want to target back to XP X32
        // I get some exceptions from DX on startup, so I'll have to revist
        // how to get joystick code integrated
        //
        //Error while loading
        //C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.dll
        //An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
        //
        // TODO poll
        //jst.UpdateStatus();

        void CbJoySticksSelectedIndexChanged(object sender, EventArgs e)
        {
            try {
                jst.AcquireJoystick(sticks[cbJoySticks.SelectedIndex]);
                label9.Text  = string.Format("Axes = {0}", jst.AxisCount);
                label10.Text = string.Format("Buttons = {0}", jst.ButtonCount);

                cbJoySticks.Items.Clear();
                cbXaxisJog.Items.Clear();
                cbYaxisJog.Items.Clear();
                cbZaxisJog.Items.Clear();
                cbAbort.Items.Clear();
                cbFeedHold.Items.Clear();
                cbJogSpeedDec.Items.Clear();
                cbJogSpeedInc.Items.Clear();

                for (int i = 0; i < jst.AxisCount; i++)
                {
                    cbXaxisJog.Items.Add("AXIS " + (i + 1).ToString());
                    cbYaxisJog.Items.Add("AXIS " + (i + 1).ToString());
                    cbZaxisJog.Items.Add("AXIS " + (i + 1).ToString());
                }

                for (int i = 0; i < jst.ButtonCount; i++)
                {
                    cbAbort.Items.Add("Button " + (i + 1).ToString());
                    cbFeedHold.Items.Add("Button " + (i + 1).ToString());
                    cbJogSpeedDec.Items.Add("Button " + (i + 1).ToString());
                    cbJogSpeedInc.Items.Add("Button " + (i + 1).ToString());
                }
            }
            catch {}
        }
Exemplo n.º 3
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            // grab the joystick
            jst = new JoystickInterface.Joystick(this.Handle);
            string[] sticks = jst.FindJoysticks();
            jst.AcquireJoystick(sticks[0]);

            // add the axis controls to the axis container
            for (int i = 0; i < jst.AxisCount; i++)
            {
                Axis ax = new Axis();
                ax.AxisId = i + 1;
                flpAxes.Controls.Add(ax);
            }

            // add the button controls to the button container
            for (int i = 0; i < jst.Buttons.Length; i++)
            {
                JoystickSample.Button btn = new Button();
                btn.ButtonId = i + 1;
                btn.ButtonStatus = jst.Buttons[i];
                flpButtons.Controls.Add(btn);
            }

            // start updating positions
            tmrUpdateStick.Enabled = true;
        }
Exemplo n.º 4
0
 private void button1_Click(object sender, EventArgs e)
 {
     //MessageBox.Show("Loading");
     // grab the joystick
     jst = new JoystickInterface.Joystick(this.Handle);
     string[] sticks = jst.FindJoysticks();
     jst.AcquireJoystick(sticks[0]);
     //MessageBox.Show("Joystick Acquired");
     // start updating positions
     tmrUpdateStick.Enabled = true;
 }
        public DrumPadEvent(Form parent)
        {
            Stick = new JoystickInterface.Joystick(parent.Handle);
            string[] st = Stick.FindJoysticks();
            Stick.AcquireJoystick(st[0]);

            ButtonReady = new bool[Stick.Buttons.Length];

            mmTimer.Period = 10;
            mmTimer.Mode = Multimedia.TimerMode.Periodic;
            mmTimer.Tick += new EventHandler(CheckTimer_Tick);
            mmTimer.Start();

            for (int i = 0; i < ButtonReady.Length; i++)
            {
                ButtonReady[i] = false;
            }
        }
Exemplo n.º 6
0
 static void setupJoystick()
 {
     _jst = new JoystickInterface.Joystick(Process.GetCurrentProcess().MainWindowHandle);
     string[] sticks = _jst.FindJoysticks();
     _jst.AcquireJoystick(sticks[0]);
 }
        private void button2_Click(object sender, EventArgs e)
        {
            Axis ax = new Axis();
            int  i  = 0;

            // Find all the GameControl devices that are attached.

            // check that we have at least one device.
            if (!(check == 1)) //not connected
            {
                DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);

                // check that we have at least one device.
                if (gameControllerList.Count > 0)
                {
                    check = 1;
                    // grab the joystick
                    jst = new JoystickInterface.Joystick(this.Handle);
                    string[] sticks = jst.FindJoysticks();

                    jst.AcquireJoystick(sticks[0]);

                    // add the axis controls to the axis container
                    for (i = 0; i < jst.AxisCount; i++)
                    {
                        ax        = new Axis();
                        ax.AxisId = i + 1;
                        flpAxes.Controls.Add(ax);
                    }


                    ///////////////////////////////////////////////////
                    ax        = new Axis();
                    ax.AxisId = i + 1;
                    flpAxes.Controls.Add(ax);

                    //////////////////////////////////////////////////

                    // add the button controls to the button container
                    for (i = 0; i < 11; i++)
                    {
                        JoystickSample.Button btn = new Button();
                        btn.ButtonId     = i + 1;
                        btn.ButtonStatus = jst.Buttons[i];
                        flpButtons.Controls.Add(btn);
                    }

                    // start updating positions
                    tmrUpdateStick.Enabled = true;
                    MessageBox.Show("Joystick Connected");
                }

                else
                {
                    check = 0;
                    MessageBox.Show("No Joystick detected");
                }
            }
            else
            {
                check = 1;
                MessageBox.Show("Joystick already connected");
            }
        }
Exemplo n.º 8
0
 static void setupJoystick()
 {
     _jst = new JoystickInterface.Joystick(Process.GetCurrentProcess().MainWindowHandle);
     string[] sticks = _jst.FindJoysticks();
     _jst.AcquireJoystick(sticks[0]);
 }
Exemplo n.º 9
0
        private void Form1_Load(object sender, EventArgs e)
        {
            #region 初始化下拉串口名称列表框

            //获取单片机与计算机连接的端口号
            string[] ports = SerialPort.GetPortNames();
            Array.Sort(ports);

            //将其显示到comboPorName控件中去
            comboBoxPortNum.Items.AddRange(ports);
            comboBoxPortNum.SelectedIndex = comboBoxPortNum.Items.Count > 0 ? 0 : -1;

            //波特率默认为9600bps,可以通过下拉选项进行调节
            comboBoxBundRate.SelectedIndex = comboBoxBundRate.Items.IndexOf("9600");

            #endregion

            //下面这句还不太懂,先照着做
            serialPort1.NewLine = "\r\n";

            //与设置RTS信号有关,虽不明,但觉厉,照着做
            serialPort1.RtsEnable = true;

            //注册对串口接收数据的响应方法
            serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);

            // grab the joystick
            jst = new JoystickInterface.Joystick(this.Handle);
            string[] sticks = jst.FindJoysticks();
            jst.AcquireJoystick(sticks[0]);

            textBoxDevice.Text = jst.ToString();

            // start updating positions
            timer1.Enabled = true;
        }