From b5a101561045b4a01f495c1eb4dcba92e642cf82 Mon Sep 17 00:00:00 2001 From: cTn Date: Sun, 8 Jun 2014 20:10:07 +0200 Subject: [PATCH] DFU detection and port UI DFU option injection --- js/port_handler.js | 23 ++++++++++++++++++++--- js/serial_backend.js | 2 +- js/stm32dfu.js | 5 +++++ tabs/firmware_flasher.js | 6 +++++- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/js/port_handler.js b/js/port_handler.js index e1efa5ce..6432baa3 100644 --- a/js/port_handler.js +++ b/js/port_handler.js @@ -131,10 +131,27 @@ port_handler.prototype.check = function() { self.initial_ports = current_ports; } - self.main_timeout_reference = setTimeout(function() { - self.check(); - }, 250); + check_usb_devices(); }); + + function check_usb_devices() { + chrome.usb.getDevices(usbDevices.STM32DFU, function(result) { + if (result.length) { + if (!$("div#port-picker .port select [value='DFU']").length) { + $('div#port-picker .port select').append(''); + $('div#port-picker .port select').val('DFU'); + } + } else { + if ($("div#port-picker .port select [value='DFU']").length) { + $("div#port-picker .port select [value='DFU']").remove(); + } + } + + self.main_timeout_reference = setTimeout(function() { + self.check(); + }, 250); + }); + } }; port_handler.prototype.update_port_select = function(ports) { diff --git a/js/serial_backend.js b/js/serial_backend.js index f03d96a0..ab49181f 100644 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -10,7 +10,7 @@ $(document).ready(function() { var selected_port = String($('div#port-picker .port select').val()); var selected_baud = parseInt($('div#port-picker #baud').val()); - if (selected_port != '0') { + if (selected_port != '0' && selected_port != 'DFU') { if (!clicks) { console.log('Connecting to: ' + selected_port); GUI.connecting_to = selected_port; diff --git a/js/stm32dfu.js b/js/stm32dfu.js index 97a1fafb..ce2c7e89 100644 --- a/js/stm32dfu.js +++ b/js/stm32dfu.js @@ -55,6 +55,11 @@ var STM32DFU_protocol = function() { }; }; +STM32DFU_protocol.prototype.connect = function(hex) { + var self = this; + self.hex = hex; +}; + STM32DFU_protocol.prototype.openDevice = function(callback) { }; diff --git a/tabs/firmware_flasher.js b/tabs/firmware_flasher.js index a14012f8..923acebc 100644 --- a/tabs/firmware_flasher.js +++ b/tabs/firmware_flasher.js @@ -103,7 +103,11 @@ function tab_initialize_firmware_flasher() { if (!$(this).hasClass('locked')) { if (!GUI.connect_lock) { // button disabled while flashing is in progress if (parsed_hex != false) { - STM32.connect(parsed_hex); + if (String($('div#port-picker .port select').val()) != 'DFU') { + STM32.connect(parsed_hex); + } else { + STM32DFU.connect(parsed_hex); + } } else { STM32.GUI_status(chrome.i18n.getMessage('firmwareFlasherFirmwareNotLoaded')); }