Exemplo n.º 1
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            UpdateUi();

            BtnTargetSpeedIncrease.Click += BtnTargetSpeedIncrease_Click;
            BtnTargetSpeedDecrease.Click += BtnTargetSpeedDecrease_Click;

            BtnToleranceDecreaseKts.Click += BtnToleranceDecreaseKts_Click;
            BtnToleranceIncreaseKts.Click += BtnToleranceIncreaseKts_Click;

            _servo = new ServoController(5);
            await _servo.Connect();

            _servo.SetPosition(ServoPosition).AllowTimeToMove(2000).Go();
        }
Exemplo n.º 2
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            ServoPosition = 0;

            TargetSpeed      = 2.5d;
            ToleranceSpeed   = 0.1d;
            ToleranceSeconds = 1.0d;

            BtnTargetSpeedActivate.Click += BtnTargetSpeedActivate_Click;
            BtnTargetSpeedIncrease.Click += BtnTargetSpeedIncrease_Click;
            BtnTargetSpeedDecrease.Click += BtnTargetSpeedDecrease_Click;

            BtnToleranceDecreaseKmh.Click += BtnToleranceDecreaseKmh_Click;
            BtnToleranceIncreaseKmh.Click += BtnToleranceIncreaseKmh_Click;

            BtnTimeFactorDecrease.Click += BtnTimeFactorDecrease_Click;
            BtnTimeFactorIncrease.Click += BtnTimeFactorIncrease_Click;

            BtnTest.Click += BtnTest_Click;

            TxtDebug.TextChanged += TxtDebug_TextChanged;

            var modes = Enum.GetValues(typeof(AutopilotOperationMode)).Cast <AutopilotOperationMode>();

            CmbMode.ItemsSource = modes.ToList();

            OpertationMode            = 0;
            CmbMode.SelectedIndex     = 0;
            CmbMode.SelectionChanged += CmbModeOnSelectionChanged;

            // Initialize Gps
            try
            {
                StartGps();

                #region Compass Initialize

                // TODO: Check I2C connection of RPi
                //StartCompass();

                //if (Compass.IsConnected())
                //{
                //    _chacheCompassTask = Task.Run(() =>
                //    {
                //        while (true)
                //        {
                //            CompassData.Add(Compass.GetRawData());

                //            if (_compassTaskToken.IsCancellationRequested)
                //            {
                //                _compassTaskToken.ThrowIfCancellationRequested();
                //            }
                //        }
                //    }, _compassTaskToken);
                //}

                #endregion

                #region ServoController

                ServoController = new ServoController(5);
                await ServoController.Connect();

                ServoController.SetPosition(ServoPosition).AllowTimeToMove(2000).Go();

                await Task.Run(async() =>
                {
                    while (UpdatingUi)
                    {
                        await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                            CoreDispatcherPriority.Normal, () =>
                        {
                            UpdateUi();
                        });

                        Task.Delay(2000).Wait();
                    }
                });

                #endregion
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("Error starting app: {0}", ex.Message));
            }
        }