23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Orientation sensor provides a simple interpretation of how the device is oriented in relation to its<br />

default position, rounding everything off, as it were, to the nearest 90-degree quadrant. The full<br />

Orientation sensor, on the other hand, combines gyrometer, accelerometer, and compass data to<br />

provide an exact 3D orientation matrix that is much more precise but much more oriented (if I might<br />

make the pun!) to advanced scenarios than simply needing to know whether the device is upside-down<br />

or rightside-up.<br />

Because all of these sensors are very similar in how they work (which is intentional, with the<br />

exception of the Simple Orientation sensor, which is intentionally dissimilar!), I want to show the general<br />

pattern of the sensor APIs rather than explicit examples for each. Such examples are readily available in<br />

these SDK samples: Accelerometer, Compass, Gyrometer, Inclinometer, Light Sensor, and<br />

OrientationSensor.<br />

The usage pattern is as follows, with the particulars summarized in the table that follows:<br />

• Obtain a sensor object via Windows.Devices.Sensors..getDefault().<br />

• Call that object’s getCurrentReading to obtain a one-time reading.<br />

• For ongoing readings, configure the object’s minimumReportInterval and reportInterval<br />

properties (both in milliseconds) and listen to the object’s readingchanged event. Your handler<br />

will receive a reading object of an appropriate type in response. As with geolocation, setting<br />

these values wisely will help optimize battery life by avoiding excess electrons flying through the<br />

sensors!<br />

Sensor Name<br />

(Windows.Devices.Sensors.)<br />

Accelerometer<br />

Added Members<br />

Event: shaken (event<br />

args contains only a<br />

timestamp property)<br />

Reading Type<br />

(Windows.Devices.Sensors)<br />

AccelerometerReading<br />

Reading Properties (timestamp<br />

is a Date; all others are Numbers<br />

unless noted)<br />

accelerationX (G’s), accelerationY,<br />

accelerationZ, timestamp<br />

Compass n/a CompassReading headingMagneticNorth (degrees),<br />

headingTrueNorth, timestamp<br />

Gyrometer n/a GyrometerReading angularVelocityX (degrees/sec),<br />

angularVelocityY,<br />

angularVelocityZ, timestamp<br />

Inclinometer n/a InclinometerReading pitchDegrees (degrees),<br />

rollDegrees (degrees), yawDegrees<br />

(degrees), timestamp<br />

LightSensor n/a LightSensorReading illuminenceInLux (lux), timestamp<br />

OrientationSensor n/a OrientationSensorReading quaternion, (SensorQuaternion<br />

containing w, x, y, and z properties)<br />

rotationMatrix<br />

(Sensor-RotationMatrix containing<br />

m11, m12, m13, m21, m22, m23,<br />

m31, m32, m33 properties),<br />

timestamp<br />

402

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!