Comparing version 0.0.5 to 0.0.6
@@ -5,4 +5,6 @@ { | ||
"no-bitwise": 0, | ||
"max-len": "warn" | ||
"max-len": "warn", | ||
"no-restricted-syntax": 0, | ||
"no-await-in-loop": 0 | ||
} | ||
} |
101
index.js
@@ -22,6 +22,69 @@ /* | ||
class cp2102 extends EventEmitter { | ||
constructor(vendorId, productId, opts) { | ||
constructor(vendorId, productId, opts, setup) { | ||
super(); | ||
this.device = usb.findByIds(vendorId, productId); | ||
this.opts = opts; | ||
const dataBits = this.opts.dataBits || 8; | ||
let stopBits; | ||
if (this.opts.stopBits === 1 || this.opts.stopBits == null) { | ||
stopBits = 0x0000; | ||
} else { | ||
stopBits = 0x0002; | ||
} | ||
let parity; | ||
switch (this.opts.parity) { | ||
case 'even': | ||
parity = 0x0020; | ||
break; | ||
case 'odd': | ||
parity = 0x0010; | ||
break; | ||
case 'none': | ||
default: | ||
parity = 0x0000; | ||
} | ||
this.setup = setup || [{ | ||
transfer: { | ||
requestType: 'vendor', | ||
recipient: 'device', | ||
request: 0x00, | ||
index: 0x00, | ||
value: 0x01, | ||
}, | ||
data: undefined, | ||
}, | ||
{ | ||
transfer: { | ||
requestType: 'vendor', | ||
recipient: 'device', | ||
request: 0x07, | ||
index: 0x00, | ||
value: 0x03 | 0x0100 | 0x0200, | ||
}, | ||
data: undefined, | ||
}, | ||
{ | ||
transfer: { | ||
requestType: 'vendor', | ||
recipient: 'device', | ||
request: 0x01, | ||
index: 0x00, | ||
value: 0x384000 / this.opts.baudRate, | ||
}, | ||
data: undefined, | ||
}, | ||
{ | ||
transfer: { | ||
requestType: 'vendor', | ||
recipient: 'device', | ||
request: 0x03, | ||
index: 0x00, | ||
value: (dataBits << 8) | parity | stopBits, | ||
}, | ||
data: undefined, | ||
}]; | ||
this.device.open(false); // don't auto-configure | ||
@@ -33,5 +96,8 @@ const self = this; | ||
self.iface.claim(); | ||
self.inEndpoint = self.iface.endpoint(0x81); | ||
self.inEndpoint.startPoll(); | ||
self.inEndpoint = self.iface.endpoint(opts.inEndpointAddress || 0x81); | ||
if (opts.transfers != null && opts.wordLength != null) { | ||
self.inEndpoint.startPoll(opts.transfers, opts.wordLength); | ||
} else { | ||
self.inEndpoint.startPoll(); | ||
} | ||
self.inEndpoint.on('data', (data) => { | ||
@@ -43,29 +109,8 @@ self.emit('data', data); | ||
try { | ||
await this.controlTransferOut({ | ||
requestType: 'vendor', | ||
recipient: 'device', | ||
request: 0x00, | ||
index: 0x00, | ||
value: 0x01, | ||
}); | ||
await this.controlTransferOut({ | ||
requestType: 'vendor', | ||
recipient: 'device', | ||
request: 0x07, | ||
index: 0x00, | ||
value: 0x03 | 0x0100 | 0x0200, | ||
}); | ||
await this.controlTransferOut({ | ||
requestType: 'vendor', | ||
recipient: 'device', | ||
request: 0x01, | ||
index: 0x00, | ||
value: 0x384000 / this.opts.baudRate, | ||
}); | ||
for (const parameter of self.setup) { | ||
await this.controlTransferOut(parameter.transfer, parameter.data); | ||
} | ||
} catch (err) { | ||
console.log('Error during CP2102 setup:', err); | ||
} | ||
self.emit('ready'); | ||
@@ -72,0 +117,0 @@ })(); |
{ | ||
"name": "cp2102", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Silicon Labs CP2102 user-space USB to serial driver", | ||
@@ -27,3 +27,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"usb": "1.6.5" | ||
"usb": "1.6.3" | ||
}, | ||
@@ -30,0 +30,0 @@ "devDependencies": { |
@@ -32,2 +32,2 @@ # CP2102 | ||
Thanks to [Seiya Nuta](https://github.com/seiyanuta) who posted a WebUSB version as a [GitHub gist](https://gist.github.com/seiyanuta/2c70ba8855f50c536a51f0c5993c1e4c). | ||
Thanks to [Seiya Nuta](https://github.com/nuta) who posted a WebUSB version as a [GitHub gist](https://gist.github.com/nuta/2c70ba8855f50c536a51f0c5993c1e4c). |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
85795
7
2276
1