Inclinometer.ReadingChanged Inclinometer.ReadingChanged Inclinometer.ReadingChanged Inclinometer.ReadingChanged Inclinometer.ReadingChanged Event

Definition

Occurs each time the inclinometer reports a new sensor reading.

public : event TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs> ReadingChanged
// Register
event_token ReadingChanged(TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs> const& handler) const;

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

// Revoke with event_revoker
ReadingChanged_revoker ReadingChanged(auto_revoke_t, TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs> const& handler) const;
public event TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs> ReadingChanged
Public Event ReadingChanged As TypedEventHandler (Of Inclinometer, InclinometerReadingChangedEventArgs)
function onReadingChanged(eventArgs){/* Your code */}


inclinometer.addEventListener("readingchanged", onReadingChanged);
inclinometer.removeEventListener("readingchanged", onReadingChanged);

Remarks

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

The following example demonstrates how a UWP 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 UWP app built 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);
}