Skip to content

Commit

Permalink
Merge pull request #2216 from iNavFlight/MrD_Set-OSD-elements-precision
Browse files Browse the repository at this point in the history
Allow the pilot to set the precision for altitude and distance in the OSD
  • Loading branch information
MrD-RC authored Oct 28, 2024
2 parents 4150613 + 0898292 commit 5cc8107
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 77 deletions.
9 changes: 9 additions & 0 deletions locale/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3593,6 +3593,12 @@
"osd_main_voltage_decimals": {
"message": "Voltage Decimals"
},
"osd_decimals_altitude": {
"message": "Altitude Decimals"
},
"osd_decimals_distance": {
"message": "Distance Decimals"
},
"osd_mah_precision": {
"message": "mAh Precision"
},
Expand Down Expand Up @@ -4775,6 +4781,9 @@
"settings": {
"message": "Settings"
},
"decimals": {
"message": "Decimals"
},
"motorMixer": {
"message": "Motor Mixer"
},
Expand Down
78 changes: 48 additions & 30 deletions tabs/osd.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,52 @@ <h1 class="tab_title" data-i18n="tabOSD"></h1>
<span data-i18n="osd_units"></span>
<div for="unit_mode" class="helpicon cf_tip" style="margin-top: 2px"></div>
</label>
<label>
<select class="update_preview" data-setting="osd_crosshairs_style" data-live="true"></select>
<span data-i18n="osd_crosshairs_style"></span>
</label>
<label>
<select class="update_preview" data-setting="osd_left_sidebar_scroll" data-live="true"></select>
<span data-i18n="osd_left_sidebar_scroll"></span>
</label>
<label>
<select class="update_preview" data-setting="osd_right_sidebar_scroll" data-live="true"></select>
<span data-i18n="osd_right_sidebar_scroll"></span>
</label>
<div for="crsfLQFormat" class="helpicon cf_tip osd_use_crsf" data-i18n_title="osdSettingCRSF_LQ_FORMAT_HELP"></div>
<label class="osd_use_crsf">
<select id="crsfLQFormat" class="update_preview" data-setting="osd_crsf_lq_format" data-live="true"></select>
<span data-i18n="osd_crsf_lq_format"></span>
</label>
<label>
<input type="checkbox" class="toggle update_preview" data-setting="osd_sidebar_scroll_arrows" data-live="true">
<span data-i18n="osd_sidebar_scroll_arrows"></span>
</label>
<label>
<input type="checkbox" class="toggle update_preview" data-setting="osd_home_position_arm_screen" data-live="true">
<span data-i18n="osd_home_position_arm_screen"></span>
</label>
</div>
</div>
</div>
<div class="gui_box grey decimals-container">
<div class="gui_box_titlebar">
<div class="spacer_box_title" data-i18n="decimals"></div>
</div>
<div class="spacer_box">
<div class="settings">
<label>
<select class="update_preview" data-setting="osd_main_voltage_decimals" data-live="true"></select>
<span data-i18n="osd_main_voltage_decimals"></span>
</label>
<label>
<select class="update_preview" data-setting="osd_decimals_altitude" data-live="true"></select>
<span data-i18n="osd_decimals_altitude"></span>
</label>
<label>
<select class="update_preview" data-setting="osd_decimals_distance" data-live="true"></select>
<span data-i18n="osd_decimals_distance"></span>
</label>
<label>
<select class="update_preview" data-setting="osd_mah_precision" data-live="true"></select>
<span data-i18n="osd_mah_precision"></span>
Expand All @@ -124,31 +166,6 @@ <h1 class="tab_title" data-i18n="tabOSD"></h1>
<select id="rpmPrecision" class="update_preview" data-setting="osd_esc_rpm_precision" data-live="true"></select>
<span data-i18n="osd_esc_rpm_precision"></span>
</label>
<label>
<select class="update_preview" data-setting="osd_crosshairs_style" data-live="true"></select>
<span data-i18n="osd_crosshairs_style"></span>
</label>
<label>
<select class="update_preview" data-setting="osd_left_sidebar_scroll" data-live="true"></select>
<span data-i18n="osd_left_sidebar_scroll"></span>
</label>
<label>
<select class="update_preview" data-setting="osd_right_sidebar_scroll" data-live="true"></select>
<span data-i18n="osd_right_sidebar_scroll"></span>
</label>
<div for="crsfLQFormat" class="helpicon cf_tip osd_use_crsf" data-i18n_title="osdSettingCRSF_LQ_FORMAT_HELP"></div>
<label class="osd_use_crsf">
<select id="crsfLQFormat" class="update_preview" data-setting="osd_crsf_lq_format" data-live="true"></select>
<span data-i18n="osd_crsf_lq_format"></span>
</label>
<label>
<input type="checkbox" class="toggle update_preview" data-setting="osd_sidebar_scroll_arrows" data-live="true">
<span data-i18n="osd_sidebar_scroll_arrows"></span>
</label>
<label>
<input type="checkbox" class="toggle update_preview" data-setting="osd_home_position_arm_screen" data-live="true">
<span data-i18n="osd_home_position_arm_screen"></span>
</label>
</div>
</div>
</div>
Expand Down Expand Up @@ -251,16 +268,17 @@ <h1 class="tab_title" data-i18n="tabOSD"></h1>
<input id="osd_gforce_axis_alarm_max" data-setting="osd_gforce_axis_alarm_max" data-setting-multiplier="1" type="number" data-step="0.1" />
<span data-i18n="osd_gforce_axis_alarm_max"></span>
</label>
<div for="adsb_distance_warning" class="helpicon cf_tip" data-i18n_title="osdAlarmADSB_MAX_DISTANCE_WARNING"></div>
<label for="adsb_distance_warning">
<input id="adsb_distance_warning" data-setting="osd_adsb_distance_warning" data-unit="m" data-setting-multiplier="1" type="number" data-step="1" />
<span data-i18n="osd_adsb_distance_warning"></span>
</label>

<div for="adsb_distance_alert" class="helpicon cf_tip" data-i18n_title="osdAlarmADSB_MAX_DISTANCE_ALERT"></div>
<label for="adsb_distance_alert">
<input id="adsb_distance_alert" data-setting="osd_adsb_distance_alert" data-unit="m" data-setting-multiplier="1" type="number" data-step="1" />
<span data-i18n="osd_adsb_distance_alert"></span>
</label>
<div for="adsb_distance_warning" class="helpicon cf_tip" data-i18n_title="osdAlarmADSB_MAX_DISTANCE_WARNING"></div>
<label for="adsb_distance_warning">
<input id="adsb_distance_warning" data-setting="osd_adsb_distance_warning" data-unit="m" data-setting-multiplier="1" type="number" data-step="1" />
<span data-i18n="osd_adsb_distance_warning"></span>
</label>
</div>
</div>
<div class="gui_box grey dji-hd-container" id="dji_settings">
Expand Down
105 changes: 58 additions & 47 deletions tabs/osd.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ function altitude_alarm_display_function(fn) {
}
}

function osdMainBatteryPreview() {
function osdDecimalsMainBatteryPreview() {
var s = '16.8';
if (Settings.getInputValue('osd_main_voltage_decimals') == 2) {
s += '3';
Expand All @@ -462,6 +462,47 @@ function osdMainBatteryPreview() {
return FONT.symbol(SYM.BATT) + FONT.embed_dot(s);
}

function osdDecimalsAltitudePreview() {
var s = ' 114';
if (Settings.getInputValue('osd_decimals_altitude') == 4) {
s += '3';
} if (Settings.getInputValue('osd_decimals_altitude') == 5) {
s += '38';
}

switch (OSD.data.preferences.units) {
case 0: // Imperial
case 3: // UK
case 4: // GA
s += FONT.symbol(SYM.ALT_FT);
default: // Metric
s += FONT.symbol(SYM.ALT_M);
}

return s;
}

function osdDecimalsDistancePreview() {
var s = '11.5';
if (Settings.getInputValue('osd_decimals_distance') == 4) {
s+= '3';
} if (Settings.getInputValue('osd_decimals_distance') == 5) {
s = '1' + s + '7';
}

switch (OSD.data.preferences.units) {
case 0: // Imperial
case 3: // UK
s += FONT.symbol(SYM.DIST_MI);
case 4: // GA
s += FONT.symbol(SYM.DIST_NM);
default: // Metric
s += FONT.symbol(SYM.DIST_KM);
}

return s;
}

function osdmAhPrecisionPreview() {
let precision = Settings.getInputValue('osd_mah_precision');
let rnd = (Math.floor(10000000000000 + Math.random() * 90000000000000)).toString();
Expand Down Expand Up @@ -849,12 +890,12 @@ OSD.constants = {
{
name: 'MAIN_BATT_VOLTAGE',
id: 1,
preview: osdMainBatteryPreview,
preview: osdDecimalsMainBatteryPreview,
},
{
name: 'SAG_COMP_MAIN_BATT_VOLTAGE',
id: 53,
preview: osdMainBatteryPreview,
preview: osdDecimalsMainBatteryPreview,
},
{
name: 'MAIN_BATT_CELL_VOLTAGE',
Expand Down Expand Up @@ -884,17 +925,7 @@ OSD.constants = {
{
name: 'REMAINING_FLIGHT_DISTANCE',
id: 49,
preview: function(osd_data) {
switch (OSD.data.preferences.units) {
case 0: // Imperial
case 3: // UK
return FONT.symbol(SYM.FLIGHT_DIST_REMAINING) + FONT.embed_dot('0.98') + FONT.symbol(SYM.DIST_MI);
case 4: // GA
return FONT.symbol(SYM.FLIGHT_DIST_REMAINING) + FONT.embed_dot('0.85') + FONT.symbol(SYM.DIST_NM);
default: // Metric
return FONT.symbol(SYM.FLIGHT_DIST_REMAINING) + FONT.embed_dot('1.73') + FONT.symbol(SYM.DIST_KM);
}
}
preview: osdDecimalsDistancePreview,
},
{
name: 'THROTTLE_POSITION',
Expand Down Expand Up @@ -1232,16 +1263,7 @@ OSD.constants = {
{
name: 'ALTITUDE',
id: 15,
preview: function () {
switch (OSD.data.preferences.units) {
case 0: // Imperial
case 3: // UK
case 4: // GA
return ' 375' + FONT.symbol(SYM.ALT_FT);
default: // Metric
return ' 114' + FONT.symbol(SYM.ALT_M);
}
}
preview: osdDecimalsAltitudePreview,
},
{
name: 'VARIO',
Expand Down Expand Up @@ -1606,33 +1628,13 @@ OSD.constants = {
{
name: 'DISTANCE_TO_HOME',
id: 23,
preview: function(osd_data) {
switch (OSD.data.preferences.units) {
case 0: // Imperial
case 3: // UK
return FONT.symbol(SYM.HOME) + FONT.embed_dot('0.98') + FONT.symbol(SYM.DIST_MI);
case 4: // GA
return FONT.symbol(SYM.HOME) + FONT.embed_dot('0.85') + FONT.symbol(SYM.DIST_NM);
default: // Metric
return FONT.symbol(SYM.HOME) + FONT.embed_dot('1.57') + FONT.symbol(SYM.DIST_KM);
}
}
preview: osdDecimalsDistancePreview,
},
{
name: 'TRIP_DIST',
id: 40,
min_version: '1.9.1',
preview: function(osd_data) {
switch (OSD.data.preferences.units) {
case 0: // Imperial
case 3: // UK
return FONT.symbol(SYM.TRIP_DIST) + FONT.embed_dot('0.98') + FONT.symbol(SYM.DIST_MI);
case 4: // GA
return FONT.symbol(SYM.TRIP_DIST) + FONT.embed_dot('0.85') + FONT.symbol(SYM.DIST_NM);
default: // Metric
return FONT.symbol(SYM.TRIP_DIST) + FONT.embed_dot('1.57') + FONT.symbol(SYM.DIST_KM);
}
}
preview: osdDecimalsDistancePreview,
},
{
name: 'ODOMETER',
Expand Down Expand Up @@ -2959,6 +2961,15 @@ OSD.GUI.updateDjiView = function(on) {
}
});

var settings = $('.decimals-container').find('.settings').children();
settings.each(function(index, element) {
var name = $(element).attr('class');
if (!OSD.DjiElements.supportedSettings.includes(name)) {
$(element).hide();
}
});


var alarms = $('.alarms-container').find('.settings').children();
alarms.each(function(index, element) {
var name = $(element).attr('for');
Expand All @@ -2977,7 +2988,7 @@ OSD.GUI.updateDjiView = function(on) {
.show()
.removeClass('no-bottom');

$('.settings-container, .alarms-container').find('.settings').children()
$('.settings-container, .decimals-container, .alarms-container').find('.settings').children()
.show()
.removeClass('no-bottom');

Expand Down

0 comments on commit 5cc8107

Please sign in to comment.