2016-03-07 04:43:13 +08:00
|
|
|
import {Plugin, Cordova} from './plugin';
|
2016-03-09 02:18:06 +08:00
|
|
|
import {Observable} from "rxjs/Observable";
|
2016-03-07 04:43:13 +08:00
|
|
|
|
2016-03-07 04:54:55 +08:00
|
|
|
export interface accelerationData {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Amount of acceleration on the x-axis. (in m/s^2)
|
|
|
|
*/
|
|
|
|
x : number,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Amount of acceleration on the y-axis. (in m/s^2)
|
|
|
|
*/
|
|
|
|
y : number,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Amount of acceleration on the z-axis. (in m/s^2)
|
|
|
|
*/
|
|
|
|
z : number,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creation timestamp in milliseconds.
|
|
|
|
*/
|
|
|
|
timestamp : any
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface accelerometerOptions {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Requested period of calls to accelerometerSuccess with acceleration data in Milliseconds. Default: 10000
|
|
|
|
*/
|
|
|
|
frequency? : number
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-07 04:43:13 +08:00
|
|
|
/**
|
2016-03-14 03:45:07 +08:00
|
|
|
* @name Device Motion
|
2016-03-13 07:30:16 +08:00
|
|
|
* @description
|
2016-03-07 04:43:13 +08:00
|
|
|
* Requires Cordova plugin: `cordova-plugin-device-motion`. For more info, please see the [Device Motion docs](https://github.com/apache/cordova-plugin-device-motion).
|
|
|
|
*
|
|
|
|
* @usage
|
2016-03-09 02:18:06 +08:00
|
|
|
* ```ts
|
2016-03-25 01:00:18 +08:00
|
|
|
* import {DeviceMotion} from 'ionic-native';
|
|
|
|
*
|
|
|
|
*
|
2016-03-09 02:18:06 +08:00
|
|
|
*
|
|
|
|
* // Get the device current acceleration
|
|
|
|
* DeviceMotion.getCurrentAcceleration().then(
|
|
|
|
* acceleration => console.log(acceleration),
|
|
|
|
* error => console.log(error)
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* // Watch device acceleration
|
2016-04-15 20:25:02 +08:00
|
|
|
* var subscription = DeviceMotion.watchAcceleration().subscribe(acceleration => {
|
2016-03-09 02:18:06 +08:00
|
|
|
* console.log(acceleration);
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
* // Stop watch
|
|
|
|
* subscription.unsubscribe();
|
|
|
|
*
|
2016-03-07 04:43:13 +08:00
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
@Plugin({
|
2016-03-13 07:30:16 +08:00
|
|
|
plugin: 'cordova-plugin-device-motion',
|
|
|
|
pluginRef: 'navigator.accelerometer',
|
|
|
|
repo: 'https://github.com/apache/cordova-plugin-device-motion'
|
2016-03-07 04:43:13 +08:00
|
|
|
})
|
|
|
|
export class DeviceMotion {
|
|
|
|
|
2016-03-07 04:54:55 +08:00
|
|
|
/**
|
|
|
|
* Get the current acceleration along the x, y, and z axes.
|
2016-03-09 02:18:06 +08:00
|
|
|
*
|
2016-03-07 04:54:55 +08:00
|
|
|
* @returns {Promise<any>} Returns object with x, y, z, and timestamp properties
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-03-11 05:48:20 +08:00
|
|
|
static getCurrentAcceleration(): Promise<accelerationData> { return }
|
2016-03-07 04:54:55 +08:00
|
|
|
|
|
|
|
/**
|
2016-03-09 02:18:06 +08:00
|
|
|
* Watch the device acceleration. Clear the watch by unsubscribing from the observable.
|
2016-03-07 04:54:55 +08:00
|
|
|
*
|
2016-03-09 02:18:06 +08:00
|
|
|
* ```ts
|
|
|
|
* // Watch device acceleration
|
|
|
|
* var subscription = DeviceMotion.watchPosition().subscribe(acceleration => {
|
|
|
|
* console.log(acceleration);
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
* // Stop watch
|
|
|
|
* subscription.unsubscribe();
|
|
|
|
* ```
|
2016-03-07 04:54:55 +08:00
|
|
|
* @param options
|
|
|
|
* @returns {Observable<accelerationData>}
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-03-09 02:18:06 +08:00
|
|
|
callbackOrder: 'reverse',
|
|
|
|
observable: true,
|
|
|
|
clearFunction: 'clearWatch'
|
2016-03-07 04:54:55 +08:00
|
|
|
})
|
2016-03-11 05:48:20 +08:00
|
|
|
static watchAcceleration (options?: accelerometerOptions): Observable<accelerationData> { return }
|
2016-03-07 04:43:13 +08:00
|
|
|
}
|