Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make measurement system units changeable. #616

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2830,6 +2830,39 @@ <h4 class="modal-title">Advanced User Settings</h4>
</div>
</div>
</div>
<div class="gui_box grey unit-settings">
<div class="gui_box_titlebar">
<div class="spacer_box_title">Measurement System</div>
</div>
<div>
<div class="speed-mode-group">
<table>
<tr>
<td>
<label>Speed Units</label>
<input type="radio" name="speed-mode" value="1">m/s</input>
<br>
<input type="radio" name="speed-mode" value="2">kph</input>
<br>
<input type="radio" name="speed-mode" value="3">mph</input>
</td>
</tr>
</table>
</div>
<div class="altitude-mode-group">
<table>
<tr>
<td>
<label>Altitude Units</label>
<input type="radio" name="altitude-mode" value="1">meters</input>
<br>
<input type="radio" name="altitude-mode" value="2">feet</input>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="cf_column half right">
Expand Down
31 changes: 28 additions & 3 deletions js/flightlog_fields_presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,24 @@ function FlightLogFieldPresenter() {
return enumNames[value];
};

/**
* Function to translate altitudes from the default meters
* to the user selected measurement unit.
* @param altitude String: Altitude in meters.
* @param altitudeUnits Integer: 1 for meters, 2 for feet.
*
* @returns String: readable meters in selected unit.
*/

FlightLogFieldPresenter.decodeCorrectAltitude = function(altitude, altitudeUnits) {
switch (altitudeUnits) {
case 1: // Keep it in meters.
return (altitude).toFixed(2) + " m";
case 2: // Translate it into feet.
return (altitude * 3.28).toFixed(2) + " ft";
}
};

/**
* Attempt to decode the given raw logged value into something more human readable, or return an empty string if
* no better representation is available.
Expand Down Expand Up @@ -967,7 +985,7 @@ function FlightLogFieldPresenter() {
return (value / Math.PI * 180).toFixed(1) + "°";

case 'baroAlt':
return (value / 100).toFixed(1) + " m";
return FlightLogFieldPresenter.decodeCorrectAltitude((value/100), userSettings.altitudeUnits);

case 'flightModeFlags':
return FlightLogFieldPresenter.presentFlags(value, FLIGHT_LOG_FLIGHT_MODE_NAME);
Expand All @@ -991,9 +1009,16 @@ function FlightLogFieldPresenter() {
case 'GPS_coord[1]':
return `${(value/10000000).toFixed(5)}`;
case 'GPS_altitude':
return `${(value/10).toFixed(2)} m`;
return FlightLogFieldPresenter.decodeCorrectAltitude((value/10), userSettings.altitudeUnits);
case 'GPS_speed':
return `${(value/100).toFixed(2)} m/s`;
switch (userSettings.speedUnits) {
case 1:
return `${(value/100).toFixed(2)} m/s`;
case 2:
return `${((value/100) * 3.6).toFixed(2)} kph`;
case 3:
return `${((value/100) * 2.2369).toFixed(2)} mph`;
}
case 'GPS_ground_course':
return `${(value/10).toFixed(1)} °`;

Expand Down
14 changes: 13 additions & 1 deletion js/user_settings_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ function UserSettingsDialog(dialog, onLoad, onSave) {
stickTrails : false, // Show stick trails?
stickInvertYaw : false, // Invert yaw in stick display?
legendUnits : true, // Show units on legend?
speedUnits : 1, // Default speed mode = m/s
altitudeUnits : 1, // Default altitude mode = meters
gapless : false,
drawCraft : "3D",
hasCraft : true,
Expand Down Expand Up @@ -314,6 +316,14 @@ function UserSettingsDialog(dialog, onLoad, onSave) {
currentSettings.legendUnits = $(this).is(":checked");
});

$('input[type=radio][name=speed-mode]').change(function() {
currentSettings.speedUnits = parseInt($(this).val());
});

$('input[type=radio][name=altitude-mode]').change(function() {
currentSettings.altitudeUnits = parseInt($(this).val());
});

// Load Custom Logo
function readURL(input) {
if (input.files && input.files[0]) {
Expand Down Expand Up @@ -390,14 +400,16 @@ function UserSettingsDialog(dialog, onLoad, onSave) {
$(".legend-units").prop('checked', currentSettings.legendUnits);
}


mixerListSelection(currentSettings.mixerConfiguration); // select current mixer configuration
stickModeSelection(currentSettings.stickMode);

// setup the stick mode and dropdowns;
$('select.mixerList').val(currentSettings.mixerConfiguration);
$('input:radio[name="stick-mode"]').filter('[value="' + currentSettings.stickMode + '"]').attr('checked', true);

$('input:radio[name="speed-mode"]').filter('[value="' + currentSettings.speedUnits + '"]').attr('checked', true);
$('input:radio[name="altitude-mode"]').filter('[value="' + currentSettings.altitudeUnits + '"]').attr('checked', true);

$('.stick-mode-group input[name="stick-top"]').val(parseInt(currentSettings.sticks.top));
$('.stick-mode-group input[name="stick-left"]').val(parseInt(currentSettings.sticks.left));
$('.stick-mode-group input[name="stick-size"]').val(parseInt(currentSettings.sticks.size));
Expand Down