From ceb5223a75e4e7d3366d0209980a4c3c02a60525 Mon Sep 17 00:00:00 2001 From: Bryan Hughes Date: Sat, 18 Nov 2017 15:31:32 -0800 Subject: [PATCH] Added part of the Raspi IO ecosystem --- types/raspi-board/index.d.ts | 27 +++++++++++++++++++ types/raspi-board/raspi-board-tests.ts | 6 +++++ types/raspi-board/tsconfig.json | 23 ++++++++++++++++ types/raspi-board/tslint.json | 1 + types/raspi-peripheral/index.d.ts | 17 ++++++++++++ .../raspi-peripheral-tests.ts | 5 ++++ types/raspi-peripheral/tsconfig.json | 23 ++++++++++++++++ types/raspi-peripheral/tslint.json | 1 + types/raspi/index.d.ts | 7 +++++ types/raspi/raspi-tests.ts | 3 +++ types/raspi/tsconfig.json | 23 ++++++++++++++++ types/raspi/tslint.json | 1 + 12 files changed, 137 insertions(+) create mode 100644 types/raspi-board/index.d.ts create mode 100644 types/raspi-board/raspi-board-tests.ts create mode 100644 types/raspi-board/tsconfig.json create mode 100644 types/raspi-board/tslint.json create mode 100644 types/raspi-peripheral/index.d.ts create mode 100644 types/raspi-peripheral/raspi-peripheral-tests.ts create mode 100644 types/raspi-peripheral/tsconfig.json create mode 100644 types/raspi-peripheral/tslint.json create mode 100644 types/raspi/index.d.ts create mode 100644 types/raspi/raspi-tests.ts create mode 100644 types/raspi/tsconfig.json create mode 100644 types/raspi/tslint.json diff --git a/types/raspi-board/index.d.ts b/types/raspi-board/index.d.ts new file mode 100644 index 0000000000..a244577c2b --- /dev/null +++ b/types/raspi-board/index.d.ts @@ -0,0 +1,27 @@ +// Type definitions for raspi-board 5.0 +// Project: https://github.com/nebrius/raspi-board +// Definitions by: Bryan Hughes +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export const VERSION_1_MODEL_A = "rpi1_a"; +export const VERSION_1_MODEL_B_REV_1 = "rpi1_b1"; +export const VERSION_1_MODEL_B_REV_2 = "rpi1_b2"; +export const VERSION_1_MODEL_B_PLUS = "rpi1_bplus"; +export const VERSION_1_MODEL_A_PLUS = "rpi1_aplus"; +export const VERSION_1_MODEL_ZERO = "rpi1_zero"; +export const VERSION_1_MODEL_ZERO_W = "rpi1_zerow"; +export const VERSION_2_MODEL_B = "rpi2_b"; +export const VERSION_3_MODEL_B = "rpi3_b"; +export const VERSION_UNKNOWN = "unknown"; +export interface PinInfo { + pins: string[]; + peripherals: string[]; + gpio: number; +} +export function getBoardRevision(): string; +export function getPins(): { + [wiringpi: number]: PinInfo; +}; +export function getPinNumber(alias: string | number): number | null; +export function getGpioNumber(alias: string | number): number | null; diff --git a/types/raspi-board/raspi-board-tests.ts b/types/raspi-board/raspi-board-tests.ts new file mode 100644 index 0000000000..23195168cf --- /dev/null +++ b/types/raspi-board/raspi-board-tests.ts @@ -0,0 +1,6 @@ +import { getBoardRevision, getPins, getPinNumber, getGpioNumber } from 'raspi-board'; + +getBoardRevision(); +getPins(); +getPinNumber('GPIO18'); +getGpioNumber('GPIO18'); diff --git a/types/raspi-board/tsconfig.json b/types/raspi-board/tsconfig.json new file mode 100644 index 0000000000..a55a514726 --- /dev/null +++ b/types/raspi-board/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "raspi-board-tests.ts" + ] +} \ No newline at end of file diff --git a/types/raspi-board/tslint.json b/types/raspi-board/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/raspi-board/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file diff --git a/types/raspi-peripheral/index.d.ts b/types/raspi-peripheral/index.d.ts new file mode 100644 index 0000000000..d52ed3ec6c --- /dev/null +++ b/types/raspi-peripheral/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for raspi-peripheral 2.0 +// Project: https://github.com/nebrius/raspi-peripheral +// Definitions by: Bryan Hughes +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// +import { EventEmitter } from 'events'; +export class Peripheral extends EventEmitter { + private _alive; + readonly alive: boolean; + private _pins; + readonly pins: number[]; + constructor(pins: string | number | Array); + destroy(): void; + validateAlive(): void; +} diff --git a/types/raspi-peripheral/raspi-peripheral-tests.ts b/types/raspi-peripheral/raspi-peripheral-tests.ts new file mode 100644 index 0000000000..dc16f863a2 --- /dev/null +++ b/types/raspi-peripheral/raspi-peripheral-tests.ts @@ -0,0 +1,5 @@ +import { Peripheral } from 'raspi-peripheral'; + +const myPeripheral = new Peripheral('GPIO2'); +myPeripheral.alive; +myPeripheral.pins.filter((pin) => true); diff --git a/types/raspi-peripheral/tsconfig.json b/types/raspi-peripheral/tsconfig.json new file mode 100644 index 0000000000..4b24a67971 --- /dev/null +++ b/types/raspi-peripheral/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "raspi-peripheral-tests.ts" + ] +} \ No newline at end of file diff --git a/types/raspi-peripheral/tslint.json b/types/raspi-peripheral/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/raspi-peripheral/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file diff --git a/types/raspi/index.d.ts b/types/raspi/index.d.ts new file mode 100644 index 0000000000..9df97fe3cc --- /dev/null +++ b/types/raspi/index.d.ts @@ -0,0 +1,7 @@ +// Type definitions for raspi 5.0 +// Project: https://github.com/nebrius/raspi +// Definitions by: Bryan Hughes +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export function init(cb: () => void): void; diff --git a/types/raspi/raspi-tests.ts b/types/raspi/raspi-tests.ts new file mode 100644 index 0000000000..705aeacc31 --- /dev/null +++ b/types/raspi/raspi-tests.ts @@ -0,0 +1,3 @@ +import { init } from 'raspi'; + +init(() => {}); diff --git a/types/raspi/tsconfig.json b/types/raspi/tsconfig.json new file mode 100644 index 0000000000..6906d607cf --- /dev/null +++ b/types/raspi/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "raspi-tests.ts" + ] +} \ No newline at end of file diff --git a/types/raspi/tslint.json b/types/raspi/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/raspi/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file