From a32e0f018bedcef331f6388587fa64c453767d60 Mon Sep 17 00:00:00 2001 From: Scavanger Date: Tue, 19 Nov 2024 21:40:10 -0300 Subject: [PATCH 1/6] More fixes --- js/fc.js | 9 ++++----- js/periodicStatusUpdater.js | 6 ++++++ tabs/auxiliary.js | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/js/fc.js b/js/fc.js index 28d50c268..a5aaf55cd 100644 --- a/js/fc.js +++ b/js/fc.js @@ -974,12 +974,11 @@ var FC = { }, getModeId: function (name) { - let mode = FLIGHT_MODES.find( mode => mode.boxName === name ); - if (mode) { - return mode.boxId; - } else { - return -1; + for (var i = 0; i < FC.AUX_CONFIG.length; i++) { + if (FC.AUX_CONFIG[i] == name) + return i; } + return -1; }, isModeBitSet: function (i) { return BitHelper.bit_check(this.CONFIG.mode[Math.trunc(i / 32)], i % 32); diff --git a/js/periodicStatusUpdater.js b/js/periodicStatusUpdater.js index b4c13289b..7a33fe15f 100644 --- a/js/periodicStatusUpdater.js +++ b/js/periodicStatusUpdater.js @@ -40,6 +40,12 @@ const mspQueue = require('./serial_queue'); var active = ((Date.now() - MSP.analog_last_received_timestamp) < publicScope.getUpdateInterval(CONFIGURATOR.connection.bitrate) * 3); + if (FC.AUX_CONFIG.length == 0) { + MSP.send_message(MSPCodes.MSP_BOXIDS, false, false, function () { + FC.generateAuxConfig(); + }); + } + if (FC.isModeEnabled('ARM')) $(".armedicon").css({ 'background-image': 'url("./images/icons/cf_icon_armed_active.svg")' diff --git a/tabs/auxiliary.js b/tabs/auxiliary.js index 4f29f4ae5..aa87ac8a2 100644 --- a/tabs/auxiliary.js +++ b/tabs/auxiliary.js @@ -464,6 +464,7 @@ TABS.auxiliary.initialize = function (callback) { function auto_select_channel(RC_channels, activeChannels, RSSI_channel) { const auto_option = $('.tab-auxiliary select.channel option[value="-1"]:selected'); if (auto_option.length === 0) { + prevChannelsValues = null; return; } From 6567aaf4396e266fe8d85c2ca4610da445e19a3c Mon Sep 17 00:00:00 2001 From: Scavanger Date: Wed, 20 Nov 2024 01:15:05 -0300 Subject: [PATCH 2/6] More... --- js/periodicStatusUpdater.js | 6 ------ js/serial_backend.js | 5 +++++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/js/periodicStatusUpdater.js b/js/periodicStatusUpdater.js index 7a33fe15f..b4c13289b 100644 --- a/js/periodicStatusUpdater.js +++ b/js/periodicStatusUpdater.js @@ -40,12 +40,6 @@ const mspQueue = require('./serial_queue'); var active = ((Date.now() - MSP.analog_last_received_timestamp) < publicScope.getUpdateInterval(CONFIGURATOR.connection.bitrate) * 3); - if (FC.AUX_CONFIG.length == 0) { - MSP.send_message(MSPCodes.MSP_BOXIDS, false, false, function () { - FC.generateAuxConfig(); - }); - } - if (FC.isModeEnabled('ARM')) $(".armedicon").css({ 'background-image': 'url("./images/icons/cf_icon_armed_active.svg")' diff --git a/js/serial_backend.js b/js/serial_backend.js index 1ff809dc1..e73022b49 100755 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -453,6 +453,11 @@ var SerialBackend = (function () { $('.mode-disconnected').hide(); $('.mode-connected').show(); + + MSP.send_message(MSPCodes.MSP_BOXIDS, false, false, function () { + FC.generateAuxConfig(); + }); + MSP.send_message(MSPCodes.MSP_DATAFLASH_SUMMARY, false, false, function () { $('#sensor-status').show(); $('#portsinput').hide(); From 324d700afab3ec83e69d60d0bae830dc974d8e9f Mon Sep 17 00:00:00 2001 From: Scavanger Date: Wed, 20 Nov 2024 03:06:44 -0300 Subject: [PATCH 3/6] Fix "save downloaded firmware" --- tabs/cli.js | 4 +-- tabs/firmware_flasher.js | 55 ++++++++++++---------------------------- tabs/mission_control.js | 6 ++--- 3 files changed, 21 insertions(+), 44 deletions(-) diff --git a/tabs/cli.js b/tabs/cli.js index 4bdf95e6c..c50ff0b67 100644 --- a/tabs/cli.js +++ b/tabs/cli.js @@ -182,9 +182,9 @@ TABS.cli.initialize = function (callback) { if (err) { GUI.log(i18n.getMessage('ErrorWritingFile')); return console.error(err); - } - GUI.log(i18n.getMessage('FileSaved')); + } }); + GUI.log(i18n.getMessage('FileSaved')); }).catch (err => { console.log(err); diff --git a/tabs/firmware_flasher.js b/tabs/firmware_flasher.js index c95746d5f..6369417ec 100755 --- a/tabs/firmware_flasher.js +++ b/tabs/firmware_flasher.js @@ -32,7 +32,8 @@ TABS.firmware_flasher.initialize = function (callback) { } var intel_hex = false, // standard intel hex in string format - parsed_hex = false; // parsed raw hex in array format + parsed_hex = false, // parsed raw hex in array format + fileName = "inav.hex"; GUI.load(path.join(__dirname, "firmware_flasher.html"), function () { // translate to user-selected language @@ -474,6 +475,7 @@ TABS.firmware_flasher.initialize = function (callback) { var summary = $('select[name="firmware_version"] option:selected').data('summary'); if (summary) { // undefined while list is loading or while running offline + fileName = summary.file; $(".load_remote_file").text(i18n.getMessage('firmwareFlasherButtonLoading')).addClass('disabled'); $.get(summary.url, function (data) { enable_load_online_button(); @@ -539,47 +541,22 @@ TABS.firmware_flasher.initialize = function (callback) { }); $(document).on('click', 'span.progressLabel a.save_firmware', function () { - chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'inav', accepts: [{extensions: ['hex']}]}, function (fileEntry) { - if (chrome.runtime.lastError) { - console.error(chrome.runtime.lastError.message); + var options = { + defaultPath: fileName, + filters: [ {name: "Intel-Hex", extensions: ['hex'] } ] + }; + dialog.showSaveDialog(options).then(result => { + if (result.canceled) { return; } - - chrome.fileSystem.getDisplayPath(fileEntry, function (path) { - console.log('Saving firmware to: ' + path); - - // check if file is writable - chrome.fileSystem.isWritableEntry(fileEntry, function (isWritable) { - if (isWritable) { - var blob = new Blob([intel_hex], {type: 'text/plain'}); - - fileEntry.createWriter(function (writer) { - var truncated = false; - - writer.onerror = function (e) { - console.error(e); - }; - - writer.onwriteend = function() { - if (!truncated) { - // onwriteend will be fired again when truncation is finished - truncated = true; - writer.truncate(blob.size); - - return; - } - }; - - writer.write(blob); - }, function (e) { - console.error(e); - }); - } else { - console.log('You don\'t have write permissions for this file, sorry.'); - GUI.log(i18n.getMessage('writePermissionsForFile')); - } - }); + fs.writeFileSync(result.filePath, intel_hex, (err) => { + if (err) { + GUI.log(i18n.getMessage('ErrorWritingFile')); + return console.error(err); + } }); + let sFilename = String(result.filePath.split('\\').pop().split('/').pop()); + GUI.log(sFilename + i18n.getMessage('savedSuccessfully')); }); }); diff --git a/tabs/mission_control.js b/tabs/mission_control.js index 0fce8675e..353588577 100644 --- a/tabs/mission_control.js +++ b/tabs/mission_control.js @@ -4029,10 +4029,10 @@ TABS.mission_control.initialize = function (callback) { GUI.log(i18n.getMessage('ErrorWritingFile')); return console.error(err); } - let sFilename = String(filename.split('\\').pop().split('/').pop()); - GUI.log(sFilename + i18n.getMessage('savedSuccessfully')); - updateFilename(sFilename); }); + let sFilename = String(filename.split('\\').pop().split('/').pop()); + GUI.log(sFilename + i18n.getMessage('savedSuccessfully')); + updateFilename(sFilename); } ///////////////////////////////////////////// From 6af70e96dd9687e4840364471555ee8850d4aa0f Mon Sep 17 00:00:00 2001 From: Scavanger Date: Wed, 20 Nov 2024 10:58:10 -0300 Subject: [PATCH 4/6] Fix: Input field lost focus after confirm() and alert() --- js/gui.js | 2 +- js/sitl.js | 2 +- tabs/mission_control.js | 14 +++++++------- tabs/pid_tuning.js | 4 ++-- tabs/setup.js | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/js/gui.js b/js/gui.js index 4010ddf11..361e3f680 100644 --- a/js/gui.js +++ b/js/gui.js @@ -542,7 +542,7 @@ GUI_control.prototype.update_dataflash_global = function () { }; /** -* Don't use alert() in Electron, it has a nasty bug: https://github.com/electron/electron/issues/31917 +* Don't use alert() or confirm() in Electron, it has a nasty bug: https://github.com/electron/electron/issues/31917 */ GUI_control.prototype.alert = function(message) { dialog.showMessageBoxSync({ message: message, icon: "./images/inav_icon_128.png" }); diff --git a/js/sitl.js b/js/sitl.js index 2575e2f7b..2d0c2e2a1 100644 --- a/js/sitl.js +++ b/js/sitl.js @@ -156,7 +156,7 @@ var SITLProcess = { }); } else { - alert(GUI.operating_system); + GUI.alert(GUI.operating_system); return; } diff --git a/tabs/mission_control.js b/tabs/mission_control.js index 353588577..2cf10b9b5 100644 --- a/tabs/mission_control.js +++ b/tabs/mission_control.js @@ -1343,7 +1343,7 @@ TABS.mission_control.initialize = function (callback) { function fileLoadMultiMissionCheck() { if (singleMissionActive()) { return true; - } else if (confirm(i18n.getMessage('confirm_overwrite_multimission_file_load_option'))) { + } else if (GUI.confirm(i18n.getMessage('confirm_overwrite_multimission_file_load_option'))) { var options = { filters: [ { name: "Mission file", extensions: ['mission'] } ] }; @@ -3620,7 +3620,7 @@ TABS.mission_control.initialize = function (callback) { // Callback for Remove buttons ///////////////////////////////////////////// $('#removeAllPoints').on('click', function () { - if (markers.length && confirm(i18n.getMessage('confirm_delete_all_points'))) { + if (markers.length && GUI.confirm(i18n.getMessage('confirm_delete_all_points'))) { if (removeAllMultiMissionCheck()) { removeAllWaypoints(); updateMultimissionState(); @@ -3638,7 +3638,7 @@ TABS.mission_control.initialize = function (callback) { GUI.alert(i18n.getMessage('MissionPlannerJumpTargetRemoval')); } else if (mission.getAttachedFromWaypoint(selectedMarker) && mission.getAttachedFromWaypoint(selectedMarker).length != 0) { - if (confirm(i18n.getMessage('confirm_delete_point_with_options'))) { + if (GUI.confirm(i18n.getMessage('confirm_delete_point_with_options'))) { mission.getAttachedFromWaypoint(selectedMarker).forEach(function (element) { if (element.getAction() == MWNP.WPTYPE.LAND) { @@ -3677,7 +3677,7 @@ TABS.mission_control.initialize = function (callback) { $('#loadFileMissionButton').on('click', function () { if (!fileLoadMultiMissionCheck()) return; - if (markers.length && !confirm(i18n.getMessage('confirm_delete_all_points'))) return; + if (markers.length && !GUI.confirm(i18n.getMessage('confirm_delete_all_points'))) return; var options = { filters: [ { name: "Mission file", extensions: ['mission'] } ] }; @@ -3706,7 +3706,7 @@ TABS.mission_control.initialize = function (callback) { $('#loadMissionButton').on('click', function () { let message = multimissionCount ? 'confirm_overwrite_multimission_file_load_option' : 'confirm_delete_all_points'; - if ((markers.length || multimissionCount) && !confirm(i18n.getMessage(message))) return; + if ((markers.length || multimissionCount) && !GUI.confirm(i18n.getMessage(message))) return; removeAllWaypoints(); $(this).addClass('disabled'); GUI.log(i18n.getMessage('startGetPoint')); @@ -3725,7 +3725,7 @@ TABS.mission_control.initialize = function (callback) { $('#loadEepromMissionButton').on('click', function () { let message = multimissionCount ? 'confirm_overwrite_multimission_file_load_option' : 'confirm_delete_all_points'; - if ((markers.length || multimissionCount) && !confirm(i18n.getMessage(message))) return; + if ((markers.length || multimissionCount) && !GUI.confirm(i18n.getMessage(message))) return; removeAllWaypoints(); $(this).addClass('disabled'); GUI.log(i18n.getMessage('startGetPoint')); @@ -3909,7 +3909,7 @@ TABS.mission_control.initialize = function (callback) { } if (missionEndFlagCount > 1) { - if (multimissionCount && !confirm(i18n.getMessage('confirm_multimission_file_load'))) { + if (multimissionCount && !GUI.confirm(i18n.getMessage('confirm_multimission_file_load'))) { mission.flush(); return; } else { diff --git a/tabs/pid_tuning.js b/tabs/pid_tuning.js index 0d218eafc..196e017cd 100644 --- a/tabs/pid_tuning.js +++ b/tabs/pid_tuning.js @@ -299,7 +299,7 @@ TABS.pid_tuning.initialize = function (callback) { $('.action-resetPIDs').on('click', function() { - if (confirm(i18n.getMessage('confirm_reset_pid'))) { + if (GUI.confirm(i18n.getMessage('confirm_reset_pid'))) { MSP.send_message(MSPCodes.MSP_SET_RESET_CURR_PID, false, false, false); GUI.updateActivatedTab(); } @@ -307,7 +307,7 @@ TABS.pid_tuning.initialize = function (callback) { $('.action-resetDefaults').on('click', function() { - if (confirm(i18n.getMessage('confirm_select_defaults'))) { + if (GUI.confirm(i18n.getMessage('confirm_select_defaults'))) { mspHelper.setSetting("applied_defaults", 0, function() { mspHelper.saveToEeprom( function () { GUI.log(i18n.getMessage('configurationEepromSaved')); diff --git a/tabs/setup.js b/tabs/setup.js index e2e1f642a..d0e6e6009 100755 --- a/tabs/setup.js +++ b/tabs/setup.js @@ -71,7 +71,7 @@ TABS.setup.initialize = function (callback) { self.initializeInstruments(); $('a.resetSettings').on('click', function () { - if (confirm(i18n.getMessage('confirm_reset_settings'))) { + if (GUI.confirm(i18n.getMessage('confirm_reset_settings'))) { MSP.send_message(MSPCodes.MSP_RESET_CONF, false, false, function () { GUI.log(i18n.getMessage('initialSetupSettingsRestored')); From 5019b1285f432926d667ddfb19333bf8e1604b7b Mon Sep 17 00:00:00 2001 From: Scavanger Date: Wed, 20 Nov 2024 18:33:48 -0300 Subject: [PATCH 5/6] Max Geozones / Vertices --- tabs/mission_control.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tabs/mission_control.js b/tabs/mission_control.js index 2cf10b9b5..4b23809b9 100644 --- a/tabs/mission_control.js +++ b/tabs/mission_control.js @@ -1002,7 +1002,7 @@ TABS.mission_control.initialize = function (callback) { return; } - if (FC.GEOZONES.getUsedVerticesCount() + 2 > FC.GEOZONES.getMaxVertices()) {FC. + if (FC.GEOZONES.getUsedVerticesCount() + 2 > FC.GEOZONES.getMaxVertices()) { GUI.alert(i18n.getMessage('missionGeozoneMaxVerticesReached')); return; } @@ -2585,7 +2585,7 @@ TABS.mission_control.initialize = function (callback) { } else if (selectedFeature && tempMarker.kind == "geozoneline" && tempMarker.selection) { - if (FC.GEOZONES.getUsedVerticesCount() + 1 >= FC.GEOZONES.getMaxVertices()) { + if (FC.GEOZONES.getUsedVerticesCount() + 1 > FC.GEOZONES.getMaxVertices()) { GUI.alert(i18n.getMessage('missionGeozoneMaxVerticesReached')); return; } @@ -3450,16 +3450,15 @@ TABS.mission_control.initialize = function (callback) { $('#geozoneShape').on('change', event => { if (selectedGeozone) { - selectedGeozone.setShape($(event.currentTarget).val()); - if ($(event.currentTarget).val() == GeozoneShapes.CIRCULAR) { $('#geozoneRadius').prop('disabled', false); let tmpVertex = selectedGeozone.getFirstVertex(); selectedGeozone.resetVertices(); selectedGeozone.setVertices([tmpVertex]); } else { - if (FC.GEOZONES.getUsedVerticesCount() + 3 > FC.GEOZONES.getMaxVertices()) { + if (FC.GEOZONES.getUsedVerticesCount() + 2 > FC.GEOZONES.getMaxVertices()) { GUI.alert(i18n.getMessage('missionGeozoneMaxVerticesReached')); + renderGeozoneOptions(); return; } $('#geozoneRadius').prop('disabled', true); @@ -3474,7 +3473,8 @@ TABS.mission_control.initialize = function (callback) { ]; selectedGeozone.setVertices(vertices); }; - } + } + selectedGeozone.setShape($(event.currentTarget).val()); renderGeozonesOnMap(); } }); From d07144a55b06fad42e0d864b5a3efd2c6172294b Mon Sep 17 00:00:00 2001 From: Scavanger Date: Wed, 20 Nov 2024 22:59:30 -0300 Subject: [PATCH 6/6] Save geozones correctly --- js/geozoneCollection.js | 2 +- js/msp/MSPHelper.js | 6 +++--- tabs/mission_control.js | 9 ++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/js/geozoneCollection.js b/js/geozoneCollection.js index 1754b966b..77fbe0860 100644 --- a/js/geozoneCollection.js +++ b/js/geozoneCollection.js @@ -7,7 +7,7 @@ let GeozoneCollection = function() { let self = {}, data = [], maxVertices = 126, - maxZones = 62; + maxZones = 63; self.getMaxVertices = () => { return maxVertices; diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index 67a50ceb5..78cf30590 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -3163,7 +3163,7 @@ var mspHelper = (function () { nextGeozone(); return; } - if (vertexID < FC.GEOZONES.at(geozoneID).getVerticesCount() - 1 && zone.getShape() == GeozoneShapes.POLYGON) { + if (vertexID < FC.GEOZONES.at(geozoneID).getVerticesCount() && zone.getShape() == GeozoneShapes.POLYGON) { MSP.send_message(MSPCodes.MSP2_INAV_GEOZONE_VERTEX, [geozoneID, vertexID], false, nextVertex); } else { MSP.send_message(MSPCodes.MSP2_INAV_GEOZONE_VERTEX, [geozoneID, vertexID], false, nextGeozone); @@ -3173,7 +3173,7 @@ var mspHelper = (function () { function nextGeozone() { geozoneID++; vertexID = -1; - if (geozoneID < FC.GEOZONES.getMaxZones() - 1) { + if (geozoneID < FC.GEOZONES.getMaxZones()) { MSP.send_message(MSPCodes.MSP2_INAV_GEOZONE, [geozoneID], false, nextVertex); } else { MSP.send_message(MSPCodes.MSP2_INAV_GEOZONE, [geozoneID], false, callback); @@ -3204,7 +3204,7 @@ var mspHelper = (function () { function nextGeozone() { geozoneID++; vertexID = -1; - if (geozoneID < FC.GEOZONES.getMaxZones() - 1) { + if (geozoneID < FC.GEOZONES.getMaxZones()) { MSP.send_message(MSPCodes.MSP2_INAV_SET_GEOZONE, FC.GEOZONES.extractBufferZone(geozoneID), false, nextVertex); } else { MSP.send_message(MSPCodes.MSP2_INAV_SET_GEOZONE, FC.GEOZONES.extractBufferZone(geozoneID), false, callback); diff --git a/tabs/mission_control.js b/tabs/mission_control.js index 4b23809b9..2161416c7 100644 --- a/tabs/mission_control.js +++ b/tabs/mission_control.js @@ -3414,8 +3414,7 @@ TABS.mission_control.initialize = function (callback) { $('#loadEepromGeozoneButton').on('click', event => { $(event.currentTarget).addClass('disabled'); GUI.log('Start of getting Geozones'); - mspHelper.loadGeozones(); - setTimeout( () => { + mspHelper.loadGeozones(() => { if (FC.GEOZONES.geozoneCount() >= 1) { selectedGeozone = FC.GEOZONES.first(); } else { @@ -3439,12 +3438,11 @@ TABS.mission_control.initialize = function (callback) { if (GUI.confirm(i18n.getMessage("missionGeozoneReboot"))) { $(event.currentTarget).addClass('disabled'); GUI.log('Start of sending Geozones'); - mspHelper.saveGeozones(); - setTimeout(() => { + mspHelper.saveGeozones(() => { mspHelper.saveToEeprom(); GUI.log('End of sending Geozones'); reboot(); - }, 1000); + }); } }); @@ -3476,6 +3474,7 @@ TABS.mission_control.initialize = function (callback) { } selectedGeozone.setShape($(event.currentTarget).val()); renderGeozonesOnMap(); + updateGeozoneInfo(); } });