'use strict';
TABS.failsafe = {};
TABS.failsafe.initialize = function (callback, scrollPosition) {
var self = this;
if (GUI.active_tab != 'failsafe') {
GUI.active_tab = 'failsafe';
}
function load_rx_config() {
MSP.send_message(MSP_codes.MSP_RX_CONFIG, false, false, load_failssafe_config);
}
function load_failssafe_config() {
MSP.send_message(MSP_codes.MSP_FAILSAFE_CONFIG, false, false, load_rxfail_config);
}
function load_rxfail_config() {
MSP.send_message(MSP_codes.MSP_RXFAIL_CONFIG, false, false, get_box_names);
}
function get_box_names() {
MSP.send_message(MSP_codes.MSP_BOXNAMES, false, false, get_mode_ranges);
}
function get_mode_ranges() {
MSP.send_message(MSP_codes.MSP_MODE_RANGES, false, false, get_box_ids);
}
function get_box_ids() {
MSP.send_message(MSP_codes.MSP_BOXIDS, false, false, get_rc_data);
}
function get_rc_data() {
MSP.send_message(MSP_codes.MSP_RC, false, false, load_config);
}
// BEGIN Support for pre API version 1.15.0
function load_config() {
MSP.send_message(MSP_codes.MSP_BF_CONFIG, false, false, load_misc);
}
function load_misc() {
MSP.send_message(MSP_codes.MSP_MISC, false, false, load_html);
}
// END (Support for pre API version 1.15.0
function load_html() {
$('#content').load("./tabs/failsafe.html", process_html);
}
var apiVersionGte1_15_0 = semver.gte(CONFIG.apiVersion, "1.15.0");
// Uncomment next line for testing older functionality on newer API version
//apiVersionGte1_15_0 = false;
if(apiVersionGte1_15_0) {
MSP.send_message(MSP_codes.MSP_IDENT, false, false, load_rx_config);
} else {
MSP.send_message(MSP_codes.MSP_IDENT, false, false, load_config);
}
function process_html() {
var failsafeFeature;
// translate to user-selected language
localize();
// Conditionally hide the old or the new control pane's
if(apiVersionGte1_15_0) {
var oldPane = $('div.oldpane');
oldPane.prop("disabled", true);
oldPane.hide();
} else {
var newPane = $('div.newpane');
newPane.prop("disabled", true);
newPane.hide();
}
if(apiVersionGte1_15_0) {
// generate labels for assigned aux modes
var auxAssignment = [],
i,
element;
for (var channelIndex = 0; channelIndex < RC.active_channels - 4; channelIndex++) {
auxAssignment.push("");
}
for (var modeIndex = 0; modeIndex < AUX_CONFIG.length; modeIndex++) {
var modeId = AUX_CONFIG_IDS[modeIndex];
// scan mode ranges to find assignments
for (var modeRangeIndex = 0; modeRangeIndex < MODE_RANGES.length; modeRangeIndex++) {
var modeRange = MODE_RANGES[modeRangeIndex];
if (modeRange.id != modeId) {
continue;
}
var range = modeRange.range;
if (!(range.start < range.end)) {
continue; // invalid!
}
auxAssignment[modeRange.auxChannelIndex] += "" + AUX_CONFIG[modeIndex] + "";
}
}
// generate full channel list
var channelNames = [
chrome.i18n.getMessage('controlAxisRoll'),
chrome.i18n.getMessage('controlAxisPitch'),
chrome.i18n.getMessage('controlAxisYaw'),
chrome.i18n.getMessage('controlAxisThrottle')
],
fullChannels_e = $('div.activechannellist'),
aux_index = 1,
aux_assignment_index = 0;
for (i = 0; i < RXFAIL_CONFIG.length; i++) {
if (i < channelNames.length) {
fullChannels_e.append('\