Skip to content

Commit a2fe532

Browse files
authored
Merge pull request #1451 from iNavFlight/MrD-Enhance-and-extend-conversions
Enhance and extend units conversion
2 parents e1a970f + 093fc22 commit a2fe532

File tree

13 files changed

+299
-168
lines changed

13 files changed

+299
-168
lines changed

_locales/en/messages.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,7 @@
21262126
"message": "<strong>Note:</strong> When Stage 2 is DISABLED, the fallback setting <strong>Auto</strong> is used instead of the user settings for all flightchannels (Roll, Pitch, Yaw and Throttle)."
21272127
},
21282128
"failsafeDelayItem": {
2129-
"message": "Guard time for activation after signal lost [1 = 0.1 sec.]"
2129+
"message": "Guard time for activation after signal lost [For deciseconds (ds): 1 = 0.1 sec.]"
21302130
},
21312131
"failsafeDelayHelp": {
21322132
"message": "Time for stage 1 to wait for recovery"
@@ -2135,7 +2135,7 @@
21352135
"message": "Throttle value used while landing"
21362136
},
21372137
"failsafeOffDelayItem": {
2138-
"message": "Delay for turning off the Motors during Failsafe [1 = 0.1 sec.]"
2138+
"message": "Delay for turning off the Motors during Failsafe [For deciseconds (ds):1 = 0.1 sec.]"
21392139
},
21402140
"failsafeOffDelayHelp": {
21412141
"message": "Time to stay in landing mode untill the motors are turned off and the craft is disarmed"
@@ -2894,16 +2894,16 @@
28942894
"message": "Fly Time (minutes)"
28952895
},
28962896
"osd_alt_alarm": {
2897-
"message": "Altitude (meters)"
2897+
"message": "Altitude"
28982898
},
28992899
"osd_dist_alarm": {
2900-
"message": "Distance (meters)"
2900+
"message": "Distance"
29012901
},
29022902
"osdAlarmDIST_HELP": {
29032903
"message": "The distance to home indicator will flash when the distance is greater than this value. Zero disables this alarm."
29042904
},
29052905
"osd_neg_alt_alarm": {
2906-
"message": "Negative Altitude (meters)"
2906+
"message": "Negative Altitude"
29072907
},
29082908
"osdAlarmMAX_NEG_ALTITUDE_HELP": {
29092909
"message": "The altitude indicator will flash when altitude is negative and its absolute value is greater than this alarm. Useful when taking off from elevated places. Zero disables this alarm."

js/settings.js

Lines changed: 118 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const GulpClient = require("gulp");
4+
35
var Settings = (function () {
46
let self = {};
57

@@ -28,6 +30,8 @@ var Settings = (function () {
2830
}
2931
parent.show();
3032

33+
input.prop('title', 'CLI: ' + input.data('setting'));
34+
3135
if (input.prop('tagName') == 'SELECT' || s.setting.table) {
3236
if (input.attr('type') == 'checkbox') {
3337
input.prop('checked', s.value > 0);
@@ -69,9 +73,9 @@ var Settings = (function () {
6973
input.val(s.value.toFixed(2));
7074
} else {
7175
var multiplier = parseFloat(input.data('setting-multiplier') || 1);
72-
input.attr('type', 'number');
73-
input.val((s.value / multiplier).toFixed(Math.log10(multiplier)));
7476

77+
input.val((s.value / multiplier).toFixed(Math.log10(multiplier)));
78+
input.attr('type', 'number');
7579
if (typeof s.setting.min !== 'undefined' && s.setting.min !== null) {
7680
input.attr('min', (s.setting.min / multiplier).toFixed(Math.log10(multiplier)));
7781
}
@@ -136,22 +140,39 @@ var Settings = (function () {
136140

137141
//display names for the units
138142
const unitDisplayDames = {
143+
// Misc
139144
'us' : "uS",
140-
'deg' : '&deg;',
141-
'cdeg' : 'centi&deg;',
145+
'cw' : 'cW',
146+
'percent' : '%',
142147
'cmss' : 'cm/s/s',
143-
'cm' : 'cm',
148+
// Time
149+
'msec' : 'ms',
150+
'dsec' : 'ds',
151+
'sec' : 's',
152+
// Angles
153+
'deg' : '&deg;',
154+
'decideg' : 'deci&deg;',
155+
// Temperature
156+
'decidegc' : 'deci&deg;C',
157+
'degc' : '&deg;C',
158+
'degf' : '&deg;F',
159+
// Speed
144160
'cms' : 'cm/s',
145-
'm' : 'm',
146-
'ms' : 'ms',
147-
'mps' : 'm/s',
161+
'v-cms' : 'cm/s',
162+
'ms' : 'm/s',
148163
'kmh' : 'Km/h',
149-
'sec' : 's',
164+
'mph' : 'mph',
165+
'hftmin' : 'x100 ft/min',
166+
'fts' : 'ft/s',
150167
'kt' : 'Kt',
168+
// Distance
169+
'cm' : 'cm',
170+
'm' : 'm',
171+
'km' : 'Km',
172+
'm-lrg' : 'm', // Metres, but converted to larger units
151173
'ft' : 'ft',
152-
'mph' : 'mph',
153-
'cw' : 'cW',
154-
'percent' : '%'
174+
'mi' : 'mi',
175+
'nm' : 'NM'
155176
}
156177

157178

@@ -169,51 +190,97 @@ var Settings = (function () {
169190
'm' : 100,
170191
'ft' : 30.48
171192
},
172-
'cms' : {
193+
'm' : {
194+
'm' : 1,
195+
'ft' : 0.3048
196+
},
197+
'm-lrg' : {
198+
'km' : 1000,
199+
'mi' : 1609.344,
200+
'nm' : 1852
201+
},
202+
'cms' : { // Horizontal speed
173203
'kmh' : 27.77777777777778,
174204
'kt': 51.44444444444457,
175205
'mph' : 44.704,
176-
'mps' : 100
206+
'ms' : 100
207+
},
208+
'v-cms' : { // Vertical speed
209+
'ms' : 100,
210+
'hftmin' : 50.8,
211+
'fts' : 30.48
177212
},
178-
'ms' : {
213+
'msec' : {
179214
'sec' : 1000
180215
},
181-
'cdeg' : {
216+
'dsec' : {
217+
'sec' : 10
218+
},
219+
'decideg' : {
182220
'deg' : 10
183221
},
222+
'decidegc' : {
223+
'degc' : 10,
224+
'degf' : 'FAHREN'
225+
},
184226
};
185227

186228
//this holds which units get converted in which unit systems
187229
const conversionTable = {
188230
0: { //imperial
189231
'cm' : 'ft',
232+
'm' : 'ft',
233+
'm-lrg' : 'mi',
190234
'cms' : 'mph',
191-
'cdeg' : 'deg',
192-
'ms' : 'sec'
235+
'v-cms' : 'fts',
236+
'msec' : 'sec',
237+
'dsec' : 'sec',
238+
'decideg' : 'deg',
239+
'decidegc' : 'degf',
193240
},
194-
1: {//metric
241+
1: { //metric
195242
'cm': 'm',
243+
'm' : 'm',
244+
'm-lrg' : 'km',
196245
'cms' : 'kmh',
197-
'ms' : 'sec',
198-
'cdeg' : 'deg'
246+
'v-cms' : 'ms',
247+
'msec' : 'sec',
248+
'dsec' : 'sec',
249+
'decideg' : 'deg',
250+
'decidegc' : 'degc',
199251
},
200252
2: { //metric with MPH
201253
'cm': 'm',
254+
'm' : 'm',
255+
'm-lrg' : 'km',
202256
'cms' : 'mph',
203-
'cdeg' : 'deg',
204-
'ms' : 'sec'
257+
'v-cms' : 'ms',
258+
'decideg' : 'deg',
259+
'msec' : 'sec',
260+
'dsec' : 'sec',
261+
'decidegc' : 'degc',
205262
},
206263
3:{ //UK
207264
'cm' : 'ft',
265+
'm' : 'ft',
266+
'm-lrg' : 'mi',
208267
'cms' : 'mph',
209-
'cdeg' : 'deg',
210-
'ms' : 'sec'
268+
'v-cms' : 'fts',
269+
'decideg' : 'deg',
270+
'msec' : 'sec',
271+
'dsec' : 'sec',
272+
'decidegc' : 'degc',
211273
},
212274
4: { //General aviation
213275
'cm' : 'ft',
276+
'm' : 'ft',
277+
'm-lrg' : 'nm',
214278
'cms': 'kt',
215-
'cdeg' : 'deg',
216-
'ms' : 'sec'
279+
'v-cms' : 'hftmin',
280+
'decideg' : 'deg',
281+
'msec' : 'sec',
282+
'dsec' : 'sec',
283+
'decidegc' : 'degc',
217284
},
218285
default:{}//show base units
219286
};
@@ -239,18 +306,31 @@ var Settings = (function () {
239306
// Update the step, min, and max; as we have the multiplier here.
240307
if (element.attr('type') == 'number') {
241308
element.attr('step', ((multiplier != 1) ? '0.01' : '1'));
242-
element.attr('min', (element.attr('min') / multiplier).toFixed(2));
243-
element.attr('max', (element.attr('max') / multiplier).toFixed(2));
309+
if (multiplier != 'FAHREN') {
310+
element.attr('min', (element.attr('min') / multiplier).toFixed(2));
311+
element.attr('max', (element.attr('max') / multiplier).toFixed(2));
312+
}
244313
}
245314

246315
// Update the input with a new formatted unit
247-
const convertedValue = Number((oldValue / multiplier).toFixed(2));
248-
const newValue = Number.isInteger(convertedValue) ? Math.round(convertedValue) : convertedValue;
316+
let newValue = "";
317+
if (multiplier == 'FAHREN') {
318+
element.attr('min', toFahrenheit(element.attr('min')).toFixed(2));
319+
element.attr('max', toFahrenheit(element.attr('max')).toFixed(2));
320+
newValue = toFahrenheit(oldValue).toFixed(2);
321+
} else {
322+
const convertedValue = Number((oldValue / multiplier).toFixed(2));
323+
newValue = Number.isInteger(convertedValue) ? Math.round(convertedValue) : convertedValue;
324+
}
249325
element.val(newValue);
250326
element.data('setting-multiplier', multiplier);
251327

252328
// Now wrap the input in a display that shows the unit
253329
element.wrap(`<div data-unit="${unitDisplayDames[unitName]}" class="unit_wrapper unit"></div>`);
330+
331+
function toFahrenheit(decidegC) {
332+
return (decidegC / 10) * 1.8 + 32;
333+
};
254334
}
255335

256336
self.saveInput = function(input) {
@@ -271,8 +351,13 @@ var Settings = (function () {
271351
} else if(setting.type == 'string') {
272352
value = input.val();
273353
} else {
274-
var multiplier = parseFloat(input.data('setting-multiplier') || 1);
275-
value = parseFloat(input.val()) * multiplier;
354+
var multiplier = input.data('setting-multiplier') || 1;
355+
if (multiplier == 'FAHREN') {
356+
value = Math.round(((parseFloat(input.val())-32) / 1.8) * 10);
357+
} else {
358+
multiplier = parseFloat(multiplier);
359+
value = Math.round(parseFloat(input.val()) * multiplier);
360+
}
276361
}
277362
return mspHelper.setSetting(settingName, value);
278363
};

main.css

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,25 +2221,33 @@ ol li {
22212221
position: relative;
22222222
}
22232223

2224+
.unit_wrapper input {
2225+
margin-right: 0 !important;
2226+
}
2227+
2228+
.unit_wrapper ~ label, select ~ label, input ~ label {
2229+
margin-left: 10px;
2230+
}
2231+
22242232
/* Position the unit to the right of the wrapper */
22252233
.unit_wrapper::after {
22262234
position: absolute;
22272235
top: 2px;
2228-
right: .7em;
2236+
right: .5em;
22292237
transition: all .05s ease-in-out;
22302238
}
22312239

22322240
/* Move unit more to the left on hover or focus within
22332241
for arrow buttons will appear to the right of number inputs */
22342242
.unit_wrapper:hover::after,
22352243
.unit_wrapper:focus-within::after {
2236-
right: 1.3em;
2244+
right: 1.0em;
22372245
}
22382246

22392247
/* Handle Firefox (arrows always shown) */
22402248
@supports (-moz-appearance:none) {
22412249
.unit_wrapper::after {
2242-
right: 1.3em;
2250+
right: 1.0em;
22432251
}
22442252
}
22452253

src/css/tabs/configuration.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
text-align: left;
2929
border: 1px solid silver;
3030
border-radius: 3px;
31-
margin-right: 11px;
3231
font-size: 12px;
3332
font-weight: normal;
3433
}
3534

3635
.config-section .number input,
36+
.config-section .checkbox input,
3737
.tab-configuration .number input {
3838
width: 106px;
3939
}
@@ -221,7 +221,7 @@ hr {
221221

222222
.config-section label {
223223
position: absolute;
224-
left: 118px;
224+
left: 108px;
225225
}
226226

227227
.config-section .radio label {

src/css/tabs/failsafe.css

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
text-align: left;
2727
border: 1px solid silver;
2828
border-radius: 3px;
29-
margin-right: 11px;
3029
font-size: 12px;
3130
font-weight: normal;
3231
}
@@ -253,10 +252,12 @@
253252
height: 90px;
254253
}
255254

256-
.tab-failsafe .minimumDistance {
257-
width: 100px !important;
258-
padding-left: 3px;
259-
margin-right: 11px;
255+
.tab-failsafe input {
256+
width: 75px !important;
257+
}
258+
259+
.tab-failsafe select {
260+
width: 79px;
260261
}
261262

262263
@media only screen and (max-width: 1055px) , only screen and (max-device-width: 1055px) {

src/css/tabs/firmware_flasher.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@
271271
text-align: left;
272272
border: 1px solid silver;
273273
border-radius: 3px;
274-
margin-right: 11px;
275274
margin-bottom: 5px;
276275
font-size: 12px;
277276
font-weight: normal;

src/css/tabs/osd.css

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,21 +477,19 @@ button {
477477
}
478478

479479
.tab-osd .settings input {
480-
width: 55px;
480+
width: 75px;
481481
padding-left: 3px;
482482
height: 18px;
483483
line-height: 20px;
484484
text-align: left;
485485
border: 1px solid silver;
486486
border-radius: 3px;
487-
margin-right: 11px;
488487
font-size: 11px;
489488
font-weight: normal;
490489
}
491490

492491
.tab-osd .settings select {
493492
width: 75px;
494-
margin-right: 11px;
495493
}
496494

497495
.tab-osd .settings .switchery {

0 commit comments

Comments
 (0)