mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-16 04:45:18 +03:00
DFU: Add additional error checks, enabled GUI connect lock while flashing
This commit is contained in:
parent
b2ec904d5a
commit
1a20b317dd
3 changed files with 58 additions and 6 deletions
|
@ -128,6 +128,22 @@
|
|||
"message": "<span style=\"color: red\">Failed</span> to close serial port"
|
||||
},
|
||||
|
||||
"usbDeviceOpened": {
|
||||
"message": "USB device <span style=\"color: green\">successfully</span> opened with ID: $1"
|
||||
},
|
||||
"usbDeviceOpenFail": {
|
||||
"message": "<span style=\"color: red\">Failed</span> to open USB device!"
|
||||
},
|
||||
"usbDeviceClosed": {
|
||||
"message": "USB device <span style=\"color: green\">successfully</span> closed"
|
||||
},
|
||||
"usbDeviceCloseFail": {
|
||||
"message": "<span style=\"color: red\">Failed</span> to close USB device"
|
||||
},
|
||||
"usbDeviceUdevNotice": {
|
||||
"message": "Are <strong>udev rules</strong> installed correctly? See docs for instructions"
|
||||
},
|
||||
|
||||
"noConfigurationReceived": {
|
||||
"message": "No configuration received within <span style=\"color: red\">10 seconds</span>, communication <span style=\"color: red\">failed</span>"
|
||||
},
|
||||
|
@ -193,6 +209,9 @@
|
|||
"dfu_connect_message": {
|
||||
"message": "Please use the Firmware Flasher to access DFU devices"
|
||||
},
|
||||
"dfu_erased_kilobytes": {
|
||||
"message": "Erased $1 kB of flash <span style=\"color: green\">successfully</span>"
|
||||
},
|
||||
|
||||
"eeprom_saved_ok": {
|
||||
"message": "EEPROM <span style=\"color: green\">saved</span>"
|
||||
|
|
|
@ -106,7 +106,6 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
|
|||
// refresh device list
|
||||
PortHandler.check_usb_devices(function(dfu_available) {
|
||||
if(dfu_available) {
|
||||
GUI.connect_lock = false;
|
||||
STM32DFU.connect(usbDevices.STM32DFU, hex, options);
|
||||
} else {
|
||||
serial.connect(port, {bitrate: self.baud, parityBit: 'even', stopBits: 'one'}, function (openInfo) {
|
||||
|
|
|
@ -102,12 +102,35 @@ STM32DFU_protocol.prototype.connect = function (device, hex, options, callback)
|
|||
});
|
||||
};
|
||||
|
||||
STM32DFU_protocol.prototype.checkChromeError = function() {
|
||||
if (chrome.runtime.lastError) {
|
||||
if(chrome.runtime.lastError.message)
|
||||
console.log(chrome.runtime.lastError.message);
|
||||
else
|
||||
console.log(chrome.runtime.lastError);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
STM32DFU_protocol.prototype.openDevice = function (device) {
|
||||
var self = this;
|
||||
|
||||
chrome.usb.openDevice(device, function (handle) {
|
||||
if(self.checkChromeError()) {
|
||||
console.log('Failed to open USB device!');
|
||||
GUI.log(chrome.i18n.getMessage('usbDeviceOpenFail'));
|
||||
if(GUI.operating_system === 'Linux') {
|
||||
GUI.log(chrome.i18n.getMessage('usbDeviceUdevNotice'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
self.handle = handle;
|
||||
|
||||
GUI.log(chrome.i18n.getMessage('usbDeviceOpened', handle.handle.toString()));
|
||||
console.log('Device opened with Handle ID: ' + handle.handle);
|
||||
self.claimInterface(0);
|
||||
});
|
||||
|
@ -117,6 +140,12 @@ STM32DFU_protocol.prototype.closeDevice = function () {
|
|||
var self = this;
|
||||
|
||||
chrome.usb.closeDevice(this.handle, function closed() {
|
||||
if(self.checkChromeError()) {
|
||||
console.log('Failed to close USB device!');
|
||||
GUI.log(chrome.i18n.getMessage('usbDeviceCloseFail'));
|
||||
}
|
||||
|
||||
GUI.log(chrome.i18n.getMessage('usbDeviceClosed'));
|
||||
console.log('Device closed with Handle ID: ' + self.handle.handle);
|
||||
|
||||
self.handle = null;
|
||||
|
@ -152,6 +181,8 @@ STM32DFU_protocol.prototype.resetDevice = function (callback) {
|
|||
};
|
||||
|
||||
STM32DFU_protocol.prototype.controlTransfer = function (direction, request, value, _interface, length, data, callback) {
|
||||
var self = this;
|
||||
|
||||
if (direction == 'in') {
|
||||
// data is ignored
|
||||
chrome.usb.controlTransfer(this.handle, {
|
||||
|
@ -163,11 +194,8 @@ STM32DFU_protocol.prototype.controlTransfer = function (direction, request, valu
|
|||
'index': _interface,
|
||||
'length': length
|
||||
}, function (result) {
|
||||
if (chrome.runtime.lastError) {
|
||||
if(chrome.runtime.lastError.message)
|
||||
console.log(chrome.runtime.lastError.message);
|
||||
else
|
||||
console.log(chrome.runtime.lastError);
|
||||
if(self.checkChromeError()) {
|
||||
console.log('USB transfer failed!');
|
||||
}
|
||||
if (result.resultCode) console.log(result.resultCode);
|
||||
|
||||
|
@ -193,6 +221,9 @@ STM32DFU_protocol.prototype.controlTransfer = function (direction, request, valu
|
|||
'index': _interface,
|
||||
'data': arrayBuf
|
||||
}, function (result) {
|
||||
if(self.checkChromeError()) {
|
||||
console.log('USB transfer failed!');
|
||||
}
|
||||
if (result.resultCode) console.log(result.resultCode);
|
||||
|
||||
callback(result);
|
||||
|
@ -331,6 +362,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
|
||||
if(page == erase_pages_n) {
|
||||
console.log("Erase: complete");
|
||||
GUI.log(chrome.i18n.getMessage('dfu_erased_kilobytes', (erase_pages_n * self.page_size / 1024).toString()));
|
||||
self.upload_procedure(4);
|
||||
}
|
||||
else
|
||||
|
@ -541,6 +573,8 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
// cleanup
|
||||
self.releaseInterface(0);
|
||||
|
||||
GUI.connect_lock = false;
|
||||
|
||||
var timeSpent = new Date().getTime() - self.upload_time_start;
|
||||
|
||||
console.log('Script finished after: ' + (timeSpent / 1000) + ' seconds');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue