mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-13 11:29:53 +03:00
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
/*global $*/
|
|
|
|
'use strict';
|
|
|
|
function constrain(input, min, max) {
|
|
|
|
if (input < min) {
|
|
return min;
|
|
}
|
|
|
|
if (input > max) {
|
|
return max;
|
|
}
|
|
|
|
return input;
|
|
}
|
|
|
|
function zeroPad(value, width) {
|
|
value = "" + value;
|
|
|
|
while (value.length < width) {
|
|
value = "0" + value;
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
function generateFilename(prefix, suffix) {
|
|
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(' ', '_');
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
function scaleRangeInt(x, srcMin, srcMax, destMin, destMax) {
|
|
let a = (destMax - destMin) * (x - srcMin);
|
|
let b = srcMax - srcMin;
|
|
return Math.round((a / b) + destMin);
|
|
}
|
|
|
|
module.exports = { constrain, zeroPad, generateFilename, scaleRangeInt };
|