2015-01-02 00:05:09 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
TABS.ports = {};
|
|
|
|
|
|
|
|
TABS.ports.initialize = function (callback, scrollPosition) {
|
|
|
|
var self = this;
|
|
|
|
|
2015-01-03 00:57:56 +00:00
|
|
|
var board_definition = {};
|
2015-02-27 01:15:37 +00:00
|
|
|
|
|
|
|
var functionRules = [
|
2015-03-03 22:56:48 +00:00
|
|
|
{name: 'MSP', groups: ['data', 'msp'], maxPorts: 2},
|
|
|
|
{name: 'GPS', groups: ['gps'], maxPorts: 1},
|
|
|
|
{name: 'TELEMETRY_FRSKY', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['blackbox'], maxPorts: 1},
|
|
|
|
{name: 'TELEMETRY_HOTT', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['blackbox'], maxPorts: 1},
|
|
|
|
{name: 'TELEMETRY_MSP', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['blackbox'], maxPorts: 1},
|
|
|
|
{name: 'TELEMETRY_SMARTPORT', groups: ['telemetry'], maxPorts: 1},
|
|
|
|
{name: 'RX_SERIAL', groups: ['rx'], maxPorts: 1},
|
|
|
|
{name: 'BLACKBOX', groups: ['logging', 'blackbox'], sharableWith: ['msp'], notSharableWith: ['telemetry'], maxPorts: 1},
|
2015-02-27 01:15:37 +00:00
|
|
|
];
|
2015-03-03 22:56:48 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < functionRules.length; i++) {
|
|
|
|
functionRules[i].displayName = chrome.i18n.getMessage('portsFunction_' + functionRules[i].name);
|
|
|
|
}
|
2015-02-27 01:15:37 +00:00
|
|
|
|
|
|
|
var mspBaudRates = [
|
|
|
|
'9600',
|
|
|
|
'19200',
|
|
|
|
'38400',
|
|
|
|
'57600',
|
|
|
|
'115200'
|
|
|
|
];
|
|
|
|
|
|
|
|
var gpsBaudRates = [
|
|
|
|
'9600',
|
|
|
|
'19200',
|
|
|
|
'38400',
|
|
|
|
'57600',
|
|
|
|
'115200'
|
|
|
|
];
|
|
|
|
|
|
|
|
var telemetryBaudRates = [
|
|
|
|
'AUTO',
|
|
|
|
'9600',
|
|
|
|
'19200',
|
|
|
|
'38400',
|
|
|
|
'57600',
|
|
|
|
'115200'
|
|
|
|
];
|
|
|
|
|
|
|
|
var blackboxBaudRates = [
|
2015-03-06 06:58:57 +00:00
|
|
|
'19200',
|
|
|
|
'38400',
|
|
|
|
'57600',
|
|
|
|
'115200',
|
|
|
|
'230400',
|
2015-03-07 00:07:32 +00:00
|
|
|
'250000',
|
2015-02-27 01:15:37 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
var columns = ['data', 'logging', 'gps', 'telemetry', 'rx'];
|
|
|
|
|
2015-01-02 00:05:09 +00:00
|
|
|
if (GUI.active_tab != 'ports') {
|
|
|
|
GUI.active_tab = 'ports';
|
|
|
|
googleAnalytics.sendAppView('Ports');
|
|
|
|
}
|
|
|
|
|
2015-01-02 16:35:54 +00:00
|
|
|
load_configuration_from_fc();
|
|
|
|
|
|
|
|
function load_configuration_from_fc() {
|
2015-01-03 00:57:56 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_CF_SERIAL_CONFIG, false, false, on_configuration_loaded_handler);
|
|
|
|
|
2015-01-02 16:35:54 +00:00
|
|
|
function on_configuration_loaded_handler() {
|
2015-03-03 22:56:48 +00:00
|
|
|
console.log(SERIAL_CONFIG.ports);
|
|
|
|
|
2015-01-02 16:35:54 +00:00
|
|
|
$('#content').load("./tabs/ports.html", on_tab_loaded_handler);
|
2015-01-03 00:57:56 +00:00
|
|
|
|
2015-11-04 21:22:23 +00:00
|
|
|
|
2015-01-03 00:57:56 +00:00
|
|
|
board_definition = BOARD.find_board_definition(CONFIG.boardIdentifier);
|
|
|
|
console.log('Using board definition', board_definition);
|
2015-01-02 16:35:54 +00:00
|
|
|
}
|
2015-11-04 21:22:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2015-01-02 00:05:09 +00:00
|
|
|
|
2015-02-27 01:15:37 +00:00
|
|
|
function update_ui() {
|
2015-01-03 00:57:56 +00:00
|
|
|
|
2015-05-07 21:10:26 +00:00
|
|
|
if (semver.lt(CONFIG.apiVersion, "1.6.0")) {
|
2015-03-11 23:34:24 +00:00
|
|
|
|
|
|
|
$(".tab-ports").removeClass("supported");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(".tab-ports").addClass("supported");
|
2015-01-03 00:57:56 +00:00
|
|
|
|
|
|
|
var portIdentifierToNameMapping = {
|
|
|
|
0: 'UART1',
|
|
|
|
1: 'UART2',
|
|
|
|
2: 'UART3',
|
|
|
|
3: 'UART4',
|
|
|
|
20: 'USB VCP',
|
|
|
|
30: 'SOFTSERIAL1',
|
|
|
|
31: 'SOFTSERIAL2'
|
|
|
|
};
|
2015-02-27 01:15:37 +00:00
|
|
|
|
|
|
|
var gps_baudrate_e = $('select.gps_baudrate');
|
|
|
|
for (var i = 0; i < gpsBaudRates.length; i++) {
|
|
|
|
gps_baudrate_e.append('<option value="' + gpsBaudRates[i] + '">' + gpsBaudRates[i] + '</option>');
|
2015-01-03 00:57:56 +00:00
|
|
|
}
|
2015-02-27 01:15:37 +00:00
|
|
|
|
|
|
|
var msp_baudrate_e = $('select.msp_baudrate');
|
|
|
|
for (var i = 0; i < mspBaudRates.length; i++) {
|
|
|
|
msp_baudrate_e.append('<option value="' + mspBaudRates[i] + '">' + mspBaudRates[i] + '</option>');
|
|
|
|
}
|
|
|
|
|
|
|
|
var telemetry_baudrate_e = $('select.telemetry_baudrate');
|
|
|
|
for (var i = 0; i < telemetryBaudRates.length; i++) {
|
|
|
|
telemetry_baudrate_e.append('<option value="' + telemetryBaudRates[i] + '">' + telemetryBaudRates[i] + '</option>');
|
|
|
|
}
|
|
|
|
|
|
|
|
var blackbox_baudrate_e = $('select.blackbox_baudrate');
|
|
|
|
for (var i = 0; i < blackboxBaudRates.length; i++) {
|
|
|
|
blackbox_baudrate_e.append('<option value="' + blackboxBaudRates[i] + '">' + blackboxBaudRates[i] + '</option>');
|
|
|
|
}
|
|
|
|
|
2015-01-03 00:57:56 +00:00
|
|
|
var ports_e = $('.tab-ports .ports');
|
|
|
|
var port_configuration_template_e = $('#tab-ports-templates .portConfiguration');
|
|
|
|
|
2015-02-04 22:59:25 +00:00
|
|
|
for (var portIndex = 0; portIndex < SERIAL_CONFIG.ports.length; portIndex++) {
|
2015-01-03 00:57:56 +00:00
|
|
|
var port_configuration_e = port_configuration_template_e.clone();
|
|
|
|
var serialPort = SERIAL_CONFIG.ports[portIndex];
|
2015-03-03 22:56:48 +00:00
|
|
|
|
|
|
|
port_configuration_e.data('serialPort', serialPort);
|
|
|
|
|
2015-02-27 01:15:37 +00:00
|
|
|
// TODO check functions
|
|
|
|
// TODO set baudrate
|
2015-03-03 22:56:48 +00:00
|
|
|
var msp_baudrate_e = port_configuration_e.find('select.msp_baudrate');
|
|
|
|
msp_baudrate_e.val(serialPort.msp_baudrate);
|
|
|
|
|
|
|
|
var telemetry_baudrate_e = port_configuration_e.find('select.telemetry_baudrate');
|
|
|
|
telemetry_baudrate_e.val(serialPort.telemetry_baudrate);
|
|
|
|
|
|
|
|
var gps_baudrate_e = port_configuration_e.find('select.gps_baudrate');
|
|
|
|
gps_baudrate_e.val(serialPort.gps_baudrate);
|
|
|
|
|
|
|
|
var blackbox_baudrate_e = port_configuration_e.find('select.blackbox_baudrate');
|
|
|
|
blackbox_baudrate_e.val(serialPort.blackbox_baudrate);
|
|
|
|
|
2015-01-03 00:57:56 +00:00
|
|
|
port_configuration_e.find('.identifier').text(portIdentifierToNameMapping[serialPort.identifier])
|
|
|
|
|
|
|
|
port_configuration_e.data('index', portIndex);
|
|
|
|
port_configuration_e.data('port', serialPort);
|
2015-03-03 22:56:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
for (var columnIndex = 0; columnIndex < columns.length; columnIndex++) {
|
|
|
|
var column = columns[columnIndex];
|
|
|
|
|
|
|
|
var functions_e = $(port_configuration_e).find('.functionsCell-' + column);
|
|
|
|
|
|
|
|
for (var i = 0; i < functionRules.length; i++) {
|
|
|
|
var functionRule = functionRules[i];
|
|
|
|
var functionName = functionRule.name;
|
|
|
|
|
|
|
|
if (functionRule.groups.indexOf(column) == -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var select_e;
|
|
|
|
if (column != 'telemetry') {
|
|
|
|
var checkboxId = 'functionCheckbox-' + portIndex + '-' + columnIndex + '-' + i;
|
2015-10-30 19:30:27 +00:00
|
|
|
functions_e.prepend('<span class="function"><input type="checkbox" class="togglesmall" id="' + checkboxId + '" value="' + functionName + '" /><label for="' + checkboxId + '"> ' + functionRule.displayName + '</label></span>');
|
2015-03-03 22:56:48 +00:00
|
|
|
|
2015-10-30 19:30:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-03 22:56:48 +00:00
|
|
|
if (serialPort.functions.indexOf(functionName) >= 0) {
|
|
|
|
var checkbox_e = functions_e.find('#' + checkboxId);
|
|
|
|
checkbox_e.prop("checked", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
var selectElementName = 'function-' + column;
|
|
|
|
var selectElementSelector = 'select[name=' + selectElementName + ']';
|
|
|
|
select_e = functions_e.find(selectElementSelector);
|
|
|
|
|
|
|
|
if (select_e.size() == 0) {
|
|
|
|
functions_e.prepend('<span class="function"><select name="' + selectElementName + '" /></span>');
|
|
|
|
select_e = functions_e.find(selectElementSelector);
|
2015-03-05 15:57:23 +00:00
|
|
|
var disabledText = chrome.i18n.getMessage('portsTelemetryDisabled');
|
|
|
|
select_e.append('<option value="">' + disabledText + '</option>');
|
2015-03-03 22:56:48 +00:00
|
|
|
}
|
|
|
|
select_e.append('<option value="' + functionName + '">' + functionRule.displayName + '</option>');
|
|
|
|
|
|
|
|
if (serialPort.functions.indexOf(functionName) >= 0) {
|
|
|
|
select_e.val(functionName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-03 00:57:56 +00:00
|
|
|
ports_e.find('tbody').append(port_configuration_e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-02 16:35:54 +00:00
|
|
|
function on_tab_loaded_handler() {
|
2015-01-02 00:05:09 +00:00
|
|
|
|
|
|
|
localize();
|
2015-01-03 00:57:56 +00:00
|
|
|
|
2015-02-27 01:15:37 +00:00
|
|
|
update_ui();
|
2015-01-02 00:05:09 +00:00
|
|
|
|
2015-01-02 16:35:54 +00:00
|
|
|
$('a.save').click(on_save_handler);
|
2015-01-02 00:05:09 +00:00
|
|
|
|
2015-01-02 16:35:54 +00:00
|
|
|
// status data pulled via separate timer with static speed
|
|
|
|
GUI.interval_add('status_pull', function status_pull() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_STATUS);
|
|
|
|
}, 250, true);
|
2015-01-02 00:05:09 +00:00
|
|
|
|
2015-01-02 16:35:54 +00:00
|
|
|
if (callback) callback();
|
|
|
|
}
|
2015-01-02 00:05:09 +00:00
|
|
|
|
2015-10-30 19:30:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function on_save_handler() {
|
2015-01-02 16:35:54 +00:00
|
|
|
|
2015-01-03 00:57:56 +00:00
|
|
|
// update configuration based on current ui state
|
2015-03-03 22:56:48 +00:00
|
|
|
SERIAL_CONFIG.ports = [];
|
|
|
|
|
|
|
|
var ports_e = $('.tab-ports .portConfiguration').each(function (portConfiguration_e) {
|
2015-01-03 00:57:56 +00:00
|
|
|
|
2015-03-03 22:56:48 +00:00
|
|
|
var portConfiguration_e = this;
|
|
|
|
|
|
|
|
var oldSerialPort = $(this).data('serialPort');
|
|
|
|
|
|
|
|
var functions = $(portConfiguration_e).find('input:checkbox:checked').map(function() {
|
|
|
|
return this.value;
|
|
|
|
}).get();
|
|
|
|
|
|
|
|
var telemetryFunction = $(portConfiguration_e).find('select[name=function-telemetry]').val();
|
|
|
|
if (telemetryFunction) {
|
|
|
|
functions.push(telemetryFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
var serialPort = {
|
|
|
|
functions: functions,
|
|
|
|
msp_baudrate: $(portConfiguration_e).find('.msp_baudrate').val(),
|
|
|
|
telemetry_baudrate: $(portConfiguration_e).find('.telemetry_baudrate').val(),
|
|
|
|
gps_baudrate: $(portConfiguration_e).find('.gps_baudrate').val(),
|
|
|
|
blackbox_baudrate: $(portConfiguration_e).find('.blackbox_baudrate').val(),
|
|
|
|
identifier: oldSerialPort.identifier
|
|
|
|
};
|
2015-10-23 13:42:32 +00:00
|
|
|
|
|
|
|
console.log(serialPort);
|
2015-03-03 22:56:48 +00:00
|
|
|
SERIAL_CONFIG.ports.push(serialPort);
|
2015-01-03 00:57:56 +00:00
|
|
|
});
|
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
|
2015-01-03 00:57:56 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SET_CF_SERIAL_CONFIG, MSP.crunch(MSP_codes.MSP_SET_CF_SERIAL_CONFIG), false, save_to_eeprom);
|
2015-01-02 00:05:09 +00:00
|
|
|
|
2015-01-02 16:35:54 +00:00
|
|
|
function save_to_eeprom() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, on_saved_handler);
|
|
|
|
}
|
2015-01-02 00:05:09 +00:00
|
|
|
|
2015-01-02 16:35:54 +00:00
|
|
|
function on_saved_handler() {
|
|
|
|
GUI.log(chrome.i18n.getMessage('configurationEepromSaved'));
|
2015-01-02 00:05:09 +00:00
|
|
|
|
2015-01-02 16:35:54 +00:00
|
|
|
GUI.tab_switch_cleanup(function() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_SET_REBOOT, false, false, on_reboot_success_handler);
|
|
|
|
});
|
|
|
|
}
|
2015-01-02 00:05:09 +00:00
|
|
|
|
2015-01-02 16:35:54 +00:00
|
|
|
function on_reboot_success_handler() {
|
|
|
|
GUI.log(chrome.i18n.getMessage('deviceRebooting'));
|
2015-01-02 00:05:09 +00:00
|
|
|
|
2015-10-23 13:42:32 +00:00
|
|
|
var rebootTimeoutDelay = 1500; // seems to be just the right amount of delay to prevent data request timeouts
|
|
|
|
|
|
|
|
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_IDENT, false, false, function () {
|
|
|
|
GUI.log(chrome.i18n.getMessage('deviceReady'));
|
|
|
|
TABS.ports.initialize(false, $('#content').scrollTop());
|
|
|
|
});
|
|
|
|
}, rebootTimeoutDelay);
|
2015-09-14 12:21:09 +00:00
|
|
|
}
|
2015-01-02 00:05:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-30 19:30:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-02 00:05:09 +00:00
|
|
|
TABS.ports.cleanup = function (callback) {
|
|
|
|
if (callback) callback();
|
2015-03-13 21:19:24 +00:00
|
|
|
};
|