2016-01-08 11:47:54 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-04-02 17:58:33 +00:00
|
|
|
|
2016-01-08 11:47:54 +00:00
|
|
|
TABS.transponder = {
|
|
|
|
available: false
|
|
|
|
};
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
TABS.transponder.initialize = function(callback, scrollPosition) {
|
2017-04-02 17:58:33 +00:00
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
let _persistentInputValues = {};
|
|
|
|
|
|
|
|
let dataTypes = {
|
|
|
|
NONE: 0,
|
|
|
|
TEXT: 1,
|
|
|
|
LIST: 2,
|
2017-04-02 17:58:33 +00:00
|
|
|
};
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
// CONFIGURATION HERE FOR ADD NEW TRANSPONDER
|
|
|
|
let transponderConfigurations = {
|
2017-04-02 17:58:33 +00:00
|
|
|
0: {
|
|
|
|
dataType: dataTypes.NONE // empty
|
|
|
|
}, //NONE
|
|
|
|
1: {
|
|
|
|
dataType: dataTypes.TEXT //<input type="text">
|
|
|
|
}, //ilap
|
|
|
|
2: {
|
|
|
|
dataType: dataTypes.LIST, // <select>...</select>
|
|
|
|
dataOptions: {
|
2017-04-11 19:19:10 +00:00
|
|
|
'ID 1': 'E00370FC0FFE07E0FF',
|
|
|
|
'ID 2': '007C003EF800FC0FFE',
|
|
|
|
'ID 3': 'F8811FF8811FFFC7FF',
|
|
|
|
'ID 4': '007C003EF81F800FFE',
|
|
|
|
'ID 5': 'F00FFF00FFF00FF0FF',
|
|
|
|
'ID 6': '007CF0C1071F7C00F0',
|
|
|
|
'ID 7': 'E003F03F00FF03F0C1',
|
|
|
|
'ID 8': '00FC0FFE071F3E00FE',
|
|
|
|
'ID 9': 'E083BFF00F9E38C0FF',
|
2017-04-02 17:58:33 +00:00
|
|
|
}
|
|
|
|
}, //arcitimer
|
2017-06-17 15:42:05 +00:00
|
|
|
3: {
|
|
|
|
dataType: dataTypes.LIST, // <select>...</select>
|
|
|
|
dataOptions: {
|
|
|
|
'0':'00',
|
|
|
|
'1':'01',
|
|
|
|
'2':'02',
|
|
|
|
'3':'03',
|
|
|
|
'4':'04',
|
|
|
|
'5':'05',
|
|
|
|
'6':'06',
|
|
|
|
'7':'07',
|
|
|
|
'8':'08',
|
|
|
|
'9':'09',
|
|
|
|
'10':'0A',
|
|
|
|
'11':'0B',
|
|
|
|
'12':'0C',
|
|
|
|
'13':'0D',
|
|
|
|
'14':'0E',
|
|
|
|
'15':'0F',
|
|
|
|
'16':'10',
|
|
|
|
'17':'11',
|
|
|
|
'18':'12',
|
|
|
|
'19':'13',
|
|
|
|
'20':'14',
|
|
|
|
'21':'15',
|
|
|
|
'22':'16',
|
|
|
|
'23':'17',
|
|
|
|
'24':'18',
|
|
|
|
'25':'19',
|
|
|
|
'26':'1A',
|
|
|
|
'27':'1B',
|
|
|
|
'28':'1C',
|
|
|
|
'29':'1D',
|
|
|
|
'30':'1E',
|
|
|
|
'31':'1F',
|
|
|
|
'32':'20',
|
|
|
|
'33':'21',
|
|
|
|
'34':'22',
|
|
|
|
'35':'23',
|
|
|
|
'36':'24',
|
|
|
|
'37':'25',
|
|
|
|
'38':'26',
|
|
|
|
'39':'27',
|
|
|
|
'40':'28',
|
|
|
|
'41':'29',
|
|
|
|
'42':'2A',
|
|
|
|
'43':'2B',
|
|
|
|
'44':'2C',
|
|
|
|
'45':'2D',
|
|
|
|
'46':'2E',
|
|
|
|
'47':'2F',
|
|
|
|
'48':'30',
|
|
|
|
'49':'31',
|
|
|
|
'50':'32',
|
|
|
|
'51':'33',
|
|
|
|
'52':'34',
|
|
|
|
'53':'35',
|
|
|
|
'54':'36',
|
|
|
|
'55':'37',
|
|
|
|
'56':'38',
|
|
|
|
'57':'39',
|
|
|
|
'58':'3A',
|
|
|
|
'59':'3B',
|
|
|
|
'60':'3C',
|
|
|
|
'61':'3D',
|
|
|
|
'62':'3E',
|
|
|
|
'63':'3F',
|
|
|
|
}
|
|
|
|
}, //ERLT
|
2017-04-02 17:58:33 +00:00
|
|
|
};
|
2017-04-11 19:19:10 +00:00
|
|
|
/////////////////////////////////////////////
|
2016-01-08 11:47:54 +00:00
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
if ( GUI.active_tab != 'transponder' ) {
|
2016-01-08 11:47:54 +00:00
|
|
|
GUI.active_tab = 'transponder';
|
2017-04-30 09:56:03 +00:00
|
|
|
// Disabled on merge into betaflight-configurator
|
|
|
|
//googleAnalytics.sendAppView('Transponder');
|
2016-01-08 11:47:54 +00:00
|
|
|
}
|
|
|
|
// transponder supported added in MSP API Version 1.16.0
|
2017-04-11 19:19:10 +00:00
|
|
|
if ( CONFIG ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
TABS.transponder.available = semver.gte(CONFIG.apiVersion, "1.16.0");
|
|
|
|
}
|
|
|
|
//////////////
|
2017-04-11 19:19:10 +00:00
|
|
|
if ( !TABS.transponder.available ) {
|
2016-01-08 11:47:54 +00:00
|
|
|
load_html();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_html() {
|
|
|
|
$('#content').load("./tabs/transponder.html", process_html);
|
|
|
|
}
|
|
|
|
|
2017-04-02 17:58:33 +00:00
|
|
|
//HELPERS
|
2016-01-08 11:47:54 +00:00
|
|
|
// Convert a hex string to a byte array
|
|
|
|
function hexToBytes(hex) {
|
2017-04-11 19:19:10 +00:00
|
|
|
var bytes = [];
|
|
|
|
for ( let c = 0; c < hex.length; c += 2 ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
bytes.push(~parseInt(hex.substr(c, 2), 16));
|
2017-04-11 19:19:10 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 11:47:54 +00:00
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
function pad(n, width) {
|
|
|
|
n = n + '';
|
|
|
|
return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
|
|
|
|
}
|
2017-04-02 17:58:33 +00:00
|
|
|
|
2016-01-08 11:47:54 +00:00
|
|
|
// Convert a byte array to a hex string
|
|
|
|
function bytesToHex(bytes) {
|
2017-04-11 19:19:10 +00:00
|
|
|
var hex = [];
|
|
|
|
for ( let i = 0; i < bytes.length; i++ ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
hex.push(pad(((~bytes[i]) & 0xFF).toString(16), 2));
|
2016-01-08 11:47:54 +00:00
|
|
|
}
|
|
|
|
return hex.join("").toUpperCase();
|
|
|
|
}
|
2017-04-11 19:19:10 +00:00
|
|
|
|
2017-04-02 17:58:33 +00:00
|
|
|
/////////////
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
function fillByTransponderProviders(transponderProviders, transponderProviderID, toggleTransponderType) {
|
|
|
|
let transponderTypeSelect = $('#transponder_type_select');
|
2017-04-02 17:58:33 +00:00
|
|
|
transponderTypeSelect.attr('data-defaultValue', transponderProviderID);
|
|
|
|
transponderTypeSelect.off('change').change(toggleTransponderType);
|
|
|
|
transponderTypeSelect.html('');
|
|
|
|
|
|
|
|
//build radio buttons
|
|
|
|
transponderTypeSelect.append(
|
|
|
|
$('<option>').attr('value', 0).html(chrome.i18n.getMessage("transponderType0")) // NONE
|
|
|
|
);
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
for ( let transponderProvidersKey in transponderProviders ) {
|
|
|
|
let transponderProvider = transponderProviders[transponderProvidersKey];
|
2017-04-02 17:58:33 +00:00
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
if ( transponderProvider.hasOwnProperty('id') ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
transponderTypeSelect.append(
|
|
|
|
$('<option>').attr('value', transponderProvider.id).html(chrome.i18n.getMessage("transponderType" + transponderProvider.id))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
transponderTypeSelect.val(transponderProviderID);
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildDataBlockForTransponderProviders(transponderProvider, data, clearValue) {
|
|
|
|
var clearValue = clearValue || false;
|
|
|
|
$('#transponderConfiguration').html('');
|
|
|
|
$('#transponderConfiguration').hide();
|
|
|
|
$('#transponderHelpBox').hide();
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
if ( !transponderProvider ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
let template = $('#transponder-configuration-template').clone();
|
2017-04-02 17:58:33 +00:00
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
template.find('.spacer_box_title').html(chrome.i18n.getMessage("transponderData" + transponderProvider.id));
|
|
|
|
template.find('.dataHelp').html(chrome.i18n.getMessage("transponderDataHelp" + transponderProvider.id));
|
2017-04-02 17:58:33 +00:00
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
|
|
|
|
if ( chrome.i18n.getMessage("transponderHelp" + transponderProvider.id).length ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
$('#transponderHelp').html(chrome.i18n.getMessage("transponderHelp" + transponderProvider.id));
|
|
|
|
$('#transponderHelpBox').show();
|
|
|
|
}
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
let transponderConfiguration = transponderConfigurations[transponderProvider.id];
|
|
|
|
let dataInput = null;
|
2017-04-02 17:58:33 +00:00
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
switch ( transponderConfiguration.dataType ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
|
|
|
|
case dataTypes.TEXT:
|
|
|
|
dataInput = $('<input>').attr('type', 'text').attr('maxlength', parseInt(transponderProvider.dataLength) * 2);
|
2017-04-11 19:19:10 +00:00
|
|
|
if ( !clearValue ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
dataInput.val(data);
|
2017-04-11 19:19:10 +00:00
|
|
|
} else {
|
|
|
|
dataInput.val(_persistentInputValues[transponderProvider.id] || '');
|
2017-04-02 17:58:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case dataTypes.LIST:
|
|
|
|
dataInput = $('<select>');
|
2017-04-11 19:19:10 +00:00
|
|
|
for ( let dataOptionsKey in transponderConfiguration.dataOptions ) {
|
|
|
|
let dataOptions = transponderConfiguration.dataOptions[dataOptionsKey];
|
2017-04-02 17:58:33 +00:00
|
|
|
dataInput.append($('<option>').val(dataOptions).html(dataOptionsKey));
|
|
|
|
}
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
if ( dataInput.find("option[value='" + data + "']").length > 0 && !clearValue ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
dataInput.val(data);
|
2017-04-11 19:19:10 +00:00
|
|
|
} else {
|
|
|
|
dataInput.val(_persistentInputValues[transponderProvider.id] || '');
|
2016-01-08 11:47:54 +00:00
|
|
|
}
|
2017-04-02 17:58:33 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
if ( !clearValue ) {
|
|
|
|
_persistentInputValues[transponderProvider.id] = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
let changedInputValue = function() {
|
|
|
|
let dataString = $(this).val();
|
|
|
|
let hexRegExp = new RegExp('[0-9a-fA-F]{' + (transponderProvider.dataLength * 2) + '}', 'gi');
|
2017-04-02 17:58:33 +00:00
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
if ( !dataString.match(hexRegExp) ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
TRANSPONDER.data = [];
|
2017-04-11 19:19:10 +00:00
|
|
|
} else {
|
2016-01-08 11:47:54 +00:00
|
|
|
TRANSPONDER.data = hexToBytes(dataString);
|
2017-04-02 17:58:33 +00:00
|
|
|
}
|
2017-04-11 19:19:10 +00:00
|
|
|
_persistentInputValues[transponderProvider.id] = dataString;
|
2017-04-02 17:58:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
dataInput.change(changedInputValue).keyup(changedInputValue);
|
2017-04-11 19:19:10 +00:00
|
|
|
template.find('.input_block').html(dataInput);
|
|
|
|
$('#transponder-configuration').html(template.show());
|
2017-04-02 17:58:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this function is called from select click scope
|
|
|
|
*/
|
2017-04-11 19:19:10 +00:00
|
|
|
function toggleTransponderType() {
|
2017-04-02 17:58:33 +00:00
|
|
|
|
|
|
|
TRANSPONDER.provider = $(this).val();
|
2017-04-11 19:19:10 +00:00
|
|
|
let defaultProvider = $(this).attr('data-defaultValue');
|
|
|
|
if ( defaultProvider == $(this).val() ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
$('.save_reboot').hide();
|
|
|
|
$('.save_no_reboot').show();
|
2017-04-11 19:19:10 +00:00
|
|
|
} else {
|
2017-04-02 17:58:33 +00:00
|
|
|
$('.save_no_reboot').hide();
|
|
|
|
$('.save_reboot').show();
|
|
|
|
}
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
let clearValue = true;
|
|
|
|
buildDataBlockForTransponderProviders(TRANSPONDER.providers.find(function(provider) {
|
2017-04-02 17:58:33 +00:00
|
|
|
return provider.id == TRANSPONDER.provider;
|
|
|
|
}), bytesToHex(TRANSPONDER.data), clearValue);
|
|
|
|
}
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
|
2017-04-02 17:58:33 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_TRANSPONDER_CONFIG, false, false, load_html);
|
|
|
|
|
|
|
|
function process_html() {
|
|
|
|
$(".tab-transponder").toggleClass("transponder-supported", TABS.transponder.available && TRANSPONDER.supported);
|
|
|
|
|
|
|
|
localize();
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
if ( TABS.transponder.available && TRANSPONDER.providers.length > 0 ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
|
|
|
|
fillByTransponderProviders(TRANSPONDER.providers, TRANSPONDER.provider, toggleTransponderType);
|
2017-04-11 19:19:10 +00:00
|
|
|
buildDataBlockForTransponderProviders(TRANSPONDER.providers.find(function(provider) {
|
2017-04-02 17:58:33 +00:00
|
|
|
return provider.id == TRANSPONDER.provider;
|
|
|
|
}), bytesToHex(TRANSPONDER.data));
|
|
|
|
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
$('a.save').click(function() {
|
|
|
|
let _this = this;
|
2017-04-02 17:58:33 +00:00
|
|
|
|
|
|
|
function save_transponder_data() {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_SET_TRANSPONDER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_TRANSPONDER_CONFIG), false, save_to_eeprom);
|
2016-01-08 11:47:54 +00:00
|
|
|
}
|
2017-04-02 17:58:33 +00:00
|
|
|
|
2016-01-08 11:47:54 +00:00
|
|
|
function save_to_eeprom() {
|
2017-04-11 19:19:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function() {
|
2017-04-02 17:58:33 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('transponderEepromSaved'));
|
2017-04-11 19:19:10 +00:00
|
|
|
if ( $(_this).hasClass('reboot') ) {
|
|
|
|
GUI.tab_switch_cleanup(function() {
|
2017-04-02 17:58:33 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitialize);
|
|
|
|
});
|
|
|
|
}
|
2016-01-08 11:47:54 +00:00
|
|
|
});
|
|
|
|
}
|
2017-04-02 17:58:33 +00:00
|
|
|
|
2017-08-28 05:51:09 +00:00
|
|
|
if (TRANSPONDER.provider !== "0" && TRANSPONDER.data.length !== TRANSPONDER.providers.find(function(provider) {
|
2017-04-02 17:58:33 +00:00
|
|
|
return provider.id == TRANSPONDER.provider;
|
2017-04-11 19:19:10 +00:00
|
|
|
}).dataLength ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('transponderDataInvalid'));
|
2017-04-11 19:19:10 +00:00
|
|
|
} else {
|
2017-04-02 17:58:33 +00:00
|
|
|
save_transponder_data();
|
|
|
|
}
|
2016-01-08 11:47:54 +00:00
|
|
|
});
|
|
|
|
}
|
2017-04-02 17:58:33 +00:00
|
|
|
|
|
|
|
function reinitialize() {
|
|
|
|
GUI.log(chrome.i18n.getMessage('deviceRebooting'));
|
2017-04-11 19:19:10 +00:00
|
|
|
if ( BOARD.find_board_definition(CONFIG.boardIdentifier).vcp ) {
|
2017-04-02 17:58:33 +00:00
|
|
|
$('a.connect').click();
|
|
|
|
GUI.timeout_add('start_connection', function start_connection() {
|
|
|
|
$('a.connect').click();
|
|
|
|
}, 2500);
|
|
|
|
} else {
|
|
|
|
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
|
2017-04-11 19:19:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_IDENT, false, false, function() {
|
2017-04-02 17:58:33 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('deviceReady'));
|
|
|
|
TABS.configuration.initialize(false, $('#content').scrollTop());
|
|
|
|
});
|
|
|
|
}, 1500);
|
|
|
|
}
|
|
|
|
}
|
2016-01-08 11:47:54 +00:00
|
|
|
|
|
|
|
GUI.content_ready(callback);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-11 19:19:10 +00:00
|
|
|
TABS.transponder.cleanup = function(callback) {
|
|
|
|
if ( callback ) callback();
|
2016-01-08 11:47:54 +00:00
|
|
|
};
|