void PlatformStart(SensorSpeed sensorSpeed) { sensor = DefaultSensor; var interval = sensorSpeed.ToPlatform(); sensor.ReportInterval = sensor.MinimumReportInterval >= interval ? sensor.MinimumReportInterval : interval; sensor.ReadingChanged += DataUpdated; }
private static Sensor GetSensor() { try { return(Sensor.GetDefault()); } catch { return(null); } }
void OnReadingChanged(Sensor sender, OrientationSensorReadingChangedEventArgs args) { var handler = changed; if (handler != null) { var value = ConvertToMatrix(args.Reading); var e = new OrientationEventArgs(value); handler.Invoke(this, e); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { _sensor = OrientationSensor.GetDefault(); if (_sensor != null) { ScenarioEnableButton.IsEnabled = true; } else { rootPage.NotifyUser("No orientation sensor found", NotifyType.ErrorMessage); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { _sensor = OrientationSensor.GetDefault(rootPage.SensorReadingType, rootPage.SensorOptimizationGoal); if (_sensor != null) { rootPage.NotifyUser(rootPage.SensorDescription + " is ready", NotifyType.StatusMessage); ScenarioEnableButton.IsEnabled = true; } else { rootPage.NotifyUser(rootPage.SensorDescription + " not found", NotifyType.ErrorMessage); } }
public Scenario2_Polling() { this.InitializeComponent(); Sensor = OrientationSensor.GetDefaultForRelativeReadings(); if (Sensor == null) { RootPage.NotifyUser("No relative orientation sensor found", NotifyType.ErrorMessage); GetDataButton.IsEnabled = false; } else { GetDataButton.IsEnabled = true; } }
public Scenario1() { this.InitializeComponent(); _sensor = OrientationSensor.GetDefault(); if (_sensor != null) { // Select a report interval that is both suitable for the purposes of the app and supported by the sensor. // This value will be used later to activate the sensor. uint minReportInterval = _sensor.MinimumReportInterval; _desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16; } else { rootPage.NotifyUser("No orientation sensor found", NotifyType.ErrorMessage); } }
public Log(MainWindow window, bool isBehavior = false) { this.window = window; this.isBehavior = isBehavior; this.statusAnalyzer = new StatusAnalyze(window); logDir = Directory.GetCurrentDirectory() + "\\logs\\" + Config.userName+ Config.startTime.ToString("_MM_dd_HH_mm_ss"); if (!Directory.Exists(logDir)) { Directory.CreateDirectory(logDir); } logList = new List<LogRecord>(); this.accelerometer = Accelerometer.GetDefault(); this.inclinometer = Inclinometer.GetDefault(); //this.inclinometer.ReadingChanged += onInclinometerReadingChanged; this.gyrometer = Gyrometer.GetDefault(); this.orientationSensor = OrientationSensor.GetDefault(); this.compass = Compass.GetDefault(); this.lightsensor = LightSensor.GetDefault(); }
public MainPage() { InitializeComponent(); _locator = new Geolocator(); Loaded += OnControlLoaded; _lightSensor = LightSensor.GetDefault(); if (_lightSensor != null) { //For now we get a base reading to use to compare later _baseReading = _lightSensor.GetCurrentReading(); //Register for the reading change _lightSensor.ReadingChanged += OnLightReadingChanged; } _accelerometerSensor = Accelerometer.GetDefault(); if (_accelerometerSensor != null) { _accelerometerSensor.Shaken += OnShaken; } _compassSensor = Compass.GetDefault(); if (_compassSensor != null) { _compassSensor.ReadingChanged += OnCompassReadingChanged; } _gyroSensor = Gyrometer.GetDefault(); if (_gyroSensor != null) { _gyroSensor.ReadingChanged += OnGyroReadingChanged; } _inclineSensor = Inclinometer.GetDefault(); if (_inclineSensor != null) { _inclineSensor.ReadingChanged += OnInclineReadingChanged; } _orientationSensor = OrientationSensor.GetDefault(); if (_orientationSensor != null) { _orientationSensor.ReadingChanged += OnOrientationReadingChanged; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { _sensor = OrientationSensor.GetDefault(); if (_sensor != null) { // Select a report interval that is both suitable for the purposes of the app and supported by the sensor. // This value will be used later to activate the sensor. _desiredReportInterval = Math.Max(_sensor.MinimumReportInterval, 16); // Set up a DispatchTimer _dispatcherTimer = new DispatcherTimer(); _dispatcherTimer.Tick += DisplayCurrentReading; _dispatcherTimer.Interval = TimeSpan.FromMilliseconds(_desiredReportInterval); ScenarioEnableButton.IsEnabled = true; } else { rootPage.NotifyUser("No orientation sensor found", NotifyType.ErrorMessage); } }
internal static void PlatformStart(SensorSpeed sensorSpeed) { sensor = DefaultSensor; var interval = NormalInterval; switch (sensorSpeed) { case SensorSpeed.Fastest: interval = FastestInterval; break; case SensorSpeed.Game: interval = GameInterval; break; } sensor.ReportInterval = sensor.MinimumReportInterval >= interval ? sensor.MinimumReportInterval : interval; sensor.ReadingChanged += DataUpdated; }
public Scenario2_Polling() { this.InitializeComponent(); _sensor = OrientationSensor.GetDefault(); if (_sensor != null) { // Select a report interval that is both suitable for the purposes of the app and supported by the sensor. // This value will be used later to activate the sensor. uint minReportInterval = _sensor.MinimumReportInterval; _desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16; // Set up a DispatchTimer _dispatcherTimer = new DispatcherTimer(); _dispatcherTimer.Tick += DisplayCurrentReading; _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, (int)_desiredReportInterval); } else { rootPage.NotifyUser("No orientation sensor found", NotifyType.ErrorMessage); } }
// 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; } }
async void MainPage_ReadingChanged( OrientationSensor sender, OrientationSensorReadingChangedEventArgs args ) { await Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { } ); }
private void CleanUpSensors() { if (_accelerometer != null) { _accelerometer.ReadingChanged -= _accelerometerEventHandler; _accelerometer.ReportInterval = 0; _accelerometer = null; } if (_gyrometer != null) { _gyrometer.ReadingChanged -= _gyrometerEventHandler; _gyrometer.ReportInterval = 0; _gyrometer = null; } if (_orientationSensor != null) { _orientationSensor.ReadingChanged -= _orientationSensorEventHandler; _orientationSensor.ReportInterval = 0; _orientationSensor = null; } if (_geolocator != null) { if (_periodicUpdateTimer != null) { _periodicUpdateTimer.Cancel(); } //_geolocator.PositionChanged -= _geolocationEventHandler; //_geolocator.ReportInterval = 0; _geolocator = null; } }
//########################################################################### //########################### OrientationSensor ############################# //########################################################################### private void InitOrientationSensor(TaskArguments taskArguments) { if (taskArguments.IsUsedQuaternion) { _orientationSensor = OrientationSensor.GetDefault(); if (_orientationSensor != null) { uint targetSensorReportInterval = taskArguments.ReportIntervalQuaternion; _orientationSensor.ReportInterval = targetSensorReportInterval >= _orientationSensor.MinimumReportInterval ? targetSensorReportInterval : _orientationSensor.MinimumReportInterval; _orientationSensorEventHandler = new TypedEventHandler<OrientationSensor, OrientationSensorReadingChangedEventArgs>(OrientationSensorReadingChanged); _orientationSensor.ReadingChanged += _orientationSensorEventHandler; } } }
private void OrientationSensorReadingChanged(OrientationSensor sender, OrientationSensorReadingChangedEventArgs args) { if (_measurementData != null) _measurementData.AddOrientationSensorReading(args.Reading); }
/// <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 OnOrientationReadingChanged(OrientationSensor sender, OrientationSensorReadingChangedEventArgs args) { }
public OrientationSensorEvents(OrientationSensor This) { this.This = This; }