Пример #1
0
        private void startCompass()
        {
            if (compass != null && compass.IsDataValid)
            {
                compass.Stop();
                timer.Stop();
                accelerometer.Stop();
            }
            else
            {
                if (compass == null)
                {
                    compass = new Compass();
                    compass.TimeBetweenUpdates   = TimeSpan.FromMilliseconds(20);
                    compass.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <CompassReading> >(compass_CurrentValueChanged);
                    compass.Calibrate           += new EventHandler <CalibrationEventArgs>(compass_Calibrate);
                }
            }

            try
            {
                compass.Start();
                timer.Start();
                accelerometer = new Accelerometer();
                // Start accelerometer for detecting compass axis
                accelerometer = new Accelerometer();
                accelerometer.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <AccelerometerReading> >(accelerometer_CurrentValueChanged);
                accelerometer.Start();
                heading = 0.0;
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("Error with sensor data");
            }
        }
        private void InitializeCompass()
        {
            if (!Compass.IsSupported)
            {
                // The device on which the application is running does not support
                // the compass sensor. Alert the user and hide the
                // application bar.
                //statusTextBlock.Text = "device does not support compass";

                MessageBox.Show("Device not supported compass sensors. Heading map will be turned off");
                HeadingPath.Visibility = Visibility.Collapsed;
            }
            else
            {
                // Initialize the timer and add Tick event handler, but don't start it yet.
                timer          = new DispatcherTimer();
                timer.Interval = TimeSpan.FromMilliseconds(30);
                timer.Tick    += new EventHandler(timer_Tick);

                //Start the compass
                if (compass != null && compass.IsDataValid)
                {
                    // Stop data acquisition from the compass.
                    compass.Stop();
                    timer.Stop();
                    //statusTextBlock.Text = "compass stopped.";
                }
                else
                {
                    if (compass == null)
                    {
                        // Instantiate the compass.
                        compass = new Compass();

                        // Specify the desired time between updates. The sensor accepts
                        // intervals in multiples of 20 ms.
                        compass.TimeBetweenUpdates = TimeSpan.FromMilliseconds(20);

                        // The sensor may not support the requested time between updates.
                        // The TimeBetweenUpdates property reflects the actual rate.
                        //timeBetweenUpdatesTextBlock.Text = compass.TimeBetweenUpdates.TotalMilliseconds + " ms";


                        compass.CurrentValueChanged += compass_CurrentValueChanged;
                        compass.Calibrate           += compass_Calibrate;

                        try
                        {
                            //statusTextBlock.Text = "starting compass.";
                            compass.Start();
                            timer.Start();
                        }
                        catch (InvalidOperationException)
                        {
                            //statusTextBlock.Text = "unable to start compass.";
                        }
                    }
                }
            }
        }
        void Stop()
        {
            if (Compass.IsMonitoring)
            {
                Compass.ReadingChanged -= Compass_ReadingChanged;
                Compass.Stop();
            }

            if (Accelerometer.IsMonitoring)
            {
                Accelerometer.ReadingChanged -= Accelerometer_Essentials_ReadingChanged;
                Accelerometer.Stop();
            }

            if (Gyroscope.IsMonitoring)
            {
                Gyroscope.ReadingChanged -= Gyroscope_ReadingChanged;
                Gyroscope.Stop();
            }

            if (Magnetometer.IsMonitoring)
            {
                Magnetometer.ReadingChanged -= Magnetometer_ReadingChanged;
                Magnetometer.Stop();
            }

            // device-specific sensor readings
            if (Device.RuntimePlatform.Equals((Device.Android)))
            {
                MessagingCenter.Unsubscribe <Sensors.Android.LinearAcceleration>(this, Sensors.Android.SubscriberMessage.LinearAcceleration);
            }
        }
Пример #4
0
        private void StartListeningCompass()
        {
            try
            {
                if (Compass.IsMonitoring)
                {
                    Compass.Stop();
                }
                else
                {
                    Compass.Start(_speed);
                }
            }
            catch (FeatureNotSupportedException)
            {
                // Feature not supported on device
            }
            catch (Exception)
            {
                // Some other exception has occured
            }


            //if (!CrossCompass.Current.IsSupported)
            //    return;

            //CrossCompass.Current.CompassChanged += Current_CompassChanged;
            //CrossCompass.Current.Start();
        }
Пример #5
0
 private void Button_Clicked_1(object sender, EventArgs e)
 {
     if (Compass.IsMonitoring)
     {
         Compass.Stop();
     }
 }
        private bool TimerStarted()
        {
            Device.BeginInvokeOnMainThread(async() =>
            {
                Compass.Start(SensorSpeed.UI, applyLowPassFilter: true);
                Compass.ReadingChanged += Compass_ReadingChanged;
                map.Pins.Clear();
                map.Polylines.Clear();
                var contents = await mapPageViewModel.LoadVehicles();
                if (contents != null)
                {
                    foreach (var item in contents)
                    {
                        Pin VehiclePins = new Pin()
                        {
                            Label = "Cars",
                            Type  = PinType.Place,

                            Icon = (Device.RuntimePlatform == Device.Android) ? BitmapDescriptorFactory.FromBundle("CarPins.png") : BitmapDescriptorFactory.FromView(new Image()
                            {
                                Source = "CarPins.png", WidthRequest = 30, HeightRequest = 30
                            }),
                            Position = new Position(Convert.ToDouble(item.Latitude), Convert.ToDouble(item.Longitude)),
                            Rotation = ToRotationPoints(headernorthvalue)
                        };
                        map.Pins.Add(VehiclePins);
                    }
                }
            }

                                           );
            Compass.Stop();
            return(true);
        }
Пример #7
0
 private async void Map_CameraMoveStarted(object sender, CameraMoveStartedEventArgs e)
 {
     if (Compass.IsMonitoring && e.IsGesture)
     {
         Compass.Stop();
     }
 }
 public void ToggleMetrics(bool isToogled)
 {
     try
     {
         if (isToogled)
         {
             Accelerometer.Start(speed);
             //Barometer.Start(speed);
             Compass.Start(speed);
             Gyroscope.Start(speed);
             Magnetometer.Start(speed);
             OrientationSensor.Start(speed);
         }
         else
         {
             Accelerometer.Stop();
             //Barometer.Stop();
             Compass.Stop();
             Gyroscope.Stop();
             Magnetometer.Stop();
             OrientationSensor.Stop();
         }
     }
     catch (FeatureNotSupportedException)
     {
         ShowNotSupportedError();
     }
     catch (Exception ex)
     {
         ShowError(ex.Message);
     }
 }
        public void ExecuteToggleDarkNavCommand()
        {
            //Make Dark nav visible/invible
            DarkNavEnabled = !DarkNavEnabled;

            //Start compass, because compass is only visible in DarkMode
            try
            {
                if (DarkNavEnabled)
                {
                    Compass.ReadingChanged += Compass_ReadingChanged;
                    Compass.Start(SensorSpeed.Fastest);
                }
                else
                {
                    Compass.ReadingChanged -= Compass_ReadingChanged;
                    Compass.Stop();
                }
            }
            catch (Exception ex)
            {
                HeadingMagneticNorth = 30;
                Crashes.TrackError(ex);
            }
        }
Пример #10
0
 public void ToggleCompass()
 {
     try
     {
         if (Compass.IsMonitoring)
         {
             Compass.Stop();
         }
         else
         {
             Compass.Start(speed);
         }
     }
     catch (FeatureNotSupportedException fnsEx)
     {
         // Feature not supported on device
         Console.WriteLine(fnsEx);
         exception.Text = "Feature not supported on device";
     }
     catch (Exception ex)
     {
         // Other error has occurred.
         Console.WriteLine(ex);
         exception.Text = "Other error has occurred";
     }
 }
Пример #11
0
 public void ControlSunscribe(bool flag)
 {
     try
     {
         if (Compass.IsMonitoring && !flag)
         {
             Compass.Stop();
             CompassWatch.Reset();
         }
         else if (!Compass.IsMonitoring && flag)
         {
             CompassWatch.Start();
             Compass.Start(Config.sensorSpeed);
         }
         else
         {
             //Dont think anything is needed here
         }
     }
     catch (FeatureNotEnabledException ex)
     {
     }
     catch (Exception ex)
     {
     }
 }
Пример #12
0
        public async Task Stop_Monitor(SensorSpeed sensorSpeed)
        {
            // TODO: the test runner app (UI version) should do this, until then...
            if (!HardwareSupport.HasCompass)
            {
                return;
            }

            var tcs = new TaskCompletionSource <CompassData>();

            Compass.ReadingChanged += Compass_ReadingChanged;
            void Compass_ReadingChanged(object sender, CompassChangedEventArgs e)
            {
                tcs.TrySetResult(e.Reading);
            }

            Compass.Start(sensorSpeed);

            var d = await tcs.Task;

            Compass.Stop();
            Compass.ReadingChanged -= Compass_ReadingChanged;

            Assert.False(Compass.IsMonitoring);
        }
Пример #13
0
 protected override void OnDisappearing()
 {
     if (Compass.IsMonitoring)
     {
         Compass.Stop();
     }
 }
Пример #14
0
 protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
 {
     if (_c != null)
     {
         _c.Stop();
         _c.CurrentValueChanged -= CompassCurrentValueChanged;
     }
 }
Пример #15
0
 protected override void OnDisappearing()
 {
     Accelerometer.Stop();
     Gyroscope.Stop();
     Magnetometer.Stop();
     Compass.Stop();
     base.OnDisappearing();
 }
Пример #16
0
 private void Click_CompassOnOff(object sender, EventArgs e)
 {
     if (compas_running == true)
     {
         if (camera_running == true)
         {
             try
             {
                 Camera_Source.CaptureImageAvailable += new System.EventHandler <ContentReadyEventArgs>(Camera_Image_Available);
                 Camera_Source.FlashMode              = FlashMode.Off;
                 Camera_Source.CaptureImage();
             }
             catch (InvalidOperationException)
             {
                 MessageBox.Show(" La caméra n'a pas eu le temps de s'initialiser.");
             }
         }
         Boussolle_Get_Timer.Stop();
         Accelerometre_Get_Timer.Stop();
         etat_TextBlock.Text = " Pause";
         compas_running      = false;
     }
     else
     {
         if (Boussolle_Get_Timer == null)
         {
             Boussolle_Get_Timer = new Compass();
             Boussolle_Get_Timer.TimeBetweenUpdates   = TimeSpan.FromMilliseconds(timer_get);
             Boussolle_Get_Timer.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <CompassReading> >(Boussolle_ValueChanged);
             Boussolle_Get_Timer.Calibrate           += new EventHandler <CalibrationEventArgs>(Calibration_Start);
         }
         try
         {
             etat_TextBlock.Text = " Démarrage...";
             Boussolle_Get_Timer.Start();
             Accelerometre_Get_Timer = new Accelerometer();
             Accelerometre_Get_Timer.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <AccelerometerReading> >(Orientation_ValueChanged);
             Accelerometre_Get_Timer.Start();
             Accelerometre_Get_Timer = new Accelerometer();
             Accelerometre_Get_Timer.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <AccelerometerReading> >(Orientation_ValueChanged);
             Accelerometre_Get_Timer.Start();
             compas_running = true;
             //MessageBox.Show("Reel : " + Boussolle_Get_Timer.TimeBetweenUpdates.TotalMilliseconds + "ms \nPrevu : " + timer_get + "ms \nDisplay : " + timer_display + "ms"); //timer affichage
             if (camera_running == false && camera_ison == true)
             {
                 Camera_Ellipse.Fill = Camera_Brush;
                 Camera_Source       = new PhotoCamera(CameraType.Primary);
                 Camera_Brush.SetSource(Camera_Source);
                 camera_running        = true;
                 Image_Ellipse.Opacity = 0;
             }
         }
         catch (InvalidOperationException)
         {
             etat_TextBlock.Text = " Erreur.";
         }
     }
 }
Пример #17
0
 void CompassCancel()
 {
     if (_compass != null)
     {
         _compass.Stop();
         _compass.Dispose();
         _compass = null;
     }
 }
Пример #18
0
 private void OnIsCompassEnabledChanged(bool value)
 {
     if (value)
     {
         _Compass.Start();
     }
     else
     {
         _Compass.Stop();
     }
 }
Пример #19
0
 public void Stop()
 {
     // Stop data acquisition from the compass.
     if (isWorking)
     {
         Logger.WriteLine("PhoneCompass: Stop");
         compass.Stop();
         timer.Stop();
     }
     isWorking = false;
 }
Пример #20
0
 public void Stop()
 {
     if (wtc != null)
     {
         wtc.Stop();
     }
     if (cmp != null)
     {
         cmp.Stop();
     }
 }
Пример #21
0
        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);

            // Ressourcen freigeben
            if (compass != null)
            {
                compass.Stop();
                compass.CurrentValueChanged -= compass_CurrentValueChanged;
                compass.Dispose();
            }
        }
Пример #22
0
        public static void ToggleCompass()        //toggles compass on and off - used in MainActivity class
        {
            SensorSpeed speed = SensorSpeed.Game; //sensor speed

            if (Compass.IsMonitoring)
            {
                Compass.Stop();
            }
            else
            {
                Compass.Start(speed, applyLowPassFilter: true);
            }
        }
Пример #23
0
        public void Stop()
        {
            if (wtc != null)
            {
                wtc.Stop();

                wtc.Dispose();
            }
            if (cmp != null)
            {
                cmp.Stop();
                cmp.Dispose();
            }
        }
Пример #24
0
        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            if (compass != null && compass.IsDataValid)
            {
                // Stop data acquisition from the compass.
                compass.Stop();
                timer.Stop();
                statusTextBlock.Text = "compass stopped.";

                // Detect compass axis
                accelerometer.Stop();
            }
            else
            {
                if (compass == null)
                {
                    // Instantiate the compass.
                    compass = new Compass();


                    // Specify the desired time between updates. The sensor accepts
                    // intervals in multiples of 20 ms.
                    compass.TimeBetweenUpdates = TimeSpan.FromMilliseconds(20);

                    // The sensor may not support the requested time between updates.
                    // The TimeBetweenUpdates property reflects the actual rate.
                    timeBetweenUpdatesTextBlock.Text = compass.TimeBetweenUpdates.TotalMilliseconds + " ms";


                    compass.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <CompassReading> >(compass_CurrentValueChanged);
                    compass.Calibrate           += new EventHandler <CalibrationEventArgs>(compass_Calibrate);
                }

                try
                {
                    statusTextBlock.Text = "starting compass.";
                    compass.Start();
                    timer.Start();

                    // Start accelerometer for detecting compass axis
                    accelerometer = new Accelerometer();
                    accelerometer.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <AccelerometerReading> >(accelerometer_CurrentValueChanged);
                    accelerometer.Start();
                }
                catch (InvalidOperationException)
                {
                    statusTextBlock.Text = "unable to start compass.";
                }
            }
        }
Пример #25
0
        public void Dispose()
        {
            if (this._compass != null)
            {
                _compass.Calibrate           -= CompassCalibrate;
                _compass.CurrentValueChanged -= CompassCurrentValueChanged;

                _compass.Stop();
                _compass.Dispose();
                _compass = null;
            }

            Dispose(true);
            GC.SuppressFinalize(this);
        }
Пример #26
0
 private void btnStop_Clicked(object sender, EventArgs e)
 {
     if (Compass.IsMonitoring)
     {
         Compass.Stop();
     }
     if (Accelerometer.IsMonitoring)
     {
         Accelerometer.Stop();
     }
     if (timerRun)
     {
         timerRun = false;
     }
 }
Пример #27
0
        public void Stop()
        {
            try
            {
                if (!Compass.IsMonitoring)
                {
                    return;
                }

                Compass.Stop();
            }
            catch (Exception ex)
            {
                throw new Exception($"Error when stopping compass. {ex.Message}");
            }
        }
        void Barometer_ReadingChanged(object sender, BarometerChangedEventArgs e)
        {
            var data = e.Reading;
            var item = new ItemBarometer
            {
                DateInfo = DateTime.Now.ToString(),
                Pressure = "Pressure: " + data.PressureInHectopascals + " hectopascals"
            };

            Calculos.Insert(0, item);
            ListViewCheck.ItemsSource = Calculos;
            if (Compass.IsMonitoring)
            {
                Compass.Stop();
            }
        }
Пример #29
0
        protected Task <bool> StopCompassIfUnusedAsync()
        {
            if (TargetPositionObservers.Any())
            {
                return(Task.FromResult(true));
            }

            Compass.ReadingChanged -= CompassOnReadingChanged;

            if (Compass.IsMonitoring)
            {
                Compass.Stop();
            }

            return(Task.FromResult(true));
        }
 private void stop_Click(object sender, EventArgs e)
 {
     timer.Stop();
     if (Accelerometer.IsSupported)
     {
         accelSensor.Stop();
     }
     if (Compass.IsSupported)
     {
         compassSensor.Stop();
     }
     if (Gyroscope.IsSupported)
     {
         gyroSensor.Stop();
     }
     messageBlock.Text = "Press start";
 }