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-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() {
|
|
|
|
$('#content').load("./tabs/ports.html", on_tab_loaded_handler);
|
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-01-02 00:05:09 +00:00
|
|
|
}
|
|
|
|
|
2015-01-03 00:57:56 +00:00
|
|
|
function addSerialPortScenarios() {
|
|
|
|
|
|
|
|
var scenarioNames = [
|
|
|
|
'Unused',
|
|
|
|
'MSP, CLI, Telemetry (when armed), GPS Passthrough',
|
|
|
|
'GPS',
|
|
|
|
'Serial RX',
|
|
|
|
'Telemetry',
|
|
|
|
'MSP, CLI, GPS Passthrough',
|
|
|
|
'CLI',
|
|
|
|
'GPS Passthrough',
|
|
|
|
'MSP',
|
|
|
|
'SmartPort Telemetry'
|
|
|
|
];
|
|
|
|
|
|
|
|
var portIdentifierToNameMapping = {
|
|
|
|
0: 'UART1',
|
|
|
|
1: 'UART2',
|
|
|
|
2: 'UART3',
|
|
|
|
3: 'UART4',
|
|
|
|
20: 'USB VCP',
|
|
|
|
30: 'SOFTSERIAL1',
|
|
|
|
31: 'SOFTSERIAL2'
|
|
|
|
};
|
|
|
|
|
|
|
|
var scenario_e = $('#tab-ports-templates select.scenario');
|
|
|
|
|
|
|
|
for (var i = 0; i < scenarioNames.length; i++) {
|
|
|
|
scenario_e.append('<option value="' + i + '">' + scenarioNames[i] + '</option>');
|
|
|
|
}
|
|
|
|
|
|
|
|
var ports_e = $('.tab-ports .ports');
|
|
|
|
var port_configuration_template_e = $('#tab-ports-templates .portConfiguration');
|
|
|
|
|
|
|
|
for (var portIndex = 0; portIndex < board_definition.serialPortCount; portIndex++) {
|
|
|
|
var port_configuration_e = port_configuration_template_e.clone();
|
|
|
|
|
|
|
|
var serialPort = SERIAL_CONFIG.ports[portIndex];
|
|
|
|
|
|
|
|
port_configuration_e.find('select').val(serialPort.scenario);
|
|
|
|
port_configuration_e.find('.identifier').text(portIdentifierToNameMapping[serialPort.identifier])
|
|
|
|
|
|
|
|
port_configuration_e.data('index', portIndex);
|
|
|
|
port_configuration_e.data('port', serialPort);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
addSerialPortScenarios();
|
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-01-02 16:35:54 +00:00
|
|
|
function on_save_handler() {
|
|
|
|
|
2015-01-03 00:57:56 +00:00
|
|
|
// update configuration based on current ui state
|
|
|
|
var ports_e = $('.tab-ports .portConfiguration').each(function () {
|
|
|
|
var portIndex = $(this).data('index');
|
|
|
|
|
|
|
|
SERIAL_CONFIG.ports[portIndex].scenario = parseInt($(this).find('select').val());
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
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-01-02 16:35:54 +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-01-02 00:05:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TABS.ports.cleanup = function (callback) {
|
|
|
|
if (callback) callback();
|
|
|
|
};
|