mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Update ESC API, include Collection class (#37572)
This commit is contained in:
parent
94f0f93013
commit
d7cdee2d0b
58
types/johnny-five/index.d.ts
vendored
58
types/johnny-five/index.d.ts
vendored
@ -1,11 +1,13 @@
|
||||
// Type definitions for johnny-five
|
||||
// Type definitions for johnny-five 1.3.0
|
||||
// Project: https://github.com/rwaldron/johnny-five
|
||||
// Definitions by: Toshiya Nakakura <https://github.com/nakakura>
|
||||
// Zoltan Ujvary <https://github.com/ujvzolee>
|
||||
// Simon Colmer <https://github.com/workshop2>
|
||||
// XtrimSystems <https://github.com/xtrimsystems>
|
||||
// Marcin Obiedziński <https://github.com/marcinobiedz>
|
||||
// Nicholas Hehr <https://github.com/HipsterBrown>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.5
|
||||
|
||||
///<reference types="node"/>
|
||||
|
||||
@ -157,6 +159,35 @@ export declare class Button {
|
||||
on(event: "release", cb: () => void): this;
|
||||
}
|
||||
|
||||
export interface CollectionPinOptions {
|
||||
pins: Array<string | number>;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export declare class Collection<Base = {}> {
|
||||
static installMethodForwarding(target: object, source: object): object;
|
||||
|
||||
constructor(options: Array<number | string | object> | CollectionPinOptions);
|
||||
|
||||
type?: Base;
|
||||
|
||||
add(...args: Array<number | object>): number;
|
||||
|
||||
each(callback: (item: Base, index: number) => void): this;
|
||||
|
||||
forEach(callback: (item: Base, index: number) => void): this;
|
||||
|
||||
includes(item: Base): boolean;
|
||||
|
||||
indexOf(item: Base): number;
|
||||
|
||||
map(callback: (item: Base, index: number) => void): Array<any>;
|
||||
|
||||
slice(begin?: number, end?: number): Collection<Base>;
|
||||
|
||||
byId(id: any): Base | undefined;
|
||||
}
|
||||
|
||||
export interface CompassOption {
|
||||
controller: string;
|
||||
gauss?: number;
|
||||
@ -175,25 +206,32 @@ export declare class Compass {
|
||||
|
||||
export interface ESCOption {
|
||||
pin: number | string;
|
||||
range?: Array<number>;
|
||||
startAt?: number;
|
||||
controller?: string;
|
||||
device?: string;
|
||||
pwmRange?: Array<number>;
|
||||
address?: string;
|
||||
controller?: 'PCA9685' | 'DEFAULT';
|
||||
device?: 'FORWARD' | 'FORWARD_REVERSE' | 'FORWARD_REVERSE_BRAKE';
|
||||
neutral?: number;
|
||||
}
|
||||
|
||||
export declare class ESC {
|
||||
static Collection: ESCs;
|
||||
|
||||
constructor(option: number | string | ESCOption);
|
||||
|
||||
id: string;
|
||||
pin: number | string;
|
||||
range: Array<number>;
|
||||
pwmRange: Array<number>;
|
||||
readonly value: number;
|
||||
|
||||
speed(value: number): void;
|
||||
min(): void;
|
||||
max(): void;
|
||||
stop(): void;
|
||||
throttle(value: number): this;
|
||||
brake(): this;
|
||||
}
|
||||
|
||||
export declare class ESCs extends Collection<ESC> {
|
||||
constructor(option: Array<number | string | ESCOption>);
|
||||
|
||||
throttle(value: number): this;
|
||||
brake(): this;
|
||||
}
|
||||
|
||||
export declare class Fn {
|
||||
|
||||
@ -56,7 +56,27 @@ board.on('ready', function(){
|
||||
var esc = new five.ESC(11);
|
||||
|
||||
// Set to top speed. (this can be physically dangerous, you've been warned.)
|
||||
esc.max();
|
||||
esc.throttle(100);
|
||||
|
||||
// other options for creating an ESC instance
|
||||
esc = new five.ESC({
|
||||
device: 'FORWARD_REVERSE',
|
||||
pin: 11,
|
||||
pwmRange: [800, 1800],
|
||||
});
|
||||
|
||||
// set a percentage value between 0 and 100
|
||||
esc.throttle(25);
|
||||
|
||||
// set a micro-second
|
||||
esc.throttle(1500);
|
||||
|
||||
// create a collection of ESC instances
|
||||
var escs = new five.ESCs([11, 12]);
|
||||
|
||||
escs.throttle(80);
|
||||
|
||||
escs.forEach(item => item.brake());
|
||||
|
||||
|
||||
var gyro = new five.Gyro({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user