mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-23 08:15:19 +03:00
Add support for configuring coordinate digit count on OSD
Depends on https://github.com/iNavFlight/inav/pull/3573
This commit is contained in:
parent
fc0c8123da
commit
142e960893
4 changed files with 38 additions and 4 deletions
|
@ -2954,6 +2954,10 @@ var mspHelper = (function (gui) {
|
|||
self.getSetting = function (name) {
|
||||
var $this = this;
|
||||
return this._getSetting(name).then(function (setting) {
|
||||
if (!setting) {
|
||||
// Setting not available in the FC
|
||||
return null;
|
||||
}
|
||||
var data = [];
|
||||
$this._encodeSettingReference(name, setting.index, data);
|
||||
return MSP.promise(MSPCodes.MSPV2_SETTING, data).then(function (resp) {
|
||||
|
|
|
@ -11,6 +11,20 @@ var Settings = (function () {
|
|||
return Promise.mapSeries(inputs, function (input, ii) {
|
||||
var settingName = input.data('setting');
|
||||
return mspHelper.getSetting(settingName).then(function (s) {
|
||||
// Check if the input declares a parent
|
||||
// to be hidden in case of the setting not being available.
|
||||
// Otherwise, default to hiding its parent
|
||||
var parent = input.parents('.setting-container:first');
|
||||
if (parent.length == 0) {
|
||||
parent = input.parent();
|
||||
}
|
||||
if (!s) {
|
||||
// Setting doesn't exist.
|
||||
input.val(null);
|
||||
parent.hide();
|
||||
return;
|
||||
}
|
||||
parent.show();
|
||||
if (input.prop('tagName') == 'SELECT' || s.setting.table) {
|
||||
if (input.attr('type') == 'checkbox') {
|
||||
input.prop('checked', s.value > 0);
|
||||
|
|
|
@ -68,6 +68,9 @@
|
|||
<label>
|
||||
<select class="update_preview" data-setting="osd_main_voltage_decimals" data-live="true"></select> Voltage Decimals
|
||||
</label>
|
||||
<label>
|
||||
<select class="update_preview" data-setting="osd_coordinate_digits" data-live="true"></select> Coordinate Digits
|
||||
</label>
|
||||
<label>
|
||||
<select class="update_preview" data-setting="osd_crosshairs_style" data-live="true"></select> Crosshairs Style
|
||||
</label>
|
||||
|
|
21
tabs/osd.js
21
tabs/osd.js
|
@ -268,7 +268,7 @@ FONT.symbol = function (hexVal) {
|
|||
|
||||
FONT.embed_dot = function(str) {
|
||||
var zero = '0'.charCodeAt(0);
|
||||
var repl = str.replace(/\d.\d/, function(match) {
|
||||
var repl = str.replace(/\d\.\d/, function(match) {
|
||||
var c1 = match.charCodeAt(0) + SYM.ZERO_HALF_TRAILING_DOT - zero;
|
||||
var c2 = match.charCodeAt(2) + SYM.ZERO_HALF_LEADING_DOT - zero;
|
||||
return FONT.symbol(c1) + FONT.symbol(c2);
|
||||
|
@ -323,6 +323,20 @@ function osdMainBatteryPreview() {
|
|||
return FONT.symbol(SYM.VOLT) + FONT.embed_dot(s);
|
||||
}
|
||||
|
||||
function osdCoordinatePreview(symbol, coordinate) {
|
||||
return function() {
|
||||
var digits = Settings.getInputValue('osd_coordinate_digits');
|
||||
if (!digits) {
|
||||
// Setting doesn't exist in the FC. Use 11, which
|
||||
// will make it look close to how it looked before 2.0
|
||||
digits = 11;
|
||||
}
|
||||
var integerLength = ('' + parseInt(coordinate)).length;
|
||||
console.log(coordinate.toFixed(digits - integerLength));
|
||||
return FONT.symbol(symbol) + FONT.embed_dot(coordinate.toFixed(digits - integerLength));
|
||||
}
|
||||
}
|
||||
|
||||
// parsed fc output and output to fc, used by to OSD.msp.encode
|
||||
OSD.initData = function () {
|
||||
OSD.data = {
|
||||
|
@ -751,13 +765,13 @@ OSD.constants = {
|
|||
name: 'LONGITUDE',
|
||||
id: 20,
|
||||
min_version: '1.6.0',
|
||||
preview: FONT.symbol(SYM.LON) + FONT.embed_dot('14.7652134 ') // 11 chars
|
||||
preview: osdCoordinatePreview(SYM.LON, -114.7652134),
|
||||
},
|
||||
{
|
||||
name: 'LATITUDE',
|
||||
id: 21,
|
||||
min_version: '1.6.0',
|
||||
preview: FONT.symbol(SYM.LAT) + FONT.embed_dot('52.9872367 ') // 11 chars
|
||||
preview: osdCoordinatePreview(SYM.LAT, 52.9872367),
|
||||
},
|
||||
{
|
||||
name: 'DIRECTION_TO_HOME',
|
||||
|
@ -1838,7 +1852,6 @@ OSD.GUI.updatePreviews = function() {
|
|||
if (OSD.data.display_size.y % 2 == 0) {
|
||||
mapCenter += OSD.data.display_size.x / 2;
|
||||
}
|
||||
console.log(OSD.data.display_size.x * OSD.data.display_size.y, mapCenter);
|
||||
OSD.GUI.updateMapPreview(mapCenter, 'MAP_NORTH', 'N', SYM.HOME);
|
||||
OSD.GUI.updateMapPreview(mapCenter, 'MAP_TAKEOFF', 'T', SYM.HOME);
|
||||
OSD.GUI.updateMapPreview(mapCenter, 'RADAR', null, SYM.DIR_TO_HOME);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue