diff --git a/types/raspi-gpio/index.d.ts b/types/raspi-gpio/index.d.ts new file mode 100644 index 0000000000..4daf607b87 --- /dev/null +++ b/types/raspi-gpio/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for raspi-gpio 5.0 +// Project: https://github.com/nebrius/raspi-gpio +// Definitions by: Bryan Hughes +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +import { Peripheral } from 'raspi-peripheral'; +export interface Config { + pin: number | string; + pullResistor?: number; +} +export const LOW = 0; +export const HIGH = 1; +export const PULL_NONE: number; +export const PULL_DOWN: number; +export const PULL_UP: number; +export class DigitalOutput extends Peripheral { + private _output; + private _currentValue; + readonly value: number; + constructor(config: number | string | Config); + write(value: number): void; +} +export class DigitalInput extends Peripheral { + private _input; + private _currentValue; + readonly value: number; + constructor(config: number | string | Config); + destroy(): void; + read(): number; +} diff --git a/types/raspi-gpio/raspi-gpio-tests.ts b/types/raspi-gpio/raspi-gpio-tests.ts new file mode 100644 index 0000000000..0f672497da --- /dev/null +++ b/types/raspi-gpio/raspi-gpio-tests.ts @@ -0,0 +1,24 @@ +import { DigitalInput, DigitalOutput, Config, LOW, HIGH, PULL_UP, PULL_DOWN, PULL_NONE } from 'raspi-gpio'; + +const inputConfig: Config = { + pin: 'P1-3', + pullResistor: PULL_UP +}; +const input = new DigitalInput(inputConfig); +input.read(); +input.value; + +new DigitalInput({ + pin: 'P1-3', + pullResistor: PULL_DOWN +}); + +new DigitalInput({ + pin: 'P1-3', + pullResistor: PULL_NONE +}); + +const output = new DigitalOutput('P1-5'); +output.write(LOW); +output.write(HIGH); +output.value; diff --git a/types/raspi-gpio/tsconfig.json b/types/raspi-gpio/tsconfig.json new file mode 100644 index 0000000000..480f995bc6 --- /dev/null +++ b/types/raspi-gpio/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-gpio-tests.ts" + ] +} \ No newline at end of file diff --git a/types/raspi-gpio/tslint.json b/types/raspi-gpio/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/raspi-gpio/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file diff --git a/types/raspi-i2c/index.d.ts b/types/raspi-i2c/index.d.ts new file mode 100644 index 0000000000..ce71190055 --- /dev/null +++ b/types/raspi-i2c/index.d.ts @@ -0,0 +1,35 @@ +// Type definitions for raspi-i2c 6.1 +// Project: https://github.com/nebrius/raspi-i2c +// Definitions by: Bryan Hughes +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// +import { Peripheral } from 'raspi-peripheral'; +export type ReadCallback = (err: null | Error | string, data: null | Buffer | number) => void; +export type WriteCallback = (err: null | Error | string) => void; +export class I2C extends Peripheral { + private _devices; + constructor(); + destroy(): void; + private _getDevice(address); + read(address: number, length: number, cb: ReadCallback): void; + read(address: number, register: number, length: number, cb: ReadCallback): void; + readSync(address: number, registerOrLength: number | undefined, length?: number): Buffer; + readByte(address: number, cb: ReadCallback): void; + readByte(address: number, register: number, cb: ReadCallback): void; + readByteSync(address: number, register?: number): number; + readWord(address: number, cb: ReadCallback): void; + readWord(address: number, register: number, cb: ReadCallback): void; + readWordSync(address: number, register?: number): number; + write(address: number, buffer: Buffer, cb?: WriteCallback): void; + write(address: number, register: number, buffer: Buffer, cb?: WriteCallback): void; + writeSync(address: number, buffer: Buffer): void; + writeSync(address: number, register: number, buffer: Buffer): void; + writeByte(address: number, byte: number, cb?: WriteCallback): void; + writeByte(address: number, register: number, byte: number, cb?: WriteCallback): void; + writeByteSync(address: number, registerOrByte: number, byte?: number): void; + writeWord(address: number, word: number, cb?: WriteCallback): void; + writeWord(address: number, register: number, word: number, cb?: WriteCallback): void; + writeWordSync(address: number, registerOrWord: number, word?: number): void; +} diff --git a/types/raspi-i2c/raspi-i2c-tests.ts b/types/raspi-i2c/raspi-i2c-tests.ts new file mode 100644 index 0000000000..8473c8c247 --- /dev/null +++ b/types/raspi-i2c/raspi-i2c-tests.ts @@ -0,0 +1,38 @@ +import { I2C } from 'raspi-i2c'; + +const i2c = new I2C(); + +i2c.read(1, 1, (err, data) => {}); +i2c.read(1, 1, 1, (err, data) => {}); + +i2c.readSync(1, 1); +i2c.readSync(1, 1, 1); + +i2c.readByte(1, (err, data) => {}); +i2c.readByte(1, 1, (err, data) => {}); + +i2c.readByteSync(1); +i2c.readByteSync(1, 1); + +i2c.readWord(1, (err, data) => {}); +i2c.readWord(1, 1, (err, data) => {}); + +const buf = Buffer.alloc(1); + +i2c.write(1, buf, (err) => {}); +i2c.write(1, 1, buf, (err) => {}); + +i2c.writeSync(1, buf); +i2c.writeSync(1, 1, buf); + +i2c.writeByte(1, 1, (err) => {}); +i2c.writeByte(1, 1, 1, (err) => {}); + +i2c.writeByteSync(1, 1); +i2c.writeByteSync(1, 1, 1); + +i2c.writeWord(1, 1, (err) => {}); +i2c.writeWord(1, 1, 1, (err) => {}); + +i2c.writeWordSync(1, 1); +i2c.writeWordSync(1, 1, 1); diff --git a/types/raspi-i2c/tsconfig.json b/types/raspi-i2c/tsconfig.json new file mode 100644 index 0000000000..4e201f4496 --- /dev/null +++ b/types/raspi-i2c/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-i2c-tests.ts" + ] +} \ No newline at end of file diff --git a/types/raspi-i2c/tslint.json b/types/raspi-i2c/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/raspi-i2c/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file diff --git a/types/raspi-led/index.d.ts b/types/raspi-led/index.d.ts new file mode 100644 index 0000000000..1c060bb347 --- /dev/null +++ b/types/raspi-led/index.d.ts @@ -0,0 +1,15 @@ +// Type definitions for raspi-led 2.0 +// Project: https://github.com/nebrius/raspi-led +// Definitions by: Bryan Hughes +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +import { Peripheral } from 'raspi-peripheral'; +export const OFF = 0; +export const ON = 1; +export class LED extends Peripheral { + constructor(); + hasLed(): boolean; + read(): 0 | 1; + write(value: 0 | 1): void; +} diff --git a/types/raspi-led/raspi-led-tests.ts b/types/raspi-led/raspi-led-tests.ts new file mode 100644 index 0000000000..7da1a09761 --- /dev/null +++ b/types/raspi-led/raspi-led-tests.ts @@ -0,0 +1,7 @@ +import { OFF, ON, LED } from 'raspi-led'; + +const led = new LED(); +led.hasLed(); +led.read(); +led.write(OFF); +led.write(ON); diff --git a/types/raspi-led/tsconfig.json b/types/raspi-led/tsconfig.json new file mode 100644 index 0000000000..7e9d3a0fcc --- /dev/null +++ b/types/raspi-led/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-led-tests.ts" + ] +} \ No newline at end of file diff --git a/types/raspi-led/tslint.json b/types/raspi-led/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/raspi-led/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file diff --git a/types/raspi-onewire/index.d.ts b/types/raspi-onewire/index.d.ts new file mode 100644 index 0000000000..168b4576b1 --- /dev/null +++ b/types/raspi-onewire/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for raspi-onewire 1.0 +// Project: https://github.com/nebrius/raspi-onewire +// Definitions by: Bryan Hughes +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// +import { Peripheral } from 'raspi-peripheral'; +export class OneWire extends Peripheral { + private _deviceIdMapping; + constructor(); + private _convertIDToMappingKey(deviceID); + private _getNameFromID(deviceID); + searchForDevices(cb: (readErr: string | Error | undefined, devices: number[][] | undefined) => void): void; + read(deviceID: number[], numBytesToRead: number, cb: (err: string | Error | undefined, data: Buffer | undefined) => void): void; + readAllAvailable(deviceID: number[], cb: (err: string | Error | undefined, data: Buffer | undefined) => void): void; +} diff --git a/types/raspi-onewire/raspi-onewire-tests.ts b/types/raspi-onewire/raspi-onewire-tests.ts new file mode 100644 index 0000000000..1f24b21f4b --- /dev/null +++ b/types/raspi-onewire/raspi-onewire-tests.ts @@ -0,0 +1,7 @@ +import { OneWire } from 'raspi-onewire'; + +const oneWire = new OneWire(); + +oneWire.searchForDevices((err, devices) => {}); +oneWire.read([ 1, 2 ], 1, (err, data) => {}); +oneWire.readAllAvailable([ 1, 2 ], (err, data) => {}); diff --git a/types/raspi-onewire/tsconfig.json b/types/raspi-onewire/tsconfig.json new file mode 100644 index 0000000000..d7df314b58 --- /dev/null +++ b/types/raspi-onewire/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-onewire-tests.ts" + ] +} \ No newline at end of file diff --git a/types/raspi-onewire/tslint.json b/types/raspi-onewire/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/raspi-onewire/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file diff --git a/types/raspi-pwm/index.d.ts b/types/raspi-pwm/index.d.ts new file mode 100644 index 0000000000..42c122c75d --- /dev/null +++ b/types/raspi-pwm/index.d.ts @@ -0,0 +1,22 @@ +// Type definitions for raspi-pwm 5.0 +// Project: https://github.com/nebrius/raspi-pwm +// Definitions by: Bryan Hughes +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +import { Peripheral } from 'raspi-peripheral'; +export interface Config { + pin?: number | string; + frequency?: number; +} +export class PWM extends Peripheral { + private _frequencyValue; + private _dutyCycleValue; + private _pwmPort; + private _pwm; + readonly frequency: number; + readonly dutyCycle: number; + constructor(config?: number | string | Config); + destroy(): void; + write(dutyCycle: number): void; +} diff --git a/types/raspi-pwm/raspi-pwm-tests.ts b/types/raspi-pwm/raspi-pwm-tests.ts new file mode 100644 index 0000000000..3b4bf7ef3a --- /dev/null +++ b/types/raspi-pwm/raspi-pwm-tests.ts @@ -0,0 +1,15 @@ +import { Config, PWM } from 'raspi-pwm'; + +const config: Config = { + pin: 'P1-3', + frequency: 1 +}; + +new PWM(); +new PWM(1); +new PWM('P1-3'); +const pwm = new PWM(config); + +pwm.write(1); +pwm.frequency; +pwm.dutyCycle; diff --git a/types/raspi-pwm/tsconfig.json b/types/raspi-pwm/tsconfig.json new file mode 100644 index 0000000000..5e38158098 --- /dev/null +++ b/types/raspi-pwm/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-pwm-tests.ts" + ] +} \ No newline at end of file diff --git a/types/raspi-pwm/tslint.json b/types/raspi-pwm/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/raspi-pwm/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file diff --git a/types/raspi-serial/index.d.ts b/types/raspi-serial/index.d.ts new file mode 100644 index 0000000000..033c0682c3 --- /dev/null +++ b/types/raspi-serial/index.d.ts @@ -0,0 +1,40 @@ +// Type definitions for raspi-serial 4.0 +// Project: https://github.com/nebrius/raspi-serial +// Definitions by: Bryan Hughes +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// +import { Peripheral } from 'raspi-peripheral'; +export const PARITY_NONE = "none"; +export const PARITY_EVEN = "even"; +export const PARITY_ODD = "odd"; +export const PARITY_MARK = "mark"; +export const PARITY_SPACE = "space"; +export const DEFAULT_PORT = "/dev/ttyAMA0"; +export interface Options { + portId?: string; + baudRate?: 115200 | 57600 | 38400 | 19200 | 9600 | 4800 | 2400 | 1800 | 1200 | 600 | 300 | 200 | 150 | 134 | 110 | 75 | 50 | number; + dataBits?: 8 | 7 | 6 | 5; + stopBits?: 1 | 2; + parity?: 'none' | 'even' | 'mark' | 'odd' | 'space'; +} +export type Callback = () => void; +export type ErrorCallback = (err: Error | string) => void; +export class Serial extends Peripheral { + private _portId; + private _options; + private _portInstance; + private _isOpen; + constructor({ portId, baudRate, dataBits, stopBits, parity }?: Options); + readonly port: string; + readonly baudRate: number; + readonly dataBits: number; + readonly stopBits: number; + readonly parity: string; + destroy(): void; + open(cb?: Callback): void; + close(cb?: ErrorCallback): void; + write(data: Buffer | string, cb?: Callback): void; + flush(cb?: ErrorCallback): void; +} diff --git a/types/raspi-serial/raspi-serial-tests.ts b/types/raspi-serial/raspi-serial-tests.ts new file mode 100644 index 0000000000..176c6e1370 --- /dev/null +++ b/types/raspi-serial/raspi-serial-tests.ts @@ -0,0 +1,34 @@ +import { + PARITY_NONE, + PARITY_EVEN, + PARITY_ODD, + PARITY_MARK, + PARITY_SPACE, + DEFAULT_PORT, + Options, + Serial +} from 'raspi-serial'; + +let options: Options = {}; +options = { + parity: PARITY_EVEN +}; +options = { + parity: PARITY_ODD +}; +options = { + parity: PARITY_MARK +}; +options = { + parity: PARITY_SPACE +}; +options = { + portId: DEFAULT_PORT, + baudRate: 9600, + dataBits: 8, + stopBits: 1, + parity: PARITY_NONE +}; + +new Serial(); +const serial = new Serial(options); diff --git a/types/raspi-serial/tsconfig.json b/types/raspi-serial/tsconfig.json new file mode 100644 index 0000000000..c2a6058397 --- /dev/null +++ b/types/raspi-serial/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-serial-tests.ts" + ] +} \ No newline at end of file diff --git a/types/raspi-serial/tslint.json b/types/raspi-serial/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/raspi-serial/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file diff --git a/types/raspi-soft-pwm/index.d.ts b/types/raspi-soft-pwm/index.d.ts new file mode 100644 index 0000000000..098cf9aff7 --- /dev/null +++ b/types/raspi-soft-pwm/index.d.ts @@ -0,0 +1,23 @@ +// Type definitions for raspi-soft-pwm 4.0 +// Project: https://github.com/nebrius/raspi-soft-pwm +// Definitions by: Bryan Hughes +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +import { Peripheral } from 'raspi-peripheral'; +export interface Config { + pin: number | string; + frequency?: number; + range?: number; +} +export class SoftPWM extends Peripheral { + private _pwm; + private _frequency; + private _range; + private _dutyCycle; + readonly frequency: number; + readonly range: number; + readonly dutyCycle: number; + constructor(config: number | string | Config); + write(dutyCycle: number): void; +} diff --git a/types/raspi-soft-pwm/raspi-soft-pwm-tests.ts b/types/raspi-soft-pwm/raspi-soft-pwm-tests.ts new file mode 100644 index 0000000000..6cefe9a706 --- /dev/null +++ b/types/raspi-soft-pwm/raspi-soft-pwm-tests.ts @@ -0,0 +1,16 @@ +import { Config, SoftPWM } from 'raspi-soft-pwm'; + +const config: Config = { + pin: 'P1-3', + frequency: 1, + range: 1 +}; + +new SoftPWM(1); +new SoftPWM('P1-3'); +const pwm = new SoftPWM(config); + +pwm.write(1); +pwm.frequency; +pwm.dutyCycle; +pwm.range; diff --git a/types/raspi-soft-pwm/tsconfig.json b/types/raspi-soft-pwm/tsconfig.json new file mode 100644 index 0000000000..aab55c4028 --- /dev/null +++ b/types/raspi-soft-pwm/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-soft-pwm-tests.ts" + ] +} \ No newline at end of file diff --git a/types/raspi-soft-pwm/tslint.json b/types/raspi-soft-pwm/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/raspi-soft-pwm/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file