journey.sensors
Returns information about the device's accelerometer, compass and orientation data.
Supported fields
getCapabilities()
getCapabilities()To retrieve a device's supported sensor capabilities.
var capabilities = await journey.sensors.getCapabilities();
view.accelerometer_supported = capabilities.accelerometerIsSupported;
view.compass_supported = capabilities.compassIsSupported;
view.orientation_supported = capabilities.orientationIsSupported;accelerometer.read()
accelerometer.read()Returns accelerometer data captured at a specific point in time.
Acceleration values include the effect of gravity (9.81 m/s^2), so that when a device lies flat and facing up, x, y, and z values returned should be 0, 0, and 9.81.
Properties returned:
x: Number valuey: Number valuez: Number valuetimestamp: Unix Timestamp when sample was taken
accelerometer.registerListener()
accelerometer.registerListener()Listeners supply an onData callback which will be invoked with the data argument set to the same format as a read function call. The onError callback will be called on an error condition, if called, no subsequent onData callbacks are executed. The argument provided to the onError function is a string error message.
Listener options:
Currently the only option supported for all sensors is the sampling period in milliseconds.
Example:
compass.read()
compass.read()Returns compass data captured at a specific point in time.
Properties returned:
magneticHeading: The heading in degrees from 0-359.99 at a single moment in time. (Number)trueHeading: The heading relative to the geographic North Pole in degrees 0-359.99 at a single moment in time. A negative value indicates that the true heading can't be determined. (Number)headingAccuracy: The deviation in degrees between the reported heading and the true heading. (Number)timestamp: Unix Timestamp when sample was taken
compass.registerListener()
compass.registerListener()See accelerometer.registerListener()
orientation.read()
orientation.read()Returns the orientation of a device with angles measured along a specific reference frame. See here for good depictions of the angles.
Properties returned:
alpha: Number valuebeta: Number valuegamma: Number valuetimestamp: Unix Timestamp when sample was taken
orientation.registerListener()
orientation.registerListener()See accelerometer.registerListener()
Example Code
The below example code shows a view that allows a user to read and start/stop watching accelerometer data. The returned data saved to LocalDB objects and is presented in tables.
Last updated