Skip to content

Commit

Permalink
Do not mix semver code
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Aug 26, 2023
1 parent fa9409a commit d68ed2e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ const FC = {
angle: 0,
returnAltitudeM: 0,
descentDistanceM: 0,
rescueGroundspeed: 0,
returnSpeed: 0,
throttleMin: 0,
throttleMax: 0,
throttleHover: 0,
Expand Down
4 changes: 2 additions & 2 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ MspHelper.prototype.process_data = function(dataHandler) {
FC.GPS_RESCUE.angle = data.readU16();
FC.GPS_RESCUE.returnAltitudeM = data.readU16();
FC.GPS_RESCUE.descentDistanceM = data.readU16();
FC.GPS_RESCUE.rescueGroundspeed = data.readU16();
FC.GPS_RESCUE.returnSpeed = data.readU16();
FC.GPS_RESCUE.throttleMin = data.readU16();
FC.GPS_RESCUE.throttleMax = data.readU16();
FC.GPS_RESCUE.throttleHover = data.readU16();
Expand Down Expand Up @@ -1802,7 +1802,7 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) {
buffer.push16(FC.GPS_RESCUE.angle)
.push16(FC.GPS_RESCUE.returnAltitudeM)
.push16(FC.GPS_RESCUE.descentDistanceM)
.push16(FC.GPS_RESCUE.rescueGroundspeed)
.push16(FC.GPS_RESCUE.returnSpeed)
.push16(FC.GPS_RESCUE.throttleMin)
.push16(FC.GPS_RESCUE.throttleMax)
.push16(FC.GPS_RESCUE.throttleHover)
Expand Down
42 changes: 25 additions & 17 deletions src/js/tabs/failsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ failsafe.initialize = function (callback) {
$('input[name="gps_rescue_angle"]').val(FC.GPS_RESCUE.angle);
$('input[name="gps_rescue_return_altitude"]').val(FC.GPS_RESCUE.returnAltitudeM);
$('input[name="gps_rescue_descent_distance"]').val(FC.GPS_RESCUE.descentDistanceM);
$('input[name="gps_rescue_ground_speed"]').val((FC.GPS_RESCUE.rescueGroundspeed / 100).toFixed(2));
$('input[name="gps_rescue_return_speed"]').val((FC.GPS_RESCUE.returnSpeed / 100).toFixed(2));
$('input[name="gps_rescue_throttle_min"]').val(FC.GPS_RESCUE.throttleMin);
$('input[name="gps_rescue_throttle_max"]').val(FC.GPS_RESCUE.throttleMax);
$('input[name="gps_rescue_throttle_hover"]').val(FC.GPS_RESCUE.throttleHover);
Expand All @@ -296,27 +296,35 @@ failsafe.initialize = function (callback) {
}

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
$('input[name="gps_rescue_min_dth"]').attr({"min": 10, "max": 30});
$('input[name="gps_rescue_ground_speed"]').attr({"min": 3.0, "max": 30.0, "step": 0.1});
$('input[name="gps_rescue_ascend_rate"]').attr({"min": 1.0, "max": 25.0, "step": 0.1});
$('input[name="gps_rescue_descend_rate"]').attr({"min": 1.0, "max": 5.0, "step": 0.1});
$('input[name="gps_rescue_descent_distance"]').attr("min", 10);
$('input[name="gps_rescue_initial_climb"]').val(FC.GPS_RESCUE.initialClimbM);
} else {
$('input[name="gps_rescue_initial_climb"]').closest('.number').hide();

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
$('input[name="gps_rescue_min_dth"]').attr("min", 20);
}
}

$('input[name="gps_rescue_min_dth"]').val(FC.GPS_RESCUE.minRescueDth);
} else {
$('input[name="gps_rescue_min_dth"]').closest('.number').hide();
}

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
$('input[name="gps_rescue_angle"]').attr("max", 80);
$('input[name="gps_rescue_return_altitude"]').attr({"min": 2, "max": 255});
$('input[name="gps_rescue_descent_distance"]').attr("min", 5);
$('input[name="gps_rescue_min_dth"]').attr("min", 20);
$('input[name="gps_rescue_return_speed"]').attr("min", 0.0);
$('input[name="gps_rescue_ascend_rate"]').attr("min", 0.5);
$('input[name="gps_rescue_descend_rate"]').attr("min", 0.3);
}

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
$('input[name="gps_rescue_initial_climb"]').val(FC.GPS_RESCUE.initialClimbM);
} else {
$('input[name="gps_rescue_initial_climb"]').closest('.number').hide();
}

// Update attributes for API version 4.5
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
$('input[name="gps_rescue_angle"]').attr({"min": 30, "max": 60});
$('input[name="gps_rescue_return_altitude"]').attr({"min": 5, "max": 1000});
$('input[name="gps_rescue_descent_distance"]').attr("min", 10);
$('input[name="gps_rescue_min_dth"]').attr({"min": 10, "max": 30});
$('input[name="gps_rescue_descend_rate"]').attr({"min": 0.2, "max": 50.0});
}

$('a.save').click(function () {
// gather data that doesn't have automatic change event bound
Expand Down Expand Up @@ -345,7 +353,7 @@ failsafe.initialize = function (callback) {
FC.GPS_RESCUE.angle = $('input[name="gps_rescue_angle"]').val();
FC.GPS_RESCUE.returnAltitudeM = $('input[name="gps_rescue_return_altitude"]').val();
FC.GPS_RESCUE.descentDistanceM = $('input[name="gps_rescue_descent_distance"]').val();
FC.GPS_RESCUE.rescueGroundspeed = $('input[name="gps_rescue_ground_speed"]').val() * 100;
FC.GPS_RESCUE.returnSpeed = $('input[name="gps_rescue_return_speed"]').val() * 100;
FC.GPS_RESCUE.throttleMin = $('input[name="gps_rescue_throttle_min"]').val();
FC.GPS_RESCUE.throttleMax = $('input[name="gps_rescue_throttle_max"]').val();
FC.GPS_RESCUE.throttleHover = $('input[name="gps_rescue_throttle_hover"]').val();
Expand Down
8 changes: 4 additions & 4 deletions src/tabs/failsafe.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@
<div class="helpicon cf_tip" i18n_title="failsafeGpsRescueItemMinDthHelp"></div>
</div>
<div class="number">
<label> <input type="number" name="gps_rescue_initial_climb" min="5" max="1000" /> <span
<label> <input type="number" name="gps_rescue_initial_climb" min="0" max="100" /> <span
i18n="failsafeGpsRescueInitialClimb"></span>
</label>
<div class="helpicon cf_tip" i18n_title="failsafeGpsRescueInitialClimbHelp"></div>
</div>
<div class="number">
<label> <input type="number" name="gps_rescue_ground_speed" min="3.00" max="30.00" step="0.01"/> <span
<label> <input type="number" name="gps_rescue_return_speed" min="3.00" max="30.00" step="0.1"/> <span
i18n="failsafeGpsRescueItemGroundSpeed"></span>
</label>
</div>
Expand All @@ -166,12 +166,12 @@
</label>
</div>
<div class="number">
<label> <input type="number" name="gps_rescue_ascend_rate" min="1.00" max="25.00" step="0.01" /> <span
<label> <input type="number" name="gps_rescue_ascend_rate" min="1.00" max="25.00" step="0.1" /> <span
i18n="failsafeGpsRescueItemAscendRate"></span>
</label>
</div>
<div class="number">
<label> <input type="number" name="gps_rescue_descend_rate" min="1.00" max="5.00" step="0.01" /> <span
<label> <input type="number" name="gps_rescue_descend_rate" min="1.00" max="5.00" step="0.1" /> <span
i18n="failsafeGpsRescueItemDescendRate"></span>
</label>
</div>
Expand Down

0 comments on commit d68ed2e

Please sign in to comment.