2014-11-09 00:46:12 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
TABS.adjustments = {};
|
2014-12-18 22:38:55 +00:00
|
|
|
|
2014-11-09 00:46:12 +00:00
|
|
|
TABS.adjustments.initialize = function (callback) {
|
2016-08-11 22:10:53 +00:00
|
|
|
var self = this;
|
2014-11-09 00:46:12 +00:00
|
|
|
GUI.active_tab_ref = this;
|
|
|
|
GUI.active_tab = 'adjustments';
|
|
|
|
|
|
|
|
function get_adjustment_ranges() {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_ADJUSTMENT_RANGES, false, false, get_box_ids);
|
2014-11-09 00:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_box_ids() {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_BOXIDS, false, false, get_rc_data);
|
2014-11-09 00:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_rc_data() {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_RC, false, false, load_html);
|
2014-11-09 00:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function load_html() {
|
2016-08-11 22:10:53 +00:00
|
|
|
self.adjust_template();
|
2014-11-09 00:46:12 +00:00
|
|
|
$('#content').load("./tabs/adjustments.html", process_html);
|
|
|
|
}
|
|
|
|
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_BOXNAMES, false, false, get_adjustment_ranges);
|
2014-11-09 00:46:12 +00:00
|
|
|
|
|
|
|
function addAdjustment(adjustmentIndex, adjustmentRange, auxChannelCount) {
|
|
|
|
|
|
|
|
var template = $('#tab-adjustments-templates .adjustments .adjustment');
|
|
|
|
var newAdjustment = template.clone();
|
|
|
|
|
|
|
|
$(newAdjustment).attr('id', 'adjustment-' + adjustmentIndex);
|
|
|
|
$(newAdjustment).data('index', adjustmentIndex);
|
|
|
|
|
|
|
|
//
|
|
|
|
// update selected slot
|
|
|
|
//
|
|
|
|
|
2016-12-02 07:31:27 +00:00
|
|
|
var adjustmentList = $(newAdjustment).find('.adjustmentSlot .slot');
|
|
|
|
adjustmentList.val(adjustmentRange.slotIndex);
|
2014-11-09 00:46:12 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// populate source channel select box
|
|
|
|
//
|
|
|
|
|
|
|
|
var channelList = $(newAdjustment).find('.channelInfo .channel');
|
|
|
|
var channelOptionTemplate = $(channelList).find('option');
|
|
|
|
channelOptionTemplate.remove();
|
|
|
|
for (var channelIndex = 0; channelIndex < auxChannelCount; channelIndex++) {
|
|
|
|
var channelOption = channelOptionTemplate.clone();
|
|
|
|
channelOption.text('AUX ' + (channelIndex + 1));
|
|
|
|
channelOption.val(channelIndex);
|
|
|
|
channelList.append(channelOption);
|
|
|
|
}
|
|
|
|
channelList.val(adjustmentRange.auxChannelIndex);
|
|
|
|
|
|
|
|
//
|
|
|
|
// update selected function
|
|
|
|
//
|
2016-08-08 21:17:22 +00:00
|
|
|
|
2015-05-17 23:09:29 +00:00
|
|
|
var functionList = $(newAdjustment).find('.functionSelection .function');
|
2016-08-08 21:17:22 +00:00
|
|
|
// update list of selected functions
|
|
|
|
|
|
|
|
functionList.val(adjustmentRange.adjustmentFunction);
|
|
|
|
|
2014-11-09 00:46:12 +00:00
|
|
|
//
|
|
|
|
// populate function channel select box
|
|
|
|
//
|
2016-08-08 21:17:22 +00:00
|
|
|
|
2016-12-02 07:31:27 +00:00
|
|
|
var switchList = $(newAdjustment).find('.functionSwitchChannel .channel');
|
|
|
|
var switchOptionTemplate = $(switchList).find('option');
|
|
|
|
switchOptionTemplate.remove();
|
|
|
|
var switchOption;
|
|
|
|
for (var switchIndex = 0; switchIndex < auxChannelCount; switchIndex++) {
|
|
|
|
switchOption = switchOptionTemplate.clone();
|
|
|
|
switchOption.text('AUX ' + (switchIndex + 1));
|
|
|
|
switchOption.val(switchIndex);
|
|
|
|
switchList.append(switchOption);
|
2014-11-09 00:46:12 +00:00
|
|
|
}
|
2016-12-02 07:31:27 +00:00
|
|
|
switchList.val(adjustmentRange.auxSwitchChannelIndex);
|
2014-11-09 00:46:12 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// configure range
|
|
|
|
//
|
|
|
|
|
|
|
|
var channel_range = {
|
|
|
|
'min': [ 900 ],
|
|
|
|
'max': [ 2100 ]
|
|
|
|
};
|
2016-12-02 07:31:27 +00:00
|
|
|
|
|
|
|
var rangeValues = [1300, 1700];
|
2014-11-09 00:46:12 +00:00
|
|
|
if (adjustmentRange.range != undefined) {
|
|
|
|
rangeValues = [adjustmentRange.range.start, adjustmentRange.range.end];
|
|
|
|
}
|
|
|
|
|
|
|
|
var rangeElement = $(newAdjustment).find('.range');
|
|
|
|
|
|
|
|
$(rangeElement).find('.channel-slider').noUiSlider({
|
|
|
|
start: rangeValues,
|
|
|
|
behaviour: 'snap-drag',
|
2016-01-12 19:19:23 +00:00
|
|
|
margin: 50,
|
2014-11-09 00:46:12 +00:00
|
|
|
step: 25,
|
|
|
|
connect: true,
|
|
|
|
range: channel_range,
|
|
|
|
format: wNumb({
|
2016-12-02 07:31:27 +00:00
|
|
|
decimals: 0
|
2014-11-09 00:46:12 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
$(newAdjustment).find('.channel-slider').Link('lower').to($(newAdjustment).find('.lowerLimitValue'));
|
|
|
|
$(newAdjustment).find('.channel-slider').Link('upper').to($(newAdjustment).find('.upperLimitValue'));
|
|
|
|
|
|
|
|
$(rangeElement).find(".pips-channel-range").noUiSlider_pips({
|
|
|
|
mode: 'values',
|
|
|
|
values: [900, 1000, 1200, 1400, 1500, 1600, 1800, 2000, 2100],
|
|
|
|
density: 4,
|
|
|
|
stepped: true
|
|
|
|
});
|
|
|
|
|
|
|
|
//
|
|
|
|
// add the enable/disable behavior
|
|
|
|
//
|
|
|
|
|
|
|
|
var enableElement = $(newAdjustment).find('.enable');
|
|
|
|
$(enableElement).data('adjustmentElement', newAdjustment);
|
|
|
|
$(enableElement).change(function() {
|
|
|
|
var adjustmentElement = $(this).data('adjustmentElement');
|
|
|
|
if ($(this).prop("checked")) {
|
|
|
|
$(adjustmentElement).find(':input').prop("disabled", false);
|
|
|
|
$(adjustmentElement).find('.channel-slider').removeAttr("disabled");
|
2014-11-09 04:55:52 +00:00
|
|
|
var rangeElement = $(adjustmentElement).find('.range .channel-slider');
|
|
|
|
var range = $(rangeElement).val();
|
|
|
|
if (range[0] == range[1]) {
|
|
|
|
var defaultRangeValues = [1300, 1700];
|
|
|
|
$(rangeElement).val(defaultRangeValues);
|
|
|
|
}
|
2014-11-09 00:46:12 +00:00
|
|
|
} else {
|
|
|
|
$(adjustmentElement).find(':input').prop("disabled", true);
|
|
|
|
$(adjustmentElement).find('.channel-slider').attr("disabled", "disabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
// keep this element enabled
|
|
|
|
$(this).prop("disabled", false);
|
|
|
|
});
|
|
|
|
|
|
|
|
var isEnabled = (adjustmentRange.range.start != adjustmentRange.range.end);
|
|
|
|
$(enableElement).prop("checked", isEnabled).change();
|
|
|
|
|
|
|
|
return newAdjustment;
|
|
|
|
}
|
|
|
|
|
|
|
|
function process_html() {
|
|
|
|
|
|
|
|
var auxChannelCount = RC.active_channels - 4;
|
|
|
|
|
2016-12-02 07:31:27 +00:00
|
|
|
var modeTableBodyElement = $('.tab-adjustments .adjustments tbody');
|
2014-11-09 00:46:12 +00:00
|
|
|
for (var adjustmentIndex = 0; adjustmentIndex < ADJUSTMENT_RANGES.length; adjustmentIndex++) {
|
|
|
|
var newAdjustment = addAdjustment(adjustmentIndex, ADJUSTMENT_RANGES[adjustmentIndex], auxChannelCount);
|
|
|
|
modeTableBodyElement.append(newAdjustment);
|
|
|
|
}
|
|
|
|
|
|
|
|
// translate to user-selected language
|
|
|
|
localize();
|
|
|
|
|
|
|
|
// UI Hooks
|
|
|
|
$('a.save').click(function () {
|
|
|
|
|
|
|
|
// update internal data structures based on current UI elements
|
|
|
|
var requiredAdjustmentRangeCount = ADJUSTMENT_RANGES.length;
|
|
|
|
|
|
|
|
ADJUSTMENT_RANGES = [];
|
|
|
|
|
|
|
|
var defaultAdjustmentRange = {
|
|
|
|
slotIndex: 0,
|
|
|
|
auxChannelIndex: 0,
|
|
|
|
range: {
|
|
|
|
start: 900,
|
|
|
|
end: 900
|
|
|
|
},
|
|
|
|
adjustmentFunction: 0,
|
|
|
|
auxSwitchChannelIndex: 0
|
|
|
|
};
|
|
|
|
|
2014-12-21 12:29:36 +00:00
|
|
|
$('.tab-adjustments .adjustments .adjustment').each(function () {
|
2014-11-09 00:46:12 +00:00
|
|
|
var adjustmentElement = $(this);
|
|
|
|
|
|
|
|
if ($(adjustmentElement).find('.enable').prop("checked")) {
|
|
|
|
var rangeValues = $(this).find('.range .channel-slider').val();
|
|
|
|
var adjustmentRange = {
|
|
|
|
slotIndex: parseInt($(this).find('.adjustmentSlot .slot').val()),
|
|
|
|
auxChannelIndex: parseInt($(this).find('.channelInfo .channel').val()),
|
|
|
|
range: {
|
|
|
|
start: rangeValues[0],
|
|
|
|
end: rangeValues[1]
|
|
|
|
},
|
|
|
|
adjustmentFunction: parseInt($(this).find('.functionSelection .function').val()),
|
2016-12-02 07:31:27 +00:00
|
|
|
auxSwitchChannelIndex: parseInt($(this).find('.functionSwitchChannel .channel').val())
|
2014-11-09 00:46:12 +00:00
|
|
|
};
|
|
|
|
ADJUSTMENT_RANGES.push(adjustmentRange);
|
|
|
|
} else {
|
|
|
|
ADJUSTMENT_RANGES.push(defaultAdjustmentRange);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for (var adjustmentRangeIndex = ADJUSTMENT_RANGES.length; adjustmentRangeIndex < requiredAdjustmentRangeCount; adjustmentRangeIndex++) {
|
|
|
|
ADJUSTMENT_RANGES.push(defaultAdjustmentRange);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// send data to FC
|
|
|
|
//
|
2016-08-13 13:15:14 +00:00
|
|
|
mspHelper.sendAdjustmentRanges(save_to_eeprom);
|
2014-11-09 00:46:12 +00:00
|
|
|
|
|
|
|
function save_to_eeprom() {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () {
|
2014-11-09 00:46:12 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('adjustmentsEepromSaved'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-11-09 04:55:52 +00:00
|
|
|
function update_marker(auxChannelIndex, channelPosition) {
|
|
|
|
if (channelPosition < 900) {
|
|
|
|
channelPosition = 900;
|
|
|
|
} else if (channelPosition > 2100) {
|
|
|
|
channelPosition = 2100;
|
|
|
|
}
|
|
|
|
var percentage = (channelPosition - 900) / (2100-900) * 100;
|
|
|
|
|
|
|
|
$('.adjustments .adjustment').each( function () {
|
|
|
|
var auxChannelCandidateIndex = $(this).find('.channel').val();
|
|
|
|
if (auxChannelCandidateIndex != auxChannelIndex) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(this).find('.range .marker').css('left', percentage + '%');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-11-09 00:46:12 +00:00
|
|
|
// data pulling functions used inside interval timer
|
|
|
|
function get_rc_data() {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_RC, false, false, update_ui);
|
2014-11-09 00:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function update_ui() {
|
2014-11-09 04:55:52 +00:00
|
|
|
var auxChannelCount = RC.active_channels - 4;
|
|
|
|
|
|
|
|
for (var auxChannelIndex = 0; auxChannelIndex < auxChannelCount; auxChannelIndex++) {
|
|
|
|
update_marker(auxChannelIndex, RC.channels[auxChannelIndex + 4]);
|
|
|
|
}
|
2014-11-09 00:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update ui instantly on first load
|
|
|
|
update_ui();
|
|
|
|
|
|
|
|
// enable data pulling
|
|
|
|
GUI.interval_add('aux_data_pull', get_rc_data, 50);
|
|
|
|
|
|
|
|
// status data pulled via separate timer with static speed
|
|
|
|
GUI.interval_add('status_pull', function () {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_STATUS);
|
2014-11-09 00:46:12 +00:00
|
|
|
}, 250, true);
|
|
|
|
|
2015-11-11 21:01:22 +00:00
|
|
|
GUI.content_ready(callback);
|
2014-11-09 00:46:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TABS.adjustments.cleanup = function (callback) {
|
|
|
|
if (callback) callback();
|
2016-06-16 05:25:11 +00:00
|
|
|
};
|
2016-08-11 22:10:53 +00:00
|
|
|
|
|
|
|
TABS.adjustments.adjust_template = function () {
|
2016-12-02 07:31:27 +00:00
|
|
|
var availableFunctionCount;
|
2017-02-26 01:16:20 +00:00
|
|
|
if (semver.lt(CONFIG.apiVersion, "1.31.0")) {
|
2016-12-02 07:31:27 +00:00
|
|
|
availableFunctionCount = 21; // Available in betaflight 2.9
|
|
|
|
} else {
|
|
|
|
availableFunctionCount = 24; // RC rate Yaw / D setpoint / D setpoint transition added to 3.1.0
|
2016-08-11 22:10:53 +00:00
|
|
|
}
|
|
|
|
var template = $('#tab-adjustments-templates .adjustments .adjustment');
|
|
|
|
var functionList = $(template).find('.functionSelection .function');
|
2016-12-02 07:31:27 +00:00
|
|
|
var functionListOptions = $(functionList).find('option').slice(0,availableFunctionCount);
|
2016-08-11 22:10:53 +00:00
|
|
|
functionList.empty().append(functionListOptions);
|
|
|
|
};
|