// Gets the rotation to rotate ui elements public SimpleOrientation GetUIOrientation() { if (IsEnclosureLocationExternal(_cameraEnclosureLocation)) { // Cameras that are not attached to the device do not rotate along with it, so apply no rotation return(SimpleOrientation.NotRotated); } // Return the difference between the orientation of the device and the orientation of the app display var deviceOrientation = _orientationSensor.GetCurrentOrientation(); var displayOrientation = ConvertDisplayOrientationToSimpleOrientation(_displayInformation.CurrentOrientation); return(SubOrientations(displayOrientation, deviceOrientation)); }
public Camera(CaptureElement element) { if (element == null) { throw new ArgumentNullException("element", "element can't be null"); } _captureElement = element; _displayOrientation = _displayInformation.CurrentOrientation; _displayInformation.OrientationChanged += DisplayInformation_OrientationChanged; if (_orientationSensor != null) { _deviceOrientation = _orientationSensor.GetCurrentOrientation(); _orientationSensor.OrientationChanged += OrientationSensor_OrientationChanged; } if (ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")) { HardwareButtons.CameraPressed += HardwareButtons_CameraPressed; } Application.Current.Suspending += Application_Suspending; Application.Current.Resuming += ApplicationResuming; Window.Current.VisibilityChanged += Current_VisibilityChanged; }
/// <summary> /// Attempts to lock the page orientation, hide the StatusBar (on Phone) and registers event handlers for hardware buttons and orientation sensors /// </summary> /// <returns></returns> private async Task SetupUiAsync() { // Attempt to lock page to landscape orientation to prevent the CaptureElement from rotating, as this gives a better experience DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape; // Hide the status bar if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { await Windows.UI.ViewManagement.StatusBar.GetForCurrentView().HideAsync(); } // Populate orientation variables with the current state _displayOrientation = _displayInformation.CurrentOrientation; if (_orientationSensor != null) { _deviceOrientation = _orientationSensor.GetCurrentOrientation(); } RegisterEventHandlers(); var picturesLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures); // Fall back to the local app storage if the Pictures Library is not available _captureFolder = picturesLibrary.SaveFolder ?? ApplicationData.Current.LocalFolder; }
private Int32 GetCurrentDeviceOrientation() { if (orientationSensor != null) { switch (orientationSensor.GetCurrentOrientation()) { case SimpleOrientation.NotRotated: return(NativeMethods.DMDO_DEFAULT); case SimpleOrientation.Rotated90DegreesCounterclockwise: return(NativeMethods.DMDO_270); case SimpleOrientation.Rotated180DegreesCounterclockwise: return(NativeMethods.DMDO_180); case SimpleOrientation.Rotated270DegreesCounterclockwise: return(NativeMethods.DMDO_90); case SimpleOrientation.Faceup: case SimpleOrientation.Facedown: default: return(DMDO_UNKNOWN); } } return(DMDO_UNKNOWN); }
public Vector3 GetOrientation() { if (OrientationSensor != null) { OrientationSensorReading orientation = OrientationSensor.GetCurrentReading(); Matrix m = new Matrix(); m.M11 = orientation.RotationMatrix.M11; m.M12 = orientation.RotationMatrix.M12; m.M13 = orientation.RotationMatrix.M13; m.M21 = orientation.RotationMatrix.M21; m.M22 = orientation.RotationMatrix.M22; m.M23 = orientation.RotationMatrix.M23; m.M31 = orientation.RotationMatrix.M31; m.M32 = orientation.RotationMatrix.M32; m.M33 = orientation.RotationMatrix.M33; return(Vector3.Transform(Vector3.UnitY, m)); } else if (SimpleOrientationSensor != null) { SimpleOrientation orientation = SimpleOrientationSensor.GetCurrentOrientation(); switch (orientation) { case SimpleOrientation.Facedown: case SimpleOrientation.Faceup: return(LastSimpleOrientation); case SimpleOrientation.NotRotated: LastSimpleOrientation = Vector3.UnitY; return(LastSimpleOrientation); case SimpleOrientation.Rotated180DegreesCounterclockwise: LastSimpleOrientation = -Vector3.UnitY; return(LastSimpleOrientation); case SimpleOrientation.Rotated270DegreesCounterclockwise: LastSimpleOrientation = -Vector3.UnitX; return(LastSimpleOrientation); case SimpleOrientation.Rotated90DegreesCounterclockwise: LastSimpleOrientation = Vector3.UnitX; return(LastSimpleOrientation); default: throw new Exception("Unrecognised Orientation"); } } else { throw new Exception("Couldn't determine orientation"); } }
private void RegisterOrientationEventHandlers() { if (_orientationSensor != null) { _orientationSensor.OrientationChanged += OrientationSensor_OrientationChanged; _deviceOrientation = _orientationSensor.GetCurrentOrientation(); } _displayInformation.OrientationChanged += DisplayInformation_OrientationChanged; _displayOrientation = _displayInformation.CurrentOrientation; }
/// <summary> /// This is the click handler for the 'Enable' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> //<SnippetGetCurrentReadingCS> private void ScenarioGet(object sender, RoutedEventArgs e) { if (_sensor != null) { DisplayOrientation(ScenarioOutput_Orientation, _sensor.GetCurrentOrientation()); } else { rootPage.NotifyUser("No simple orientation sensor found", NotifyType.StatusMessage); } }
private void RegisterOrientationEventHandlers() { // If there is an orientation sensor present on the device, register for notifications if (_orientationSensor != null) { _orientationSensor.OrientationChanged += OrientationSensor_OrientationChanged; _deviceOrientation = _orientationSensor.GetCurrentOrientation(); } _displayInformation.OrientationChanged += DisplayInformation_OrientationChanged; _displayOrientation = _displayInformation.CurrentOrientation; }
void SetupUI() { // Lock page to landscape to prevent the capture element from rotating DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape; displayOrientation = displayInformation.CurrentOrientation; if (orientationSensor != null) { deviceOrientation = orientationSensor.GetCurrentOrientation(); } RegisterEventHandlers(); }
public SimpleOrientation GetSimpleOrientationReading() { if (_simpleOrientation == null) { throw new InvalidOperationException("The simple orientation sensor is either not present or has not been initialized"); } var orientation = _simpleOrientation.GetCurrentOrientation(); return(orientation); // Available reading values include: //args.Orientation //args.Timestamp }
public MainPage() { this.InitializeComponent(); // SimpleOrientationSensor initialization if (simpleOrientationSensor != null) { SetOrientationSensorText(simpleOrientationSensor.GetCurrentOrientation()); simpleOrientationSensor.OrientationChanged += OnSimpleOrientationChanged; } // DisplayProperties initialization SetDisplayOrientationText(DisplayProperties.CurrentOrientation); DisplayProperties.OrientationChanged += OnDisplayPropertiesOrientationChanged; }
// Attach event handlers protected override void OnNavigatedTo(NavigationEventArgs args) { if (accelerometer != null) { SetAccelerometerText(accelerometer.GetCurrentReading()); accelerometer.ReadingChanged += OnAccelerometerReadingChanged; } if (simpleOrientationSensor != null) { SetSimpleOrientationText(simpleOrientationSensor.GetCurrentOrientation()); simpleOrientationSensor.OrientationChanged += OnSimpleOrientationChanged; } base.OnNavigatedTo(args); }
public Task InitializeAsync() { // Attempt to lock page to landscape orientation to prevent the CaptureElement from rotating, as this gives a better experience //DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape; // Populate orientation variables with the current state displayOrientation = displayInformation.CurrentOrientation; if (orientationSensor != null) { deviceOrientation = orientationSensor.GetCurrentOrientation(); } this.RegisterEventHandlers(); return(Task.CompletedTask); }
/// <summary> /// Attempts to lock the page orientation and registers the event handlers for orientation sensors. /// </summary> /// <returns></returns> private void SetupUi() { // Attempt to lock page to portrait orientation to prevent the CaptureElement from // rotating, as this gives a better experience DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait; // Populate orientation variables with the current state _displayOrientation = _displayInformation.CurrentOrientation; if (_orientationSensor != null) { _deviceOrientation = _orientationSensor.GetCurrentOrientation(); } SetEventHandlers(true); }
private void setUI() { DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait; // Populate orientation variables with the current state _displayOrientation = _displayInformation.CurrentOrientation; if (_orientationSensor != null) { _deviceOrientation = _orientationSensor.GetCurrentOrientation(); this._orientationSensor.OrientationChanged += OrientationSensor_OrientationChanged; } this._displayInformation.OrientationChanged += DisplayInformation_OrientationChanged; }
/// <summary> /// Attempts to lock the page orientation, hide the StatusBar (on Phone) and registers event handlers for hardware buttons and orientation sensors /// </summary> /// <returns></returns> private async Task SetupUiAsync() { // Hide the status bar if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { await Windows.UI.ViewManagement.StatusBar.GetForCurrentView().HideAsync(); } // Populate orientation variables with the current state _displayOrientation = _displayInformation.CurrentOrientation; if (_orientationSensor != null) { _deviceOrientation = _orientationSensor.GetCurrentOrientation(); } RegisterEventHandlers(); }
/// <summary> /// This is the click handler for the 'Enable' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ScenarioEnable(object sender, RoutedEventArgs e) { if (_sensor != null) { Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged); _sensor.OrientationChanged += new TypedEventHandler <SimpleOrientationSensor, SimpleOrientationSensorOrientationChangedEventArgs>(OrientationChanged); ScenarioEnableButton.IsEnabled = false; ScenarioDisableButton.IsEnabled = true; // Display the current orientation once while waiting for the next orientation change DisplayOrientation(ScenarioOutput_Orientation, _sensor.GetCurrentOrientation()); } else { rootPage.NotifyUser("No simple orientation sensor found", NotifyType.ErrorMessage); } }
/// <summary> /// Gets the rotation of the camera to rotate pictures/videos when saving to file /// </summary> public SimpleOrientation GetCameraCaptureOrientation() { if (IsEnclosureLocationExternal(_cameraEnclosureLocation)) { // Cameras that are not attached to the device do not rotate along with it, so apply no rotation return(SimpleOrientation.NotRotated); } // Get the device orientation offset by the camera hardware offset var deviceOrientation = _orientationSensor?.GetCurrentOrientation() ?? SimpleOrientation.NotRotated; var result = SubtractOrientations(deviceOrientation, GetCameraOrientationRelativeToNativeOrientation()); // If the preview is being mirrored for a front-facing camera, then the rotation should be inverted if (ShouldMirrorPreview()) { result = MirrorOrientation(result); } return(result); }
private void ConfigureSimpleOrientation() { // Get the reference to the sensor and see if it is available _simpleOrientation = SimpleOrientationSensor.GetDefault(); if (_simpleOrientation == null) { return; } _sensorSettings.IsSimpleOrientationAvailable = true; // NOTE - Simple Orientation does not offer a minimum interval setting _simpleOrientation.OrientationChanged += SimpleOrientationOnOrientationChanged; // Read the initial sensor value _sensorSettings.LatestSimpleOrientationReading = _simpleOrientation.GetCurrentOrientation(); }
async Task SetupUIAsync() { // Lock page to landscape to prevent the capture element from rotating DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape; // Hide status bar if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { await Windows.UI.ViewManagement.StatusBar.GetForCurrentView().HideAsync(); } displayOrientation = displayInformation.CurrentOrientation; if (orientationSensor != null) { deviceOrientation = orientationSensor.GetCurrentOrientation(); } RegisterEventHandlers(); }
public InCall() { this.InitializeComponent(); this.DataContext = new InCallModel(); askingVideo = false; if (LinphoneManager.Instance.IsVideoAvailable) { StartVideoStream(); VideoGrid.Visibility = Visibility.Collapsed; } if (LinphoneManager.Instance.Core.CurrentCall.State == CallState.StreamsRunning) { Status.Text = "00:00:00"; } displayOrientation = ApplicationView.GetForCurrentView().Orientation; displayInformation = DisplayInformation.GetForCurrentView(); deviceOrientation = SimpleOrientation.NotRotated; orientationSensor = SimpleOrientationSensor.GetDefault(); if (orientationSensor != null) { deviceOrientation = orientationSensor.GetCurrentOrientation(); SetVideoOrientation(); orientationSensor.OrientationChanged += OrientationSensor_OrientationChanged; } buttons.HangUpClick += buttons_HangUpClick; buttons.StatsClick += buttons_StatsClick; buttons.CameraClick += buttons_CameraClick; buttons.PauseClick += buttons_PauseClick; buttons.SpeakerClick += buttons_SpeakerClick; buttons.MuteClick += buttons_MuteClick; buttons.VideoClick += buttons_VideoClick; buttons.BluetoothClick += buttons_BluetoothClick; buttons.DialpadClick += buttons_DialpadClick; // Handling event when app will be suspended Application.Current.Suspending += new SuspendingEventHandler(App_Suspended); Application.Current.Resuming += new EventHandler <object>(App_Resumed); pausedCall = null; }
/// <summary> /// Attempts to lock the page orientation, hide the StatusBar (on Phone) and registers event handlers for hardware buttons and orientation sensors /// </summary> /// <returns></returns> private async Task SetupUiAsync() { // Attempt to lock page to landscape orientation to prevent the CaptureElement from rotating, as this gives a better experience DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape; // Hide the status bar if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { await Windows.UI.ViewManagement.StatusBar.GetForCurrentView().HideAsync(); } // Populate orientation variables with the current state _displayOrientation = _displayInformation.CurrentOrientation; if (_orientationSensor != null) { _deviceOrientation = _orientationSensor.GetCurrentOrientation(); } RegisterEventHandlers(); }
public Page0() { this.InitializeComponent(); pname.Text = "Page 0"; this.SizeChanged += OnMainPageSizeChanged; displayInformation = DisplayInformation.GetForCurrentView(); displayInformation.DpiChanged += OnDpiChanged; Loaded += (sender, args) => { UpdateDisplay(); }; if (simpleOrientationSensor != null) { SetOrientationSensorText(simpleOrientationSensor.GetCurrentOrientation()); simpleOrientationSensor.OrientationChanged += OnSimpleOrientationChanged; } }
public MainPage() { this.InitializeComponent(); // SimpleOrientationSensor initialization if (simpleOrientationSensor != null) { SetOrientationSensorText(simpleOrientationSensor.GetCurrentOrientation()); simpleOrientationSensor.OrientationChanged += OnSimpleOrientationChanged; } // DisplayProperties initialization //SetDisplayOrientationText(DisplayProperties.CurrentOrientation); //DisplayProperties.OrientationChanged += OnDisplayPropertiesOrientationChanged; // Windows 8.1 change from DisplayProperties to DisplayInformation DisplayInformation displayInformation = DisplayInformation.GetForCurrentView(); SetDisplayOrientationText(displayInformation.CurrentOrientation); displayInformation.OrientationChanged += onDisplayInforamtionOrientationChanged; }
/// <summary> /// Attempts to lock the page orientation, hide the StatusBar (on Phone) and registers event handlers for hardware buttons and orientation sensors /// </summary> /// <returns></returns> private async Task SetupUiAsync() { // Hide the status bar if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { await Windows.UI.ViewManagement.StatusBar.GetForCurrentView().HideAsync(); } // Populate orientation variables with the current state _displayOrientation = _displayInformation.CurrentOrientation; if (_orientationSensor != null) { _deviceOrientation = _orientationSensor.GetCurrentOrientation(); } RegisterEventHandlers(); var picturesLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures); // Fall back to the local app storage if the Pictures Library is not available _captureFolder = picturesLibrary.SaveFolder ?? ApplicationData.Current.LocalFolder; }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); try { await StartCamera(); _orientationSensor = SimpleOrientationSensor.GetDefault(); if (_orientationSensor != null) { _orientationSensor.OrientationChanged += SimpleOrientationSensorReadingChanged; UpdateOrientation(_orientationSensor.GetCurrentOrientation()); } _compass = Compass.GetDefault(); if (_compass != null) { _compass.ReadingChanged += CompassReadingChanged; CompassChanged(_compass.GetCurrentReading()); } _gps = new Geolocator(); _gps.MovementThreshold = _movementThreshold; _gps.PositionChanged += GpsPositionChanged; if (_gps.LocationStatus == PositionStatus.Ready) { var pos = await _gps.GetGeopositionAsync(); if (pos != null && pos.Coordinate != null && pos.Coordinate.Point != null) { GpsChanged(pos.Coordinate.Point.Position); } } } catch { } }
/// <summary> /// Initializes the MediaCapture, registers events, gets camera device information for mirroring and rotating, starts preview and unlocks the UI /// </summary> /// <returns></returns> public async Task Initialize(string faceKey, string emotionKey) { Debug.WriteLine("Initialize-Facedetector"); _faceKey = faceKey; _emotionKey = emotionKey; _faceMetaData = new FaceMetaData(_faceKey, _emotionKey); _faceMetaData.DetectedFaces += FaceMetaData_DetectedFaces; _displayOrientation = _displayInformation.CurrentOrientation; if (_orientationSensor != null) { _deviceOrientation = _orientationSensor.GetCurrentOrientation(); } // Clear any rectangles that may have been left over from a previous instance of the effect FacesCanvas.Children.Clear(); DeviceInformationCollection allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); CameraListBox.ItemsSource = allVideoDevices; }
async Task SetupUIAsync() { // Lock page to landscape to prevent the capture element from rotating DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape; // Hide status bar if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { await Windows.UI.ViewManagement.StatusBar.GetForCurrentView().HideAsync(); } displayOrientation = displayInformation.CurrentOrientation; if (orientationSensor != null) { deviceOrientation = orientationSensor.GetCurrentOrientation(); } RegisterEventHandlers(); var picturesLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures); // Fallback to local app storage if no pictures library captureFolder = picturesLibrary.SaveFolder ?? ApplicationData.Current.LocalFolder; }
public void PrintSensors(bool fast = false) { //BarometerReading read = baro.GetCurrentReading(); var accR = acc.GetCurrentReading(); //Debug.WriteLine(Math.Sqrt(Math.Pow(accR.AccelerationX; 2) + Math.Pow(accR.AccelerationY; 2) + Math.Pow(accR.AccelerationZ; 2)) + " (" + accR.AccelerationX + "/" + accR.AccelerationX + "/" + accR.AccelerationX + ")"); //var actR = act.GetCurrentReadingAsync().GetResults(); //Debug.WriteLine(actR.Activity + " (" + actR.Confidence + ")"); //Debug.WriteLine(alt.GetCurrentReading().AltitudeChangeInMeters); //Debug.WriteLine(baro.GetCurrentReading().StationPressureInHectopascals); var compR = comp.GetCurrentReading(); //Debug.WriteLine(compR.HeadingMagneticNorth + " (+/-" + compR.HeadingAccuracy + ")"); var gyroR = gyro.GetCurrentReading(); //Debug.WriteLine("(" + gyroR.AngularVelocityX + "/" + gyroR.AngularVelocityY + "/" + gyroR.AngularVelocityZ + ")"); var incR = inc.GetCurrentReading(); //Debug.WriteLine("(" + incR.PitchDegrees + "/" + incR.RollDegrees + "/" + incR.YawDegrees + ")"); //var psR=ps.GetCurrentReading(); //Debug.WriteLine(psR.IsDetected + ": " + psR.DistanceInMillimeters); //Debug.WriteLine(sos.GetCurrentOrientation()); String csv = (Math.Sqrt(Math.Pow(accR.AccelerationX, 2) + Math.Pow(accR.AccelerationY, 2) + Math.Pow(accR.AccelerationZ, 2)) + ";" + accR.AccelerationX + ";" + accR.AccelerationY + ";" + accR.AccelerationZ + ";" + alt.GetCurrentReading().AltitudeChangeInMeters + ";" + baro.GetCurrentReading().StationPressureInHectopascals + ";" + compR.HeadingMagneticNorth + ";" + compR.HeadingTrueNorth + ";" + compR.HeadingAccuracy + ";" + gyroR.AngularVelocityX + ";" + gyroR.AngularVelocityY + ";" + gyroR.AngularVelocityZ + ";" + incR.PitchDegrees + ";" + incR.RollDegrees + ";" + incR.YawDegrees + ";" + sos.GetCurrentOrientation() + ";" + accR.Timestamp.ToUnixTimeMilliseconds() + ";" + fast); Debug.WriteLine(csv); StorageInterface.AppendToKnownStorageFile(Token, csv + "\r\n").GetAwaiter(); OUT.Text += csv + "\r\n"; }