diff --git a/types/gyronorm/gyronorm-tests.ts b/types/gyronorm/gyronorm-tests.ts new file mode 100644 index 0000000000..d944b72bd0 --- /dev/null +++ b/types/gyronorm/gyronorm-tests.ts @@ -0,0 +1,21 @@ +import * as gyronorm from 'gyronorm'; + +const instance = new gyronorm.GyroNorm(); +const options: gyronorm.Options = { + frequency: 100 +}; + +instance.init(options) + .then(() => { + instance.startLogging((data) => { + const { message, code } = data; + }); + + instance.start((data) => { + const motion = data.dm; + const orientation = data.do; + }); + }) + .catch(() => { + // init failure + }); diff --git a/types/gyronorm/index.d.ts b/types/gyronorm/index.d.ts new file mode 100644 index 0000000000..2a1508da1f --- /dev/null +++ b/types/gyronorm/index.d.ts @@ -0,0 +1,88 @@ +// Type definitions for gyronorm 2.0 +// Project: https://github.com/dorukeker/gyronorm.js +// Definitions by: Evan Shortiss +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface MotionAndOrientationPayload { + do: { + alpha: number; + beta: number; + gamma: number; + absolute: number; + }; + + dm: { + x: number; + y: number; + z: number; + + gx: number; + gy: number; + gz: number; + + alpha: number; + beta: number; + gamma: number; + }; +} + +export interface Options { + /** + * How often GyroNorm returns data (in milliseconds) + */ + frequency?: number; + + /** + * If the gravity related values to be normalized + */ + gravityNormalized?: boolean; + + /** + * Can be GyroNorm.GAME or GyroNorm.WORLD. gn.GAME returns + * orientation values with respect to the head direction of the device. + * gn.WORLD returns the orientation values with respect to the actual + * north direction of the world. + */ + orientationBase?: string; + + /** + * How many digits after the decimal point will there be in the return values + */ + decimalCount?: number; + + /** + * Function to be called to log messages from gyronorm.js + */ + logger?: LogListener; + + /** + * If set to true it will return screen adjusted values + */ + screenAdjusted?: boolean; +} + +export interface LoggerData { + code: number; + message: string; +} + +export type LogListener = (data: LoggerData) => void; + +export class GyroNorm { + constructor() + + static GAME: string; + static WORLD: string; + + static DEVICE_ORIENTATION: string; + static ACCELERATION: string; + static ACCELERATION_INCLUDING_GRAVITY: string; + static ROTATION_RATE: string; + + init(options: Options): Promise; + + start(callback: (data: MotionAndOrientationPayload) => void): void; + + startLogging(listener: LogListener): void; + stopLogging(): void; +} diff --git a/types/gyronorm/tsconfig.json b/types/gyronorm/tsconfig.json new file mode 100644 index 0000000000..8b8dedb9c0 --- /dev/null +++ b/types/gyronorm/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "strictFunctionTypes": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "gyronorm-tests.ts" + ] +} diff --git a/types/gyronorm/tslint.json b/types/gyronorm/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/gyronorm/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }