1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-16 04:45:18 +03:00

cli filename fix

This commit is contained in:
breadoven 2024-05-10 09:09:06 +01:00
parent 30765ae731
commit 1f3c55b075
2 changed files with 47 additions and 18 deletions

View file

@ -24,7 +24,7 @@ function zeroPad(value, width) {
return value; return value;
} }
function generateFilename(prefix, suffix) { function generateFilename(prefix, suffix) { // TODO, code used directly in cli.js instead
var date = new Date(); var date = new Date();
var filename = prefix; var filename = prefix;
@ -32,7 +32,7 @@ function generateFilename(prefix, suffix) {
if (CONFIG.flightControllerIdentifier) { if (CONFIG.flightControllerIdentifier) {
filename = CONFIG.flightControllerIdentifier + '_' + CONFIG.flightControllerVersion + "_" + filename; filename = CONFIG.flightControllerIdentifier + '_' + CONFIG.flightControllerVersion + "_" + filename;
} }
if (CONFIG.name && CONFIG.name.trim() !== '') { if (CONFIG.name && CONFIG.name.trim() !== '') {
filename = filename + '_' + CONFIG.name.trim().replace(' ', '_'); filename = filename + '_' + CONFIG.name.trim().replace(' ', '_');
} }
@ -65,7 +65,7 @@ function distanceOnLine(start, end, distance)
var px = start[0] + vx * (mag + distance); var px = start[0] + vx * (mag + distance);
var py = start[1] + vy * (mag + distance); var py = start[1] + vy * (mag + distance);
return [px, py]; return [px, py];
} }
function wrap_360(angle) function wrap_360(angle)
@ -77,7 +77,7 @@ function wrap_360(angle)
return angle; return angle;
} }
function rad2Deg(rad) function rad2Deg(rad)
{ {
return rad * (180 / Math.PI); return rad * (180 / Math.PI);
} }
@ -92,8 +92,8 @@ function calculate_new_cooridatnes(coord, bearing, distance)
var lat = deg2Rad(coord.lat); var lat = deg2Rad(coord.lat);
var lon = deg2Rad(coord.lon); var lon = deg2Rad(coord.lon);
bearing = deg2Rad(bearing); 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 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)); var lonNew = lon + Math.atan2(Math.sin(bearing) * Math.sin(delta) * Math.cos(lat), Math.cos(delta) - Math.sin(lat) * Math.sin(lat));
return { return {

View file

@ -15,6 +15,8 @@ const CliAutoComplete = require('./../js/CliAutoComplete');
const { ConnectionType } = require('./../js/connection/connection'); const { ConnectionType } = require('./../js/connection/connection');
const jBox = require('./../js/libraries/jBox/jBox.min'); const jBox = require('./../js/libraries/jBox/jBox.min');
const mspDeduplicationQueue = require('./../js/msp/mspDeduplicationQueue'); const mspDeduplicationQueue = require('./../js/msp/mspDeduplicationQueue');
const { zeroPad } = require('./../js/helpers');
const FC = require('./../js/fc');
TABS.cli = { TABS.cli = {
lineDelayMs: 50, lineDelayMs: 50,
@ -82,7 +84,7 @@ function copyToClipboard(text) {
function onCopyFailed(ex) { function onCopyFailed(ex) {
console.warn(ex); console.warn(ex);
} }
navigator.clipboard.writeText(text) navigator.clipboard.writeText(text)
.then(onCopySuccessful, onCopyFailed); .then(onCopySuccessful, onCopyFailed);
} }
@ -115,8 +117,8 @@ TABS.cli.initialize = function (callback) {
self.history.add(out_string.trim()); self.history.add(out_string.trim());
var outputArray = out_string.split("\n"); var outputArray = out_string.split("\n");
return outputArray.reduce((p, line, index) => return outputArray.reduce((p, line, index) =>
p.then((delay) => p.then((delay) =>
new Promise((resolve) => { new Promise((resolve) => {
timeout.add('CLI_send_slowly', () => { timeout.add('CLI_send_slowly', () => {
let processingDelay = TABS.cli.lineDelayMs; let processingDelay = TABS.cli.lineDelayMs;
@ -160,11 +162,14 @@ TABS.cli.initialize = function (callback) {
}); });
$('.tab-cli .save').on('click', function () { $('.tab-cli .save').on('click', function () {
var prefix = 'cli';
var suffix = 'txt';
var filename = generateFilename(prefix, suffix);
var options = { var options = {
filters: [ defaultPath: filename,
{ name: 'CLI', extensions: ['cli'] } , filters: [
{ name: 'TXT', extensions: ['txt'] } { name: suffix.toUpperCase(), extensions: [suffix] },
{ name: prefix.toUpperCase(), extensions: [prefix] }
], ],
}; };
dialog.showSaveDialog(options).then(result => { dialog.showSaveDialog(options).then(result => {
@ -172,7 +177,7 @@ TABS.cli.initialize = function (callback) {
GUI.log(i18n.getMessage('cliSaveToFileAborted')); GUI.log(i18n.getMessage('cliSaveToFileAborted'));
return; return;
} }
fs.writeFile(result.filePath, self.outputHistory, (err) => { fs.writeFile(result.filePath, self.outputHistory, (err) => {
if (err) { if (err) {
GUI.log(i18n.getMessage('ErrorWritingFile')); GUI.log(i18n.getMessage('ErrorWritingFile'));
@ -219,7 +224,7 @@ TABS.cli.initialize = function (callback) {
$('.tab-cli .load').on('click', function () { $('.tab-cli .load').on('click', function () {
var options = { var options = {
filters: [ filters: [
{ name: 'CLI/TXT', extensions: ['cli', 'txt'] }, { name: 'CLI/TXT', extensions: ['cli', 'txt'] },
{ name: 'ALL', extensions: ['*'] } { name: 'ALL', extensions: ['*'] }
], ],
@ -353,14 +358,14 @@ TABS.cli.initialize = function (callback) {
if (CONFIGURATOR.connection.type == ConnectionType.BLE) { if (CONFIGURATOR.connection.type == ConnectionType.BLE) {
let delay = CONFIGURATOR.connection.deviceDescription.delay; let delay = CONFIGURATOR.connection.deviceDescription.delay;
if (delay > 0) { if (delay > 0) {
timeout.add('cli_delay', () => { timeout.add('cli_delay', () => {
self.send(getCliCommand("cli_delay " + delay + '\n', TABS.cli.cliBuffer)); self.send(getCliCommand("cli_delay " + delay + '\n', TABS.cli.cliBuffer));
self.send(getCliCommand('# ' + i18n.getMessage('connectionBleCliEnter') + '\n', TABS.cli.cliBuffer)); self.send(getCliCommand('# ' + i18n.getMessage('connectionBleCliEnter') + '\n', TABS.cli.cliBuffer));
}, 400); }, 400);
} }
} }
GUI.content_ready(callback); GUI.content_ready(callback);
}); });
}; };
@ -411,6 +416,30 @@ function setPrompt(text) {
$('.tab-cli textarea').val(text); $('.tab-cli textarea').val(text);
} }
function generateFilename(prefix, suffix) {
var date = new Date();
var filename = prefix;
if (FC.CONFIG) {
if (FC.CONFIG.flightControllerIdentifier) {
filename = FC.CONFIG.flightControllerIdentifier + '_' + FC.CONFIG.flightControllerVersion + "_" + filename;
}
if (FC.CONFIG.name && FC.CONFIG.name.trim() !== '') {
filename = filename + '_' + FC.CONFIG.name.trim().replace(' ', '_');
}
}
filename = filename + '_' + date.getFullYear()
+ zeroPad(date.getMonth() + 1, 2)
+ zeroPad(date.getDate(), 2)
+ '_' + zeroPad(date.getHours(), 2)
+ zeroPad(date.getMinutes(), 2)
+ zeroPad(date.getSeconds(), 2);
return filename + '.' + suffix;
}
TABS.cli.read = function (readInfo) { TABS.cli.read = function (readInfo) {
/* Some info about handling line feeds and carriage return /* Some info about handling line feeds and carriage return