diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 8c14b6d2..3325fb7d 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -190,11 +190,8 @@ "message": "Cycle Time:" }, - "please_grant_usb_permissions": { - "message": "Please click on \"Request Optional Permissions\" button to grant application required USB access" - }, - "usb_permissions_granted": { - "message": "Optional USB permissions granted" + "dfu_connect_message": { + "message": "Please use the Firmware Flasher to access DFU devices" }, "eeprom_saved_ok": { diff --git a/js/gui.js b/js/gui.js index 0f21ed35..bf7c142b 100644 --- a/js/gui.js +++ b/js/gui.js @@ -10,7 +10,6 @@ var GUI_control = function () { this.active_tab; this.tab_switch_in_progress = false; this.operating_system; - this.optional_usb_permissions = false; // controlled by usb permissions code this.interval_array = []; this.timeout_array = []; this.defaultAllowedTabsWhenDisconnected = [ diff --git a/js/port_handler.js b/js/port_handler.js index 88e022b3..6a053cad 100755 --- a/js/port_handler.js +++ b/js/port_handler.js @@ -1,9 +1,14 @@ 'use strict'; +var usbDevices = { + STM32DFU: {'vendorId': 1155, 'productId': 57105} +}; + var PortHandler = new function () { this.initial_ports = false; this.port_detected_callbacks = []; this.port_removed_callbacks = []; + this.dfu_available = false; }; PortHandler.initialize = function () { @@ -131,30 +136,32 @@ PortHandler.check = function () { self.initial_ports = current_ports; } - if (GUI.optional_usb_permissions) { - check_usb_devices(); - } + self.check_usb_devices(); GUI.updateManualPortVisibility(); setTimeout(function () { self.check(); }, 250); }); +}; - function check_usb_devices() { - chrome.usb.getDevices(usbDevices.STM32DFU, function (result) { - if (result.length) { - if (!$("div#port-picker #port [value='DFU']").length) { - $('div#port-picker #port').append(''); - $('div#port-picker #port').val('DFU'); - } - } else { - if ($("div#port-picker #port [value='DFU']").length) { - $("div#port-picker #port [value='DFU']").remove(); - } +PortHandler.check_usb_devices = function (callback) { + chrome.usb.getDevices(usbDevices.STM32DFU, function (result) { + if (result.length) { + if (!$("div#port-picker #port [value='DFU']").length) { + $('div#port-picker #port').append($('', {value: "DFU", text: "DFU", data: {isDFU: true}})); + $('div#port-picker #port').val('DFU'); } - }); - } + self.dfu_available = true; + } else { + if ($("div#port-picker #port [value='DFU']").length) { + $("div#port-picker #port [value='DFU']").remove(); + } + self.dfu_available = false; + } + + if(callback) callback(self.dfu_available); + }); }; PortHandler.update_port_select = function (ports) { diff --git a/js/protocols/stm32.js b/js/protocols/stm32.js index 4777b756..951ac57f 100644 --- a/js/protocols/stm32.js +++ b/js/protocols/stm32.js @@ -103,19 +103,22 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback) // delay to allow board to boot in bootloader mode // required to detect if a DFU device appears setTimeout(function() { - if($("div#port-picker #port [value='DFU']").length) { - GUI.connect_lock = false; - STM32DFU.connect(usbDevices.STM32DFU, hex); - } else { - serial.connect(port, {bitrate: self.baud, parityBit: 'even', stopBits: 'one'}, function (openInfo) { - if (openInfo) { - self.initialize(); - } else { - GUI.connect_lock = false; - GUI.log('Failed to open serial port'); - } - }); - } + // refresh device list + PortHandler.check_usb_devices(function(dfu_available) { + if(dfu_available) { + GUI.connect_lock = false; + STM32DFU.connect(usbDevices.STM32DFU, hex); + } else { + serial.connect(port, {bitrate: self.baud, parityBit: 'even', stopBits: 'one'}, function (openInfo) { + if (openInfo) { + self.initialize(); + } else { + GUI.connect_lock = false; + GUI.log('Failed to open serial port'); + } + }); + } + }); }, 1000); } else { GUI.connect_lock = false; diff --git a/js/serial_backend.js b/js/serial_backend.js index cc0d1e33..28e95866 100755 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -3,12 +3,19 @@ $(document).ready(function () { GUI.updateManualPortVisibility = function(){ - if ($('div#port-picker #port option:selected').data().isManual) { + var selected_port = $('div#port-picker #port option:selected'); + if (selected_port.data().isManual) { $('#port-override-option').show(); } else { $('#port-override-option').hide(); } + if (selected_port.data().isDFU) { + $('select#baud').hide(); + } + else { + $('select#baud').show(); + } }; GUI.updateManualPortVisibility(); @@ -33,8 +40,10 @@ $(document).ready(function () { var selected_port = $('div#port-picker #port option:selected').data().isManual ? $('#port-override').val() : String($('div#port-picker #port').val()); - - if (selected_port != '0' && selected_port != 'DFU') { + if (selected_port === 'DFU') { + GUI.log(chrome.i18n.getMessage('dfu_connect_message')); + } + else if (selected_port != '0') { if (!clicks) { console.log('Connecting to: ' + selected_port); GUI.connecting_to = selected_port; diff --git a/js/usb.js b/js/usb.js deleted file mode 100644 index 4833cce4..00000000 --- a/js/usb.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -var usbDevices = { - STM32DFU: {'vendorId': 1155, 'productId': 57105} -}; -var usbPermissions = {permissions: [{'usbDevices': [usbDevices.STM32DFU]}]}; - -function check_usb_permissions(callback) { - chrome.permissions.contains(usbPermissions, function (result) { - if (result) { - GUI.optional_usb_permissions = true; - } else { - console.log('Optional USB permissions: missing'); - GUI.log(chrome.i18n.getMessage('please_grant_usb_permissions')); - - // display optional usb permissions request box - $('div.optional_permissions').show(); - - // UI hooks - document.getElementById("requestOptionalPermissions").addEventListener('click', function () { - chrome.permissions.request(usbPermissions, function (result) { - if (result) { - GUI.log(chrome.i18n.getMessage('usb_permissions_granted')); - $('div.optional_permissions').hide(); - - GUI.optional_usb_permissions = true; - } - }); - }); - } - - if (callback) { - callback(); - } - }); -} \ No newline at end of file diff --git a/main.html b/main.html index fb9bc4b4..93d2cc0b 100755 --- a/main.html +++ b/main.html @@ -44,7 +44,6 @@ - diff --git a/manifest.json b/manifest.json index 3051e9bd..3d84fc91 100644 --- a/manifest.json +++ b/manifest.json @@ -32,10 +32,7 @@ "fileSystem.write", "fileSystem.retainEntries", "notifications", - "alwaysOnTopWindows" - ], - - "optional_permissions": [ + "alwaysOnTopWindows", {"usbDevices": [ {"vendorId": 1155, "productId": 57105} ]} diff --git a/tabs/landing.html b/tabs/landing.html index 6184c4b6..1c1a45b6 100644 --- a/tabs/landing.html +++ b/tabs/landing.html @@ -1,11 +1,4 @@