Пример #1
0
        private void timer_Tick(object sender, EventArgs e)
        {
            string[] test = SerialPort.GetPortNames().ToArray();
            if (SerialPortListBox.DroppedDown == false) //Prevent list updates during drop down activated so list doesn't flash
            {
                PortArray = SerialPort.GetPortNames().ToArray();
                SerialPortListBox.Items.Clear();
                foreach (string portname in PortArray)
                {
                    SerialPortListBox.Items.Add(portname);
                }
            }

            //Retrieve Acceleration data from one data packet
            if (DisconnectButton.Text == "Disconnect")
            {
                int QueueData;
                SerialReceivedQueue.TryDequeue(out QueueData);
                GlobalVariables.AccelerationData.X = QueueData;
                SerialReceivedQueue.TryDequeue(out QueueData);
                GlobalVariables.AccelerationData.Y = QueueData;
                SerialReceivedQueue.TryDequeue(out QueueData);
                GlobalVariables.AccelerationData.Z = QueueData;

                if (GlobalVariables.AccelerationData.X == 0 || GlobalVariables.AccelerationData.Y == 0 || GlobalVariables.AccelerationData.Z == 0)
                {
                    return;
                }

                XaxisBox.Text = Bin2Acc(GlobalVariables.AccelerationData).X.ToString();
                YaxisBox.Text = Bin2Acc(GlobalVariables.AccelerationData).Y.ToString();
                ZaxisBox.Text = Bin2Acc(GlobalVariables.AccelerationData).Z.ToString();

                GlobalVariables.Accel_X.Add(GlobalVariables.AccelerationData.X);
                GlobalVariables.Accel_Y.Add(GlobalVariables.AccelerationData.Y);
                GlobalVariables.Accel_Z.Add(GlobalVariables.AccelerationData.Z);

                XDataBox.AppendText(GlobalVariables.Accel_X[GlobalVariables.Accel_X.Count() - 1].ToString() + " ");
                YDataBox.AppendText(GlobalVariables.Accel_Y[GlobalVariables.Accel_Y.Count() - 1].ToString() + " ");
                ZDataBox.AppendText(GlobalVariables.Accel_Z[GlobalVariables.Accel_Z.Count() - 1].ToString() + " ");

                AccelGraph.Series["Accel_X"].Points.AddXY(AccelGraph.Series["Accel_X"].Points.Count(), GlobalVariables.AccelerationData.X.ToString());
                AccelGraph.Series["Accel_Y"].Points.AddXY(AccelGraph.Series["Accel_Y"].Points.Count(), GlobalVariables.AccelerationData.Y.ToString());
                AccelGraph.Series["Accel_Z"].Points.AddXY(AccelGraph.Series["Accel_Z"].Points.Count(), GlobalVariables.AccelerationData.Z.ToString());

                if (AccelGraph.ChartAreas[0].AxisX.Maximum - AccelGraph.ChartAreas[0].AxisX.Minimum > 100)
                {
                    AccelGraph.ChartAreas[0].AxisX.Minimum = AccelGraph.ChartAreas[0].AxisX.Minimum + 1;;
                }
            }
        }
Пример #2
0
        private void timer_Tick(object sender, EventArgs e)
        {
            string[] test = SerialPort.GetPortNames().ToArray();
            if (SerialPortListBox.DroppedDown == false) //Prevent list updates during drop down activated so list doesn't flash
            {
                PortArray = SerialPort.GetPortNames().ToArray();
                SerialPortListBox.Items.Clear();
                foreach (string portname in PortArray)
                {
                    SerialPortListBox.Items.Add(portname);
                }
            }

            //Retrieve Acceleration data from one data packet
            if (DisconnectButton.Text == "Disconnect")
            {
                int QueueData;
                SerialReceivedQueue.TryDequeue(out QueueData);
                GlobalVariables.AccelerationData.X = QueueData;
                SerialReceivedQueue.TryDequeue(out QueueData);
                GlobalVariables.AccelerationData.Y = QueueData;
                SerialReceivedQueue.TryDequeue(out QueueData);
                GlobalVariables.AccelerationData.Z = QueueData;

                if (GlobalVariables.AccelerationData.X == 0 || GlobalVariables.AccelerationData.Y == 0 || GlobalVariables.AccelerationData.Z == 0)
                {
                    return;
                }

                XaxisBox.Text = GlobalVariables.AccelerationData.X.ToString();
                YaxisBox.Text = GlobalVariables.AccelerationData.Y.ToString();
                ZaxisBox.Text = GlobalVariables.AccelerationData.Z.ToString();

                int YUpper = 135;
                int YLower = 120;
                int XUpper = 160;
                int XLower = 122;

                if (Convert.ToInt32(YaxisBox.Text) < YLower && Convert.ToInt32(YaxisBox.Text) > 0 && keystate != "left") //Left
                {
                    InputSimulator.Keyboard.KeyUp(VirtualKeyCode.RIGHT);
                    InputSimulator.Keyboard.KeyDown(VirtualKeyCode.LEFT);
                    keystate = "left";
                }
                else if (Convert.ToInt32(YaxisBox.Text) > YUpper && Convert.ToInt32(YaxisBox.Text) > 0 && keystate != "right") //Right
                {
                    InputSimulator.Keyboard.KeyUp(VirtualKeyCode.LEFT);
                    InputSimulator.Keyboard.KeyDown(VirtualKeyCode.RIGHT);
                    keystate = "right";
                }
                else if (Convert.ToInt32(YaxisBox.Text) < YUpper && Convert.ToInt32(YaxisBox.Text) > YLower)
                {
                    InputSimulator.Keyboard.KeyUp(VirtualKeyCode.RIGHT);
                    InputSimulator.Keyboard.KeyUp(VirtualKeyCode.LEFT);
                    keystate = "";
                }

                if (Convert.ToInt32(XaxisBox.Text) < XLower && Convert.ToInt32(XaxisBox.Text) > 0 && keystate2 != "up") //Up
                {
                    InputSimulator.Keyboard.KeyUp(VirtualKeyCode.DOWN);
                    InputSimulator.Keyboard.KeyDown(VirtualKeyCode.UP);
                    keystate2 = "up";
                }
                else if (Convert.ToInt32(XaxisBox.Text) > XUpper && Convert.ToInt32(XaxisBox.Text) > 0 && keystate2 != "down") //Right
                {
                    InputSimulator.Keyboard.KeyUp(VirtualKeyCode.UP);
                    InputSimulator.Keyboard.KeyDown(VirtualKeyCode.DOWN);
                    keystate2 = "down";
                }
                else if (Convert.ToInt32(XaxisBox.Text) < XUpper && Convert.ToInt32(XaxisBox.Text) > XLower)
                {
                    InputSimulator.Keyboard.KeyUp(VirtualKeyCode.UP);
                    InputSimulator.Keyboard.KeyUp(VirtualKeyCode.DOWN);
                    keystate2 = "";
                }


                GlobalVariables.Accel_X.Add(GlobalVariables.AccelerationData.X);
                GlobalVariables.Accel_Y.Add(GlobalVariables.AccelerationData.Y);
                GlobalVariables.Accel_Z.Add(GlobalVariables.AccelerationData.Z);

                XDataBox.AppendText(GlobalVariables.Accel_X[GlobalVariables.Accel_X.Count() - 1].ToString() + " ");
                YDataBox.AppendText(GlobalVariables.Accel_Y[GlobalVariables.Accel_Y.Count() - 1].ToString() + " ");
                ZDataBox.AppendText(GlobalVariables.Accel_Z[GlobalVariables.Accel_Z.Count() - 1].ToString() + " ");

                AccelGraph.Series["Accel_X"].Points.AddXY(AccelGraph.Series["Accel_X"].Points.Count(), GlobalVariables.AccelerationData.X.ToString());
                AccelGraph.Series["Accel_Y"].Points.AddXY(AccelGraph.Series["Accel_Y"].Points.Count(), GlobalVariables.AccelerationData.Y.ToString());
                AccelGraph.Series["Accel_Z"].Points.AddXY(AccelGraph.Series["Accel_Z"].Points.Count(), GlobalVariables.AccelerationData.Z.ToString());

                if (AccelGraph.ChartAreas[0].AxisX.Maximum - AccelGraph.ChartAreas[0].AxisX.Minimum > 100)
                {
                    AccelGraph.ChartAreas[0].AxisX.Minimum = AccelGraph.ChartAreas[0].AxisX.Minimum + 1;;
                }
            }
        }