Beispiel #1
0
        /// <summary>
        /// Handles OnClick event for Start button.
        /// Creates socket connection and opens ControllerView.
        /// Initializes, modifies and handles events for all widgets.
        /// Starts socket reader thread.
        /// </summary>
        private void OnStartController(object sender, EventArgs e)
        {
            // Create socket connection
            while (mSocketConnection.IsConnectingFinished == false)
            {
                Java.Lang.Thread.Sleep(100);
            }

            if (mSocketConnection.IsConnected == false)
            {
                StartActivity(typeof(MainActivity));
                return;
            }
            byte[] logInit = new byte[19];
            logInit[0] = INIT_COMMUNICATION;
            logInit[1] = (byte)(mLoggingActive == true ? 1 : 0);
            logInit[2] = (byte)(mLogBatteryActive == true ? 1 : 0);
            logInit[3] = (byte)(mLogRadarActive == true ? 1 : 0);
            logInit[4] = (byte)(mLogCollisionStatusActive == true ? 1 : 0);
            // For testing
            logInit[5] = (byte)(mLogControlsDroneActive == true ? 1 : 0);
            //
            logInit[6] = (byte)(mLogDebug1Active == true ? 1 : 0);
            logInit[7] = (byte)(mLogDebug2Active == true ? 1 : 0);
            logInit[8] = (byte)(mLogDebug3Active == true ? 1 : 0);
            logInit[9] = (byte)(mLogDebug4Active == true ? 1 : 0);

            mSocketConnection.WriteLog(logInit);

            // Start reading from Raspberry
            mSocketConnection.StartListening();

            // Read min and max values
            mMinYaw   = Convert.ToInt32(mEtMinYaw.Text);
            mMaxYaw   = Convert.ToInt32(mEtMaxYaw.Text);
            mMinPitch = Convert.ToInt32(mEtMinPitch.Text);
            mMaxPitch = Convert.ToInt32(mEtMaxPitch.Text);
            mMinRoll  = Convert.ToInt32(mEtMinRoll.Text);
            mMaxRoll  = Convert.ToInt32(mEtMaxRoll.Text);

            // Read log data
            mLogBatteryActive = mCbxBattery.Checked;
            if (mLogBatteryActive == true)
            {
                mSocketConnection.DroneLogs.Add("Battery", new LogData("Battery", 1));
            }
            mLogRadarActive = mCbxRadarData.Checked;
            if (mLogRadarActive == true)
            {
                mSocketConnection.DroneLogs.Add("Radar", new LogData("Radar", 1));
            }
            mLogCollisionStatusActive = mCbxCollisionStatus.Checked;
            if (mLogCollisionStatusActive == true)
            {
                mSocketConnection.DroneLogs.Add("CollisionStatus", new LogData("CollisionStatus", 1));
            }
            mLogControlsMobileActive = mCbxControlsMobile.Checked;

            // For testing
            mLogControlsDroneActive = mCbxControlsDrone.Checked;
            if (mLogControlsDroneActive == true)
            {
                mSocketConnection.DroneLogs.Add("ControlsDrone", new LogData("ControlsDrone", 1));
            }
            //
            mLogDebug1Active = mCbxDebug1.Checked;
            if (mLogDebug1Active == true)
            {
                mSocketConnection.DroneLogs.Add("Debug1", new LogData("Debug1", 1));
            }
            mLogDebug2Active = mCbxDebug2.Checked;
            if (mLogDebug2Active == true)
            {
                mSocketConnection.DroneLogs.Add("Debug2", new LogData("Debug2", 1));
            }
            mLogDebug3Active = mCbxDebug3.Checked;
            if (mLogDebug3Active == true)
            {
                mSocketConnection.DroneLogs.Add("Debug3", new LogData("Debug3", 1));
            }
            mLogDebug4Active = mCbxDebug4.Checked;
            if (mLogDebug4Active == true)
            {
                mSocketConnection.DroneLogs.Add("Debug4", new LogData("Debug4", 1));
            }

            // Change to Controller with joysticks
            SetContentView(Resource.Layout.ControllerLayout);

            // Set values for controller settings
            if (mPeerSettings.Any(kvp => kvp.Key == mSelectedBssid) == true)
            {
                ControllerView.Settings.TrimYaw          = mPeerSettings[mSelectedBssid].TrimYaw;
                ControllerView.Settings.TrimPitch        = mPeerSettings[mSelectedBssid].TrimPitch;
                ControllerView.Settings.TrimRoll         = mPeerSettings[mSelectedBssid].TrimRoll;
                ControllerView.Settings.LoggingActivated = mLoggingActive;
                ControllerView.Settings.MinYaw           = mMinYaw;
                ControllerView.Settings.MaxYaw           = mMaxYaw;
                ControllerView.Settings.MinPitch         = mMinPitch;
                ControllerView.Settings.MaxPitch         = mMaxPitch;
                ControllerView.Settings.MinRoll          = mMinRoll;
                ControllerView.Settings.MaxRoll          = mMaxRoll;
            }

            // Create font
            var font = Typeface.CreateFromAsset(Assets, "SourceSansPro-Light.ttf");

            // Initialize widgets of ControllerLayout
            mControllerView     = FindViewById <ControllerView>(Resource.Id.JoystickView);
            mSbTrimBar          = FindViewById <SeekBar>(Resource.Id.sbTrimbar);
            mTvTrimValue        = FindViewById <TextView>(Resource.Id.tvTrimValue);
            mBtnAltitudeControl = FindViewById <Button>(Resource.Id.btnAltitudeControl);
            mRbYawTrim          = FindViewById <RadioButton>(Resource.Id.rbYawTrim);
            mRbPitchTrim        = FindViewById <RadioButton>(Resource.Id.rbPitchTrim);
            mRbRollTrim         = FindViewById <RadioButton>(Resource.Id.rbRollTrim);

            mControllerView.SetSocketConnection(mSocketConnection);

            // Set font to widgets
            mTvTrimValue.Typeface        = font;
            mBtnAltitudeControl.Typeface = font;
            mRbYawTrim.Typeface          = font;
            mRbPitchTrim.Typeface        = font;
            mRbRollTrim.Typeface         = font;

            mBtnAltitudeControl.Click += OnAltitudeControlClick;

            mSbTrimBar.Progress = ControllerView.Settings.TrimYaw - mMinTrim;
            mTvTrimValue.Text   = ControllerView.Settings.TrimYaw.ToString();

            // Change value of trim
            mSbTrimBar.ProgressChanged += delegate
            {
                if (mRbYawTrim.Checked == true)
                {
                    ControllerView.Settings.TrimYaw = mSbTrimBar.Progress + mMinTrim;
                }
                else if (mRbPitchTrim.Checked == true)
                {
                    ControllerView.Settings.TrimPitch = mSbTrimBar.Progress + mMinTrim;
                }
                else
                {
                    ControllerView.Settings.TrimRoll = mSbTrimBar.Progress + mMinTrim;
                }
                mTvTrimValue.Text = (mSbTrimBar.Progress + mMinTrim).ToString();
            };

            // Change seekbar to yaw trim
            mRbYawTrim.Click += delegate
            {
                mTvTrimValue.Text   = ControllerView.Settings.TrimYaw.ToString();
                mSbTrimBar.Progress = ControllerView.Settings.TrimYaw - mMinTrim;
            };

            // Change seekbar to pitch trim
            mRbPitchTrim.Click += delegate
            {
                mTvTrimValue.Text   = ControllerView.Settings.TrimPitch.ToString();
                mSbTrimBar.Progress = ControllerView.Settings.TrimPitch - mMinTrim;
            };

            // Change seekbar to roll trim
            mRbRollTrim.Click += delegate
            {
                mTvTrimValue.Text   = ControllerView.Settings.TrimRoll.ToString();
                mSbTrimBar.Progress = ControllerView.Settings.TrimRoll - mMinTrim;
            };
        }
Beispiel #2
0
        partial void OnStartMode1(UIButton sender)
        {
            ControllerView cv = new ControllerView();

            this.View = cv;
        }