Merge pull request #31513 from dsanders11/patch-2

[usb] Update type for transfer errors
This commit is contained in:
Nathan Shively-Sanders 2018-12-18 14:16:25 -08:00 committed by GitHub
commit eab01caa91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

12
types/usb/index.d.ts vendored
View File

@ -8,6 +8,10 @@
import { EventEmitter } from "events";
export class LibUSBException extends Error {
errno: number;
}
export class Device {
timeout: number;
busNumber: number;
@ -25,7 +29,7 @@ export class Device {
open(defaultConfig?: boolean): void;
close(): void;
interface(addr: number): Interface;
controlTransfer(bmRequestType: number, bRequest: number, wValue: number, wIndex: number, data_or_length: any, callback: (error?: string, buf?: Buffer) => void): Device;
controlTransfer(bmRequestType: number, bRequest: number, wValue: number, wIndex: number, data_or_length: any, callback: (error?: LibUSBException, buf?: Buffer) => void): Device;
getStringDescriptor(desc_index: number, callback: (error?: string, buf?: Buffer) => void): void;
setConfiguration(desired: number, cb: (err?: string) => void): void;
reset(callback: (err?: string) => void): void;
@ -104,7 +108,7 @@ export class InEndpoint extends EventEmitter implements Endpoint {
timeout: number;
descriptor: EndpointDescriptor;
constructor(device: Device, descriptor: EndpointDescriptor);
transfer(length: number, callback: (error: string, data: Buffer) => void): InEndpoint;
transfer(length: number, callback: (error: LibUSBException, data: Buffer) => void): InEndpoint;
startPoll(nTransfers?: number, transferSize?: number): void;
stopPoll(cb?: () => void): void;
}
@ -115,8 +119,8 @@ export class OutEndpoint extends EventEmitter implements Endpoint {
timeout: number;
descriptor: EndpointDescriptor;
constructor(device: Device, descriptor: EndpointDescriptor);
transfer(buffer: Buffer, cb: (err?: string) => void): OutEndpoint;
transferWithZLP(buf: Buffer, cb: (err?: string) => void): void;
transfer(buffer: Buffer, cb: (err?: LibUSBException) => void): OutEndpoint;
transferWithZLP(buf: Buffer, cb: (err?: LibUSBException) => void): void;
}
export class EndpointDescriptor {

View File

@ -12,7 +12,7 @@ device.__claimInterface(0);
device.open(true);
device.close();
const xferDevice: usb.Device = device.controlTransfer(1, 1, 1, 1, 1, (error: string, buf: Buffer): usb.Device => new usb.Device());
const xferDevice: usb.Device = device.controlTransfer(1, 1, 1, 1, 1, (error: usb.LibUSBException, buf: Buffer): usb.Device => new usb.Device());
device.getStringDescriptor(1, (error: string, buf: Buffer) => null);
device.setConfiguration(1, (error: string) => null);
device.reset((error: string) => null);
@ -103,7 +103,7 @@ inEndpoint.direction = "in";
inEndpoint.transferType = 1;
inEndpoint.timeout = 1;
inEndpoint.descriptor = endpointDesc;
const xferInEndpoint: usb.InEndpoint = inEndpoint.transfer(1, (error: string, data: Buffer) => inEndpoint);
const xferInEndpoint: usb.InEndpoint = inEndpoint.transfer(1, (error: usb.LibUSBException, data: Buffer) => inEndpoint);
inEndpoint.on("data", (data) => null);
inEndpoint.startPoll(1, 1);
inEndpoint.startPoll(1);
@ -117,8 +117,8 @@ outEndpoint.transferType = 1;
outEndpoint.timeout = 1;
outEndpoint.descriptor = endpointDesc;
inEndpoint.on("error", (err) => null);
const xferOutEndpoint: usb.OutEndpoint = outEndpoint.transfer(new Buffer([]), (error: string) => null);
outEndpoint.transferWithZLP(new Buffer([]), (error: string) => null);
const xferOutEndpoint: usb.OutEndpoint = outEndpoint.transfer(new Buffer([]), (error: usb.LibUSBException) => null);
outEndpoint.transferWithZLP(new Buffer([]), (error: usb.LibUSBException) => null);
iface.endpoints = [inEndpoint, outEndpoint];