Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const CHECK_LIBUSB_REQUEST_TYPE_RESERVED: number = usb.LIBUSB_REQUEST_TYPE_RESERVED;
// libusb_request_recipient
const CHECK_LIBUSB_RECIPIENT_DEVICE: number = usb.LIBUSB_RECIPIENT_DEVICE;
const CHECK_LIBUSB_RECIPIENT_INTERFACE: number = usb.LIBUSB_RECIPIENT_INTERFACE;
const CHECK_LIBUSB_RECIPIENT_ENDPOINT: number = usb.LIBUSB_RECIPIENT_ENDPOINT;
const CHECK_LIBUSB_RECIPIENT_OTHER: number = usb.LIBUSB_RECIPIENT_OTHER;
const CHECK_LIBUSB_CONTROL_SETUP_SIZE: number = usb.LIBUSB_CONTROL_SETUP_SIZE;
// libusb_error
// Input/output error
const CHECK_LIBUSB_ERROR_IO: number = usb.LIBUSB_ERROR_IO;
// Invalid parameter
const CHECK_LIBUSB_ERROR_INVALID_PARAM: number = usb.LIBUSB_ERROR_INVALID_PARAM;
// Access denied (insufficient permissions)
const CHECK_LIBUSB_ERROR_ACCESS: number = usb.LIBUSB_ERROR_ACCESS;
// No such device (it may have been disconnected)
const CHECK_LIBUSB_ERROR_NO_DEVICE: number = usb.LIBUSB_ERROR_NO_DEVICE;
// Entity not found
const CHECK_LIBUSB_ERROR_NOT_FOUND: number = usb.LIBUSB_ERROR_NOT_FOUND;
// Resource busy
const CHECK_LIBUSB_ERROR_BUSY: number = usb.LIBUSB_ERROR_BUSY;
// Operation timed out
const CHECK_LIBUSB_ERROR_TIMEOUT: number = usb.LIBUSB_ERROR_TIMEOUT;
// Overflow
const CHECK_LIBUSB_ERROR_OVERFLOW: number = usb.LIBUSB_ERROR_OVERFLOW;
// Pipe error
const CHECK_LIBUSB_ERROR_PIPE: number = usb.LIBUSB_ERROR_PIPE;
// System call interrupted (perhaps due to signal)
const CHECK_LIBUSB_ERROR_INTERRUPTED: number = usb.LIBUSB_ERROR_INTERRUPTED;
// Insufficient memory
const CHECK_LIBUSB_ERROR_NO_MEM: number = usb.LIBUSB_ERROR_NO_MEM;
.help('h')
.argv;
var vid = parseInt(argv.v, 16);
var pid = parseInt(argv.p, 16);
var button = usb.findByIds(vid, pid);
if (button) {
console.log('Found button at vid, pid: 0x' + vid.toString(16) + ', 0x' + pid.toString(16));
try {
button.open();
} catch (e) {
if (e.errnum === usb.LIBUSB_ERROR_ACCESS) {
console.error('Access denied, you probably need to define a udev rule for your device. Check README for advice.');
process.exit(EXIT_CODE_ACCESS_DENIED);
}
}
if (button.interfaces.length !== 1) {
// Maybe try to figure out which interface we care about?
throw new Error('Expected a single USB interface, but found ' + button.interfaces.length);
} else {
var interface = button.interface(0);
if (interface.endpoints.length !== 1) {
// Maybe try to figure out which interface we care about?
throw new Error('Expected a single USB interface, but found: ' + interface.endpoints.length);
} else {
if (interface.isKernelDriverActive()) {
console.log('Kernel driver active.');