Retrieving inclinometer data in simple apps
Collapse the table of content
Expand the table of content

Retrieving inclinometer data in simple apps (Windows Runtime apps)

An app can track changes in pitch, roll, and yaw by registering to receive event notifications from a device’s inclinometer, by using the Inclinometer class.

The following code examples demonstrate how to retrieve the default inclinometer and register an event handler to receive ReadingChanged notifications when the sensor issues a new reading.


inclinometer = Windows.Devices.Sensors.Inclinometer.getDefault();



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 ReadingChanged event handler then receives the new values for the pitch, roll, and yaw as shown in this code example.


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);
}


 

 

Show:
© 2017 Microsoft