Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (bridgeRunning)
            {
                return;
            }

            if (firmataPortsSelection.SelectedIndex < 0)
            {
                MessageBox.Show("You need to select a serial port before you can start bridge");
                bridgeRunning = false;
                return;
            }

            disableControls();

            string serialPortName = firmataPortsSelection.SelectedItem.ToString();

            try
            {
                arduinoInterface = new Firmata(serialPortName, 57600, true, 1000);

                // setup test led
                arduinoInterface.pinMode(13, Firmata.OUTPUT);

                if (turnCoordinatorTurnRateEnabled.Checked)
                {
                    arduinoInterface.pinMode(Convert.ToInt32(turnRatePinNr.Value), Firmata.SERVO);
                    arduinoInterface.analogWrite(Convert.ToInt32(turnRatePinNr.Value), 90);
                }

                if (TASEnabled.Checked)
                {
                    arduinoInterface.pinMode(Convert.ToInt32(TASpinnr), Firmata.SERVO);
                    arduinoInterface.analogWrite(Convert.ToInt32(TASpinnr), 0);
                }

                if (turnCoordinatorBallPosEnabled.Checked)
                {
                    arduinoInterface.pinMode(Convert.ToInt32(turnBallPosPinNr.Value), Firmata.SERVO);
                    arduinoInterface.analogWrite(Convert.ToInt32(turnBallPosPinNr.Value), 90);
                }

                bridgeRunning = true;

                startStopLabel.Text      = "Running";
                startStopLabel.ForeColor = Color.Green;
            }
            catch (Exception Ex)
            {
                startStopLabel.Text      = "Stopped";
                startStopLabel.ForeColor = Color.Red;
                MessageBox.Show("Start Bridge Error: " + Ex.Message);
                bridgeRunning = false;
                enableControls();
            }
        }
Example #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     arduinoInterface = new Firmata("com85", 57600, true, 1000);
     arduinoInterface.pinMode(13, Firmata.OUTPUT);
     arduinoInterface.pinMode(9, Firmata.SERVO);
     arduinoInterface.pinMode(11, Firmata.SERVO);
     arduinoInterface.analogWrite(9, trackBar1.Value);
     arduinoInterface.analogWrite(11, trackBar1.Value);
 }
Example #3
0
        private void bridgeTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                FSUIPCConnection.Process();

                turnRateValueLabel.Text    = turn_Rate.Value.ToString();
                turnBallPosValueLabel.Text = turn_ballPosition.Value.ToString();
                TASValueLabel.Text         = (speedo_TAS.Value / 128).ToString();

                short modTASValue = -1;

                try
                {
                    modTASValue           = Convert.ToInt16(map((speedo_TAS.Value / 128), Convert.ToInt64(TASMapInputMinText.Text), Convert.ToInt64(TASMapInputMaxText.Text), Convert.ToInt64(TASMapOutputMinText.Text), Convert.ToInt64(TASMapOutputMaxText.Text)));
                    TASModValueLabel.Text = modTASValue.ToString();
                }
                catch (Exception Ex)
                {
                    TASModValueLabel.Text = "Error";
                }


                short modTurnRateValue = -1;

                try
                {
                    modTurnRateValue = Convert.ToInt16(map(turn_Rate.Value, Convert.ToInt64(turnRateMapInputMinText.Text), Convert.ToInt64(turnRateMapInputMaxText.Text), Convert.ToInt64(turnRateMapOutputMinText.Text), Convert.ToInt64(turnRateMapOutputMaxText.Text)));
                    turnRateModifiedValueLabel.Text = modTurnRateValue.ToString();
                }
                catch (Exception Ex)
                {
                    turnRateModifiedValueLabel.Text = "Error";
                }

                short modBallPositionValue = -1;

                try
                {
                    modBallPositionValue = Convert.ToInt16(map(turn_ballPosition.Value, Convert.ToInt64(turnBallPosMapInputMinText.Text), Convert.ToInt64(turnBallPosMapInputMaxText.Text), Convert.ToInt64(turnBallPosMapOutputMinText.Text), Convert.ToInt64(turnBallPosMapOutputMaxText.Text)));
                    turnBallPosModifiedValueLabel.Text = modBallPositionValue.ToString();
                }
                catch (Exception Ex)
                {
                    turnBallPosModifiedValueLabel.Text = "Error";
                }

                // if bridgeRunning then send values to arduino/firmata
                if (bridgeRunning)
                {
                    if (TASEnabled.Checked && modTASValue > -1)
                    {
                        arduinoInterface.analogWrite(Convert.ToInt32(TASpinnr.Value), modTASValue);
                    }

                    if (turnCoordinatorTurnRateEnabled.Checked && modTurnRateValue > -1)
                    {
                        arduinoInterface.analogWrite(Convert.ToInt32(turnRatePinNr.Value), modTurnRateValue);
                    }

                    if (turnCoordinatorBallPosEnabled.Checked && modBallPositionValue > -1)
                    {
                        arduinoInterface.analogWrite(Convert.ToInt32(turnBallPosPinNr.Value), modBallPositionValue);
                    }
                }
            }
            catch (FSUIPCException ex)
            {
                if (ex.FSUIPCErrorCode == FSUIPCError.FSUIPC_ERR_SENDMSG)
                {
                    this.bridgeTimer.Enabled = false;
                    FSUIPCConnection.Close();
                    MessageBox.Show("The connection to Flight Sim has been lost.", "Firmata Bridge", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    throw ex;
                }
            }
            catch (Exception)
            {
            }
        }
Example #4
0
 private void trackBar1_Scroll(object sender, EventArgs e)
 {
     arduinoInterface.analogWrite(9, trackBar1.Value);
     arduinoInterface.analogWrite(11, trackBar1.Value);
     label1.Text = trackBar1.Value.ToString();
 }