diff --git a/js/helpers.js b/js/helpers.js index 661efeef2..30ad118d2 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -24,7 +24,7 @@ function zeroPad(value, width) { return value; } -function generateFilename(prefix, suffix) { +function generateFilename(prefix, suffix) { // TODO, code used directly in cli.js instead var date = new Date(); var filename = prefix; @@ -32,7 +32,7 @@ function generateFilename(prefix, suffix) { if (CONFIG.flightControllerIdentifier) { filename = CONFIG.flightControllerIdentifier + '_' + CONFIG.flightControllerVersion + "_" + filename; } - + 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 { diff --git a/tabs/cli.js b/tabs/cli.js index d6f9b4ff9..da0da1ef5 100644 --- a/tabs/cli.js +++ b/tabs/cli.js @@ -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 { zeroPad } = require('./../js/helpers'); +const FC = require('./../js/fc'); 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,11 +162,14 @@ TABS.cli.initialize = function (callback) { }); $('.tab-cli .save').on('click', function () { - + var prefix = 'cli'; + var suffix = 'txt'; + var filename = generateFilename(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 => { @@ -172,7 +177,7 @@ TABS.cli.initialize = function (callback) { 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); }); }; @@ -411,6 +416,30 @@ function setPrompt(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) { /* Some info about handling line feeds and carriage return