예제 #1
0
        public void Send(byte[] data)
        {
            if (CommTypeSerial_radioButton.Checked)
            {
                if (serialPort.IsOpen)
                {
                    try
                    {
                        serialPort.Write(data, 0, data.Length);

                        byte[] checksum = new byte[1];
                        checksum[0] = JoystickHandler.CreateChecksum(data);
                        serialPort.Write(checksum, 0, 1);
                    }
                    catch
                    {
                        //ClientDisconnect_button_Click(null, null);
                    }
                }
            }
            else if (IpModeServer_radioButton.Checked)
            {
                if (CommTypeTCP_radioButton.Checked)
                {
                    serverTCP.Send(data);
                }
                else if (CommTypeUDP_radioButton.Checked)
                {
                    serverUDP.Send(data);
                }
            }
            else if (IpModeClient_radioButton.Checked)
            {
                if (CommTypeTCP_radioButton.Checked)
                {
                    clientTCP.Send(data);
                }
                else if (CommTypeUDP_radioButton.Checked)
                {
                    clientUDP.Send(data);
                }
            }
        }
예제 #2
0
        private void Joystick_timer_Tick(object sender, EventArgs e)
        {
            if (joystickComboBox.SelectedIndex < 0)
            {
                // No joystick available, nothing to do.
                return;
            }

            jyst.Poll();
            if (doCalibartion)
            {
                doCalibartion       = false;
                jystHandler.CenterX = jyst.state.X;
                jystHandler.CenterY = jyst.state.Y;
            }

            PlaneAttributes planeAttrib = ReassignJystValues(jyst.state);

            JoystickHandler.FbW_Data PwmData = new JoystickHandler.FbW_Data();


            // write joystick to the UI
            if (OverrideAileron_checkBox.Checked)
            {
                PwmData.aileron = Aileron_trackBar.Value;
            }
            else
            {
                PwmData.aileron = jystHandler.ConvertForUI(planeAttrib.aileron,
                                                           AileronScalar_numericUpDown.Value,
                                                           AileronTrim_numericUpDown.Value,
                                                           InvertAileron_checkBox.Checked);
                Aileron_trackBar.Value = MainForm.Clip(PwmData.aileron, PWMminValue, PWMmaxValue);
            }
            Aileron_label.Text = "Aileron\r" + PwmData.aileron.ToString();


            if (OverrideElevator_checkBox.Checked)
            {
                PwmData.elevator = Elevator_trackBar.Value;
            }
            else
            {
                PwmData.elevator = jystHandler.ConvertForUI(planeAttrib.elevator,
                                                            ElevatorScalar_numericUpDown.Value,
                                                            ElevatorTrim_numericUpDown.Value,
                                                            InvertElevator_checkBox.Checked);
                Elevator_trackBar.Value = MainForm.Clip(PwmData.elevator, PWMminValue, PWMmaxValue);
            }
            Elevator_label.Text = "Elevator\r" + PwmData.elevator.ToString();


            if (OverrideRudder_checkBox.Checked)
            {
                PwmData.rudder = Rudder_trackBar.Value;
            }
            else
            {
                PwmData.rudder = jystHandler.ConvertForUI(planeAttrib.rudder,
                                                          RudderScalar_numericUpDown.Value,
                                                          RudderTrim_numericUpDown.Value,
                                                          InvertRudder_checkBox.Checked);
                Rudder_trackBar.Value = MainForm.Clip(PwmData.rudder, PWMminValue, PWMmaxValue);
            }
            Rudder_label.Text = "Rudder\r" + PwmData.rudder.ToString();


            if (OverrideThrottle_checkBox.Checked)
            {
                PwmData.throttle = Throttle_trackBar.Value;
            }
            else
            {
                PwmData.throttle = jystHandler.ConvertForUI(planeAttrib.throttle,
                                                            ThrottleScalar_numericUpDown.Value,
                                                            ThrottleTrim_numericUpDown.Value,
                                                            InvertThrottle_checkBox.Checked);
                Throttle_trackBar.Value = MainForm.Clip(PwmData.throttle, PWMminValue, PWMmaxValue);
            }
            Throttle_label.Text = "Throttle\r" + PwmData.throttle.ToString();


            switch (Mode_comboBox.SelectedIndex)
            {
            default:
            case 0: PwmData.mode = PWMminValue; break;     // Manual

            case 1: PwmData.mode = PWMmidValue; break;     // Stabilized

            case 2: PwmData.mode = PWMmaxValue; break;     // WayPoint
            }

            byte[] packet = JoystickHandler.CreateTxPacket(PwmData);
            Send(packet);
        }