2014-08-09 18:01:17 +00:00
|
|
|
'use strict';
|
2013-11-11 04:38:48 +00:00
|
|
|
|
2014-08-12 13:51:31 +00:00
|
|
|
TABS.servos = {};
|
2014-08-12 14:20:26 +00:00
|
|
|
TABS.servos.initialize = function (callback) {
|
2014-10-01 10:58:09 +00:00
|
|
|
var self = this;
|
|
|
|
|
2014-10-01 11:16:22 +00:00
|
|
|
if (GUI.active_tab != 'servos') {
|
|
|
|
GUI.active_tab = 'servos';
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
function get_servo_configurations() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_SERVO_CONFIGURATIONS, false, false, get_servo_mix_rules);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_servo_mix_rules() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_SERVO_MIX_RULES, false, false, get_channel_forwarding);
|
2014-07-06 11:26:41 +00:00
|
|
|
}
|
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
function get_channel_forwarding() {
|
|
|
|
var nextFunction = get_rc_data;
|
|
|
|
|
|
|
|
if (semver.lt(CONFIG.apiVersion, "1.12.0")) {
|
|
|
|
MSP.send_message(MSP_codes.MSP_CHANNEL_FORWARDING, false, false, nextFunction);
|
|
|
|
} else {
|
|
|
|
nextFunction();
|
|
|
|
}
|
2015-01-18 16:57:41 +00:00
|
|
|
}
|
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
function get_rc_data() {
|
2015-01-18 16:57:41 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_RC, false, false, get_boxnames_data);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_boxnames_data() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_BOXNAMES, false, false, load_html);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function load_html() {
|
|
|
|
$('#content').load("./tabs/servos.html", process_html);
|
|
|
|
}
|
2015-10-23 13:42:32 +00:00
|
|
|
|
2015-11-10 01:31:04 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_IDENT, false, false, get_servo_configurations);
|
2015-11-04 21:22:23 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
function update_ui() {
|
|
|
|
|
2015-12-18 13:48:08 +00:00
|
|
|
if (semver.lt(CONFIG.apiVersion, "1.12.0") || SERVO_CONFIG.length == 0) {
|
2015-10-23 13:42:32 +00:00
|
|
|
|
|
|
|
$(".tab-servos").removeClass("supported");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(".tab-servos").addClass("supported");
|
|
|
|
|
2015-01-18 21:00:39 +00:00
|
|
|
var servoCheckbox = '';
|
|
|
|
var servoHeader = '';
|
|
|
|
for (var i = 0; i < RC.active_channels-4; i++) {
|
|
|
|
servoHeader = servoHeader + '\
|
2015-01-18 16:57:41 +00:00
|
|
|
<th >A' + (i+1) + '</th>\
|
2015-01-18 21:00:39 +00:00
|
|
|
';
|
|
|
|
}
|
2015-11-08 12:56:01 +00:00
|
|
|
servoHeader = servoHeader + '<th style="width: 110px" i18n="servosDirectionAndRate"></th>';
|
2015-01-18 16:57:41 +00:00
|
|
|
|
2015-01-18 21:00:39 +00:00
|
|
|
for (var i = 0; i < RC.active_channels; i++) {
|
|
|
|
servoCheckbox = servoCheckbox + '\
|
2015-01-18 16:57:41 +00:00
|
|
|
<td class="channel"><input type="checkbox"/></td>\
|
2015-01-18 21:00:39 +00:00
|
|
|
';
|
|
|
|
}
|
2015-01-18 16:57:41 +00:00
|
|
|
|
|
|
|
$('div.tab-servos table.fields tr.main').append(servoHeader);
|
2014-05-06 14:48:46 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
function process_servos(name, alternate, obj) {
|
2015-01-18 21:00:39 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
$('div.supported_wrapper').show();
|
2015-01-18 21:00:39 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
$('div.tab-servos table.fields').append('\
|
|
|
|
<tr> \
|
|
|
|
<td style="text-align: center">' + name + '</td>\
|
2015-10-23 13:42:32 +00:00
|
|
|
<td class="middle"><input type="number" min="500" max="2500" value="' + SERVO_CONFIG[obj].middle + '" /></td>\
|
|
|
|
<td class="min"><input type="number" min="500" max="2500" value="' + SERVO_CONFIG[obj].min +'" /></td>\
|
|
|
|
<td class="max"><input type="number" min="500" max="2500" value="' + SERVO_CONFIG[obj].max +'" /></td>\
|
2015-12-14 13:23:54 +00:00
|
|
|
<td class="angleAtMin"><input type="number" min="-90" max="0" value="' + (-SERVO_CONFIG[obj].angleAtMin) +'" /></td>\
|
2015-10-23 13:42:32 +00:00
|
|
|
<td class="angleAtMax"><input type="number" min="0" max="90" value="' + SERVO_CONFIG[obj].angleAtMax +'" /></td>\
|
2015-01-18 21:00:39 +00:00
|
|
|
' + servoCheckbox + '\
|
2014-03-22 23:28:41 +00:00
|
|
|
<td class="direction">\
|
|
|
|
</td>\
|
|
|
|
</tr> \
|
|
|
|
');
|
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
if (SERVO_CONFIG[obj].indexOfChannelToForward >= 0) {
|
|
|
|
$('div.tab-servos table.fields tr:last td.channel input').eq(SERVO_CONFIG[obj].indexOfChannelToForward).prop('checked', true);
|
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
// adding select box and generating options
|
|
|
|
$('div.tab-servos table.fields tr:last td.direction').append('\
|
|
|
|
<select class="rate" name="rate"></select>\
|
|
|
|
');
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
var select = $('div.tab-servos table.fields tr:last td.direction select');
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
for (var i = 100; i > -101; i--) {
|
|
|
|
select.append('<option value="' + i + '">Rate: ' + i + '%</option>');
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
// select current rate
|
|
|
|
select.val(SERVO_CONFIG[obj].rate);
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
$('div.tab-servos table.fields tr:last').data('info', {'obj': obj});
|
2014-07-06 11:26:41 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// UI hooks
|
2014-07-06 11:26:41 +00:00
|
|
|
|
|
|
|
// only one checkbox for indicating a channel to forward can be selected at a time, perhaps a radio group would be best here.
|
2014-08-12 14:20:26 +00:00
|
|
|
$('div.tab-servos table.fields tr:last td.channel input').click(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
if($(this).is(':checked')) {
|
2014-04-02 13:47:34 +00:00
|
|
|
$(this).parent().parent().find('.channel input').not($(this)).prop('checked', false);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2013-11-12 10:43:08 +00:00
|
|
|
});
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
function servos_update(save_configuration_to_eeprom) {
|
2014-08-12 14:20:26 +00:00
|
|
|
$('div.tab-servos table.fields tr:not(".main")').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
var info = $(this).data('info');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
|
|
|
|
2014-07-06 11:26:41 +00:00
|
|
|
var selection = $('.channel input', this);
|
2015-02-10 01:12:26 +00:00
|
|
|
var channelIndex = parseInt(selection.index(selection.filter(':checked')));
|
|
|
|
if (channelIndex == -1) {
|
|
|
|
channelIndex = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
SERVO_CONFIG[info.obj].indexOfChannelToForward = channelIndex;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-07-06 11:26:41 +00:00
|
|
|
|
|
|
|
SERVO_CONFIG[info.obj].middle = parseInt($('.middle input', this).val());
|
2014-03-22 23:28:41 +00:00
|
|
|
SERVO_CONFIG[info.obj].min = parseInt($('.min input', this).val());
|
|
|
|
SERVO_CONFIG[info.obj].max = parseInt($('.max input', this).val());
|
2015-12-14 13:23:54 +00:00
|
|
|
SERVO_CONFIG[info.obj].angleAtMin = -parseInt($('.angleAtMin input', this).val());
|
2015-10-23 13:42:32 +00:00
|
|
|
SERVO_CONFIG[info.obj].angleAtMax = parseInt($('.angleAtMax input', this).val());
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
var val = parseInt($('.direction select', this).val());
|
|
|
|
SERVO_CONFIG[info.obj].rate = val;
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
2014-07-06 11:26:41 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
//
|
|
|
|
// send data to FC
|
|
|
|
//
|
|
|
|
MSP.sendServoConfigurations(send_servo_mixer_rules);
|
|
|
|
|
|
|
|
function send_servo_mixer_rules() {
|
|
|
|
MSP.sendServoConfigurations(save_to_eeprom);
|
|
|
|
}
|
|
|
|
|
|
|
|
function save_to_eeprom() {
|
|
|
|
if (save_configuration_to_eeprom) {
|
|
|
|
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () {
|
|
|
|
GUI.log(chrome.i18n.getMessage('servosEepromSave'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-12-18 22:38:55 +00:00
|
|
|
|
2013-11-11 05:56:03 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// drop previous table
|
|
|
|
$('div.tab-servos table.fields tr:not(:first)').remove();
|
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
for (var servoIndex = 0; servoIndex < 8; servoIndex++) {
|
|
|
|
process_servos('Servo ' + servoIndex, '', servoIndex, false);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// UI hooks for dynamically generated elements
|
2014-08-12 14:20:26 +00:00
|
|
|
$('table.directions select, table.directions input, table.fields select, table.fields input').change(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
if ($('div.live input').is(':checked')) {
|
|
|
|
// apply small delay as there seems to be some funky update business going wrong
|
|
|
|
GUI.timeout_add('servos_update', servos_update, 10);
|
|
|
|
}
|
|
|
|
});
|
2015-10-23 13:42:32 +00:00
|
|
|
|
2015-11-10 01:31:04 +00:00
|
|
|
$('a.update').click(function () {
|
2015-10-23 13:42:32 +00:00
|
|
|
servos_update(true);
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
2015-10-23 13:42:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function process_html() {
|
|
|
|
|
|
|
|
update_ui();
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
// translate to user-selected language
|
|
|
|
localize();
|
|
|
|
|
2014-03-30 09:51:16 +00:00
|
|
|
// status data pulled via separate timer with static speed
|
2014-08-12 14:20:26 +00:00
|
|
|
GUI.interval_add('status_pull', function () {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_STATUS);
|
2014-03-30 09:51:16 +00:00
|
|
|
}, 250, true);
|
2014-07-10 16:24:56 +00:00
|
|
|
|
2015-11-11 21:01:22 +00:00
|
|
|
GUI.content_ready(callback);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-07-10 16:24:56 +00:00
|
|
|
};
|
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
TABS.servos.cleanup = function (callback) {
|
2014-07-10 16:24:56 +00:00
|
|
|
if (callback) callback();
|
2015-10-23 13:42:32 +00:00
|
|
|
};
|