Inclinometer.GetCurrentReading Inclinometer.GetCurrentReading Inclinometer.GetCurrentReading Inclinometer.GetCurrentReading Inclinometer.GetCurrentReading Method


Gets the current inclinometer reading.

public : InclinometerReading GetCurrentReading()
InclinometerReading GetCurrentReading() const;
public InclinometerReading GetCurrentReading()
Public Function GetCurrentReading() As InclinometerReading
var inclinometerReading = inclinometer.getCurrentReading();


The current inclinometer reading.


An application may use this method to poll the sensor for the current reading as an alternative to registering a ReadingChanged event handler. This would be the preferred alternative for an application that updates its user interface at a specific frame rate. Whether polling once or many times, the application must establish a desired ReportInterval. This informs the sensor driver that resources should be allocated to satisfy subsequent polling requests

Before using the return value from this method, the application must first check that the value is not null. (If the value is null and you attempt to retrieve it, Windows will generate an exception.)

The following example demonstrates how a UWP app built with XAML and C# retrieves the current reading for the default inclinometer.

private void DisplayCurrentReading(object sender, object args)
    InclinometerReading reading = _inclinometer.GetCurrentReading();
    if (reading != null)
        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 for Windows using JavaScript retrieves the current reading for the default inclinometer.

function getCurrentReading() {
    var reading = inclinometer.getCurrentReading();
    if (reading) {
        document.getElementById("readingOutputX").innerHTML = reading.pitchDegrees.toFixed(2);
        document.getElementById("readingOutputY").innerHTML = reading.rollDegrees.toFixed(2);
        document.getElementById("readingOutputZ").innerHTML = reading.yawDegrees.toFixed(2);