2014-08-09 18:01:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
TABS.receiver = {
|
|
|
|
rateChartHeight: 120
|
|
|
|
};
|
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
TABS.receiver.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 != 'receiver') {
|
|
|
|
GUI.active_tab = 'receiver';
|
2014-10-30 11:33:39 +00:00
|
|
|
googleAnalytics.sendAppView('Receiver');
|
2014-10-01 11:16:22 +00:00
|
|
|
}
|
2014-09-24 14:01:23 +00:00
|
|
|
|
|
|
|
function get_misc_data() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_MISC, false, false, get_rc_data);
|
|
|
|
}
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
function get_rc_data() {
|
2014-09-19 15:44:04 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_RC, false, false, get_rc_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_rc_map() {
|
2015-10-23 13:42:32 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_RX_MAP, false, false, load_config);
|
|
|
|
}
|
2015-11-05 17:22:39 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
// Fetch features so we can check if RX_MSP is enabled:
|
|
|
|
function load_config() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_BF_CONFIG, false, false, load_html);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function load_html() {
|
|
|
|
$('#content').load("./tabs/receiver.html", process_html);
|
|
|
|
}
|
|
|
|
|
2014-09-24 14:01:23 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_RC_TUNING, false, false, get_misc_data);
|
2014-08-14 14:48:16 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
function process_html() {
|
2014-05-06 14:48:46 +00:00
|
|
|
// translate to user-selected language
|
|
|
|
localize();
|
|
|
|
|
2015-11-04 21:22:23 +00:00
|
|
|
// locating link to used CF version
|
|
|
|
var documentationButton = $('div#content #button-documentation');
|
|
|
|
documentationButton.html("Documentation for "+CONFIG.flightControllerVersion);
|
|
|
|
documentationButton.attr("href","https://github.com/cleanflight/cleanflight/tree/v{0}/docs".format(CONFIG.flightControllerVersion));
|
|
|
|
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// fill in data from RC_tuning
|
|
|
|
$('.tunings .throttle input[name="mid"]').val(RC_tuning.throttle_MID.toFixed(2));
|
|
|
|
$('.tunings .throttle input[name="expo"]').val(RC_tuning.throttle_EXPO.toFixed(2));
|
|
|
|
|
|
|
|
$('.tunings .rate input[name="rate"]').val(RC_tuning.RC_RATE.toFixed(2));
|
|
|
|
$('.tunings .rate input[name="expo"]').val(RC_tuning.RC_EXPO.toFixed(2));
|
2015-05-08 23:00:59 +00:00
|
|
|
$('.tunings .yaw_rate input[name="yaw_expo"]').val(RC_tuning.RC_YAW_EXPO.toFixed(2));
|
2015-10-23 13:42:32 +00:00
|
|
|
|
2015-05-08 23:00:59 +00:00
|
|
|
if (semver.lt(CONFIG.apiVersion, "1.10.0")) {
|
2015-05-07 23:30:45 +00:00
|
|
|
$('.tunings .yaw_rate input[name="yaw_expo"]').hide();
|
2015-05-07 23:11:43 +00:00
|
|
|
}
|
2015-10-23 13:42:32 +00:00
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
chrome.storage.local.get('rx_refresh_rate', function (result) {
|
2014-08-14 14:41:49 +00:00
|
|
|
if (result.rx_refresh_rate) {
|
2014-03-22 23:28:41 +00:00
|
|
|
$('select[name="rx_refresh_rate"]').val(result.rx_refresh_rate).change();
|
|
|
|
} else {
|
|
|
|
$('select[name="rx_refresh_rate"]').change(); // start with default value
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-19 21:36:04 +00:00
|
|
|
// generate bars
|
2015-10-23 13:42:32 +00:00
|
|
|
var bar_names = [
|
|
|
|
chrome.i18n.getMessage('controlAxisRoll'),
|
|
|
|
chrome.i18n.getMessage('controlAxisPitch'),
|
|
|
|
chrome.i18n.getMessage('controlAxisYaw'),
|
|
|
|
chrome.i18n.getMessage('controlAxisThrottle')
|
|
|
|
],
|
2014-08-12 14:20:26 +00:00
|
|
|
bar_container = $('.tab-receiver .bars'),
|
|
|
|
aux_index = 1;
|
2014-05-20 12:06:15 +00:00
|
|
|
|
2014-05-19 21:36:04 +00:00
|
|
|
for (var i = 0; i < RC.active_channels; i++) {
|
2014-05-20 12:06:15 +00:00
|
|
|
var name;
|
|
|
|
if (i < bar_names.length) {
|
|
|
|
name = bar_names[i];
|
|
|
|
} else {
|
2015-10-23 13:42:32 +00:00
|
|
|
name = chrome.i18n.getMessage("controlAxisAux" + (aux_index++));
|
2014-05-20 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 21:36:04 +00:00
|
|
|
bar_container.append('\
|
|
|
|
<ul>\
|
2014-05-20 12:06:15 +00:00
|
|
|
<li class="name">' + name + '</li>\
|
2014-09-22 16:58:56 +00:00
|
|
|
<li class="meter">\
|
2014-09-23 12:23:56 +00:00
|
|
|
<div class="meter-bar">\
|
|
|
|
<div class="label"></div>\
|
|
|
|
<div class="fill">\
|
|
|
|
<div class="label"></div>\
|
|
|
|
</div>\
|
|
|
|
</div>\
|
2014-09-22 16:58:56 +00:00
|
|
|
</li>\
|
2014-05-19 21:36:04 +00:00
|
|
|
</ul>\
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
2014-09-23 12:23:56 +00:00
|
|
|
// we could probably use min and max throttle for the range, will see
|
|
|
|
var meter_scale = {
|
|
|
|
'min': 800,
|
|
|
|
'max': 2200
|
|
|
|
};
|
|
|
|
|
|
|
|
var meter_fill_array = [];
|
|
|
|
$('.meter .fill', bar_container).each(function () {
|
|
|
|
meter_fill_array.push($(this));
|
2014-05-19 21:36:04 +00:00
|
|
|
});
|
|
|
|
|
2014-09-23 12:23:56 +00:00
|
|
|
var meter_label_array = [];
|
|
|
|
$('.meter', bar_container).each(function () {
|
|
|
|
meter_label_array.push($('.label' , this));
|
2014-05-19 21:36:04 +00:00
|
|
|
});
|
|
|
|
|
2014-09-23 12:23:56 +00:00
|
|
|
// correct inner label margin on window resize (i don't know how we could do this in css)
|
2014-10-06 17:16:48 +00:00
|
|
|
self.resize = function () {
|
2014-09-23 12:23:56 +00:00
|
|
|
var containerWidth = $('.meter:first', bar_container).width(),
|
|
|
|
labelWidth = $('.meter .label:first', bar_container).width(),
|
|
|
|
margin = (containerWidth / 2) - (labelWidth / 2);
|
|
|
|
|
|
|
|
for (var i = 0; i < meter_label_array.length; i++) {
|
|
|
|
meter_label_array[i].css('margin-left', margin);
|
|
|
|
}
|
2014-10-06 17:16:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$(window).on('resize', self.resize).resize(); // trigger so labels get correctly aligned on creation
|
2014-09-23 12:23:56 +00:00
|
|
|
|
2014-09-24 14:01:23 +00:00
|
|
|
// handle rcmap & rssi aux channel
|
2014-10-12 16:38:04 +00:00
|
|
|
var RC_MAP_Letters = ['A', 'E', 'R', 'T', '1', '2', '3', '4'];
|
2014-09-19 15:44:04 +00:00
|
|
|
|
2014-10-12 16:38:04 +00:00
|
|
|
var strBuffer = [];
|
|
|
|
for (var i = 0; i < RC_MAP.length; i++) {
|
|
|
|
strBuffer[RC_MAP[i]] = RC_MAP_Letters[i];
|
|
|
|
}
|
2014-09-19 15:44:04 +00:00
|
|
|
|
2014-10-12 16:38:04 +00:00
|
|
|
// reconstruct
|
|
|
|
var str = strBuffer.join('');
|
2014-09-19 18:05:32 +00:00
|
|
|
|
2014-10-12 16:38:04 +00:00
|
|
|
// set current value
|
|
|
|
$('input[name="rcmap"]').val(str);
|
2014-09-19 15:44:04 +00:00
|
|
|
|
2014-10-12 16:38:04 +00:00
|
|
|
// validation / filter
|
|
|
|
var last_valid = str;
|
2014-09-19 15:44:04 +00:00
|
|
|
|
2014-10-12 16:38:04 +00:00
|
|
|
$('input[name="rcmap"]').on('input', function () {
|
|
|
|
var val = $(this).val();
|
2014-09-19 15:44:04 +00:00
|
|
|
|
2014-10-12 16:38:04 +00:00
|
|
|
// limit length to max 8
|
|
|
|
if (val.length > 8) {
|
|
|
|
val = val.substr(0, 8);
|
|
|
|
$(this).val(val);
|
|
|
|
}
|
|
|
|
});
|
2014-09-19 15:44:04 +00:00
|
|
|
|
2014-10-12 16:38:04 +00:00
|
|
|
$('input[name="rcmap"]').focusout(function () {
|
|
|
|
var val = $(this).val(),
|
|
|
|
strBuffer = val.split(''),
|
|
|
|
duplicityBuffer = [];
|
|
|
|
|
|
|
|
if (val.length != 8) {
|
|
|
|
$(this).val(last_valid);
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-19 15:44:04 +00:00
|
|
|
|
2014-10-12 16:38:04 +00:00
|
|
|
// check if characters inside are all valid, also check for duplicity
|
|
|
|
for (var i = 0; i < val.length; i++) {
|
|
|
|
if (RC_MAP_Letters.indexOf(strBuffer[i]) < 0) {
|
2014-09-19 15:44:04 +00:00
|
|
|
$(this).val(last_valid);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-12 16:38:04 +00:00
|
|
|
if (duplicityBuffer.indexOf(strBuffer[i]) < 0) {
|
|
|
|
duplicityBuffer.push(strBuffer[i]);
|
|
|
|
} else {
|
|
|
|
$(this).val(last_valid);
|
|
|
|
return false;
|
2014-09-19 15:44:04 +00:00
|
|
|
}
|
2014-10-12 16:38:04 +00:00
|
|
|
}
|
|
|
|
});
|
2014-09-19 15:44:04 +00:00
|
|
|
|
2014-10-12 16:38:04 +00:00
|
|
|
// handle helper
|
|
|
|
$('select[name="rcmap_helper"]').val(0); // go out of bounds
|
|
|
|
$('select[name="rcmap_helper"]').change(function () {
|
|
|
|
$('input[name="rcmap"]').val($(this).val());
|
|
|
|
});
|
2014-09-24 14:01:23 +00:00
|
|
|
|
2015-01-07 13:50:24 +00:00
|
|
|
// rssi
|
2015-01-07 20:11:25 +00:00
|
|
|
var rssi_channel_e = $('select[name="rssi_channel"]');
|
2015-01-07 13:50:24 +00:00
|
|
|
rssi_channel_e.append('<option value="0">Disabled</option>');
|
|
|
|
for (var i = 0; i < RC.active_channels; i++) {
|
|
|
|
rssi_channel_e.append('<option value="' + i + '">' + i + '</option>');
|
|
|
|
}
|
|
|
|
|
|
|
|
$('select[name="rssi_channel"]').val(MISC.rssi_channel);
|
2014-09-19 15:44:04 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
var rateHeight = TABS.receiver.rateChartHeight;
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// UI Hooks
|
|
|
|
// curves
|
2014-09-22 09:03:00 +00:00
|
|
|
$('.tunings .throttle input').on('input change', function () {
|
2014-09-22 09:06:29 +00:00
|
|
|
setTimeout(function () { // let global validation trigger and adjust the values first
|
|
|
|
var throttleMidE = $('.tunings .throttle input[name="mid"]'),
|
|
|
|
throttleExpoE = $('.tunings .throttle input[name="expo"]'),
|
|
|
|
mid = parseFloat(throttleMidE.val()),
|
|
|
|
expo = parseFloat(throttleExpoE.val()),
|
|
|
|
throttle_curve = $('.throttle_curve canvas').get(0),
|
|
|
|
context = throttle_curve.getContext("2d");
|
|
|
|
|
|
|
|
// local validation to deal with input event
|
|
|
|
if (mid >= parseFloat(throttleMidE.prop('min')) &&
|
|
|
|
mid <= parseFloat(throttleMidE.prop('max')) &&
|
|
|
|
expo >= parseFloat(throttleExpoE.prop('min')) &&
|
|
|
|
expo <= parseFloat(throttleExpoE.prop('max'))) {
|
|
|
|
// continue
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2014-09-22 08:50:34 +00:00
|
|
|
|
2014-09-22 09:06:29 +00:00
|
|
|
// math magic by englishman
|
|
|
|
var midx = 220 * mid,
|
|
|
|
midxl = midx * 0.5,
|
|
|
|
midxr = (((220 - midx) * 0.5) + midx),
|
2015-10-23 13:42:32 +00:00
|
|
|
midy = rateHeight - (midx * (rateHeight / 220)),
|
|
|
|
midyl = rateHeight - ((rateHeight - midy) * 0.5 *(expo + 1)),
|
2014-09-22 09:06:29 +00:00
|
|
|
midyr = (midy / 2) * (expo + 1);
|
|
|
|
|
|
|
|
// draw
|
2015-10-23 13:42:32 +00:00
|
|
|
context.clearRect(0, 0, 220, rateHeight);
|
2014-09-22 09:06:29 +00:00
|
|
|
context.beginPath();
|
2015-10-23 13:42:32 +00:00
|
|
|
context.moveTo(0, rateHeight);
|
2014-09-22 09:06:29 +00:00
|
|
|
context.quadraticCurveTo(midxl, midyl, midx, midy);
|
|
|
|
context.moveTo(midx, midy);
|
|
|
|
context.quadraticCurveTo(midxr, midyr, 220, 0);
|
|
|
|
context.lineWidth = 2;
|
|
|
|
context.stroke();
|
|
|
|
}, 0);
|
2014-09-22 08:50:34 +00:00
|
|
|
}).trigger('input');
|
|
|
|
|
2014-09-22 09:03:00 +00:00
|
|
|
$('.tunings .rate input').on('input change', function () {
|
2014-09-22 09:06:29 +00:00
|
|
|
setTimeout(function () { // let global validation trigger and adjust the values first
|
|
|
|
var rateE = $('.tunings .rate input[name="rate"]'),
|
|
|
|
expoE = $('.tunings .rate input[name="expo"]'),
|
|
|
|
rate = parseFloat(rateE.val()),
|
|
|
|
expo = parseFloat(expoE.val()),
|
|
|
|
pitch_roll_curve = $('.pitch_roll_curve canvas').get(0),
|
|
|
|
context = pitch_roll_curve.getContext("2d");
|
|
|
|
|
|
|
|
// local validation to deal with input event
|
|
|
|
if (rate >= parseFloat(rateE.prop('min')) &&
|
|
|
|
rate <= parseFloat(rateE.prop('max')) &&
|
|
|
|
expo >= parseFloat(expoE.prop('min')) &&
|
|
|
|
expo <= parseFloat(expoE.prop('max'))) {
|
|
|
|
// continue
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2014-09-22 08:50:34 +00:00
|
|
|
|
2014-09-22 09:06:29 +00:00
|
|
|
// math magic by englishman
|
2015-10-23 13:42:32 +00:00
|
|
|
var ratey = rateHeight * rate;
|
2014-09-22 09:06:29 +00:00
|
|
|
|
|
|
|
// draw
|
2015-10-23 13:42:32 +00:00
|
|
|
context.clearRect(0, 0, 220, rateHeight);
|
2014-09-22 09:06:29 +00:00
|
|
|
context.beginPath();
|
2015-10-23 13:42:32 +00:00
|
|
|
context.moveTo(0, rateHeight);
|
|
|
|
context.quadraticCurveTo(110, rateHeight - ((ratey / 2) * (1 - expo)), 220, rateHeight - ratey);
|
2014-09-22 09:06:29 +00:00
|
|
|
context.lineWidth = 2;
|
|
|
|
context.stroke();
|
|
|
|
}, 0);
|
2014-09-22 08:50:34 +00:00
|
|
|
}).trigger('input');
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
$('a.refresh').click(function () {
|
|
|
|
MSP.send_message(MSP_codes.MSP_RC_TUNING, false, false, function () {
|
2014-05-06 21:33:47 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('receiverDataRefreshed'));
|
2014-03-29 18:21:13 +00:00
|
|
|
|
2014-02-14 21:17:51 +00:00
|
|
|
// fill in data from RC_tuning
|
|
|
|
$('.tunings .throttle input[name="mid"]').val(RC_tuning.throttle_MID.toFixed(2));
|
|
|
|
$('.tunings .throttle input[name="expo"]').val(RC_tuning.throttle_EXPO.toFixed(2));
|
2013-04-10 16:49:25 +00:00
|
|
|
|
2014-02-14 21:17:51 +00:00
|
|
|
$('.tunings .rate input[name="rate"]').val(RC_tuning.RC_RATE.toFixed(2));
|
|
|
|
$('.tunings .rate input[name="expo"]').val(RC_tuning.RC_EXPO.toFixed(2));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// update visual representation
|
|
|
|
$('.tunings .throttle input').change();
|
|
|
|
$('.tunings .rate input').change();
|
|
|
|
});
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
$('a.update').click(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
// catch RC_tuning changes
|
|
|
|
RC_tuning.throttle_MID = parseFloat($('.tunings .throttle input[name="mid"]').val());
|
|
|
|
RC_tuning.throttle_EXPO = parseFloat($('.tunings .throttle input[name="expo"]').val());
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
RC_tuning.RC_RATE = parseFloat($('.tunings .rate input[name="rate"]').val());
|
|
|
|
RC_tuning.RC_EXPO = parseFloat($('.tunings .rate input[name="expo"]').val());
|
2015-05-07 23:30:45 +00:00
|
|
|
RC_tuning.RC_YAW_EXPO = parseFloat($('.tunings .yaw_rate input[name="yaw_expo"]').val());
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-09-19 15:44:04 +00:00
|
|
|
// catch rc map
|
2014-09-19 18:05:32 +00:00
|
|
|
var RC_MAP_Letters = ['A', 'E', 'R', 'T', '1', '2', '3', '4'];
|
2014-09-19 15:44:04 +00:00
|
|
|
var strBuffer = $('input[name="rcmap"]').val().split('');
|
|
|
|
|
|
|
|
for (var i = 0; i < RC_MAP.length; i++) {
|
2014-09-19 18:05:32 +00:00
|
|
|
RC_MAP[i] = strBuffer.indexOf(RC_MAP_Letters[i]);
|
2014-09-19 15:44:04 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 14:01:23 +00:00
|
|
|
// catch rssi aux
|
2015-01-07 13:50:24 +00:00
|
|
|
MISC.rssi_channel = parseInt($('select[name="rssi_channel"]').val());
|
2014-09-24 14:01:23 +00:00
|
|
|
|
2014-09-19 15:44:04 +00:00
|
|
|
function save_rc_map() {
|
2015-03-29 13:51:28 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SET_RX_MAP, MSP.crunch(MSP_codes.MSP_SET_RX_MAP), false, save_misc);
|
2014-09-24 14:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function save_misc() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_SET_MISC, MSP.crunch(MSP_codes.MSP_SET_MISC), false, save_to_eeprom);
|
2014-09-19 15:44:04 +00:00
|
|
|
}
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
function save_to_eeprom() {
|
2014-08-12 14:20:26 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () {
|
2014-05-06 21:33:47 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('receiverEepromSaved'));
|
2014-03-06 18:50:01 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-09-16 21:07:52 +00:00
|
|
|
|
2014-10-12 16:38:04 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch(MSP_codes.MSP_SET_RC_TUNING), false, save_rc_map);
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
2015-11-05 17:22:39 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
$("a.sticks").click(function() {
|
|
|
|
var
|
|
|
|
windowWidth = 370,
|
|
|
|
windowHeight = 510;
|
2015-11-05 17:22:39 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
chrome.app.window.create("/tabs/receiver_msp.html", {
|
|
|
|
id: "receiver_msp",
|
|
|
|
innerBounds: {
|
|
|
|
minWidth: windowWidth, minHeight: windowHeight,
|
2015-11-05 17:22:39 +00:00
|
|
|
width: windowWidth, height: windowHeight,
|
2015-10-23 13:42:32 +00:00
|
|
|
maxWidth: windowWidth, maxHeight: windowHeight
|
|
|
|
},
|
|
|
|
alwaysOnTop: true
|
|
|
|
}, function(createdWindow) {
|
|
|
|
// Give the window a callback it can use to send the channels (otherwise it can't see those objects)
|
|
|
|
createdWindow.contentWindow.setRawRx = function(channels) {
|
|
|
|
if (CONFIGURATOR.connectionValid && GUI.active_tab != 'cli') {
|
|
|
|
MSP.setRawRx(channels);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2015-11-05 17:22:39 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
// Only show the MSP control sticks if the MSP Rx feature is enabled
|
2015-11-05 17:22:39 +00:00
|
|
|
$(".sticks_btn").toggle(bit_check(BF_CONFIG.features, 14 /* RX_MSP */));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
$('select[name="rx_refresh_rate"]').change(function () {
|
2014-04-12 15:20:43 +00:00
|
|
|
var plot_update_rate = parseInt($(this).val(), 10);
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
// save update rate
|
|
|
|
chrome.storage.local.set({'rx_refresh_rate': plot_update_rate});
|
|
|
|
|
|
|
|
function get_rc_data() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_RC, false, false, update_ui);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-03-29 18:21:13 +00:00
|
|
|
// setup plot
|
2014-05-15 11:12:13 +00:00
|
|
|
var RX_plot_data = new Array(RC.active_channels);
|
|
|
|
for (var i = 0; i < RX_plot_data.length; i++) {
|
2014-03-29 18:21:13 +00:00
|
|
|
RX_plot_data[i] = [];
|
|
|
|
}
|
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
var samples = 0,
|
|
|
|
svg = d3.select("svg"),
|
|
|
|
RX_plot_e = $('#RX_plot'),
|
|
|
|
margin = {top: 20, right: 0, bottom: 10, left: 40},
|
|
|
|
width, height, widthScale, heightScale;
|
2014-03-29 18:21:13 +00:00
|
|
|
|
2014-04-21 10:14:03 +00:00
|
|
|
function update_receiver_plot_size() {
|
2014-05-05 09:34:20 +00:00
|
|
|
width = RX_plot_e.width() - margin.left - margin.right;
|
|
|
|
height = RX_plot_e.height() - margin.top - margin.bottom;
|
2014-04-21 10:14:03 +00:00
|
|
|
|
|
|
|
widthScale.range([0, width]);
|
|
|
|
heightScale.range([height, 0]);
|
|
|
|
}
|
|
|
|
|
2014-03-28 17:45:50 +00:00
|
|
|
function update_ui() {
|
2014-05-15 11:12:13 +00:00
|
|
|
// update bars with latest data
|
|
|
|
for (var i = 0; i < RC.active_channels; i++) {
|
2014-10-05 17:46:27 +00:00
|
|
|
meter_fill_array[i].css('width', ((RC.channels[i] - meter_scale.min) / (meter_scale.max - meter_scale.min) * 100).clamp(0, 100) + '%');
|
2014-09-23 12:23:56 +00:00
|
|
|
meter_label_array[i].text(RC.channels[i]);
|
2014-05-15 11:12:13 +00:00
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
// push latest data to the main array
|
2014-05-15 11:12:13 +00:00
|
|
|
for (var i = 0; i < RC.active_channels; i++) {
|
|
|
|
RX_plot_data[i].push([samples, RC.channels[i]]);
|
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
// Remove old data from array
|
|
|
|
while (RX_plot_data[0].length > 300) {
|
2014-05-15 11:12:13 +00:00
|
|
|
for (var i = 0; i < RX_plot_data.length; i++) {
|
|
|
|
RX_plot_data[i].shift();
|
|
|
|
}
|
2014-04-12 15:20:43 +00:00
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-03-29 18:21:13 +00:00
|
|
|
// update required parts of the plot
|
2014-04-21 10:14:03 +00:00
|
|
|
widthScale = d3.scale.linear().
|
2014-04-20 21:12:18 +00:00
|
|
|
domain([(samples - 299), samples]);
|
2014-04-12 15:20:43 +00:00
|
|
|
|
2014-04-21 10:14:03 +00:00
|
|
|
heightScale = d3.scale.linear().
|
2014-04-20 21:12:18 +00:00
|
|
|
domain([800, 2200]);
|
|
|
|
|
|
|
|
update_receiver_plot_size();
|
|
|
|
|
2014-04-12 15:20:43 +00:00
|
|
|
var xGrid = d3.svg.axis().
|
|
|
|
scale(widthScale).
|
|
|
|
orient("bottom").
|
|
|
|
tickSize(-height, 0, 0).
|
|
|
|
tickFormat("");
|
|
|
|
|
|
|
|
var yGrid = d3.svg.axis().
|
|
|
|
scale(heightScale).
|
|
|
|
orient("left").
|
|
|
|
tickSize(-width, 0, 0).
|
|
|
|
tickFormat("");
|
|
|
|
|
|
|
|
var xAxis = d3.svg.axis().
|
|
|
|
scale(widthScale).
|
|
|
|
orient("bottom").
|
2014-08-12 14:20:26 +00:00
|
|
|
tickFormat(function (d) {return d;});
|
2014-04-12 15:20:43 +00:00
|
|
|
|
|
|
|
var yAxis = d3.svg.axis().
|
|
|
|
scale(heightScale).
|
|
|
|
orient("left").
|
2014-08-12 14:20:26 +00:00
|
|
|
tickFormat(function (d) {return d;});
|
2014-04-12 15:20:43 +00:00
|
|
|
|
|
|
|
var line = d3.svg.line().
|
2014-08-12 14:20:26 +00:00
|
|
|
x(function (d) {return widthScale(d[0]);}).
|
|
|
|
y(function (d) {return heightScale(d[1]);});
|
2014-04-12 15:20:43 +00:00
|
|
|
|
|
|
|
svg.select(".x.grid").call(xGrid);
|
|
|
|
svg.select(".y.grid").call(yGrid);
|
|
|
|
svg.select(".x.axis").call(xAxis);
|
|
|
|
svg.select(".y.axis").call(yAxis);
|
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
var data = svg.select("g.data"),
|
|
|
|
lines = data.selectAll("path").data(RX_plot_data, function (d, i) {return i;}),
|
|
|
|
newLines = lines.enter().append("path").attr("class", "line");
|
2014-04-12 15:20:43 +00:00
|
|
|
lines.attr('d', line);
|
2014-03-30 09:11:06 +00:00
|
|
|
|
2014-03-29 18:21:13 +00:00
|
|
|
samples++;
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// timer initialization
|
2014-03-30 09:51:16 +00:00
|
|
|
GUI.interval_remove('receiver_pull');
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
// enable RC data pulling
|
2014-03-30 09:51:16 +00:00
|
|
|
GUI.interval_add('receiver_pull', get_rc_data, plot_update_rate, true);
|
2014-01-24 16:06:54 +00:00
|
|
|
});
|
2014-03-30 09:51:16 +00:00
|
|
|
|
|
|
|
// status data pulled via separate timer with static speed
|
2014-10-01 10:58:09 +00:00
|
|
|
GUI.interval_add('status_pull', function status_pull() {
|
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:20:09 +00:00
|
|
|
|
|
|
|
if (callback) callback();
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-07-10 16:20:09 +00:00
|
|
|
};
|
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
TABS.receiver.cleanup = function (callback) {
|
2014-10-06 17:16:48 +00:00
|
|
|
$(window).off('resize', this.resize);
|
2014-09-23 12:23:56 +00:00
|
|
|
|
2014-07-10 16:20:09 +00:00
|
|
|
if (callback) callback();
|
|
|
|
};
|