UNPKG

11.2 kBTypeScriptView Raw
1import type { DeviceDescriptor, ConfigDescriptor, BosDescriptor } from './descriptors';
2/**
3 * Return a list of `Device` objects for the USB devices attached to the system.
4 */
5export declare function getDeviceList(): Device[];
6/**
7 * Force polling loop for hotplug events
8 */
9export declare let pollHotplug: boolean;
10/**
11 * Hotplug polling loop delay (ms)
12 */
13export declare let pollHotplugDelay: number;
14export declare const INIT_ERROR: number;
15export declare class LibUSBException extends Error {
16 errno: number;
17}
18/**
19 * Set the libusb debug level (between 0 and 4)
20 * @param level libusb debug level (between 0 and 4)
21 */
22export declare function setDebugLevel(level: number): void;
23/**
24 * Use USBDK Backend (Windows only)
25 */
26export declare function useUsbDkBackend(): void;
27export declare function _supportedHotplugEvents(): number;
28export declare function _enableHotplugEvents(): void;
29export declare function _disableHotplugEvents(): void;
30export declare function _getLibusbCapability(capability: number): number;
31/**
32 * Restore (re-reference) the hotplug events unreferenced by `unrefHotplugEvents()`
33 */
34export declare function refHotplugEvents(): void;
35/**
36 * Unreference the hotplug events from the event loop, allowing the process to exit even when listening for the `attach` and `detach` events
37 */
38export declare function unrefHotplugEvents(): void;
39/** Represents a USB transfer */
40export declare class Transfer {
41 constructor(device: Device, endpointAddr: number, type: number, timeout: number, callback: (error: LibUSBException, buf: Buffer, actual: number) => void);
42 /**
43 * (Re-)submit the transfer.
44 *
45 * @param buffer Buffer where data will be written (for IN transfers) or read from (for OUT transfers).
46 */
47 submit(buffer: Buffer, callback?: (error: LibUSBException | undefined, buffer: Buffer, actualLength: number) => void): Transfer;
48 /**
49 * Cancel the transfer.
50 *
51 * Returns `true` if the transfer was canceled, `false` if it wasn't in pending state.
52 */
53 cancel(): boolean;
54}
55/** Represents a USB device. */
56export declare class Device {
57 /** Integer USB device number */
58 busNumber: number;
59 /** Integer USB device address */
60 deviceAddress: number;
61 /** Array containing the USB device port numbers, or `undefined` if not supported on this platform. */
62 portNumbers: number[];
63 /** Object with properties for the fields of the device descriptor. */
64 deviceDescriptor: DeviceDescriptor;
65 _bosDescriptor?: BosDescriptor;
66 __open(): void;
67 __close(): void;
68 __getParent(): Device;
69 __getConfigDescriptor(): ConfigDescriptor;
70 __getAllConfigDescriptors(): ConfigDescriptor[];
71 __setConfiguration(desired: number, callback: (error?: LibUSBException) => void): void;
72 __clearHalt(addr: number, callback: (error?: LibUSBException) => void): void;
73 __setInterface(addr: number, altSetting: number, callback: (error?: LibUSBException) => void): void;
74 __claimInterface(addr: number): void;
75 __releaseInterface(addr: number, callback: (error?: LibUSBException) => void): void;
76 __detachKernelDriver(addr: number): void;
77 __attachKernelDriver(addr: number): void;
78 __isKernelDriverActive(addr: number): boolean;
79 /**
80 * Performs a reset of the device. Callback is called when complete.
81 *
82 * The device must be open to use this method.
83 * @param callback
84 */
85 reset(callback: (error?: LibUSBException) => void): void;
86}
87/**
88 * In the context of a \ref libusb_device_descriptor "device descriptor",
89 * this bDeviceClass value indicates that each interface specifies its
90 * own class information and all interfaces operate independently.
91 */
92export declare const LIBUSB_CLASS_PER_INTERFACE: number;
93/** Audio class */
94export declare const LIBUSB_CLASS_AUDIO: number;
95/** Communications class */
96export declare const LIBUSB_CLASS_COMM: number;
97/** Human Interface Device class */
98export declare const LIBUSB_CLASS_HID: number;
99/** Printer class */
100export declare const LIBUSB_CLASS_PRINTER: number;
101/** Image class */
102export declare const LIBUSB_CLASS_PTP: number;
103/** Mass storage class */
104export declare const LIBUSB_CLASS_MASS_STORAGE: number;
105/** Hub class */
106export declare const LIBUSB_CLASS_HUB: number;
107/** Data class */
108export declare const LIBUSB_CLASS_DATA: number;
109/** Wireless class */
110export declare const LIBUSB_CLASS_WIRELESS: number;
111/** Application class */
112export declare const LIBUSB_CLASS_APPLICATION: number;
113/** Class is vendor-specific */
114export declare const LIBUSB_CLASS_VENDOR_SPEC: number;
115/** Request status of the specific recipient */
116export declare const LIBUSB_REQUEST_GET_STATUS: number;
117/** Clear or disable a specific feature */
118export declare const LIBUSB_REQUEST_CLEAR_FEATURE: number;
119/** Set or enable a specific feature */
120export declare const LIBUSB_REQUEST_SET_FEATURE: number;
121/** Set device address for all future accesses */
122export declare const LIBUSB_REQUEST_SET_ADDRESS: number;
123/** Get the specified descriptor */
124export declare const LIBUSB_REQUEST_GET_DESCRIPTOR: number;
125/** Used to update existing descriptors or add new descriptors */
126export declare const LIBUSB_REQUEST_SET_DESCRIPTOR: number;
127/** Get the current device configuration value */
128export declare const LIBUSB_REQUEST_GET_CONFIGURATION: number;
129/** Set device configuration */
130export declare const LIBUSB_REQUEST_SET_CONFIGURATION: number;
131/** Return the selected alternate setting for the specified interface */
132export declare const LIBUSB_REQUEST_GET_INTERFACE: number;
133/** Select an alternate interface for the specified interface */
134export declare const LIBUSB_REQUEST_SET_INTERFACE: number;
135/** Set then report an endpoint's synchronization frame */
136export declare const LIBUSB_REQUEST_SYNCH_FRAME: number;
137/** Device descriptor. See libusb_device_descriptor. */
138export declare const LIBUSB_DT_DEVICE: number;
139/** Configuration descriptor. See libusb_config_descriptor. */
140export declare const LIBUSB_DT_CONFIG: number;
141/** String descriptor */
142export declare const LIBUSB_DT_STRING: number;
143export declare const LIBUSB_DT_BOS: number;
144/** Interface descriptor. See libusb_interface_descriptor. */
145export declare const LIBUSB_DT_INTERFACE: number;
146/** Endpoint descriptor. See libusb_endpoint_descriptor. */
147export declare const LIBUSB_DT_ENDPOINT: number;
148/** HID descriptor */
149export declare const LIBUSB_DT_HID: number;
150/** HID report descriptor */
151export declare const LIBUSB_DT_REPORT: number;
152/** Physical descriptor */
153export declare const LIBUSB_DT_PHYSICAL: number;
154/** Hub descriptor */
155export declare const LIBUSB_DT_HUB: number;
156/** In: device-to-host */
157export declare const LIBUSB_ENDPOINT_IN: number;
158/** Out: host-to-device */
159export declare const LIBUSB_ENDPOINT_OUT: number;
160/** Control endpoint */
161export declare const LIBUSB_TRANSFER_TYPE_CONTROL: number;
162/** Isochronous endpoint */
163export declare const LIBUSB_TRANSFER_TYPE_ISOCHRONOUS: number;
164/** Bulk endpoint */
165export declare const LIBUSB_TRANSFER_TYPE_BULK: number;
166/** Interrupt endpoint */
167export declare const LIBUSB_TRANSFER_TYPE_INTERRUPT: number;
168/** No synchronization */
169export declare const LIBUSB_ISO_SYNC_TYPE_NONE: number;
170/** Asynchronous */
171export declare const LIBUSB_ISO_SYNC_TYPE_ASYNC: number;
172/** Adaptive */
173export declare const LIBUSB_ISO_SYNC_TYPE_ADAPTIVE: number;
174/** Synchronous */
175export declare const LIBUSB_ISO_SYNC_TYPE_SYNC: number;
176/** Data endpoint */
177export declare const LIBUSB_ISO_USAGE_TYPE_DATA: number;
178/** Feedback endpoint */
179export declare const LIBUSB_ISO_USAGE_TYPE_FEEDBACK: number;
180/** Implicit feedback Data endpoint */
181export declare const LIBUSB_ISO_USAGE_TYPE_IMPLICIT: number;
182/**
183 * Transfer completed without error. Note that this does not indicate
184 * that the entire amount of requested data was transferred.
185 */
186export declare const LIBUSB_TRANSFER_COMPLETED: number;
187/** Transfer failed */
188export declare const LIBUSB_TRANSFER_ERROR: number;
189/** Transfer timed out */
190export declare const LIBUSB_TRANSFER_TIMED_OUT: number;
191/** Transfer was cancelled */
192export declare const LIBUSB_TRANSFER_CANCELLED: number;
193/**
194 * For bulk/interrupt endpoints: halt condition detected (endpoint
195 * stalled). For control endpoints: control request not supported.
196 */
197export declare const LIBUSB_TRANSFER_STALL: number;
198/** Device was disconnected */
199export declare const LIBUSB_TRANSFER_NO_DEVICE: number;
200/** Device sent more data than requested */
201export declare const LIBUSB_TRANSFER_OVERFLOW: number;
202/** Report short frames as errors */
203export declare const LIBUSB_TRANSFER_SHORT_NOT_OK: number;
204/**
205 * Automatically free() transfer buffer during libusb_free_transfer().
206 * Note that buffers allocated with libusb_dev_mem_alloc() should not
207 * be attempted freed in this way, since free() is not an appropriate
208 * way to release such memory.
209 */
210export declare const LIBUSB_TRANSFER_FREE_BUFFER: number;
211/**
212 * Automatically call libusb_free_transfer() after callback returns.
213 * If this flag is set, it is illegal to call libusb_free_transfer()
214 * from your transfer callback, as this will result in a double-free
215 * when this flag is acted upon.
216 */
217export declare const LIBUSB_TRANSFER_FREE_TRANSFER: number;
218/** Standard */
219export declare const LIBUSB_REQUEST_TYPE_STANDARD: number;
220/** Class */
221export declare const LIBUSB_REQUEST_TYPE_CLASS: number;
222/** Vendor */
223export declare const LIBUSB_REQUEST_TYPE_VENDOR: number;
224/** Reserved */
225export declare const LIBUSB_REQUEST_TYPE_RESERVED: number;
226/** Device */
227export declare const LIBUSB_RECIPIENT_DEVICE: number;
228/** Interface */
229export declare const LIBUSB_RECIPIENT_INTERFACE: number;
230/** Endpoint */
231export declare const LIBUSB_RECIPIENT_ENDPOINT: number;
232/** Other */
233export declare const LIBUSB_RECIPIENT_OTHER: number;
234export declare const LIBUSB_CONTROL_SETUP_SIZE: number;
235export declare const LIBUSB_DT_BOS_SIZE: number;
236export declare const LIBUSB_CAP_HAS_CAPABILITY: number;
237export declare const LIBUSB_CAP_HAS_HOTPLUG: number;
238export declare const LIBUSB_CAP_HAS_HID_ACCESS: number;
239export declare const LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER: number;
240/** Input/output error */
241export declare const LIBUSB_ERROR_IO: number;
242/** Invalid parameter */
243export declare const LIBUSB_ERROR_INVALID_PARAM: number;
244/** Access denied (insufficient permissions) */
245export declare const LIBUSB_ERROR_ACCESS: number;
246/** No such device (it may have been disconnected) */
247export declare const LIBUSB_ERROR_NO_DEVICE: number;
248/** Entity not found */
249export declare const LIBUSB_ERROR_NOT_FOUND: number;
250/** Resource busy */
251export declare const LIBUSB_ERROR_BUSY: number;
252/** Operation timed out */
253export declare const LIBUSB_ERROR_TIMEOUT: number;
254/** Overflow */
255export declare const LIBUSB_ERROR_OVERFLOW: number;
256/** Pipe error */
257export declare const LIBUSB_ERROR_PIPE: number;
258/** System call interrupted (perhaps due to signal) */
259export declare const LIBUSB_ERROR_INTERRUPTED: number;
260/** Insufficient memory */
261export declare const LIBUSB_ERROR_NO_MEM: number;
262/** Operation not supported or unimplemented on this platform */
263export declare const LIBUSB_ERROR_NOT_SUPPORTED: number;
264/** Other error */
265export declare const LIBUSB_ERROR_OTHER: number;