DFU: Make permissions compulsary, make DFU detection more robust
parent
88a59f05c9
commit
d89e9682c2
|
@ -190,11 +190,8 @@
|
|||
"message": "Cycle Time:"
|
||||
},
|
||||
|
||||
"please_grant_usb_permissions": {
|
||||
"message": "Please click on <strong>\"Request Optional Permissions\"</strong> button to grant application <strong style=\"color: red\">required</strong> <strong>USB</strong> access"
|
||||
},
|
||||
"usb_permissions_granted": {
|
||||
"message": "Optional <strong>USB</strong> permissions <strong style=\"color: green\">granted</strong>"
|
||||
"dfu_connect_message": {
|
||||
"message": "Please use the Firmware Flasher to access DFU devices"
|
||||
},
|
||||
|
||||
"eeprom_saved_ok": {
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -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() {
|
||||
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('<option value="DFU">DFU</option>');
|
||||
$('div#port-picker #port').append($('<option/>', {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) {
|
||||
|
|
|
@ -103,7 +103,9 @@ 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) {
|
||||
// refresh device list
|
||||
PortHandler.check_usb_devices(function(dfu_available) {
|
||||
if(dfu_available) {
|
||||
GUI.connect_lock = false;
|
||||
STM32DFU.connect(usbDevices.STM32DFU, hex);
|
||||
} else {
|
||||
|
@ -116,6 +118,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
|
|||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
} else {
|
||||
GUI.connect_lock = false;
|
||||
|
|
|
@ -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;
|
||||
|
|
36
js/usb.js
36
js/usb.js
|
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
|
@ -44,7 +44,6 @@
|
|||
<script type="text/javascript" src="./js/port_handler.js"></script>
|
||||
<script type="text/javascript" src="./js/port_usage.js"></script>
|
||||
<script type="text/javascript" src="./js/serial.js"></script>
|
||||
<script type="text/javascript" src="./js/usb.js"></script>
|
||||
<script type="text/javascript" src="./js/gui.js"></script>
|
||||
<script type="text/javascript" src="./js/model.js"></script>
|
||||
<script type="text/javascript" src="./js/request_balancer.js"></script>
|
||||
|
|
|
@ -32,10 +32,7 @@
|
|||
"fileSystem.write",
|
||||
"fileSystem.retainEntries",
|
||||
"notifications",
|
||||
"alwaysOnTopWindows"
|
||||
],
|
||||
|
||||
"optional_permissions": [
|
||||
"alwaysOnTopWindows",
|
||||
{"usbDevices": [
|
||||
{"vendorId": 1155, "productId": 57105}
|
||||
]}
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<div class="tab-landing">
|
||||
<div class="section optional_permissions">
|
||||
<div class="title" i18n="default_optional_permissions_head"></div>
|
||||
<p i18n="default_optional_permissions_text"></p>
|
||||
<a id="requestOptionalPermissions" href="#" i18n="default_request_optional_permissions"></a>
|
||||
<div class="clear-both"></div>
|
||||
</div>
|
||||
|
||||
<div class="row welcome_and_sponsors">
|
||||
<div class="left">
|
||||
<div class="section welcome">
|
||||
|
|
|
@ -10,8 +10,6 @@ TABS.landing.initialize = function (callback) {
|
|||
}
|
||||
|
||||
$('#content').load("./tabs/landing.html", function () {
|
||||
check_usb_permissions(); // check for permissions require for USB DFU support
|
||||
|
||||
// translate to user-selected language
|
||||
localize();
|
||||
|
||||
|
|
Loading…
Reference in New Issue