Skip to content

Commit

Permalink
cordova_serial.requestPermission() driver fix
Browse files Browse the repository at this point in the history
Fight controller based on silabs CP2104 was not working as function call cordova_serial.requestPermission() without specify the driver parameter uses the default driver "CdcAcmSerialDriver" which is the wrong when usb-uart chip is a CP2104. This chip requires the driver "Cp21xxSerialDriver"

fix code smells

fix the automatically reported code smells

'CdcAcmSerialDriver' as default driver

In order to not rely on the fallback driver in the driver library define 'CdcAcmSerialDriver' explicit locally

Co-authored-by: haslinghuis <[email protected]>

add CP2102 and other CP210x single port devices into usb device filter
  • Loading branch information
danybd authored and mikeller committed Jun 16, 2021
1 parent 898a6b9 commit f4abe55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions cordova/usb_device_filter.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="1155" product-id="22336" /> <!--STMicroelectronics / Virtual COM Port -->
<usb-device vendor-id="4292" product-id="60000" /> <!--CP2102 and other CP210x single port devices -->
</resources>
9 changes: 8 additions & 1 deletion src/js/cordova_chromeapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ const chromeapiSerial = {
stopBits: 'one',
ctsFlowControl: false,
},
getDriver: function(vid, pid) {
if (vid === 4292 && pid === 60000) {
return 'Cp21xxSerialDriver'; //for Silabs CP2102 and all other CP210x
} else {
return 'CdcAcmSerialDriver';
}
},
setConnectionOptions: function(ConnectionOptions) {
if (ConnectionOptions.persistent) {
this.connection.persistent = ConnectionOptions.persistent;
Expand Down Expand Up @@ -158,7 +165,7 @@ const chromeapiSerial = {
const vid = parseInt(pathSplit[0]);
const pid = parseInt(pathSplit[1]);
console.log(`${self.logHeader}request permission (vid=${vid} / pid=${pid})`);
cordova_serial.requestPermission({vid: vid, pid: pid}, function() {
cordova_serial.requestPermission({vid: vid, pid: pid, driver: self.getDriver(vid, pid)}, function() {
const options = self.getCordovaSerialConnectionOptions();
cordova_serial.open(options, function () {
cordova_serial.registerReadCallback(function (data) {
Expand Down

0 comments on commit f4abe55

Please sign in to comment.