Skip to content

Commit

Permalink
Merge pull request #2258 from Scavanger/Failsafe-icon-&-auto-mode-sel…
Browse files Browse the repository at this point in the history
…ection

... Various minor bugfixes
  • Loading branch information
mmosca authored Nov 21, 2024
2 parents cf3efb8 + d07144a commit b2396e6
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 51 deletions.
9 changes: 4 additions & 5 deletions js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion js/geozoneCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let GeozoneCollection = function() {
let self = {},
data = [],
maxVertices = 126,
maxZones = 62;
maxZones = 63;

self.getMaxVertices = () => {
return maxVertices;
Expand Down
2 changes: 1 addition & 1 deletion js/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
Expand Down
6 changes: 3 additions & 3 deletions js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion js/sitl.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ var SITLProcess = {
});

} else {
alert(GUI.operating_system);
GUI.alert(GUI.operating_system);
return;
}

Expand Down
1 change: 1 addition & 0 deletions tabs/auxiliary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions tabs/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 19 additions & 14 deletions tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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
file_name = 'inav.hex'; // default suggested filename of locally saved file
fileName = "inav.hex";

GUI.load(path.join(__dirname, "firmware_flasher.html"), function () {
// translate to user-selected language
Expand Down Expand Up @@ -451,7 +451,6 @@ TABS.firmware_flasher.initialize = function (callback) {
$('div.release_info .date').text(summary.date);
$('div.release_info .status').text(summary.status);
$('div.release_info .file').text(summary.file).prop('href', summary.url);
file_name = summary.file;

var formattedNotes = marked.parse(summary.notes);
$('div.release_info .notes').html(formattedNotes);
Expand All @@ -476,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();
Expand Down Expand Up @@ -540,19 +540,24 @@ TABS.firmware_flasher.initialize = function (callback) {
}
});

$(document).on('click', 'span.progressLabel a.save_firmware', async function () {
const result = await dialog.showSaveDialog({
defaultPath: file_name,
$(document).on('click', 'span.progressLabel a.save_firmware', function () {
var options = {
defaultPath: fileName,
filters: [ {name: "HEX File", extensions: ['hex'] } ]
};
dialog.showSaveDialog(options).then(result => {
if (result.canceled) {
return;
}
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'));
});

try {
fs.writeFileSync(result.filePath, intel_hex);
GUI.log('Saved firmware to: ' + result.filePath);
}
catch(e) {
console.error(e);
GUI.log('Failed to save the file !');
}
});


Expand Down
41 changes: 20 additions & 21 deletions tabs/mission_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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'] } ]
};
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand All @@ -3439,27 +3438,25 @@ 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);
});
}
});

$('#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);
Expand All @@ -3474,8 +3471,10 @@ TABS.mission_control.initialize = function (callback) {
];
selectedGeozone.setVertices(vertices);
};
}
}
selectedGeozone.setShape($(event.currentTarget).val());
renderGeozonesOnMap();
updateGeozoneInfo();
}
});

Expand Down Expand Up @@ -3620,7 +3619,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();
Expand All @@ -3638,7 +3637,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) {
Expand Down Expand Up @@ -3677,7 +3676,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'] } ]
};
Expand Down Expand Up @@ -3706,7 +3705,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'));
Expand All @@ -3725,7 +3724,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'));
Expand Down Expand Up @@ -3909,7 +3908,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 {
Expand Down Expand Up @@ -4029,10 +4028,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);
}

/////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions tabs/pid_tuning.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,15 @@ 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();
}
});

$('.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'));
Expand Down
2 changes: 1 addition & 1 deletion tabs/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down

0 comments on commit b2396e6

Please sign in to comment.