From f4abe5530806901384ae9bdee5c6cbc71c54c18d Mon Sep 17 00:00:00 2001 From: danybd <34835503+danybd@users.noreply.github.com> Date: Sun, 14 Mar 2021 14:55:27 +0100 Subject: [PATCH] cordova_serial.requestPermission() driver fix 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 add CP2102 and other CP210x single port devices into usb device filter --- cordova/usb_device_filter.xml | 1 + src/js/cordova_chromeapi.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cordova/usb_device_filter.xml b/cordova/usb_device_filter.xml index f14a3b86..ebb5f515 100644 --- a/cordova/usb_device_filter.xml +++ b/cordova/usb_device_filter.xml @@ -1,4 +1,5 @@ + diff --git a/src/js/cordova_chromeapi.js b/src/js/cordova_chromeapi.js index 4b7a1d65..26585545 100644 --- a/src/js/cordova_chromeapi.js +++ b/src/js/cordova_chromeapi.js @@ -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; @@ -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) {