1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-16 04:45:20 +03:00

Move FC global vars inside FC object

This commit is contained in:
Miguel Angel Mulero Martinez 2020-07-06 08:05:27 +02:00
parent b9137a68e6
commit 24010a2e2a
32 changed files with 2799 additions and 2797 deletions

View file

@ -19,7 +19,7 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
function load_rxfail_config() {
MSP.send_message(MSPCodes.MSP_RXFAIL_CONFIG, false, false,
semver.gte(CONFIG.apiVersion, "1.41.0") ? load_gps_rescue : get_box_names);
semver.gte(FC.CONFIG.apiVersion, "1.41.0") ? load_gps_rescue : get_box_names);
}
function load_gps_rescue() {
@ -89,21 +89,21 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
i,
element;
for (var channelIndex = 0; channelIndex < RC.active_channels - 4; channelIndex++) {
for (var channelIndex = 0; channelIndex < FC.RC.active_channels - 4; channelIndex++) {
auxAssignment.push("");
}
if (typeof RSSI_CONFIG.channel !== 'undefined') {
auxAssignment[RSSI_CONFIG.channel - 5] += "<span class=\"modename\">" + "RSSI" + "</span>"; // Aux channels start at 5 in backend so we have to substract 5
if (typeof FC.RSSI_CONFIG.channel !== 'undefined') {
auxAssignment[FC.RSSI_CONFIG.channel - 5] += "<span class=\"modename\">" + "RSSI" + "</span>"; // Aux channels start at 5 in backend so we have to substract 5
}
for (var modeIndex = 0; modeIndex < AUX_CONFIG.length; modeIndex++) {
for (var modeIndex = 0; modeIndex < FC.AUX_CONFIG.length; modeIndex++) {
var modeId = AUX_CONFIG_IDS[modeIndex];
var modeId = FC.AUX_CONFIG_IDS[modeIndex];
// scan mode ranges to find assignments
for (var modeRangeIndex = 0; modeRangeIndex < MODE_RANGES.length; modeRangeIndex++) {
var modeRange = MODE_RANGES[modeRangeIndex];
for (var modeRangeIndex = 0; modeRangeIndex < FC.MODE_RANGES.length; modeRangeIndex++) {
var modeRange = FC.MODE_RANGES[modeRangeIndex];
if (modeRange.id != modeId) {
continue;
@ -115,7 +115,7 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
}
// Search for the real name if it belongs to a peripheral
var modeName = AUX_CONFIG[modeIndex];
var modeName = FC.AUX_CONFIG[modeIndex];
modeName = adjustBoxNameIfPeripheralWithModeID(modeId, modeName);
auxAssignment[modeRange.auxChannelIndex] += "<span class=\"modename\">" + modeName + "</span>";
@ -133,9 +133,9 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
aux_index = 1,
aux_assignment_index = 0;
for (i = 0; i < RXFAIL_CONFIG.length; i++) {
for (i = 0; i < FC.RXFAIL_CONFIG.length; i++) {
if (i < channelNames.length) {
if (semver.lt(CONFIG.apiVersion, "1.41.0")) {
if (semver.lt(FC.CONFIG.apiVersion, "1.41.0")) {
fullChannels_e.append('\
<div class="number">\
<div class="channelprimary">\
@ -202,7 +202,7 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
channelMode.change(function () {
var currentMode = parseInt($(this).val());
var i = parseInt($(this).prop("id"));
RXFAIL_CONFIG[i].mode = currentMode;
FC.RXFAIL_CONFIG[i].mode = currentMode;
if (currentMode == 2) {
channel_value_array[i].prop("disabled", false);
channel_value_array[i].show();
@ -215,7 +215,7 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
// UI hooks
channelValue.change(function () {
var i = parseInt($(this).prop("id"));
RXFAIL_CONFIG[i].value = parseInt($(this).val());
FC.RXFAIL_CONFIG[i].value = parseInt($(this).val());
});
// for some odd reason chrome 38+ changes scroll according to the touched select element
@ -224,19 +224,19 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
$('#content').scrollTop((scrollPosition) ? scrollPosition : 0);
// fill stage 1 Valid Pulse Range Settings
$('input[name="rx_min_usec"]').val(RX_CONFIG.rx_min_usec);
$('input[name="rx_max_usec"]').val(RX_CONFIG.rx_max_usec);
$('input[name="rx_min_usec"]').val(FC.RX_CONFIG.rx_min_usec);
$('input[name="rx_max_usec"]').val(FC.RX_CONFIG.rx_max_usec);
// fill fallback settings (mode and value) for all channels
for (i = 0; i < RXFAIL_CONFIG.length; i++) {
channel_value_array[i].val(RXFAIL_CONFIG[i].value);
channel_mode_array[i].val(RXFAIL_CONFIG[i].mode);
for (i = 0; i < FC.RXFAIL_CONFIG.length; i++) {
channel_value_array[i].val(FC.RXFAIL_CONFIG[i].value);
channel_mode_array[i].val(FC.RXFAIL_CONFIG[i].mode);
channel_mode_array[i].change();
}
FEATURE_CONFIG.features.generateElements($('.tab-failsafe .featuresNew'));
FC.FEATURE_CONFIG.features.generateElements($('.tab-failsafe .featuresNew'));
if (semver.gte(CONFIG.apiVersion, "1.36.0")) {
if (semver.gte(FC.CONFIG.apiVersion, "1.36.0")) {
$('tbody.rxFailsafe').hide();
toggleStage2(true);
} else {
@ -244,13 +244,13 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
failsafeFeature.change(function () {
toggleStage2($(this).is(':checked'));
});
toggleStage2(FEATURE_CONFIG.features.isEnabled('FAILSAFE'));
toggleStage2(FC.FEATURE_CONFIG.features.isEnabled('FAILSAFE'));
}
$('input[name="failsafe_throttle"]').val(FAILSAFE_CONFIG.failsafe_throttle);
$('input[name="failsafe_off_delay"]').val(FAILSAFE_CONFIG.failsafe_off_delay);
$('input[name="failsafe_throttle_low_delay"]').val(FAILSAFE_CONFIG.failsafe_throttle_low_delay);
$('input[name="failsafe_delay"]').val(FAILSAFE_CONFIG.failsafe_delay);
$('input[name="failsafe_throttle"]').val(FC.FAILSAFE_CONFIG.failsafe_throttle);
$('input[name="failsafe_off_delay"]').val(FC.FAILSAFE_CONFIG.failsafe_off_delay);
$('input[name="failsafe_throttle_low_delay"]').val(FC.FAILSAFE_CONFIG.failsafe_throttle_low_delay);
$('input[name="failsafe_delay"]').val(FC.FAILSAFE_CONFIG.failsafe_delay);
// set stage 2 failsafe procedure
$('input[type="radio"].procedure').change(function () {
@ -264,7 +264,7 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
element.parent().parent().find(':input').attr('disabled',false);
});
switch(FAILSAFE_CONFIG.failsafe_procedure) {
switch(FC.FAILSAFE_CONFIG.failsafe_procedure) {
default:
case 0:
element = $('input[id="land"]') ;
@ -283,37 +283,37 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
break;
}
if (semver.gte(CONFIG.apiVersion, "1.39.0")) {
if (semver.gte(FC.CONFIG.apiVersion, "1.39.0")) {
// `failsafe_kill_switch` has been renamed to `failsafe_switch_mode`.
// It is backwards compatible with `failsafe_kill_switch`
$('select[name="failsafe_switch_mode"]').val(FAILSAFE_CONFIG.failsafe_switch_mode);
$('select[name="failsafe_switch_mode"]').val(FC.FAILSAFE_CONFIG.failsafe_switch_mode);
$('div.kill_switch').hide();
}
else {
$('input[name="failsafe_kill_switch"]').prop('checked', FAILSAFE_CONFIG.failsafe_switch_mode);
$('input[name="failsafe_kill_switch"]').prop('checked', FC.FAILSAFE_CONFIG.failsafe_switch_mode);
$('div.failsafe_switch').hide();
}
// The GPS Rescue tab is only available for 1.40 or later, and the parameters for 1.41
if (semver.gte(CONFIG.apiVersion, "1.40.0")) {
if (semver.gte(FC.CONFIG.apiVersion, "1.40.0")) {
if (semver.gte(CONFIG.apiVersion, "1.41.0")) {
if (semver.gte(FC.CONFIG.apiVersion, "1.41.0")) {
// Load GPS Rescue parameters
$('input[name="gps_rescue_angle"]').val(GPS_RESCUE.angle);
$('input[name="gps_rescue_initial_altitude"]').val(GPS_RESCUE.initialAltitudeM);
$('input[name="gps_rescue_descent_distance"]').val(GPS_RESCUE.descentDistanceM);
$('input[name="gps_rescue_ground_speed"]').val((GPS_RESCUE.rescueGroundspeed / 100).toFixed(2));
$('input[name="gps_rescue_throttle_min"]').val(GPS_RESCUE.throttleMin);
$('input[name="gps_rescue_throttle_max"]').val(GPS_RESCUE.throttleMax);
$('input[name="gps_rescue_throttle_hover"]').val(GPS_RESCUE.throttleHover);
$('input[name="gps_rescue_min_sats"]').val(GPS_RESCUE.minSats);
$('select[name="gps_rescue_sanity_checks"]').val(GPS_RESCUE.sanityChecks);
$('input[name="gps_rescue_angle"]').val(FC.GPS_RESCUE.angle);
$('input[name="gps_rescue_initial_altitude"]').val(FC.GPS_RESCUE.initialAltitudeM);
$('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_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);
$('input[name="gps_rescue_min_sats"]').val(FC.GPS_RESCUE.minSats);
$('select[name="gps_rescue_sanity_checks"]').val(FC.GPS_RESCUE.sanityChecks);
if (semver.gte(CONFIG.apiVersion, API_VERSION_1_43)) {
$('input[name="gps_rescue_ascend_rate"]').val((GPS_RESCUE.ascendRate / 100).toFixed(2));
$('input[name="gps_rescue_descend_rate"]').val((GPS_RESCUE.descendRate / 100).toFixed(2));
$('input[name="gps_rescue_allow_arming_without_fix"]').prop('checked', GPS_RESCUE.allowArmingWithoutFix > 0);
$('select[name="gps_rescue_altitude_mode"]').val(GPS_RESCUE.altitudeMode);
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) {
$('input[name="gps_rescue_ascend_rate"]').val((FC.GPS_RESCUE.ascendRate / 100).toFixed(2));
$('input[name="gps_rescue_descend_rate"]').val((FC.GPS_RESCUE.descendRate / 100).toFixed(2));
$('input[name="gps_rescue_allow_arming_without_fix"]').prop('checked', FC.GPS_RESCUE.allowArmingWithoutFix > 0);
$('select[name="gps_rescue_altitude_mode"]').val(FC.GPS_RESCUE.altitudeMode);
} else {
$('input[name="gps_rescue_ascend_rate"]').closest('.number').hide();
$('input[name="gps_rescue_descend_rate"]').closest('.number').hide();
@ -337,49 +337,49 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
$('a.save').click(function () {
// gather data that doesn't have automatic change event bound
FEATURE_CONFIG.features.updateData($('input[name="FAILSAFE"]'));
FC.FEATURE_CONFIG.features.updateData($('input[name="FAILSAFE"]'));
RX_CONFIG.rx_min_usec = parseInt($('input[name="rx_min_usec"]').val());
RX_CONFIG.rx_max_usec = parseInt($('input[name="rx_max_usec"]').val());
FC.RX_CONFIG.rx_min_usec = parseInt($('input[name="rx_min_usec"]').val());
FC.RX_CONFIG.rx_max_usec = parseInt($('input[name="rx_max_usec"]').val());
FAILSAFE_CONFIG.failsafe_throttle = parseInt($('input[name="failsafe_throttle"]').val());
FAILSAFE_CONFIG.failsafe_off_delay = parseInt($('input[name="failsafe_off_delay"]').val());
FAILSAFE_CONFIG.failsafe_throttle_low_delay = parseInt($('input[name="failsafe_throttle_low_delay"]').val());
FAILSAFE_CONFIG.failsafe_delay = parseInt($('input[name="failsafe_delay"]').val());
FC.FAILSAFE_CONFIG.failsafe_throttle = parseInt($('input[name="failsafe_throttle"]').val());
FC.FAILSAFE_CONFIG.failsafe_off_delay = parseInt($('input[name="failsafe_off_delay"]').val());
FC.FAILSAFE_CONFIG.failsafe_throttle_low_delay = parseInt($('input[name="failsafe_throttle_low_delay"]').val());
FC.FAILSAFE_CONFIG.failsafe_delay = parseInt($('input[name="failsafe_delay"]').val());
if( $('input[id="land"]').is(':checked')) {
FAILSAFE_CONFIG.failsafe_procedure = 0;
FC.FAILSAFE_CONFIG.failsafe_procedure = 0;
} else if( $('input[id="drop"]').is(':checked')) {
FAILSAFE_CONFIG.failsafe_procedure = 1;
FC.FAILSAFE_CONFIG.failsafe_procedure = 1;
} else if( $('input[id="gps_rescue"]').is(':checked')) {
FAILSAFE_CONFIG.failsafe_procedure = 2;
FC.FAILSAFE_CONFIG.failsafe_procedure = 2;
}
if (semver.gte(CONFIG.apiVersion, "1.39.0")) {
FAILSAFE_CONFIG.failsafe_switch_mode = $('select[name="failsafe_switch_mode"]').val();
if (semver.gte(FC.CONFIG.apiVersion, "1.39.0")) {
FC.FAILSAFE_CONFIG.failsafe_switch_mode = $('select[name="failsafe_switch_mode"]').val();
}
else {
FAILSAFE_CONFIG.failsafe_switch_mode = $('input[name="failsafe_kill_switch"]').is(':checked') ? 1 : 0;
FC.FAILSAFE_CONFIG.failsafe_switch_mode = $('input[name="failsafe_kill_switch"]').is(':checked') ? 1 : 0;
}
if (semver.gte(CONFIG.apiVersion, "1.41.0")) {
if (semver.gte(FC.CONFIG.apiVersion, "1.41.0")) {
// Load GPS Rescue parameters
GPS_RESCUE.angle = $('input[name="gps_rescue_angle"]').val();
GPS_RESCUE.initialAltitudeM = $('input[name="gps_rescue_initial_altitude"]').val();
GPS_RESCUE.descentDistanceM = $('input[name="gps_rescue_descent_distance"]').val();
GPS_RESCUE.rescueGroundspeed = $('input[name="gps_rescue_ground_speed"]').val() * 100;
GPS_RESCUE.throttleMin = $('input[name="gps_rescue_throttle_min"]').val();
GPS_RESCUE.throttleMax = $('input[name="gps_rescue_throttle_max"]').val();
GPS_RESCUE.throttleHover = $('input[name="gps_rescue_throttle_hover"]').val();
GPS_RESCUE.minSats = $('input[name="gps_rescue_min_sats"]').val();
GPS_RESCUE.sanityChecks = $('select[name="gps_rescue_sanity_checks"]').val();
FC.GPS_RESCUE.angle = $('input[name="gps_rescue_angle"]').val();
FC.GPS_RESCUE.initialAltitudeM = $('input[name="gps_rescue_initial_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.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();
FC.GPS_RESCUE.minSats = $('input[name="gps_rescue_min_sats"]').val();
FC.GPS_RESCUE.sanityChecks = $('select[name="gps_rescue_sanity_checks"]').val();
}
if (semver.gte(CONFIG.apiVersion, API_VERSION_1_43)) {
GPS_RESCUE.ascendRate = $('input[name="gps_rescue_ascend_rate"]').val() * 100;
GPS_RESCUE.descendRate = $('input[name="gps_rescue_descend_rate"]').val() * 100;
GPS_RESCUE.allowArmingWithoutFix = $('input[name="gps_rescue_allow_arming_without_fix"]').prop('checked') ? 1 : 0;
GPS_RESCUE.altitudeMode = parseInt($('select[name="gps_rescue_altitude_mode"]').val());
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) {
FC.GPS_RESCUE.ascendRate = $('input[name="gps_rescue_ascend_rate"]').val() * 100;
FC.GPS_RESCUE.descendRate = $('input[name="gps_rescue_descend_rate"]').val() * 100;
FC.GPS_RESCUE.allowArmingWithoutFix = $('input[name="gps_rescue_allow_arming_without_fix"]').prop('checked') ? 1 : 0;
FC.GPS_RESCUE.altitudeMode = parseInt($('select[name="gps_rescue_altitude_mode"]').val());
}
function save_failssafe_config() {
@ -392,7 +392,7 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
function save_feature_config() {
MSP.send_message(MSPCodes.MSP_SET_FEATURE_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FEATURE_CONFIG), false,
semver.gte(CONFIG.apiVersion, "1.41.0") ? save_gps_rescue : save_to_eeprom);
semver.gte(FC.CONFIG.apiVersion, "1.41.0") ? save_gps_rescue : save_to_eeprom);
}
function save_gps_rescue() {