Skip to content

Commit

Permalink
Merge pull request #2066 from iNavFlight/abo_cli_filesave_name_fix
Browse files Browse the repository at this point in the history
Fix CLI diff file name generation
DzikuVx authored May 10, 2024
2 parents 30765ae + 37172a9 commit 7224309
Showing 2 changed files with 28 additions and 23 deletions.
22 changes: 11 additions & 11 deletions js/helpers.js
Original file line number Diff line number Diff line change
@@ -24,17 +24,17 @@ function zeroPad(value, width) {
return value;
}

function generateFilename(prefix, suffix) {
function generateFilename(config, prefix, suffix) {
var date = new Date();
var filename = prefix;

if (CONFIG) {
if (CONFIG.flightControllerIdentifier) {
filename = CONFIG.flightControllerIdentifier + '_' + CONFIG.flightControllerVersion + "_" + filename;
if (config) {
if (config.flightControllerIdentifier) {
filename = config.flightControllerIdentifier + '_' + config.flightControllerVersion + "_" + filename;
}
if (CONFIG.name && CONFIG.name.trim() !== '') {
filename = filename + '_' + CONFIG.name.trim().replace(' ', '_');

if (config.name && config.name.trim() !== '') {
filename = filename + '_' + config.name.trim().replace(' ', '_');
}
}

@@ -65,7 +65,7 @@ function distanceOnLine(start, end, distance)
var px = start[0] + vx * (mag + distance);
var py = start[1] + vy * (mag + distance);

return [px, py];
return [px, py];
}

function wrap_360(angle)
@@ -77,7 +77,7 @@ function wrap_360(angle)
return angle;
}

function rad2Deg(rad)
function rad2Deg(rad)
{
return rad * (180 / Math.PI);
}
@@ -92,8 +92,8 @@ function calculate_new_cooridatnes(coord, bearing, distance)
var lat = deg2Rad(coord.lat);
var lon = deg2Rad(coord.lon);
bearing = deg2Rad(bearing);
var delta = distance / 637100000; // Earth radius in cm
var delta = distance / 637100000; // Earth radius in cm

var latNew = Math.asin(Math.sin(lat) * Math.cos(delta) + Math.cos(lat) * Math.sin(delta) * Math.cos(bearing));
var lonNew = lon + Math.atan2(Math.sin(bearing) * Math.sin(delta) * Math.cos(lat), Math.cos(delta) - Math.sin(lat) * Math.sin(lat));
return {
29 changes: 17 additions & 12 deletions tabs/cli.js
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ const CliAutoComplete = require('./../js/CliAutoComplete');
const { ConnectionType } = require('./../js/connection/connection');
const jBox = require('./../js/libraries/jBox/jBox.min');
const mspDeduplicationQueue = require('./../js/msp/mspDeduplicationQueue');
const FC = require('./../js/fc');
const { generateFilename } = require('./../js/helpers');

TABS.cli = {
lineDelayMs: 50,
@@ -82,7 +84,7 @@ function copyToClipboard(text) {
function onCopyFailed(ex) {
console.warn(ex);
}

navigator.clipboard.writeText(text)
.then(onCopySuccessful, onCopyFailed);
}
@@ -115,8 +117,8 @@ TABS.cli.initialize = function (callback) {
self.history.add(out_string.trim());

var outputArray = out_string.split("\n");
return outputArray.reduce((p, line, index) =>
p.then((delay) =>
return outputArray.reduce((p, line, index) =>
p.then((delay) =>
new Promise((resolve) => {
timeout.add('CLI_send_slowly', () => {
let processingDelay = TABS.cli.lineDelayMs;
@@ -160,19 +162,22 @@ TABS.cli.initialize = function (callback) {
});

$('.tab-cli .save').on('click', function () {

var prefix = 'cli';
var suffix = 'txt';
var filename = generateFilename(FC.CONFIG, prefix, suffix);
var options = {
filters: [
{ name: 'CLI', extensions: ['cli'] } ,
{ name: 'TXT', extensions: ['txt'] }
defaultPath: filename,
filters: [
{ name: suffix.toUpperCase(), extensions: [suffix] },
{ name: prefix.toUpperCase(), extensions: [prefix] }
],
};
dialog.showSaveDialog(options).then(result => {
if (result.canceled) {
GUI.log(i18n.getMessage('cliSaveToFileAborted'));
return;
}

fs.writeFile(result.filePath, self.outputHistory, (err) => {
if (err) {
GUI.log(i18n.getMessage('ErrorWritingFile'));
@@ -219,7 +224,7 @@ TABS.cli.initialize = function (callback) {

$('.tab-cli .load').on('click', function () {
var options = {
filters: [
filters: [
{ name: 'CLI/TXT', extensions: ['cli', 'txt'] },
{ name: 'ALL', extensions: ['*'] }
],
@@ -353,14 +358,14 @@ TABS.cli.initialize = function (callback) {

if (CONFIGURATOR.connection.type == ConnectionType.BLE) {
let delay = CONFIGURATOR.connection.deviceDescription.delay;
if (delay > 0) {
if (delay > 0) {
timeout.add('cli_delay', () => {
self.send(getCliCommand("cli_delay " + delay + '\n', TABS.cli.cliBuffer));
self.send(getCliCommand('# ' + i18n.getMessage('connectionBleCliEnter') + '\n', TABS.cli.cliBuffer));
}, 400);
}
}
}

GUI.content_ready(callback);
});
};

0 comments on commit 7224309

Please sign in to comment.