-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: usb scripts can be executed with vid,pid
- Loading branch information
Showing
8 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { CommandLineArgs } from 'uhk-common'; | ||
|
||
const USB_PROPERTIES = ['vid', 'pid', 'usb-interface']; | ||
|
||
export function assertCommandLineOptions (options: CommandLineArgs) { | ||
let anyUsbOption = false; | ||
let allUsbOptions = true; | ||
|
||
for (const usbProperty of USB_PROPERTIES) { | ||
if (options.hasOwnProperty(usbProperty)) { | ||
anyUsbOption = true; | ||
} else { | ||
allUsbOptions = false; | ||
} | ||
} | ||
|
||
if (anyUsbOption && !allUsbOptions) { | ||
throw new Error('You have to set all of the following options: vid, pid, usb-interface'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Device } from 'node-hid'; | ||
import { CommandLineArgs } from 'uhk-common'; | ||
|
||
export function findDeviceByOptions(options: CommandLineArgs): (device: Device) => boolean { | ||
return (device: Device) => { | ||
return device.vendorId === options.vid | ||
&& device.productId === options.pid | ||
&& device.interface === options['usb-interface']; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Device, devices } from 'node-hid'; | ||
import { UHK_VENDOR_ID } from 'uhk-common'; | ||
|
||
export function getUhkDevices(): Array<Device> { | ||
return devices().filter(x => x.vendorId === UHK_VENDOR_ID); | ||
export function getUhkDevices(vendorId: number = UHK_VENDOR_ID): Array<Device> { | ||
return devices().filter(x => x.vendorId === vendorId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters