1 | import { EventEmitter } from 'events';
|
2 | import { LibUSBException, Transfer, Device } from './bindings';
|
3 | import { EndpointDescriptor } from './descriptors';
|
4 |
|
5 | export declare abstract class Endpoint extends EventEmitter {
|
6 | protected device: Device;
|
7 | address: number;
|
8 |
|
9 | abstract direction: 'in' | 'out';
|
10 |
|
11 | transferType: number;
|
12 |
|
13 | timeout: number;
|
14 |
|
15 | descriptor: EndpointDescriptor;
|
16 | constructor(device: Device, descriptor: EndpointDescriptor);
|
17 | /** Clear the halt/stall condition for this endpoint. */
|
18 | clearHalt(callback: (error: LibUSBException | undefined) => void): void;
|
19 | /**
|
20 | * Create a new `Transfer` object for this endpoint.
|
21 | *
|
22 | * The passed callback will be called when the transfer is submitted and finishes. Its arguments are the error (if any), the submitted buffer, and the amount of data actually written (for
|
23 | * OUT transfers) or read (for IN transfers).
|
24 | *
|
25 | * @param timeout Timeout for the transfer (0 means unlimited).
|
26 | * @param callback Transfer completion callback.
|
27 | */
|
28 | makeTransfer(timeout: number, callback: (error: LibUSBException | undefined, buffer: Buffer, actualLength: number) => void): Transfer;
|
29 | }
|
30 | /** Endpoints in the IN direction (device->PC) have this type. */
|
31 | export declare class InEndpoint extends Endpoint {
|
32 |
|
33 | direction: 'in' | 'out';
|
34 | protected pollTransfers: Transfer[];
|
35 | protected pollTransferSize: number;
|
36 | protected pollPending: number;
|
37 | pollActive: boolean;
|
38 | transferAsync: (length: number) => Promise<Buffer | undefined>;
|
39 | constructor(device: Device, descriptor: EndpointDescriptor);
|
40 | /**
|
41 | * Perform a transfer to read data from the endpoint.
|
42 | *
|
43 | * If length is greater than maxPacketSize, libusb will automatically split the transfer in multiple packets, and you will receive one callback with all data once all packets are complete.
|
44 | *
|
45 | * `this` in the callback is the InEndpoint object.
|
46 | *
|
47 | * The device must be open to use this method.
|
48 | * @param length
|
49 | * @param callback
|
50 | */
|
51 | transfer(length: number, callback: (error: LibUSBException | undefined, data?: Buffer) => void): InEndpoint;
|
52 | /**
|
53 | * Start polling the endpoint.
|
54 | *
|
55 | * The library will keep `nTransfers` transfers of size `transferSize` pending in the kernel at all times to ensure continuous data flow.
|
56 | * This is handled by the libusb event thread, so it continues even if the Node v8 thread is busy. The `data` and `error` events are emitted as transfers complete.
|
57 | *
|
58 | * The device must be open to use this method.
|
59 | * @param nTransfers
|
60 | * @param transferSize
|
61 | * @param callback
|
62 | */
|
63 | startPoll(nTransfers?: number, transferSize?: number, callback?: (error: LibUSBException | undefined, buffer: Buffer, actualLength: number, cancelled: boolean) => void): Transfer[];
|
64 | protected startPollTransfers(nTransfers: number | undefined, transferSize: number | undefined, callback: (error: LibUSBException | undefined, buffer: Buffer, actualLength: number) => void): Transfer[];
|
65 | /**
|
66 | * Stop polling.
|
67 | *
|
68 | * Further data may still be received. The `end` event is emitted and the callback is called once all transfers have completed or canceled.
|
69 | *
|
70 | * The device must be open to use this method.
|
71 | * @param callback
|
72 | */
|
73 | stopPoll(callback?: () => void): void;
|
74 | }
|
75 | /** Endpoints in the OUT direction (PC->device) have this type. */
|
76 | export declare class OutEndpoint extends Endpoint {
|
77 |
|
78 | direction: 'in' | 'out';
|
79 | transferAsync: (buffer: Buffer) => Promise<number>;
|
80 | constructor(device: Device, descriptor: EndpointDescriptor);
|
81 | /**
|
82 | * Perform a transfer to write `data` to the endpoint.
|
83 | *
|
84 | * If length is greater than maxPacketSize, libusb will automatically split the transfer in multiple packets, and you will receive one callback once all packets are complete.
|
85 | *
|
86 | * `this` in the callback is the OutEndpoint object.
|
87 | *
|
88 | * The device must be open to use this method.
|
89 | * @param buffer
|
90 | * @param callback
|
91 | */
|
92 | transfer(buffer: Buffer, callback?: (error: LibUSBException | undefined, actual: number) => void): OutEndpoint;
|
93 | transferWithZLP(buffer: Buffer, callback: (error: LibUSBException | undefined) => void): void;
|
94 | }
|