public void tmrUpdateStick_Tick(object sender, EventArgs e)
        {
            // get status
            jst.UpdateStatus();

            // update the axes positions
            foreach (Control ax in flpAxes.Controls)
            {
                if (ax is Axis)
                {
                    switch (((Axis)ax).AxisId)
                    {
                    case 1:
                        ((Axis)ax).AxisPos = jst.AxisA;
                        break;

                    case 2:
                        ((Axis)ax).AxisPos = jst.AxisB;
                        break;

                    case 3:
                        ((Axis)ax).AxisPos = jst.AxisC;                                 //X
                        break;

                    case 4:
                        ((Axis)ax).AxisPos = jst.AxisD;                                 //Y
                        break;

                    case 5:
                        ((Axis)ax).AxisPos = jst.AxisE;
                        break;

                    case 6:
                        ((Axis)ax).AxisPos = jst.AxisF;
                        break;
                    }
                }
            }

            // update each button status
            foreach (Control btn in flpButtons.Controls)
            {
                if (btn is JoystickSample.Button)
                {
                    ((JoystickSample.Button)btn).ButtonStatus =
                        jst.Buttons[((JoystickSample.Button)btn).ButtonId - 1];
                }
            }

            Current_Status();

            label1.Text = AxisArr[0].ToString();
            label2.Text = AxisArr[1].ToString();

            send = axistochar();
            transmit(send);

            send = buttochar();
            transmit(send);
        }
Exemple #2
0
        static void read()
        {
            while (true)
            {
                _jst.UpdateStatus();

                if ((_lastKey != "Z") && (_sendingKey == "") && (KeyboardInfo.GetKeyState(Keys.Z).IsPressed || (_jst.AxisC < 32767)))
                {
                    _lastKey    = "Z";
                    _sendingKey = "Z";
                    _sp.Write("Z");
                }
                else if ((_lastKey != "X") && (_sendingKey == "") && (KeyboardInfo.GetKeyState(Keys.X).IsPressed || (_jst.AxisC > 32767)))
                {
                    _lastKey    = "X";
                    _sendingKey = "X";
                    _sp.Write("X");
                }
                else if (!(_jst.AxisC < 32767) && !(_jst.AxisC > 32767))
                {
                    _lastKey = "";
                }
                else if (KeyboardInfo.GetKeyState(Keys.Escape).IsPressed)
                {
                    break;
                }

                Application.DoEvents();
            }
            Console.WriteLine("Exit!");
        }
Exemple #3
0
 private void tmrUpdateStick_Tick(object sender, EventArgs e)
 {
     // get status
     jst.UpdateStatus();
     // update the axes positions
     Zbar.Value = (int)(100.0f * (((float)jst.AxisA) / 65535.0f));
     Xbar.Value = (int)(100.0f * (((float)jst.AxisC) / 65535.0f));
     Ybar.Value = 100 - (int)(100.0f * (((float)jst.AxisD) / 65535.0f));
 }
        private void tmrUpdateStick_Tick(object sender, EventArgs e)
        {
            // get status
            jst.UpdateStatus();

            // update the axes positions
            foreach (Control ax in flpAxes.Controls)
            {
                if (ax is Axis)
                {
                    switch (((Axis)ax).AxisId)
                    {
                    case 1:
                        ((Axis)ax).AxisPos = jst.AxisA;
                        break;

                    case 2:
                        ((Axis)ax).AxisPos = jst.AxisB;
                        break;

                    case 3:
                        ((Axis)ax).AxisPos = jst.AxisC;
                        break;

                    case 4:
                        ((Axis)ax).AxisPos = jst.AxisD;
                        break;

                    case 5:
                        ((Axis)ax).AxisPos = jst.AxisE;
                        break;

                    case 6:
                        ((Axis)ax).AxisPos = jst.AxisF;
                        break;
                    }
                }
            }

            // update each button status
            foreach (Control btn in flpButtons.Controls)
            {
                if (btn is JoystickSample.Button)
                {
                    ((JoystickSample.Button)btn).ButtonStatus =
                        jst.Buttons[((JoystickSample.Button)btn).ButtonId - 1];
                }
            }
        }
Exemple #5
0
        private void joystickTimer_Tick(object sender, EventArgs e)
        {
            // get status
            jst.UpdateStatus();
            // update the axes positions
            JoyX = (int)(100.0f * (((float)jst.AxisA) / 65535.0f));
            JoyY = (int)(100.0f * (((float)jst.AxisC) / 65535.0f));
            JoyZ = 100 - (int)(100.0f * (((float)jst.AxisD) / 65535.0f));


            shoulderVal += ((float)JoyY * 0.1f);
            elbowVal    += ((float)JoyX * 0.1f);

            packet[0] = Convert.ToString((int)shoulderVal);
            packet[1] = Convert.ToString((int)elbowVal);
        }
        private void tmrUpdateStick_Tick(object sender, EventArgs e)
        {
            label1.Text = DateTime.Now.ToString();

            // get status
            jst.UpdateStatus();

            //*********************************摇杆状态检测************************************//

            if (f == 0 && jst.AxisC == 32511 && jst.AxisD == 32511 && jst.Buttons[6] == false && jst.Buttons[7] == false && jst.Buttons[4] == false && jst.Buttons[5] == false)
            {
                stop(); f = 1;
            }

            if (jst.AxisC == 65535 && jst.AxisD == 32511)
            {
                //data = jst.AxisC.ToString();
                //serialPort1.Write(data);
                left(); f = 0;
            }

            if (jst.AxisC == 0 && jst.AxisD == 32511)
            {
                right(); f = 0;
            }



            if (jst.AxisD == 65535)
            {
                //data = jst.AxisC.ToString();
                //serialPort1.Write(data);
                if (jst.Buttons[4] == true)
                {
                    accelerate_b(); f = 0;
                }

                else if (jst.Buttons[5] == true)
                {
                    shiftdown_b(); f = 0;
                }
                else if (jst.AxisC == 0)
                {
                    left_backward(); f = 0;
                }

                else if (jst.AxisC == 65535)
                {
                    right_backward(); f = 0;
                }

                else
                {
                    backward();
                } f = 0;
            }


            else if (jst.AxisD == 0)
            {
                if (jst.Buttons[4] == true)
                {
                    accelerate_f(); f = 0;
                }

                else if (jst.Buttons[5] == true)
                {
                    shiftdown_f(); f = 0;
                }

                else if (jst.AxisC == 0)
                {
                    left_forward(); f = 0;
                }


                else if (jst.AxisC == 65535)
                {
                    right_forward(); f = 0;
                }


                else
                {
                    forward();
                } f = 0;
            }



//*********************************按键状态检测************************************//


            if (jst.Buttons[0] == true)
            {
                button1(); f = 1;
            }


            if (jst.Buttons[1] == true)
            {
                button2(); f = 0;
            }


            if (jst.Buttons[2] == true)
            {
                button3(); f = 0;
            }


            if (jst.Buttons[3] == true)
            {
                button4(); f = 0;
            }

            if (jst.Buttons[6] == true)
            {
                button7(); f = 0;
            }

            if (jst.Buttons[7] == true)
            {
                button8(); f = 0;
            }

            if (jst.Buttons[9] == true)
            {
                flag_continue(); f = 0;
            }



            // update the axes positions
            foreach (Control ax in flpAxes.Controls)
            {
                if (ax is Axis)
                {
                    switch (((Axis)ax).AxisId)                        //对应六个滑动条
                    {
                    case 1:
                        ((Axis)ax).AxisPos = jst.AxisA;
                        break;

                    case 2:
                        ((Axis)ax).AxisPos = jst.AxisB;
                        break;

                    case 3:
                        ((Axis)ax).AxisPos = jst.AxisC;              //只使用3号和4号滑动条


                        /*
                         * if (jst.AxisC==65535)
                         * {
                         * //data = jst.AxisC.ToString();
                         * //serialPort1.Write(data);
                         * right();
                         * }
                         *
                         * else if (jst.AxisC==0)
                         * {
                         *
                         * left();
                         * }
                         *
                         *
                         */


                        break;

                    case 4:
                        ((Axis)ax).AxisPos = jst.AxisD;

                        /*
                         * if (jst.AxisD ==65535)
                         * {
                         *  //data = jst.AxisC.ToString();
                         *  //serialPort1.Write(data);
                         *  backward();
                         * }
                         *
                         * else if (jst.AxisD==0)
                         * {
                         *
                         *  forward();
                         * }
                         */
                        break;


                    case 5:
                        ((Axis)ax).AxisPos = jst.AxisE;
                        break;

                    case 6:
                        ((Axis)ax).AxisPos = jst.AxisF;
                        break;
                    }
                }
            }



            // update each button status
            foreach (Control btn in flpButtons.Controls)
            {
                if (btn is JoystickSample.Button)
                {
                    ((JoystickSample.Button)btn).ButtonStatus =
                        jst.Buttons[((JoystickSample.Button)btn).ButtonId - 1];

                    if (((JoystickSample.Button)btn).ButtonStatus == true)
                    {
                        /*
                         * if (((JoystickSample.Button)btn).ButtonId == 1)
                         * {
                         *  button1();
                         *
                         * }
                         *
                         *
                         * if (((JoystickSample.Button)btn).ButtonId == 2)
                         * {
                         *  button2();
                         *
                         * }
                         *
                         *
                         * if (((JoystickSample.Button)btn).ButtonId == 3)
                         * {
                         *  button3();
                         *
                         * }
                         *
                         *
                         * if (((JoystickSample.Button)btn).ButtonId == 4)
                         * {
                         *  button4();
                         *
                         * }
                         *
                         * if (((JoystickSample.Button)btn).ButtonId == 7)
                         * {
                         *  button7();
                         *
                         * }
                         *
                         * if (((JoystickSample.Button)btn).ButtonId == 8)
                         * {
                         *  button8();
                         *
                         * }
                         *
                         */
                    }
                }
            }
        }