1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-13 11:29:53 +03:00

Convert to CommonJS Modules

This commit is contained in:
Andi Kanzler 2024-02-26 11:58:56 -03:00
parent 7df8253099
commit 91f1699659
100 changed files with 9685 additions and 3735 deletions

View file

@ -7,6 +7,12 @@
*/
'use strict';
const CONFIGURATOR = require('./../data_storage');
const { GUI } = require('./../gui');
const interval = require('./../intervals');
const { usbDevices, PortHandler } = require('./../port_handler');
const ConnectionSerial = require('./../connection/connectionSerial');
var STM32_protocol = function () {
this.baud;
this.options = {};
@ -81,7 +87,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
self.initialize();
} else {
GUI.log(localization.getMessage('failedToOpenSerialPort'));
GUI.log(i18n.getMessage('failedToOpenSerialPort'));
}
});
} else {
@ -108,7 +114,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
retries++;
if (retries > maxRetries) {
clearInterval(interval);
GUI.log(localization.getMessage('failedToFlash') + port);
GUI.log(i18n.getMessage('failedToFlash') + port);
}
}
// Check for DFU devices
@ -145,7 +151,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
});
});
} else {
GUI.log(localization.getMessage('failedToOpenSerialPort'));
GUI.log(i18n.getMessage('failedToOpenSerialPort'));
}
});
}
@ -170,11 +176,11 @@ STM32_protocol.prototype.initialize = function () {
// lock some UI elements TODO needs rework
$('select[name="release"]').prop('disabled', true);
CONFIGURATOR.connection.onReceive.addListener(function (info) {
CONFIGURATOR.connection.addOnReceiveCallback(function (info) {
self.read(info);
});
helper.interval.add('STM32_timeout', function () {
interval.add('STM32_timeout', function () {
if (self.upload_process_alive) { // process is running
self.upload_process_alive = false;
} else {
@ -185,7 +191,7 @@ STM32_protocol.prototype.initialize = function () {
// protocol got stuck, clear timer and disconnect
helper.interval.remove('STM32_timeout');
interval.remove('STM32_timeout');
// exit
self.upload_procedure(99);
@ -380,10 +386,10 @@ STM32_protocol.prototype.upload_procedure = function (step) {
$('span.progressLabel').text('Contacting bootloader ...');
var send_counter = 0;
helper.interval.add('stm32_initialize_mcu', function () { // 200 ms interval (just in case mcu was already initialized), we need to break the 2 bytes command requirement
interval.add('stm32_initialize_mcu', function () { // 200 ms interval (just in case mcu was already initialized), we need to break the 2 bytes command requirement
self.send([0x7F], 1, function (reply) {
if (reply[0] == 0x7F || reply[0] == self.status.ACK || reply[0] == self.status.NACK) {
helper.interval.remove('stm32_initialize_mcu');
interval.remove('stm32_initialize_mcu');
console.log('STM32 - Serial interface initialized on the MCU side');
// proceed to next step
@ -392,7 +398,7 @@ STM32_protocol.prototype.upload_procedure = function (step) {
$('span.progressLabel').text('Communication with bootloader failed');
self.progress_bar_e.addClass('invalid');
helper.interval.remove('stm32_initialize_mcu');
interval.remove('stm32_initialize_mcu');
// disconnect
self.upload_procedure(99);
@ -406,8 +412,8 @@ STM32_protocol.prototype.upload_procedure = function (step) {
$('span.progressLabel').text('No response from the bootloader, programming: FAILED');
self.progress_bar_e.addClass('invalid');
helper.interval.remove('stm32_initialize_mcu');
helper.interval.remove('STM32_timeout');
interval.remove('stm32_initialize_mcu');
interval.remove('STM32_timeout');
// exit
self.upload_procedure(99);
@ -766,7 +772,7 @@ STM32_protocol.prototype.upload_procedure = function (step) {
break;
case 99:
// disconnect
helper.interval.remove('STM32_timeout'); // stop STM32 timeout timer (everything is finished now)
interval.remove('STM32_timeout'); // stop STM32 timeout timer (everything is finished now)
// close connection
CONFIGURATOR.connection.disconnect(function (result) {
@ -790,3 +796,5 @@ STM32_protocol.prototype.upload_procedure = function (step) {
// initialize object
var STM32 = new STM32_protocol();
module.exports = STM32;