diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 08e8541f2f..b2823c7631 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -112,10 +112,26 @@ "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" + }, + "eeprom_saved_ok": { "message": "EEPROM saved" }, + "default_optional_permissions_head": { + "message": "Optional USB Permissions" + }, + "default_optional_permissions_text": { + "message": "Due to addition of Naze32PRO to the supported hardware family, Configurator requires USB access to allow firmware flashing via DFU" + }, + "default_request_optional_permissions": { + "message": "Request Optional Permissions" + }, "defaultWelcomeText": { "message": "This application is a configuration utility for baseflight, a 32 bit fork of the popular open source RC flight control firmware project MultiWii.

Application supports hardware that run Baseflight exclusively (acro naze, naze, afromini)

Official Resellers & Backers
AbuseMark - International (Japan)
Multirotor Superstore - International (United States)

The firmware source code can be downloaded from here
The newest binary firmware image is available here
" }, diff --git a/js/gui.js b/js/gui.js index 0933c3e6db..cdf00f0618 100644 --- a/js/gui.js +++ b/js/gui.js @@ -4,6 +4,7 @@ var GUI_control = function() { this.connected_to = false; this.active_tab; this.operating_system; + this.optional_usb_permissions = false; // controlled by usb permissions code this.interval_array = []; this.timeout_array = []; diff --git a/js/stm32dfu.js b/js/stm32dfu.js index dc4a73682f..97a1fafb01 100644 --- a/js/stm32dfu.js +++ b/js/stm32dfu.js @@ -53,12 +53,6 @@ var STM32DFU_protocol = function() { dfuUPLOAD_IDLE: 9, // The device is processing an upload operation. Expecting DFU_UPLOAD requests. dfuERROR: 10 // An error has occurred. Awaiting the DFU_CLRSTATUS request. }; - - this.usbDevices = { - F3DiscoveryDFU: {'vendorId': 1155, 'productId': 57105} - }; - - this.usbPermissions = {permissions: [{'usbDevices': [this.usbDevices.F3DiscoveryDFU]}]}; }; STM32DFU_protocol.prototype.openDevice = function(callback) { diff --git a/js/usb.js b/js/usb.js new file mode 100644 index 0000000000..1134658ae4 --- /dev/null +++ b/js/usb.js @@ -0,0 +1,32 @@ +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 59373e691a..5be08ecebd 100644 --- a/main.html +++ b/main.html @@ -25,6 +25,7 @@ + diff --git a/tabs/default.css b/tabs/default.css index 0aea6ddb75..259ed23d62 100644 --- a/tabs/default.css +++ b/tabs/default.css @@ -8,6 +8,45 @@ width: calc(40% - 10px); } +.tab-default .optional_permissions { + display: none; + + margin-bottom: 10px; + + border: 1px solid silver; +} + .tab-default .optional_permissions .title { + line-height: 20px; + + text-align: center; + font-weight: bold; + color: white; + + border-bottom: 1px solid silver; + background-color: #cd4c4c; + } + .tab-default .optional_permissions p { + padding: 5px; + } + .tab-default .optional_permissions a { + display: block; + float: left; + + height: 28px; + line-height: 28px; + + margin: 0 0 5px 5px; + padding: 0 15px 0 15px; + + text-align: center; + font-weight: bold; + + border: 1px solid silver; + background-color: #ececec; + } + .tab-default .optional_permissions a:hover { + background-color: #dedcdc; + } .welcome { margin-bottom: 10px; diff --git a/tabs/default.html b/tabs/default.html index 616dc8db4b..548425c275 100644 --- a/tabs/default.html +++ b/tabs/default.html @@ -1,5 +1,12 @@
+
+
+

+

+ +
+