2013-04-10 16:49:25 +00:00
|
|
|
function tab_initialize_motor_outputs() {
|
2013-08-26 13:16:49 +00:00
|
|
|
ga_tracker.sendAppView('Motor Outputs Page');
|
2014-02-14 21:17:51 +00:00
|
|
|
GUI.active_tab = 'motor_outputs';
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_MISC, false, false, get_motor_data);
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
function get_motor_data() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_MOTOR, false, false, load_html);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function load_html() {
|
|
|
|
$('#content').load("./tabs/motor_outputs.html", process_html);
|
|
|
|
}
|
|
|
|
|
|
|
|
function process_html() {
|
2014-05-06 14:48:46 +00:00
|
|
|
// translate to user-selected language
|
|
|
|
localize();
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// if CAP_DYNBALANCE is true
|
|
|
|
if (bit_check(CONFIG.capability, 2)) {
|
|
|
|
$('div.motor_testing').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
var number_of_valid_outputs = (MOTOR_DATA.indexOf(0) > -1) ? MOTOR_DATA.indexOf(0) : 8;
|
|
|
|
|
|
|
|
$('input.min').val(MISC.mincommand);
|
|
|
|
$('input.max').val(MISC.maxthrottle);
|
|
|
|
|
|
|
|
|
|
|
|
$('div.sliders input').prop('min', MISC.mincommand);
|
|
|
|
$('div.sliders input').prop('max', MISC.maxthrottle);
|
|
|
|
$('div.sliders input').val(MISC.mincommand);
|
|
|
|
$('div.values li:not(:last)').html(MISC.mincommand);
|
|
|
|
|
|
|
|
// UI hooks
|
2014-04-10 15:36:26 +00:00
|
|
|
$('div.sliders input:not(.master)').on('input', function() {
|
2014-03-22 23:28:41 +00:00
|
|
|
var index = $(this).index();
|
|
|
|
|
|
|
|
$('div.values li').eq(index).html($(this).val());
|
|
|
|
|
|
|
|
// send data to mcu
|
|
|
|
var buffer_out = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < 8; i++) {
|
|
|
|
var val = parseInt($('div.sliders input').eq(i).val());
|
|
|
|
|
|
|
|
buffer_out.push(lowByte(val));
|
|
|
|
buffer_out.push(highByte(val));
|
|
|
|
}
|
|
|
|
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SET_MOTOR, buffer_out);
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
|
|
|
|
2014-04-10 15:36:26 +00:00
|
|
|
$('div.sliders input.master').on('input', function() {
|
2014-03-22 23:28:41 +00:00
|
|
|
var val = $(this).val();
|
|
|
|
|
|
|
|
$('div.sliders input:not(:disabled, :last)').val(val);
|
|
|
|
$('div.values li:not(:last)').slice(0, number_of_valid_outputs).html(val);
|
2014-04-10 15:36:26 +00:00
|
|
|
$('div.sliders input:not(:last):first').trigger('input');
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('div.notice input[type="checkbox"]').change(function() {
|
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
$('div.sliders input').slice(0, number_of_valid_outputs).prop('disabled', false);
|
|
|
|
|
|
|
|
// unlock master slider
|
|
|
|
$('div.sliders input:last').prop('disabled', false);
|
|
|
|
} else {
|
|
|
|
// disable sliders / min max
|
|
|
|
$('div.sliders input').prop('disabled', true);
|
|
|
|
|
|
|
|
// change all values to default
|
|
|
|
$('div.sliders input').val(1000);
|
|
|
|
$('div.values li:not(:last)').html(1000);
|
|
|
|
|
|
|
|
// trigger change event so values are sent to mcu
|
2014-04-10 15:36:26 +00:00
|
|
|
$('div.sliders input').trigger('input');
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-02-14 21:17:51 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
// data pulling functions used inside interval timer
|
|
|
|
function get_motor_data() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_MOTOR, false, false, get_servo_data);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_servo_data() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SERVO, false, false, update_ui);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function update_ui() {
|
|
|
|
var block_height = $('div.m-block:first').height();
|
|
|
|
|
|
|
|
for (var i = 0; i < MOTOR_DATA.length; i++) {
|
|
|
|
var data = MOTOR_DATA[i] - 1000;
|
|
|
|
var margin_top = block_height - (data * (block_height / 1000));
|
|
|
|
var height = (data * (block_height / 1000));
|
|
|
|
var color = parseInt(data * 0.256);
|
|
|
|
|
|
|
|
$('.motor-' + i + ' .indicator').css({'margin-top' : margin_top + 'px', 'height' : height + 'px', 'background-color' : 'rgb(' + color + ',0,0)'});
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < SERVO_DATA.length; i++) {
|
|
|
|
var data = SERVO_DATA[i] - 1000;
|
|
|
|
var margin_top = block_height - (data * (block_height / 1000));
|
|
|
|
var height = (data * (block_height / 1000));
|
|
|
|
var color = parseInt(data * 0.256);
|
|
|
|
|
|
|
|
$('.servo-' + i + ' .indicator').css({'margin-top' : margin_top + 'px', 'height' : height + 'px', 'background-color' : 'rgb(' + color + ',0,0)'});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable Motor data pulling
|
2014-03-30 09:51:16 +00:00
|
|
|
GUI.interval_add('motor_pull', get_motor_data, 50, true);
|
|
|
|
|
|
|
|
// status data pulled via separate timer with static speed
|
|
|
|
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-03-22 23:28:41 +00:00
|
|
|
}
|
2013-04-10 16:49:25 +00:00
|
|
|
}
|