Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CLI diff file name generation #2066

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ', '_');
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -77,7 +77,7 @@ function wrap_360(angle)
return angle;
}

function rad2Deg(rad)
function rad2Deg(rad)
{
return rad * (180 / Math.PI);
}
Expand All @@ -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 {
Expand Down
30 changes: 18 additions & 12 deletions tabs/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ 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 { zeroPad } = require('./../js/helpers');
DzikuVx marked this conversation as resolved.
Show resolved Hide resolved
const FC = require('./../js/fc');
const { generateFilename } = require('./../js/helpers');

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

navigator.clipboard.writeText(text)
.then(onCopySuccessful, onCopyFailed);
}
Expand Down Expand Up @@ -115,8 +118,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;
Expand Down Expand Up @@ -160,19 +163,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'));
Expand Down Expand Up @@ -219,7 +225,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: ['*'] }
],
Expand Down Expand Up @@ -353,14 +359,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);
});
};
Expand Down
Loading