Jaa


Accelerometer.ReadingChanged Event

Definition

Occurs each time the accelerometer reports a new sensor reading.

// Register
event_token ReadingChanged(TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs const&> const& handler) const;

// Revoke with event_token
void ReadingChanged(event_token const* cookie) const;

// Revoke with event_revoker
Accelerometer::ReadingChanged_revoker ReadingChanged(auto_revoke_t, TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs const&> const& handler) const;
public event TypedEventHandler<Accelerometer,AccelerometerReadingChangedEventArgs> ReadingChanged;
function onReadingChanged(eventArgs) { /* Your code */ }
accelerometer.addEventListener("readingchanged", onReadingChanged);
accelerometer.removeEventListener("readingchanged", onReadingChanged);
- or -
accelerometer.onreadingchanged = onReadingChanged;
Public Custom Event ReadingChanged As TypedEventHandler(Of Accelerometer, AccelerometerReadingChangedEventArgs) 

Event Type

Examples

The following example demonstrates how a UWP app built with C# and XAML registers its ReadingChanged event handler.

private void ScenarioEnable(object sender, RoutedEventArgs e)
{
    if (_accelerometer != null)
    {
        // Establish the report interval
        _accelerometer.ReportInterval = _desiredReportInterval;

        Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
        _accelerometer.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);

        ScenarioEnableButton.IsEnabled = false;
        ScenarioDisableButton.IsEnabled = true;
    }
    else
    {
        rootPage.NotifyUser("No accelerometer found", NotifyType.StatusMessage);
    }
}

The following example shows the ReadingChanged event handler.

async private void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
{
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
        AccelerometerReading reading = e.Reading;
        ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
        ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
        ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);
    });
}

Remarks

An application may register this event handler to obtain sensor readings. The application must establish a desired ReportInterval. This informs the sensor driver that resources should be allocated to satisfy the requirements of the application.

Applies to

See also