|
|
@ -100,25 +100,45 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
|
|
|
|
serial.send(bufferOut, function () {
|
|
|
|
serial.send(bufferOut, function () {
|
|
|
|
serial.disconnect(function (result) {
|
|
|
|
serial.disconnect(function (result) {
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
// delay to allow board to boot in bootloader mode
|
|
|
|
var intervalMs = 200;
|
|
|
|
// required to detect if a DFU device appears
|
|
|
|
var retries = 0;
|
|
|
|
setTimeout(function() {
|
|
|
|
var maxRetries = 50; // timeout after intervalMs * 50
|
|
|
|
// refresh device list
|
|
|
|
var interval = setInterval(function() {
|
|
|
|
|
|
|
|
var tryFailed = function() {
|
|
|
|
|
|
|
|
retries++;
|
|
|
|
|
|
|
|
if (retries > maxRetries) {
|
|
|
|
|
|
|
|
clearInterval(interval);
|
|
|
|
|
|
|
|
GUI.log('<span style="color: red">Failed</span> to flash ' + port);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for DFU devices
|
|
|
|
PortHandler.check_usb_devices(function(dfu_available) {
|
|
|
|
PortHandler.check_usb_devices(function(dfu_available) {
|
|
|
|
if(dfu_available) {
|
|
|
|
if (dfu_available) {
|
|
|
|
|
|
|
|
clearInterval(interval);
|
|
|
|
STM32DFU.connect(usbDevices.STM32DFU, hex, options);
|
|
|
|
STM32DFU.connect(usbDevices.STM32DFU, hex, options);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
serial.connect(port, {bitrate: self.baud, parityBit: 'even', stopBits: 'one'}, function (openInfo) {
|
|
|
|
|
|
|
|
if (openInfo) {
|
|
|
|
|
|
|
|
self.initialize();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
GUI.connect_lock = false;
|
|
|
|
|
|
|
|
GUI.log('<span style="color: red">Failed</span> to open serial port');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for the serial port
|
|
|
|
|
|
|
|
serial.getDevices(function(devices) {
|
|
|
|
|
|
|
|
if (devices && devices.includes(port)) {
|
|
|
|
|
|
|
|
// Serial port might briefly reappear on DFU devices while
|
|
|
|
|
|
|
|
// the FC is rebooting, so we don't clear the interval
|
|
|
|
|
|
|
|
// until we succesfully connect.
|
|
|
|
|
|
|
|
serial.connect(port, {bitrate: self.baud, parityBit: 'even', stopBits: 'one'}, function (openInfo) {
|
|
|
|
|
|
|
|
if (openInfo) {
|
|
|
|
|
|
|
|
clearInterval(interval);
|
|
|
|
|
|
|
|
self.initialize();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
GUI.connect_lock = false;
|
|
|
|
|
|
|
|
tryFailed();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tryFailed();
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, 1000);
|
|
|
|
}, intervalMs);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
GUI.connect_lock = false;
|
|
|
|
GUI.connect_lock = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|