2014-08-09 18:01:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-05 14:08:20 +00:00
|
|
|
// TODO: rework box_highlight & update_ui to accept flexible amount of aux channels
|
2014-08-12 13:51:31 +00:00
|
|
|
TABS.auxiliary_configuration = {};
|
2014-08-12 14:05:22 +00:00
|
|
|
TABS.auxiliary_configuration.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 != 'auxiliary_configuration') {
|
|
|
|
GUI.active_tab = 'auxiliary_configuration';
|
|
|
|
googleAnalytics.sendAppView('Auxiliary Configuration');
|
|
|
|
}
|
2013-04-10 13:31:51 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
function get_box_data() {
|
2014-07-11 15:52:56 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_BOX, false, false, get_box_ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_box_ids() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_BOXIDS, false, false, get_rc_data);
|
2014-06-05 14:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_rc_data() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_RC, false, false, load_html);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
function load_html() {
|
|
|
|
$('#content').load("./tabs/auxiliary_configuration.html", process_html);
|
|
|
|
}
|
2014-01-24 16:06:54 +00:00
|
|
|
|
2014-08-14 14:48:16 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_BOXNAMES, false, false, get_box_data);
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
function process_html() {
|
2014-06-05 14:08:20 +00:00
|
|
|
// generate heads according to RC count
|
|
|
|
var table_head = $('table.boxes .heads');
|
|
|
|
var main_head = $('table.boxes .main');
|
|
|
|
for (var i = 0; i < (RC.active_channels - 4); i++) {
|
|
|
|
table_head.append('<th colspan="3">AUX ' + (i + 1) + '</th>');
|
|
|
|
|
|
|
|
// 3 columns per aux channel (this might be requested to change to 6 in the future, so watch out)
|
|
|
|
main_head.append('\
|
|
|
|
<th i18n="auxiliaryLow"></th>\
|
|
|
|
<th i18n="auxiliaryMed"></th>\
|
|
|
|
<th i18n="auxiliaryHigh"></th>\
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
2014-05-06 14:48:46 +00:00
|
|
|
// translate to user-selected language
|
|
|
|
localize();
|
|
|
|
|
2014-06-05 14:08:20 +00:00
|
|
|
// generate table from the supplied AUX names and AUX data
|
|
|
|
for (var i = 0; i < AUX_CONFIG.length; i++) {
|
|
|
|
var line = '<tr class="switches">';
|
|
|
|
line += '<td class="name">' + AUX_CONFIG[i] + '</td>';
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-06-05 14:08:20 +00:00
|
|
|
for (var j = 0; j < (RC.active_channels - 4) * 3; j++) {
|
|
|
|
if (bit_check(AUX_CONFIG_values[i], j)) {
|
|
|
|
line += '<td><input type="checkbox" checked="checked" /></td>';
|
|
|
|
} else {
|
|
|
|
line += '<td><input type="checkbox" /></td>';
|
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 14:08:20 +00:00
|
|
|
line += '</tr>';
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-06-05 14:08:20 +00:00
|
|
|
$('.boxes > tbody:last').append(line);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UI Hooks
|
2014-08-12 14:05:22 +00:00
|
|
|
$('a.update').click(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
// catch the input changes
|
2014-09-16 21:07:52 +00:00
|
|
|
var main_needle = 0,
|
|
|
|
needle = 0;
|
|
|
|
|
2014-08-12 14:05:22 +00:00
|
|
|
$('.boxes input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
AUX_CONFIG_values[main_needle] = bit_set(AUX_CONFIG_values[main_needle], needle);
|
|
|
|
} else {
|
|
|
|
AUX_CONFIG_values[main_needle] = bit_clear(AUX_CONFIG_values[main_needle], needle);
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
needle++;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-06-05 14:08:20 +00:00
|
|
|
if (needle >= (RC.active_channels - 4) * 3) { // 1 aux * 3 checkboxes, 4 AUX = 12 bits per line
|
2014-03-22 23:28:41 +00:00
|
|
|
main_needle++;
|
|
|
|
needle = 0;
|
|
|
|
}
|
2014-01-24 16:06:54 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
function save_to_eeprom() {
|
2014-08-12 14:05:22 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () {
|
2014-05-06 21:39:37 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('auxiliaryEepromSaved'));
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
|
|
|
}
|
2014-09-16 21:07:52 +00:00
|
|
|
|
2014-09-17 07:27:54 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SET_BOX, MSP.crunch(MSP_codes.MSP_SET_BOX), false, save_to_eeprom);
|
2013-12-05 08:54:49 +00:00
|
|
|
});
|
2013-10-29 13:51:56 +00:00
|
|
|
|
2014-06-05 14:08:20 +00:00
|
|
|
// val = channel value
|
|
|
|
// aux_num = position of corresponding aux channel in the html table
|
|
|
|
var switches_e = $('table.boxes .switches');
|
|
|
|
function box_highlight(aux_num, val) {
|
|
|
|
var pos = 0; // < 1300
|
|
|
|
|
|
|
|
if (val > 1300 && val < 1700) {
|
|
|
|
pos = 1;
|
|
|
|
} else if (val > 1700) {
|
|
|
|
pos = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
var highlight_column = (aux_num * 3) + pos + 2; // +2 to skip name column and index starting on 1 instead of 0
|
|
|
|
var erase_columns = (aux_num * 3) + 2;
|
|
|
|
|
|
|
|
$('td:nth-child(n+' + erase_columns + '):nth-child(-n+' + (erase_columns + 2) + ')', switches_e).css('background-color', 'transparent');
|
|
|
|
$('td:nth-child(' + highlight_column + ')', switches_e).css('background-color', 'orange');
|
|
|
|
}
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// data pulling functions used inside interval timer
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
function update_ui() {
|
|
|
|
for (var i = 0; i < AUX_CONFIG.length; i++) {
|
|
|
|
if (bit_check(CONFIG.mode, i)) {
|
|
|
|
$('td.name').eq(i).addClass('on').removeClass('off');
|
|
|
|
} else {
|
|
|
|
$('td.name').eq(i).removeClass('on').removeClass('off');
|
|
|
|
|
|
|
|
if (AUX_CONFIG_values[i] > 0) {
|
|
|
|
$('td.name').eq(i).addClass('off');
|
|
|
|
}
|
|
|
|
}
|
2014-06-05 14:08:20 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 14:08:20 +00:00
|
|
|
for (var i = 0; i < (RC.active_channels - 4); i++) {
|
|
|
|
box_highlight(i, RC.channels[i + 4]);
|
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 14:08:20 +00:00
|
|
|
// update ui instantly on first load
|
|
|
|
update_ui();
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// enable data pulling
|
2014-06-05 14:08:20 +00:00
|
|
|
GUI.interval_add('aux_data_pull', get_rc_data, 50);
|
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:22:50 +00:00
|
|
|
|
|
|
|
if (callback) callback();
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-07-10 16:22:50 +00:00
|
|
|
};
|
|
|
|
|
2014-08-12 14:05:22 +00:00
|
|
|
TABS.auxiliary_configuration.cleanup = function (callback) {
|
2014-07-10 16:22:50 +00:00
|
|
|
if (callback) callback();
|
|
|
|
};
|