From 49ad949bea332b8214a35d67d6c09277a812f40b Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Tue, 22 Sep 2020 01:19:39 +0200 Subject: [PATCH] Unlock DFU using FC boot button after #2169 --- src/js/port_handler.js | 197 +++++++++++++++++++++-------------------- 1 file changed, 103 insertions(+), 94 deletions(-) diff --git a/src/js/port_handler.js b/src/js/port_handler.js index d1232cd0..b4e590bb 100644 --- a/src/js/port_handler.js +++ b/src/js/port_handler.js @@ -1,6 +1,6 @@ 'use strict'; -const TIMEOUT_CHECK = 250 ; // With 250 it seems that it produces a memory leak and slowdown in some versions, reason unknown +const TIMEOUT_CHECK = 500 ; // With 250 it seems that it produces a memory leak and slowdown in some versions, reason unknown const usbDevices = { filters: [ {'vendorId': 1155, 'productId': 57105}, @@ -15,7 +15,6 @@ const PortHandler = new function () { }; PortHandler.initialize = function () { - this.portPickerElement = $('div#port-picker #port'); // start listening, check after TIMEOUT_CHECK ms @@ -23,111 +22,31 @@ PortHandler.initialize = function () { }; PortHandler.check = function () { - const self = this; - if (!GUI.connect_lock) { - self.check_serial_devices(); - } else { - self.check_usb_devices(); - } + + self.check_usb_devices(); + self.check_serial_devices(); + GUI.updateManualPortVisibility(); setTimeout(function () { self.check(); }, TIMEOUT_CHECK); - }; PortHandler.check_serial_devices = function () { const self = this; - // disable Exit DFU Mode button - if (self.dfu_available){ - if (!$('option:selected', self.portPickerElement).data().isDFU) { - self.portPickerElement.trigger('change'); - self.dfu_available = false; - } - } - serial.getDevices(function(currentPorts) { - // auto-select last used port (only during initialization) + + // auto-select port (only during initialization) if (!self.initialPorts) { currentPorts = self.updatePortSelect(currentPorts); - self.detectPort(currentPorts); + self.selectPort(currentPorts); self.initialPorts = currentPorts; - } else if (self.array_difference(self.initialPorts, currentPorts).length > 0) { - // port got removed - const removedPorts = self.array_difference(self.initialPorts, currentPorts); - if (removedPorts.length > 0) { - console.log(`PortHandler - Removed: ${JSON.stringify(removedPorts)}`); - // disconnect "UI" - routine can't fire during atmega32u4 reboot procedure !!! - if (GUI.connected_to) { - for (let i = 0; i < removedPorts.length; i++) { - if (removedPorts[i] === GUI.connected_to) { - $('div#header_btns a.connect').click(); - } - } - } - // trigger callbacks (only after initialization) - for (let i = (self.port_removed_callbacks.length - 1); i >= 0; i--) { - const obj = self.port_removed_callbacks[i]; - - // remove timeout - clearTimeout(obj.timer); - - // trigger callback - obj.code(removedPorts); - - // remove object from array - const index = self.port_removed_callbacks.indexOf(obj); - if (index > -1) { - self.port_removed_callbacks.splice(index, 1); - } - } - for (let i = 0; i < removedPorts.length; i++) { - self.initialPorts.splice(self.initialPorts.indexOf(removedPorts[i]), 1); - } - self.initialPorts = false; - } } else { - // new port detected - const newPorts = self.array_difference(currentPorts, self.initialPorts); - if (typeof newPorts.length !== 'undefined') { - if (newPorts.length > 0) { - currentPorts = self.updatePortSelect(currentPorts); - console.log(`PortHandler - Found: ${JSON.stringify(newPorts)}`); - // select / highlight new port, if connected -> select connected port - if (GUI.connected_to) { - self.portPickerElement.val(GUI.connected_to); - } else if (newPorts.length === 1) { - self.portPickerElement.val(newPorts[0].path); - } else if (newPorts.length > 1) { - self.detectPort(currentPorts); - } else if (GUI.active_tab !== 'firmware_flasher' && GUI.auto_connect && !GUI.connecting_to) { - // start connect procedure. We need firmware flasher protection over here - GUI.timeout_add('auto-connect_timeout', function () { - $('div#header_btns a.connect').click(); - }, 100); // timeout so bus have time to initialize after being detected by the system - } - // trigger callbacks - for (let i = (self.port_detected_callbacks.length - 1); i >= 0; i--) { - const obj = self.port_detected_callbacks[i]; - - // remove timeout - clearTimeout(obj.timer); - - // trigger callback - obj.code(newPorts); - - // remove object from array - const index = self.port_detected_callbacks.indexOf(obj); - if (index > -1) { - self.port_detected_callbacks.splice(index, 1); - } - } - self.initialPorts = currentPorts; - } - } + self.removePort(currentPorts); + self.detectPort(currentPorts); } }); }; @@ -152,6 +71,12 @@ PortHandler.check_usb_devices = function (callback) { text: usbText, data: {isDFU: true}, })); + + self.portPickerElement.append($('