-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add TypeScript definitions #176
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,274 @@ | ||
// Type definitions for bonescript 0.6 | ||
// Project: https://github.com/jadonk/bonescript | ||
// Definitions by: Troy W. <https://github.com/troywweber7> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
import * as SerialPort from 'serialport'; | ||
import * as VError from 'verror'; | ||
|
||
// OBJECTS | ||
export const bone: BoneObj; | ||
|
||
// FUNCTIONS - TODO obliterate all "any" types where possible! --- TWW | ||
// https://github.com/jadonk/bonescript#system | ||
|
||
export function getPlatform(callback?: (error: ErrorType, platform: PlatformObj) => void): any; | ||
|
||
export function echo(data: string, callback?: (error: ErrorType, data: string) => void): any; | ||
|
||
export function readTextFile(filename: string, callback?: (error: ErrorType, data: string) => void): string; | ||
|
||
export function writeTextFile(filename: string, data: any, callback?: (error: ErrorType) => void): any; | ||
|
||
export function writeCModule(filename: string, data: any, callback?: (error: ErrorType) => void): any; | ||
|
||
export function setDate(date: string, callback?: (error: ErrorType) => void): any; | ||
|
||
export function analogRead(pin: string, callback?: (err: ErrorType, value: number) => void): any; | ||
|
||
export function analogWrite(pin: string, value: number, freq?: number, callback?: ErrorCb): any; | ||
|
||
export function attachInterrupt( | ||
pin: string, | ||
handler: InterruptFn, | ||
mode: InterruptType, | ||
callback?: AttachIntCb | ||
): any; | ||
|
||
export function detachInterrupt(pin: string, callback?: DetachIntCb): any; | ||
|
||
export function digitalRead(pin: string, callback?: (err: ErrorType, value: number) => void): any; | ||
|
||
export function digitalWrite(pin: string, value: PinStateType, callback?: DigitalWriteCb): any; | ||
|
||
export function pinMode( | ||
pin: string, | ||
direction: 'in' | 'out' | 'analog_out' | 'in_pullup', | ||
mux?: string, | ||
pullup?: 'disabled' | 'pullup' | 'pulldown', | ||
slew?: 'fast' | 'slow', | ||
callback?: PinModeCb | ||
): any; | ||
|
||
export function getPinMode(pin: string, callback?: (err: ErrorType, mode: PinModeObj) => void): any; | ||
|
||
export function shiftOut(dataPin: string, clockPin: string, bitOrder: BitOrderType, val: number, callback?: ErrorCb): any; | ||
|
||
// https://github.com/jadonk/bonescript#serial | ||
export function serialOpen(port: any, options: any, callback?: ErrorCb): any; | ||
|
||
export function serialWrite(port: any, data: any, callback?: ErrorCb): any; | ||
|
||
export const serialParsers: typeof SerialPort.parsers; | ||
|
||
export function i2cOpen(port: any, address: any, options: any, callback?: ErrorCb): any; | ||
|
||
export function i2cScan(port: any, callback?: ErrorCb): any; | ||
|
||
export function i2cWriteByte(port: any, byte: any, callback?: ErrorCb): any; | ||
|
||
export function i2cWriteBytes(port: any, command: any, bytes: any, callback?: ErrorCb): any; | ||
|
||
export function i2cReadByte(port: any, callback?: ErrorCb): any; | ||
|
||
export function i2cReadBytes(port: any, command: any, length: any, callback?: ErrorCb): any; | ||
|
||
export function i2cStream(port: any, command: any, length: any, callback?: ErrorCb): any; | ||
// ffi | ||
export function loadCModule(filename: string, data: any, isMRAA?: boolean): any; | ||
|
||
export function lowByte(value: number): number; | ||
|
||
export function highByte(value: number): number; | ||
|
||
export function bitRead(value: number, bitnum: number): number; | ||
|
||
export function bitWrite(value: number, bitnum: number, bitdata: any): number; | ||
|
||
export function bitSet(value: number, bitnum: number): number; | ||
|
||
export function bitClear(value: number, bitnum: number): number; | ||
|
||
export function bit(bitnum: number): number; | ||
|
||
export function min(x: number, y: number): number; | ||
|
||
export function max(x: number, y: number): number; | ||
|
||
export function abs(x: number): number; | ||
|
||
export function constrain(x: number, a: number, b: number): number; | ||
|
||
export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number; | ||
|
||
export function pow(x: number, y: number): number; | ||
|
||
export function sqrt(x: number): number; | ||
|
||
export function sin(radians: number): number; | ||
|
||
export function cos(radians: number): number; | ||
|
||
export function tan(radians: number): number; | ||
|
||
export function randomSeed(x: number): void; | ||
|
||
export function random(min: number, max?: number): number; | ||
|
||
export function delay(...args: any[]): any; | ||
|
||
export function autorun(...args: any[]): any; | ||
|
||
export function serverStart(...args: any[]): any; | ||
|
||
export function socketJSReqHandler(...args: any[]): any; | ||
|
||
export function addSocketListeners(...args: any[]): any; | ||
|
||
export function setGlobals(...args: any[]): any; | ||
|
||
// CONSTANTS | ||
export const OUTPUT: 'out'; | ||
export const INPUT: 'in'; | ||
export const INPUT_PULLUP: 'in_pullup'; | ||
export const ANALOG_OUTPUT: 'analog_out'; | ||
export const HIGH: 1; | ||
export const LOW: 0; | ||
export const LSBFIRST: 1; | ||
export const MSBFIRST: 0; | ||
export const CHANGE: 'both'; | ||
export const RISING: 'rising'; | ||
export const FALLING: 'falling'; | ||
|
||
// INTERFACES - adjusted based on observation / testing | ||
interface PlatformObj { | ||
name: string; | ||
platform: BoneObj; | ||
bonescript: string; | ||
serialNumber?: string; | ||
dogtag?: string; | ||
os: { | ||
hostname: string, | ||
type: string, | ||
arch: string, | ||
release: string, | ||
uptime: number, | ||
loadavg: number[], | ||
totalmem: number, | ||
freemem: number, | ||
networkInterfaces?: any | ||
}; | ||
} | ||
|
||
export interface PinModeObj { | ||
gpio?: { | ||
active: boolean, | ||
direction: 'in' | 'out', | ||
allocated: boolean, | ||
}; | ||
modes: string[]; | ||
mux?: number; | ||
name: string; | ||
pin: string; | ||
pinState: string; | ||
pullup?: 'disabled' | 'pullup' | 'pulldown'; | ||
pwm?: { | ||
freq: number, | ||
value: number, | ||
}; | ||
rx?: 'enabled' | 'disabled'; | ||
slew?: 'fast' | 'slow'; | ||
} | ||
|
||
interface BoneObj { | ||
i2c: i2cObj; | ||
uarts: UartsObj; | ||
getPinKeys(): string[]; | ||
getPinObjects(): any; | ||
naturalCompare(): any; | ||
} | ||
|
||
interface PinsObj { | ||
[i: string]: PinInfo; | ||
} | ||
|
||
interface UartsObj { | ||
[i: string]: UartInfo; | ||
} | ||
|
||
interface i2cObj { | ||
[i: string]: i2cInfo; | ||
} | ||
|
||
export interface PinInfo { | ||
// Analog In | ||
ain?: number; | ||
// GPIO / LEDs / Analog In | ||
eeprom?: number; | ||
// GPIO / LEDs | ||
gpio?: number; | ||
key: string; | ||
// LEDs | ||
led?: string; | ||
mux?: string; | ||
muxRegOffset?: string; | ||
// All | ||
name: string; | ||
options?: string[]; | ||
// PWM | ||
pwm?: PwmInfo; | ||
scale?: number; | ||
universalName?: string; | ||
} | ||
|
||
interface PwmInfo { | ||
addr: string; | ||
chip: string; | ||
index: number; | ||
module: string; | ||
muxmode: number; | ||
name: string; | ||
path: string; | ||
sysfs: number; | ||
} | ||
|
||
interface UartInfo { | ||
devicetree?: string; | ||
rx?: string; | ||
tx?: string; | ||
} | ||
|
||
interface i2cInfo { | ||
devicetree?: string; | ||
path?: string; | ||
scl?: string; | ||
sda?: string; | ||
} | ||
|
||
// TYPES - adjusted based on observation / testing | ||
type PinStateType = typeof HIGH | typeof LOW; | ||
type PinModeType = typeof ANALOG_OUTPUT | typeof INPUT | typeof INPUT_PULLUP | typeof OUTPUT; | ||
type InterruptType = typeof RISING | typeof FALLING | typeof CHANGE; | ||
type BitOrderType = typeof LSBFIRST | typeof MSBFIRST; | ||
type ErrorCb = (err: ErrorType) => void; | ||
type InterruptFn = (resp: { | ||
pin: PinInfo, | ||
value: number | ||
}) => void; | ||
type AttachIntCb = (resp: { | ||
pin: PinInfo, | ||
attached: boolean | ||
}) => void; | ||
type DetachIntCb = (resp: { | ||
pin: PinInfo, | ||
detached: boolean | ||
}) => void; | ||
type PinModeCb = (resp: { | ||
value: number, | ||
err: VError | ||
}) => void; | ||
type DigitalWriteCb = (resp: { | ||
data: any, | ||
err: VError | ||
}) => void; | ||
type ErrorType = VError; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did these get used up above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is a reasonable way to do string enums!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, most of them were used above, i have removed some of the exports which were not necessary, had to export them previously due to this rule: https://github.com/Microsoft/dtslint/blob/master/docs/strict-export-declare-modifiers.md