mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-19 06:15:11 +03:00
Merge branch 'master' into MrD-Add-switch-indicators-to-OSD
This commit is contained in:
commit
27d1897c24
41 changed files with 1033 additions and 824 deletions
229
js/settings.js
229
js/settings.js
|
@ -28,6 +28,8 @@ var Settings = (function () {
|
|||
}
|
||||
parent.show();
|
||||
|
||||
input.prop('title', 'CLI: ' + input.data('setting'));
|
||||
|
||||
if (input.prop('tagName') == 'SELECT' || s.setting.table) {
|
||||
if (input.attr('type') == 'checkbox') {
|
||||
input.prop('checked', s.value > 0);
|
||||
|
@ -64,15 +66,15 @@ var Settings = (function () {
|
|||
} else {
|
||||
input.attr('step', "0.01");
|
||||
}
|
||||
|
||||
|
||||
input.attr('min', s.setting.min);
|
||||
input.attr('max', s.setting.max);
|
||||
input.val(s.value.toFixed(2));
|
||||
} else {
|
||||
var multiplier = parseFloat(input.data('setting-multiplier') || 1);
|
||||
input.attr('type', 'number');
|
||||
input.val((s.value / multiplier).toFixed(Math.log10(multiplier)));
|
||||
|
||||
input.val((s.value / multiplier).toFixed(Math.log10(multiplier)));
|
||||
input.attr('type', 'number');
|
||||
if (typeof s.setting.min !== 'undefined' && s.setting.min !== null) {
|
||||
input.attr('min', (s.setting.min / multiplier).toFixed(Math.log10(multiplier)));
|
||||
}
|
||||
|
@ -113,19 +115,19 @@ var Settings = (function () {
|
|||
const getUnitDisplayTypeValue = () => {
|
||||
// Try and match the values
|
||||
switch (configUnitType) {
|
||||
case UnitType.imperial:
|
||||
return 0;
|
||||
break;
|
||||
case UnitType.metric:
|
||||
return 1;
|
||||
break;
|
||||
case UnitType.OSD: // Match the OSD value on the UI
|
||||
return globalSettings.osdUnits;
|
||||
break;
|
||||
case UnitType.imperial:
|
||||
return 0; // Imperial OSD Value
|
||||
break;
|
||||
case UnitType.metric:
|
||||
return 1; // Metric + MPH OSD Value
|
||||
break;
|
||||
case UnitType.none:
|
||||
default:
|
||||
// Something went wrong
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,67 +137,199 @@ var Settings = (function () {
|
|||
|
||||
const oldValue = element.val();
|
||||
|
||||
//display names for the units
|
||||
const unitDisplayDames = {
|
||||
// Misc
|
||||
'us' : "uS",
|
||||
'cw' : 'cW',
|
||||
'percent' : '%',
|
||||
'cmss' : 'cm/s/s',
|
||||
// Time
|
||||
'msec' : 'ms',
|
||||
'dsec' : 'ds',
|
||||
'sec' : 's',
|
||||
// Angles
|
||||
'deg' : '°',
|
||||
'decideg' : 'deci°',
|
||||
// Temperature
|
||||
'decidegc' : 'deci°C',
|
||||
'degc' : '°C',
|
||||
'degf' : '°F',
|
||||
// Speed
|
||||
'cms' : 'cm/s',
|
||||
'v-cms' : 'cm/s',
|
||||
'ms' : 'm/s',
|
||||
'kmh' : 'Km/h',
|
||||
'mph' : 'mph',
|
||||
'hftmin' : 'x100 ft/min',
|
||||
'fts' : 'ft/s',
|
||||
'kt' : 'Kt',
|
||||
// Distance
|
||||
'cm' : 'cm',
|
||||
'm' : 'm',
|
||||
'km' : 'Km',
|
||||
'm-lrg' : 'm', // Metres, but converted to larger units
|
||||
'ft' : 'ft',
|
||||
'mi' : 'mi',
|
||||
'nm' : 'NM'
|
||||
}
|
||||
|
||||
|
||||
// Ensure we can do conversions
|
||||
if (configUnitType === UnitType.none || uiUnitValue === -1 || !inputUnit || !oldValue || !element) {
|
||||
if (!inputUnit || !oldValue || !element) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Used to convert between a value and a value matching the int
|
||||
// unit display value. Eg 1 = Metric
|
||||
// units. We use the OSD unit values here for easy
|
||||
const conversionTable = {
|
||||
1: {
|
||||
'cm': { multiplier: 100, unitName: 'm' },
|
||||
'cms': { multiplier: 27.77777777777778, unitName: 'Km/h' }
|
||||
//this is used to get the factor in which we multiply
|
||||
//to get the correct conversion, the first index is the from
|
||||
//unit and the second is the too unit
|
||||
//unitConversionTable[toUnit][fromUnit] -> factor
|
||||
const unitRatioTable = {
|
||||
'cm' : {
|
||||
'm' : 100,
|
||||
'ft' : 30.48
|
||||
},
|
||||
2: {
|
||||
'cm': { multiplier: 100, unitName: 'm' },
|
||||
},
|
||||
4: {
|
||||
'cms': { multiplier: 51.44444444444457, unitName: 'Kt' }
|
||||
'm' : {
|
||||
'm' : 1,
|
||||
'ft' : 0.3048
|
||||
},
|
||||
default: {
|
||||
'cm': { multiplier: 30.48, unitName: 'ft' },
|
||||
'cms': { multiplier: 44.704, unitName: 'mph' },
|
||||
'ms': { multiplier: 1000, unitName: 'sec' }
|
||||
'm-lrg' : {
|
||||
'km' : 1000,
|
||||
'mi' : 1609.344,
|
||||
'nm' : 1852
|
||||
},
|
||||
}
|
||||
'cms' : { // Horizontal speed
|
||||
'kmh' : 27.77777777777778,
|
||||
'kt': 51.44444444444457,
|
||||
'mph' : 44.704,
|
||||
'ms' : 100
|
||||
},
|
||||
'v-cms' : { // Vertical speed
|
||||
'ms' : 100,
|
||||
'hftmin' : 50.8,
|
||||
'fts' : 30.48
|
||||
},
|
||||
'msec' : {
|
||||
'sec' : 1000
|
||||
},
|
||||
'dsec' : {
|
||||
'sec' : 10
|
||||
},
|
||||
'decideg' : {
|
||||
'deg' : 10
|
||||
},
|
||||
'decidegc' : {
|
||||
'degc' : 10,
|
||||
'degf' : 'FAHREN'
|
||||
},
|
||||
};
|
||||
|
||||
// Small closure to try and get the multiplier
|
||||
// needed from the conversion table
|
||||
//this holds which units get converted in which unit systems
|
||||
const conversionTable = {
|
||||
0: { //imperial
|
||||
'cm' : 'ft',
|
||||
'm' : 'ft',
|
||||
'm-lrg' : 'mi',
|
||||
'cms' : 'mph',
|
||||
'v-cms' : 'fts',
|
||||
'msec' : 'sec',
|
||||
'dsec' : 'sec',
|
||||
'decideg' : 'deg',
|
||||
'decidegc' : 'degf',
|
||||
},
|
||||
1: { //metric
|
||||
'cm': 'm',
|
||||
'm' : 'm',
|
||||
'm-lrg' : 'km',
|
||||
'cms' : 'kmh',
|
||||
'v-cms' : 'ms',
|
||||
'msec' : 'sec',
|
||||
'dsec' : 'sec',
|
||||
'decideg' : 'deg',
|
||||
'decidegc' : 'degc',
|
||||
},
|
||||
2: { //metric with MPH
|
||||
'cm': 'm',
|
||||
'm' : 'm',
|
||||
'm-lrg' : 'km',
|
||||
'cms' : 'mph',
|
||||
'v-cms' : 'ms',
|
||||
'decideg' : 'deg',
|
||||
'msec' : 'sec',
|
||||
'dsec' : 'sec',
|
||||
'decidegc' : 'degc',
|
||||
},
|
||||
3:{ //UK
|
||||
'cm' : 'ft',
|
||||
'm' : 'ft',
|
||||
'm-lrg' : 'mi',
|
||||
'cms' : 'mph',
|
||||
'v-cms' : 'fts',
|
||||
'decideg' : 'deg',
|
||||
'msec' : 'sec',
|
||||
'dsec' : 'sec',
|
||||
'decidegc' : 'degc',
|
||||
},
|
||||
4: { //General aviation
|
||||
'cm' : 'ft',
|
||||
'm' : 'ft',
|
||||
'm-lrg' : 'nm',
|
||||
'cms': 'kt',
|
||||
'v-cms' : 'hftmin',
|
||||
'decideg' : 'deg',
|
||||
'msec' : 'sec',
|
||||
'dsec' : 'sec',
|
||||
'decidegc' : 'degc',
|
||||
},
|
||||
default:{}//show base units
|
||||
};
|
||||
|
||||
//this returns the factor in which to multiply to convert a unit
|
||||
const getUnitMultiplier = () => {
|
||||
if(conversionTable[uiUnitValue] && conversionTable[uiUnitValue][inputUnit]) {
|
||||
return conversionTable[uiUnitValue][inputUnit];
|
||||
if (conversionTable[uiUnitValue]){
|
||||
const fromUnits = conversionTable[uiUnitValue];
|
||||
if (fromUnits[inputUnit]){
|
||||
const multiplier = unitRatioTable[inputUnit][fromUnits[inputUnit]];
|
||||
return {'multiplier':multiplier, 'unitName':fromUnits[inputUnit]};
|
||||
}
|
||||
}
|
||||
|
||||
return conversionTable['default'][inputUnit];
|
||||
return {multiplier:1, unitName:inputUnit};
|
||||
}
|
||||
|
||||
// Get the default multi obj or the custom
|
||||
const multiObj = getUnitMultiplier();
|
||||
|
||||
if(!multiObj) {
|
||||
return;
|
||||
}
|
||||
|
||||
const multiplier = multiObj.multiplier;
|
||||
const unitName = multiObj.unitName;
|
||||
|
||||
// Update the step, min, and max; as we have the multiplier here.
|
||||
if (element.attr('type') == 'number') {
|
||||
element.attr('step', ((multiplier != 1) ? '0.01' : '1'));
|
||||
element.attr('min', (element.attr('min') / multiplier).toFixed(2));
|
||||
element.attr('max', (element.attr('max') / multiplier).toFixed(2));
|
||||
if (multiplier != 'FAHREN') {
|
||||
element.attr('min', (element.attr('min') / multiplier).toFixed(2));
|
||||
element.attr('max', (element.attr('max') / multiplier).toFixed(2));
|
||||
}
|
||||
}
|
||||
|
||||
// Update the input with a new formatted unit
|
||||
const convertedValue = Number((oldValue / multiplier).toFixed(2));
|
||||
const newValue = Number.isInteger(convertedValue) ? Math.round(convertedValue) : convertedValue;
|
||||
let newValue = "";
|
||||
if (multiplier == 'FAHREN') {
|
||||
element.attr('min', toFahrenheit(element.attr('min')).toFixed(2));
|
||||
element.attr('max', toFahrenheit(element.attr('max')).toFixed(2));
|
||||
newValue = toFahrenheit(oldValue).toFixed(2);
|
||||
} else {
|
||||
const convertedValue = Number((oldValue / multiplier).toFixed(2));
|
||||
newValue = Number.isInteger(convertedValue) ? Math.round(convertedValue) : convertedValue;
|
||||
}
|
||||
element.val(newValue);
|
||||
element.data('setting-multiplier', multiplier);
|
||||
|
||||
// Now wrap the input in a display that shows the unit
|
||||
element.wrap(`<div data-unit="${unitName}" class="unit_wrapper unit"></div>`);
|
||||
element.wrap(`<div data-unit="${unitDisplayDames[unitName]}" class="unit_wrapper unit"></div>`);
|
||||
|
||||
function toFahrenheit(decidegC) {
|
||||
return (decidegC / 10) * 1.8 + 32;
|
||||
};
|
||||
}
|
||||
|
||||
self.saveInput = function(input) {
|
||||
|
@ -216,8 +350,13 @@ var Settings = (function () {
|
|||
} else if(setting.type == 'string') {
|
||||
value = input.val();
|
||||
} else {
|
||||
var multiplier = parseFloat(input.data('setting-multiplier') || 1);
|
||||
value = parseFloat(input.val()) * multiplier;
|
||||
var multiplier = input.data('setting-multiplier') || 1;
|
||||
if (multiplier == 'FAHREN') {
|
||||
value = Math.round(((parseFloat(input.val())-32) / 1.8) * 10);
|
||||
} else {
|
||||
multiplier = parseFloat(multiplier);
|
||||
value = Math.round(parseFloat(input.val()) * multiplier);
|
||||
}
|
||||
}
|
||||
return mspHelper.setSetting(settingName, value);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue