/// <summary> /// Initializes a new instance of the DeviceMotionImplementation class. /// </summary> public DeviceMotionImplementation() { if (Accelerometer.IsSupported) { accelerometer = new Accelerometer(); sensors.Add(accelerometer); } if (Gyroscope.IsSupported) { gyroscope = new Gyroscope(); sensors.Add(gyroscope); } if (Magnetometer.IsSupported) { magnetometer = new Magnetometer(); sensors.Add(magnetometer); } if (OrientationSensor.IsSupported) { orientation = new OrientationSensor(); sensors.Add(orientation); } sensorStatus = new Dictionary <MotionSensorType, bool>() { { MotionSensorType.Accelerometer, false }, { MotionSensorType.Gyroscope, false }, { MotionSensorType.Magnetometer, false }, { MotionSensorType.Compass, false } }; }
// For more information on using orientation sensors, see the OrientationSensor sample. void GetOrientationReport() { OrientationSensor sensor; // If there is a version of GetDefault that lets us specify the optimization goal, // then use it. Otherwise, use the regular version. if (hasOrientationWithOptimizationGoal) { sensor = OrientationSensor.GetDefault(SensorReadingType.Absolute, SensorOptimizationGoal.PowerEfficiency); } else { sensor = OrientationSensor.GetDefault(); } if (sensor != null) { OrientationSensorReading reading = sensor.GetCurrentReading(); SensorQuaternion quaternion = reading.Quaternion; rootPage.NotifyUser($"X: {quaternion.X}, Y: {quaternion.Y}, Z: {quaternion.Z}, W: {quaternion.W}", NotifyType.StatusMessage); // Restore the default report interval to release resources while the sensor is not in use. sensor.ReportInterval = 0; } else { rootPage.NotifyUser("Sorry, no sensor found", NotifyType.ErrorMessage); } }
/// <summary> /// Update orientation readings event and update UI /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">The <see cref="object"/> instance containing the event data.</param> private void UpdateOrientation(object sender, EventArgs e) { try { OrientationSensor orientation = OrientationSensor.GetDefault(); if (orientation != null) { SensorQuaternion quaternion = orientation.GetCurrentReading().Quaternion; XLabel.Text = LocRM.GetString("XAxis") + ": " + String.Format("{0,8:0.00000}", quaternion.X); YLabel.Text = LocRM.GetString("YAxis") + ": " + String.Format("{0,8:0.00000}", quaternion.Y); ZLabel.Text = LocRM.GetString("ZAxis") + ": " + String.Format("{0,8:0.00000}", quaternion.Z); WLabel.Text = LocRM.GetString("WAxis") + ": " + String.Format("{0,8:0.00000}", quaternion.W); } else { XLabel.Text = LocRM.GetString("NotFound"); _timer.Stop(); } } catch (Exception ex) { Log.LogError(ex.ToString()); _timer.Stop(); } }
public MainPage() { InitializeComponent(); bMeasuringDistance = false; bAngledWalk = false; bRotation = false; try { OrientationSensorStart(true); OrientationSensor.Start(speed); } catch (FeatureNotSupportedException) { StartingLocation.Text = "The Orientation sensor is not supported on this device!"; } catch (FeatureNotEnabledException) { StartingLocation.Text = "The Orientation sensor is not enabled on this device!"; } catch (PermissionException) {//ex is null StartingLocation.Text = "Permission Exception"; } catch (Exception) { StartingLocation.Text = "Unknown Startup Exception!"; } }
public async void NewQuan(OrientationSensor sender, OrientationSensorReadingChangedEventArgs args) { var reading = args == null?sender?.GetCurrentReading() : args.Reading; await this.dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { this[QUANTIZATION] = reading == null ? this[QUANTIZATION].New(0, 0, 0, 0) : this[QUANTIZATION].New( reading.Quaternion.X, reading.Quaternion.Y, reading.Quaternion.Z, reading.Quaternion.W); if (this[QUANTIZATION].IsChanged) { this.OnPropertyChanged(new PropertyChangedEventArgs("ItemsList")); this.OnSensorUpdated?.Invoke(this[QUANTIZATION]); } }); if (this.SensorSwitches.Q.HasValue && (this.SensorSwitches.Q.Value == 1 || this.SensorSwitches.Q.Value == 3)) { this.SensorSwitches.Q = 0; } }
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 AppModel() { CubeTransform = InitializeCubeTransform(); var inclinometer = Inclinometer.GetDefault(); if (inclinometer != null) { inclinometer.ReportInterval = 200; inclinometer.ReadingChanged += (o, e) => InclinationData.Value = e.Reading; } var orientationSensor = OrientationSensor.GetDefault(); if (orientationSensor != null) { orientationSensor.ReportInterval = 200; orientationSensor.ReadingChanged += (o, e) => OrientationData.Value = e.Reading; } RotationQuaternion = OrientationData.Select(d => d.Quaternion.ToQuaternion()).ToReadOnlyReactiveProperty(); RotationQuaternionString = RotationQuaternion.Select(q => $"{q.W:F2}; ({q.X:F2}, {q.Y:F2}, {q.Z:F2})").ToReadOnlyReactiveProperty(); // Rotation is represented by a matrix, a quaternion or Euler angles (roll, pitch and yaw). RotationMatrix = OrientationData.Select(d => d.RotationMatrix.ToMatrix3D()).ToReadOnlyReactiveProperty(); //RotationMatrix = RotationQuaternion.Select(q => q.ToMatrix3D()).ToReadOnlyReactiveProperty(); //RotationMatrix = InclinationData.Select(i => i.ToMatrix3D()).ToReadOnlyReactiveProperty(); // An inverse matrix represents the inverse rotation. RotationMatrix .ObserveOn(SynchronizationContext.Current) //.Subscribe(m => matrixTransform.Matrix = m); .Subscribe(m => { m.Invert(); matrixTransform.Matrix = m; }); }
protected async override void OnAppearing() { base.OnAppearing(); var hasPermission = await Utils.CheckPermissions(Permission.Location); if (!hasPermission) { return; } if (CrossGeolocator.Current.IsListening) { return; } await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(5), 10, true); locator = CrossGeolocator.Current; locator.PositionChanged += Locator_PositionChanged; if (OrientationSensor.IsMonitoring) { OrientationSensor.Stop(); } else { OrientationSensor.Start(SensorSpeed.Normal); } OrientationSensor.ReadingChanged += OrientationSensor_ReadingChanged;; }
public bool ToggleOrientationSensor() { try { if (OrientationSensor.IsMonitoring) { OrientationSensor.Stop(); } else { OrientationSensor.Start(speed); } } catch (FeatureNotSupportedException fnsEx) { return(false); // Feature not supported on device } catch (Exception ex) { return(false); // Other error has occurred. } return(true); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { OrientationSensor = OrientationSensor.GetDefault(); if (OrientationSensor == null) { SimpleOrientationSensor = SimpleOrientationSensor.GetDefault(); if (SimpleOrientationSensor == null) { throw new Exception("No way of determining orientation"); } } TouchPanel.EnabledGestures = GestureType.Hold | GestureType.Flick | GestureType.HorizontalDrag | GestureType.VerticalDrag | GestureType.DragComplete; vertexBuffer = new DynamicVertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionColor), 8, BufferUsage.WriteOnly); indexBuffer = new DynamicIndexBuffer(graphics.GraphicsDevice, typeof(ushort), 36, BufferUsage.WriteOnly); basicEffect = new BasicEffect(graphics.GraphicsDevice); //(device, null); basicEffect.LightingEnabled = false; basicEffect.VertexColorEnabled = true; basicEffect.TextureEnabled = false; DepthStencilState depthBufferState = new DepthStencilState(); depthBufferState.DepthBufferEnable = true; GraphicsDevice.DepthStencilState = depthBufferState; TetrisState.Initialize(graphics.GraphicsDevice); Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().SuppressSystemOverlays = true; graphics.SupportedOrientations = DisplayOrientation.Portrait; base.Initialize(); }
private void OnGetOrientation(object sender, RoutedEventArgs e) { OrientationSensor orientation = OrientationSensor.GetDefault(); OrientationSensorReading reading = orientation.GetCurrentReading(); this.DefaultViewModel["OrientationSensorResult"] = GetOrientationSensorResult(reading); }
public TouristToolkit() { blobUrl = ""; this.InitializeComponent(); i = 0; li = new List <Scrap>(); li2 = new List <PointerViewAR>(); li3 = new List <Pointer>(); id = new List <string>(); or = OrientationSensor.GetDefault(); myBool = false; c = Compass.GetDefault(); try { c.ReportInterval = 4; c.ReadingChanged += C_ReadingChanged; or.ReportInterval = 4; or.ReadingChanged += Or_ReadingChanged; } catch { } this.InitializeComponent(); PreviewControl.Loaded += PreviewControl_Loaded; Application.Current.Suspending += Application_Suspending; }
public void ToggleOrientationSensor() { try { if (OrientationSensor.IsMonitoring) { OrientationSensor.Stop(); isStarted = false; } else { OrientationSensor.Start(speed); isStarted = true; } } catch (FeatureNotSupportedException fnsEx) { // Feature not supported on device throw fnsEx.InnerException; } catch (Exception ex) { // Other error has occurred. throw ex.InnerException; } }
public void ToggleOrientationSensor() { try { if (OrientationSensor.IsMonitoring) { OrientationSensor.Stop(); } else { OrientationSensor.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"; } }
public void OrientationSwitch_Toggled(object sender, ToggledEventArgs e) { try { if (e.Value && !OrientationSensor.IsMonitoring) { OrientationSensor.ReadingChanged += Orientation_ReadingChanged; OrientationSensor.Start(speed); } else if (!e.Value && OrientationSensor.IsMonitoring) { OrientationSensor.Stop(); OrientationSensor.ReadingChanged -= Orientation_ReadingChanged; OrientationMin = null; OrientationMax = null; } } catch (FeatureNotSupportedException) { // Feature not supported on device } catch (Exception) { // Other error has occurred. } }
public void ToggleOrientationSensor() { try { if (OrientationSensor.IsMonitoring) { OrientationSensor.Stop(); this.Started = false; Console.WriteLine("Orientation is stopped"); } else { OrientationSensor.Start(Speed); this.Started = true; Console.WriteLine("Orientation is started"); } } catch (FeatureNotSupportedException fnsEx) { Console.WriteLine("Non Pris en charge" + fnsEx); } catch (Exception ex) { Console.WriteLine("Une Exception s'est produite" + ex); } }
void Start() { #if WINDOWS_STORE_APP _sensor = OrientationSensor.GetDefault(); _hasSensor = _sensor != null; #endif }
public void ControlSunscribe(bool flag) { try { if (OrientationSensor.IsMonitoring && !flag) { OrientationSensor.Stop(); OrientationWatch.Reset(); } else if (!OrientationSensor.IsMonitoring && flag) { OrientationWatch.Start(); OrientationSensor.Start(Config.sensorSpeed); } else { //Dont think anything is needed here } } catch (FeatureNotEnabledException ex) { } catch (Exception ex) { } }
public void Stop() { if (OrientationSensor.IsMonitoring) { OrientationSensor.Stop(); } OrientationSensor.ReadingChanged -= OrientationSensor_ReadingChanged; }
/// <summary> /// Constructor of OrientationSensorAdapter. /// </summary> public OrientationSensorAdapter() { sensor = new OrientationSensor { Interval = 100, PausePolicy = SensorPausePolicy.None }; }
private void OnGetOrientation2(object sender, RoutedEventArgs e) { orientation = OrientationSensor.GetDefault(); orientation.ReadingChanged += (sender1, e1) => { this.DefaultViewModel["OrientationSensorResult"] = GetOrientationSensorResult(e1.Reading); }; }
public MainPageViewModel() { HorizontalGauge = GaugeViewModel.Compass(GaugeUnit.Mils()); VerticalGauge = GaugeViewModel.Gradometer(GaugeUnit.Mils()); OrientationSensor.ReadingChanged += OrientationChanged; OrientationSensor.Start(SensorSpeed.Default); }
async void OrientationSensorChanged(OrientationSensor sender, OrientationSensorReadingChangedEventArgs args) { await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { ShowOrientation(args.Reading); }); }
public MainPage() { InitializeComponent(); OrientationSensor.Start(SensorSpeed.Game); OrientationSensor.ReadingChanged += Update; }
// Sample code for building a localized ApplicationBar //private void BuildLocalizedApplicationBar() //{ // // Set the page's ApplicationBar to a new instance of ApplicationBar. // ApplicationBar = new ApplicationBar(); // // Create a new button and set the text value to the localized string from AppResources. // ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative)); // appBarButton.Text = AppResources.AppBarButtonText; // ApplicationBar.Buttons.Add(appBarButton); // // Create a new menu item with the localized string from AppResources. // ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText); // ApplicationBar.MenuItems.Add(appBarMenuItem); //} private async void Start() { if (!timer.IsEnabled) { string runningMessage = "Reading: "; accelSensor = Accelerometer.GetDefault(); if (accelSensor != null) { accelSensor.ReportInterval = 66; runningMessage += "Accelerometer "; } // while not shown in the chapter, get the current location so that // true heading is more accurate. Geolocator locator = new Geolocator(); await locator.GetGeopositionAsync(); compassSensor = Compass.GetDefault(); if (compassSensor != null) { compassSensor.ReportInterval = 66; runningMessage += "Compass "; } try { gyroSensor = Gyrometer.GetDefault(); } catch (FileNotFoundException) { } if (gyroSensor != null) { gyroSensor.ReportInterval = 66; runningMessage += "Gyroscope "; } inclineSensor = Inclinometer.GetDefault(); if (inclineSensor != null) { inclineSensor.ReportInterval = 66; runningMessage += "Inclinometer "; } orientationSensor = OrientationSensor.GetDefault(); if (orientationSensor != null) { orientationSensor.ReportInterval = 66; runningMessage += "Orientation "; } timer.Start(); messageBlock.Text = runningMessage; } }
public OrientationController(NanoDrone drone) { this.drone = drone; this.running = false; sensor = new OrientationSensor(); this.SetOwnOrientation(0, 0, 0); this.SetTargetOrientation(0, 0, 0); Start(); }
/// <summary> /// Initializes the service. /// </summary> public void Init() { if (!OrientationSensor.IsSupported) { NotSupported?.Invoke(this, null); return; } _orientationSensor = new OrientationSensor(); _orientationSensor.Interval = 10; _orientationSensor.DataUpdated += OnDataUpdated; }
protected override void OnNavigatedTo(NavigationEventArgs e) { _sensor = OrientationSensor.GetDefault(); if (_sensor != null) { ScenarioEnableButton.IsEnabled = true; } else { rootPage.NotifyUser("No orientation sensor found", NotifyType.ErrorMessage); } }
public bool Initialize() { _sensor = OrientationSensor.GetDefault(); if (_sensor != null) { return(true); } else { return(false); } }
public void ToggleOrientationSensor() { if (OrientationSensor.IsMonitoring) { OrientationSensor.ReadingChanged += OrientationSensor_ReadingChanged; OrientationSensor.Stop(); } else { OrientationSensor.ReadingChanged += OrientationSensor_ReadingChanged; OrientationSensor.Start(speed); } }