From 19353307e3b509a9e408343792f5fda1695eb51a Mon Sep 17 00:00:00 2001 From: Evan Shortiss Date: Fri, 8 Mar 2019 14:48:49 -0800 Subject: [PATCH 1/2] add support for gyronorm --- types/gyronorm/gyronorm-tests.ts | 21 ++++++++ types/gyronorm/index.d.ts | 88 ++++++++++++++++++++++++++++++++ types/gyronorm/tsconfig.json | 21 ++++++++ types/gyronorm/tslint.json | 3 ++ 4 files changed, 133 insertions(+) create mode 100644 types/gyronorm/gyronorm-tests.ts create mode 100644 types/gyronorm/index.d.ts create mode 100644 types/gyronorm/tsconfig.json create mode 100644 types/gyronorm/tslint.json 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..3035f3607b --- /dev/null +++ b/types/gyronorm/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "gyronorm-tests.ts", + "index.d.ts" + ] +} diff --git a/types/gyronorm/tslint.json b/types/gyronorm/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/gyronorm/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} From 9a99eec613e4400daa406df3d025b69de000d1c2 Mon Sep 17 00:00:00 2001 From: Evan Shortiss Date: Fri, 8 Mar 2019 14:56:07 -0800 Subject: [PATCH 2/2] generate with dts --- types/gyronorm/tsconfig.json | 10 ++++++---- types/gyronorm/tslint.json | 4 +--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/types/gyronorm/tsconfig.json b/types/gyronorm/tsconfig.json index 3035f3607b..8b8dedb9c0 100644 --- a/types/gyronorm/tsconfig.json +++ b/types/gyronorm/tsconfig.json @@ -7,15 +7,17 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, - "strictFunctionTypes": true, "baseUrl": "../", - "typeRoots": ["../"], + "typeRoots": [ + "../" + ], "types": [], "noEmit": true, + "strictFunctionTypes": true, "forceConsistentCasingInFileNames": true }, "files": [ - "gyronorm-tests.ts", - "index.d.ts" + "index.d.ts", + "gyronorm-tests.ts" ] } diff --git a/types/gyronorm/tslint.json b/types/gyronorm/tslint.json index f93cf8562a..3db14f85ea 100644 --- a/types/gyronorm/tslint.json +++ b/types/gyronorm/tslint.json @@ -1,3 +1 @@ -{ - "extends": "dtslint/dt.json" -} +{ "extends": "dtslint/dt.json" }