public MainPage() { InitializeComponent(); // this.NavigationCacheMode = NavigationCacheMode.Required; //DataEntry.saveAll(); //DataEntry.loadAll(); this.accelSensor = Accelerometer.GetDefault(); if (this.accelSensor != null) this.accelSensor.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(myAccelHandler); this.compSensor = Compass.GetDefault(); if (this.compSensor != null) this.compSensor.ReadingChanged += new TypedEventHandler<Compass, CompassReadingChangedEventArgs>(myCompassHandler); this.gyroSensor = Gyrometer.GetDefault(); if (this.gyroSensor != null) this.gyroSensor.ReadingChanged += new TypedEventHandler<Gyrometer, GyrometerReadingChangedEventArgs>(myGyroHandler); this.incliSensor = Inclinometer.GetDefault(); if (this.incliSensor != null) this.incliSensor.ReadingChanged += new TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs>(myIncliHandler); this.lightSensor = LightSensor.GetDefault(); if (this.lightSensor != null) this.lightSensor.ReadingChanged += new TypedEventHandler<LightSensor, LightSensorReadingChangedEventArgs>(myLightHandler); accelX = accelY = accelZ = comp = gyroX = gyroY = gyroZ = incliYaw = incliPitch = incliRoll = light = 0; // Sample code to localize the ApplicationBar //BuildLocalizedApplicationBar(); }
public Scenario3_Porting() { this.InitializeComponent(); // Get two instances of the gyrometer: // One that returns the raw gyrometer data gyrometerWindows = Gyrometer.GetDefault(); // Other on which the 'ReadingTransform' is updated so that data returned aligns with the native WP orientation (portrait) gyrometerWP = Gyrometer.GetDefault(); if (gyrometerWP == null || gyrometerWindows == null) { rootPage.NotifyUser("No gyrometer found", NotifyType.ErrorMessage); } else { // Assumption is that this app has been developed for Windows Phone 8.1 (or earlier) // and hence assumes that the sensor returns readings in Portrait Mode, which may // not be true when the app or sensor logic is being ported over to a // Landscape-First Windows device // While we encourage you to re-design your app as a universal app to gain access // to many other advantages of developing a universal app, this scenario demonstrates // a simple approach to let the runtime honor your assumption on the // "native orientation" of the sensor. gyrometerWP.ReadingTransform = Windows.Graphics.Display.DisplayOrientations.Portrait; // If you were to go the route of universal app, make no assumptions about the // native orientation of the device. Instead rely on using a display orientation // (absolute or current) to enforce the reference frame for the sensor readings. // (which is done by updating 'ReadingTransform' property with the appropriate orientation) } }
void gyrometer_ReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args) { Deployment.Current.Dispatcher.BeginInvoke(() => { gyrometerReading = args.Reading; ShowData(); }); }
private void SetupSensor() { _gyrometer = Sensor.Gyrometer.GetDefault(); if (_gyrometer == null) { // this is no gyrometer... } }
private void SetupSensor() { _gyrometer = Sensor.Gyrometer.GetDefault(); if ( _gyrometer == null ) { // this is no gyrometer... } }
internal static void PlatformStart(SensorSpeed sensorSpeed) { sensor = DefaultSensor; var interval = sensorSpeed.ToPlatform(); sensor.ReportInterval = sensor.MinimumReportInterval >= interval ? sensor.MinimumReportInterval : interval; sensor.ReadingChanged += DataUpdated; }
// 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 XNAInputService() { accelerometer = Accelerometer.GetDefault(); gyrometer = Gyrometer.GetDefault(); inclinometer = Inclinometer.GetDefault(); keyboardState = oldKeyboardState = new KeyboardState(); mouseState = oldMouseState = new MouseState(); oldTouchCollection = touchCollection = new Touch[0]; xboxStates = oldXboxStates = new GamePadState[4]; }
private async void GyrometerOnReadingChanged(Sensor.Gyrometer sender, Sensor.GyrometerReadingChangedEventArgs args) { await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { XAxisReading = args.Reading.AngularVelocityX; YAxisReading = args.Reading.AngularVelocityY; ZAxisReading = args.Reading.AngularVelocityZ; SetupNewLocation(); }); }
void OnReadingChanged(Sensor sender, GyrometerReadingChangedEventArgs args) { var handler = changed; if (handler != null) { var value = ConvertToVector(args.Reading); var e = new GyrometerEventArgs(value); handler.Invoke(this, e); } }
private static Sensor GetSensor() { try { return(Sensor.GetDefault()); } catch { return(null); } }
public void startUpdates() { if (_gyrometer == null) { _gyrometer = Sensors.Gyrometer.GetDefault(); if (_gyrometer == null) { throw new Exception("No Gyroscope found"); } } _gyrometer.ReadingChanged += new TypedEventHandler <Sensors.Gyrometer, Sensors.GyrometerReadingChangedEventArgs>(ReadingChanged); }
protected override void OnNavigatedTo(NavigationEventArgs e) { gyrometer = Gyrometer.GetDefault(); if (gyrometer != null) { gyrometer.ReadingChanged += gyrometer_ReadingChanged; Data.Visibility = Visibility.Visible; } else { NoSensorMessage.Visibility = Visibility.Visible; } }
async void gyrometer_ReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { XValue.Text = args.Reading.AngularVelocityX.ToString(); YValue.Text = args.Reading.AngularVelocityY.ToString(); ZValue.Text = args.Reading.AngularVelocityZ.ToString(); TimeStamp.Text = args.Reading.Timestamp.ToString(); xLine.X2 = xLine.X1 + args.Reading.AngularVelocityX * 200; yLine.Y2 = yLine.Y1 - args.Reading.AngularVelocityY * 200; zLine.X2 = zLine.X1 - args.Reading.AngularVelocityZ * 100; zLine.Y2 = zLine.Y1 + args.Reading.AngularVelocityZ * 100; }); }
public GameInput() { // Get the accelerometer object accelerometer = Accelerometer.GetDefault(); gyrometer = Gyrometer.GetDefault(); window = Window.Current.CoreWindow; // Set up the gesture recognizer. In this example, it only responds to TranslateX, Scale and Tap events gestureRecognizer = new Windows.UI.Input.GestureRecognizer(); gestureRecognizer.GestureSettings = GestureSettings.ManipulationTranslateX | GestureSettings.ManipulationScale | GestureSettings.Tap; // Register event handlers for pointer events window.PointerPressed += OnPointerPressed; window.PointerMoved += OnPointerMoved; window.PointerReleased += OnPointerReleased; }
public static Gyrometer GetDefault() { if (_initializationAttempted) { return(_instance); } lock (_syncLock) { if (!_initializationAttempted) { _instance = TryCreateInstance(); _initializationAttempted = true; } return(_instance); } }
public Scenario1_DataEvents() { this.InitializeComponent(); _gyrometer = Gyrometer.GetDefault(); if (_gyrometer != 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 = _gyrometer.MinimumReportInterval; _desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16; } else { rootPage.NotifyUser("No gyrometer found", NotifyType.ErrorMessage); } }
/// <summary> /// Initializes a new instance of the DeviceMotionImplementation class. /// </summary> public DeviceMotionImplementation() { accelerometer = Accelerometer.GetDefault(); gyrometer = Gyrometer.GetDefault(); compass = Compass.GetDefault(); #if WINDOWS_PHONE_APP magnetometer = Magnetometer.GetDefault(); #endif sensorStatus = new Dictionary<MotionSensorType, bool>() { { MotionSensorType.Accelerometer, false}, { MotionSensorType.Gyroscope, false}, { MotionSensorType.Magnetometer, false}, { MotionSensorType.Compass, false} }; }
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(); }
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 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; } }
public Scenario2() { this.InitializeComponent(); _gyrometer = Gyrometer.GetDefault(); if (_gyrometer != 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 = _gyrometer.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 gyrometer found", NotifyType.ErrorMessage); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { try { gyrometer = Gyrometer.GetDefault(); if (gyrometer == null) { MessageBox.Show("不支持陀螺仪"); return; } gyrometer.ReportInterval = 1000; gyrometer.ReadingChanged += gyrometer_ReadingChanged; gyrometerReading = gyrometer.GetCurrentReading(); ShowData(); } catch (Exception err) { MessageBox.Show(err.Message); } }
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; } }
//########################################################################### //########################### Gyrometer ##################################### //########################################################################### private void InitGyrometer(TaskArguments taskArguments) { if (taskArguments.IsUsedGyrometer) { _gyrometer = Gyrometer.GetDefault(); if (_gyrometer != null) { uint targetSensorReportInterval = taskArguments.ReportIntervalGyrometer; _gyrometer.ReportInterval = targetSensorReportInterval >= _gyrometer.MinimumReportInterval ? targetSensorReportInterval : _gyrometer.MinimumReportInterval; _gyrometerEventHandler = new TypedEventHandler<Gyrometer, GyrometerReadingChangedEventArgs>(GyrometerReadingChanged); _gyrometer.ReadingChanged += _gyrometerEventHandler; } } }
private void GyrometerReadingChanged(Gyrometer gyrometer, GyrometerReadingChangedEventArgs args) { if (_measurementData != null) _measurementData.AddGyrometerReading(args.Reading); }
public GyrometerEvents(Gyrometer This) { this.This = This; }
void GyrometerReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args) { if (SensorValueChanged != null) SensorValueChanged(this, new SensorValueChangedEventArgs { ValueType= MotionSensorValueType.Vector, SensorType = MotionSensorType.Gyroscope, Value = new MotionVector() { X = args.Reading.AngularVelocityX, Y = args.Reading.AngularVelocityY, Z = args.Reading.AngularVelocityZ } }); }
private void OnGyroReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args) { }
async void MainPage_ReadingChanged( Gyrometer sender, GyrometerReadingChangedEventArgs args ) { await Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { TextGyrometer.Text = string.Format( @"Gyrometer : X={0} Y={1} Z={2}", args.Reading.AngularVelocityX.ToString(), args.Reading.AngularVelocityY.ToString(), args.Reading.AngularVelocityZ.ToString() ); } ); }
/// <summary> /// Gyroscope reading has changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The gyroscope event arguments.</param> private void GyroscopeReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args) { LatestReading = args.Reading.AsVector3(); readingAvailable.Invoke(this, this.LatestReading); }
public void myGyroHandler(Gyrometer g, GyrometerReadingChangedEventArgs e) { Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.value_gyro_x.Text = e.Reading.AngularVelocityX.ToString("0.00"); this.gyroX = e.Reading.AngularVelocityX; this.value_gyro_y.Text = e.Reading.AngularVelocityY.ToString("0.00"); this.gyroY = e.Reading.AngularVelocityY; this.value_gyro_z.Text = e.Reading.AngularVelocityZ.ToString("0.00"); this.gyroZ = e.Reading.AngularVelocityZ; checkTimeToLog(); } ); }
/// <summary> /// The methods provided in this section are simply used to allow /// NavigationHelper to respond to the page's navigation methods. /// <para> /// Page specific logic should be placed in event handlers for the /// <see cref="NavigationHelper.LoadState"/> /// and <see cref="NavigationHelper.SaveState"/>. /// The navigation parameter is available in the LoadState method /// in addition to page state preserved during an earlier session. /// </para> /// </summary> /// <param name="e">Provides data for navigation methods and event /// handlers that cannot cancel the navigation request.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { this._navigationHelper.OnNavigatedTo(e); if (_accelerometer == null || _gyrometer == null) { _gyrometer = Gyrometer.GetDefault(); _accelerometer = Accelerometer.GetDefault(); _accelerometer.ReadingChanged += async (s, args) => { await Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { ForceReadingUpdated(args.Reading); }); }; _gyrometer.ReadingChanged += async (s, args) => { await Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { GyrometerReadingUpdated(args.Reading); }); }; } }