mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-31 18:49:43 +08:00
feat(plugin): add functionality to device motion plugin
This commit is contained in:
parent
a4df21e99c
commit
7f7ba3b52a
@ -1,5 +1,38 @@
|
|||||||
import {Plugin, Cordova} from './plugin';
|
import {Plugin, Cordova} from './plugin';
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requires Cordova plugin: `cordova-plugin-device-motion`. For more info, please see the [Device Motion docs](https://github.com/apache/cordova-plugin-device-motion).
|
* Requires Cordova plugin: `cordova-plugin-device-motion`. For more info, please see the [Device Motion docs](https://github.com/apache/cordova-plugin-device-motion).
|
||||||
*
|
*
|
||||||
@ -17,10 +50,45 @@ import {Plugin, Cordova} from './plugin';
|
|||||||
})
|
})
|
||||||
export class DeviceMotion {
|
export class DeviceMotion {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current acceleration along the x, y, and z axes.
|
||||||
|
* @returns {Promise<any>} Returns object with x, y, z, and timestamp properties
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
static getCurrentAcceleration () : Promise<accelerationData> {
|
||||||
// This Promise is replaced by one from the @Cordova decorator that wraps
|
// This Promise is replaced by one from the @Cordova decorator that wraps
|
||||||
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
||||||
// knows that the correct return type is Promise, because there's no way
|
// knows that the correct return type is Promise, because there's no way
|
||||||
// for it to know the return type from a decorator.
|
// for it to know the return type from a decorator.
|
||||||
// See https://github.com/Microsoft/TypeScript/issues/4881
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
||||||
|
return new Promise<accelerationData>((res, rej) => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param options
|
||||||
|
* @returns {Observable<accelerationData>}
|
||||||
|
*/
|
||||||
|
@Cordova({
|
||||||
|
successIndex: 0,
|
||||||
|
errorIndex: 1
|
||||||
|
})
|
||||||
|
static watchAcceleration (options? : accelerometerOptions) : Promise<accelerationData> {
|
||||||
|
// This Promise is replaced by one from the @Cordova decorator that wraps
|
||||||
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
||||||
|
// knows that the correct return type is Promise, because there's no way
|
||||||
|
// for it to know the return type from a decorator.
|
||||||
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
||||||
|
return new Promise<accelerationData>((res, rej) => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop watching the Acceleration referenced by the watchID parameter.
|
||||||
|
* @param watchID The ID returned by watchAcceleration method
|
||||||
|
*/
|
||||||
|
@Cordova({
|
||||||
|
sync: true
|
||||||
|
})
|
||||||
|
static clearWatch(watchID : any) : void {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user