Skip to content

Commit 179ad50

Browse files
committed
Export all transports as conitional
1 parent dbe7a5a commit 179ad50

File tree

13 files changed

+49
-25
lines changed

13 files changed

+49
-25
lines changed

examples/daplink-flash/hid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
const hid = require("node-hid");
2424
const common = require("./common");
25-
const hidTransport = require("../../lib/transport/hid");
25+
const DAPjs = require("../../");
2626

2727
// Allow user to select a device
2828
function selectDevice(vendorID) {
@@ -50,7 +50,7 @@ common.getFile()
5050
common.setupEmitter();
5151
return selectDevice(0xD28)
5252
.then(device => {
53-
const transport = new hidTransport.HID(device);
53+
const transport = new DAPjs.HID(device);
5454
return common.flash(transport, program);
5555
});
5656
})

examples/daplink-flash/usb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
const usb = require("usb");
2424
const common = require("./common");
25-
const usbTransport = require("../../lib/transport/usb");
25+
const DAPjs = require("../../");
2626

2727
// Read USB device descriptor
2828
function getStringDescriptor(device, index) {
@@ -69,7 +69,7 @@ common.getFile()
6969
common.setupEmitter();
7070
return selectDevice(0xD28)
7171
.then(device => {
72-
const transport = new usbTransport.USB(device);
72+
const transport = new DAPjs.USB(device);
7373
return common.flash(transport, program);
7474
});
7575
})

examples/daplink-serial/hid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
const hid = require("node-hid");
2424
const common = require("./common");
25-
const hidTransport = require("../../lib/transport/hid");
25+
const DAPjs = require("../../");
2626

2727
// Allow user to select a device
2828
function selectDevice(vendorID) {
@@ -56,7 +56,7 @@ function selectDevice(vendorID) {
5656

5757
selectDevice(0xD28)
5858
.then(device => {
59-
const transport = new hidTransport.HID(device);
59+
const transport = new DAPjs.HID(device);
6060
return common.listen(transport);
6161
})
6262
.catch(error => {

examples/daplink-serial/usb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
const usb = require("usb");
2424
const common = require("./common");
25-
const usbTransport = require("../../lib/transport/usb");
25+
const DAPjs = require("../../");
2626

2727
// Read USB device descriptor
2828
function getStringDescriptor(device, index) {
@@ -75,7 +75,7 @@ function selectDevice(vendorID) {
7575

7676
selectDevice(0xD28)
7777
.then(device => {
78-
const transport = new usbTransport.USB(device);
78+
const transport = new DAPjs.USB(device);
7979
return common.listen(transport);
8080
})
8181
.catch(error => {

examples/read-registers/hid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
const hid = require("node-hid");
2424
const common = require("./common");
25-
const hidTransport = require("../../lib/transport/hid");
25+
const DAPjs = require("../../");
2626

2727
// Allow user to select a device
2828
function selectDevice(vendorID) {
@@ -48,7 +48,7 @@ function selectDevice(vendorID) {
4848

4949
selectDevice(0xD28)
5050
.then(device => {
51-
const transport = new hidTransport.HID(device);
51+
const transport = new DAPjs.HID(device);
5252
return common.readRegisters(transport);
5353
})
5454
.then(() => {

examples/read-registers/usb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
const usb = require("usb");
2424
const common = require("./common");
25-
const usbTransport = require("../../lib/transport/usb");
25+
const DAPjs = require("../../");
2626

2727
// Read USB device descriptor
2828
function getStringDescriptor(device, index) {
@@ -66,7 +66,7 @@ function selectDevice(vendorID) {
6666

6767
selectDevice(0xD28)
6868
.then(device => {
69-
const transport = new usbTransport.USB(device);
69+
const transport = new DAPjs.USB(device);
7070
return common.readRegisters(transport);
7171
})
7272
.then(() => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"webusb"
3535
],
3636
"scripts": {
37-
"build": "rollup -c && typedoc src",
37+
"build": "rollup -c && typedoc --tsconfig ./typedoc.tsconfig.json src",
3838
"watch": "rollup -c -w"
3939
},
4040
"engines": {

src/transport/hid.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ export class HID implements Transport {
5858
}
5959

6060
try {
61-
this.device = new nodeHID(this.path);
62-
resolve();
61+
return import("node-hid")
62+
.then(hid => {
63+
this.device = new hid.HID(this.path);
64+
resolve();
65+
});
6366
} catch (ex) {
6467
reject(ex);
6568
}

src/transport/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ export interface Transport {
5656
write(data: BufferSource): Promise<void>;
5757
}
5858

59+
export * from "./hid";
60+
export * from "./usb";
5961
export * from "./webusb";

src/transport/usb.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,25 @@
2121
* SOFTWARE.
2222
*/
2323

24-
import {
25-
LIBUSB_REQUEST_TYPE_CLASS,
26-
LIBUSB_RECIPIENT_INTERFACE,
27-
LIBUSB_ENDPOINT_IN,
28-
LIBUSB_ENDPOINT_OUT,
29-
Device,
30-
InEndpoint,
31-
OutEndpoint
32-
} from "usb";
24+
import { Device, InEndpoint, OutEndpoint} from "usb";
3325
import { Transport } from "./";
3426

27+
/**
28+
* @hidden
29+
*/
30+
const LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5);
31+
/**
32+
* @hidden
33+
*/
34+
const LIBUSB_RECIPIENT_INTERFACE = 0x01;
35+
/**
36+
* @hidden
37+
*/
38+
const LIBUSB_ENDPOINT_OUT = 0x00;
39+
/**
40+
* @hidden
41+
*/
42+
const LIBUSB_ENDPOINT_IN = 0x80;
3543
/**
3644
* @hidden
3745
*/

0 commit comments

Comments
 (0)