Windows Dev Center

Collapse the table of content
Expand the table of content
Expand Minimize
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Inclinometer.ReadingChanged | readingchanged event

Occurs each time the inclinometer reports a new sensor reading.

Syntax


function onReadingChanged(eventArgs) { /* Your code */ }
 
// addEventListener syntax
inclinometer.addEventListener("readingchanged", onReadingChanged);
inclinometer.removeEventListener("readingchanged", onReadingChanged);
 
- or -

inclinometer.onreadingchanged = onReadingChanged;


Event information

Delegate TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs>

Remarks

Applications can set the frequency of this event by setting the ReportInterval property.

The following example demonstrates how a Windows Store app built with C# and XAML registered its ReadingChanged event handler.


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

        Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
        _inclinometer.ReadingChanged += new TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs>(ReadingChanged);

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


The following example shows the ReadingChanged event handler.


async private void ReadingChanged(object sender, InclinometerReadingChangedEventArgs e)
{
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
        InclinometerReading reading = e.Reading;
        ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.PitchDegrees);
        ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.RollDegrees);
        ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.YawDegrees);
    });
}


The following example demonstrates how a Windows Store appbuilt with JavaScript registers its ReadingChanged event handler.


function enableReadingChangedScenario() {
    if (inclinometer) {
        // Set the reportInterval to enable the sensor events
        inclinometer.reportInterval = reportInterval;

        document.addEventListener("msvisibilitychange", msVisibilityChangeHandler, false);
        inclinometer.addEventListener("readingchanged", onDataChanged);
        document.getElementById("scenario1Open").disabled = true;
        document.getElementById("scenario1Revoke").disabled = false;
    } else {
        WinJS.log && WinJS.log("No inclinometer found", "sample", "error");
    }
}


The following example shows the ReadingChanged event handler.


function onDataChanged(e) {
    var reading = e.reading;

    document.getElementById("eventOutputX").innerHTML = reading.pitchDegrees.toFixed(2);
    document.getElementById("eventOutputY").innerHTML = reading.rollDegrees.toFixed(2);
    document.getElementById("eventOutputZ").innerHTML = reading.yawDegrees.toFixed(2);
}


Requirements (Windows 10 device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Devices.Sensors
Windows::Devices::Sensors [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

None supported

Minimum supported phone

Windows Phone 8

Namespace

Windows.Devices.Sensors
Windows::Devices::Sensors [C++]

Metadata

Windows.winmd

See also

Inclinometer

 

 

Show:
© 2015 Microsoft