Skip to content

Commit

Permalink
cli filename fix
Browse files Browse the repository at this point in the history
  • Loading branch information
breadoven committed May 10, 2024
1 parent 30765ae commit 1f3c55b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
12 changes: 6 additions & 6 deletions js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ 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;

if (CONFIG) {
if (CONFIG.flightControllerIdentifier) {
filename = CONFIG.flightControllerIdentifier + '_' + CONFIG.flightControllerVersion + "_" + filename;
}

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
53 changes: 41 additions & 12 deletions tabs/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -82,7 +84,7 @@ function copyToClipboard(text) {
function onCopyFailed(ex) {
console.warn(ex);
}

navigator.clipboard.writeText(text)
.then(onCopySuccessful, onCopyFailed);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -160,19 +162,22 @@ 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 => {
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 +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: ['*'] }
],
Expand Down Expand Up @@ -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);
});
};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1f3c55b

Please sign in to comment.