diff --git a/main.js b/main.js index 37af0a8a42..6a11f0810e 100644 --- a/main.js +++ b/main.js @@ -174,7 +174,7 @@ $(document).ready(function() { $("#content").on('keydown', 'input[type="number"]', function(e) { // whitelist all that we need for numeric control if ((e.keyCode >= 96 && e.keyCode <= 105) || (e.keyCode >= 48 && e.keyCode <= 57)) { // allow numpad and standard number keypad - } else if(e.keyCode == 109 || e.keyCode == 189) { // minus on numpad and in standard keyboard + } else if (e.keyCode == 109 || e.keyCode == 189) { // minus on numpad and in standard keyboard } else if (e.keyCode == 8 || e.keyCode == 46) { // backspace and delete } else if (e.keyCode == 190 || e.keyCode == 110) { // allow and decimal point } else if ((e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13) { // allow arrows, enter diff --git a/tabs/auxiliary_configuration.html b/tabs/auxiliary_configuration.html index 9a0eb8653b..43f4f4667e 100644 --- a/tabs/auxiliary_configuration.html +++ b/tabs/auxiliary_configuration.html @@ -2,25 +2,9 @@ - - - - - - - - - - - - - - - -
AUX 1AUX 2AUX 3AUX 4
diff --git a/tabs/auxiliary_configuration.js b/tabs/auxiliary_configuration.js index c6be127f9d..c7ed1adb85 100644 --- a/tabs/auxiliary_configuration.js +++ b/tabs/auxiliary_configuration.js @@ -1,3 +1,4 @@ +// TODO: rework box_highlight & update_ui to accept flexible amount of aux channels function tab_initialize_auxiliary_configuration() { ga_tracker.sendAppView('Auxiliary Configuration'); GUI.active_tab = 'auxiliary_configuration'; @@ -5,7 +6,11 @@ function tab_initialize_auxiliary_configuration() { MSP.send_message(MSP_codes.MSP_BOXNAMES, false, false, get_box_data); function get_box_data() { - MSP.send_message(MSP_codes.MSP_BOX, false, false, load_html); + MSP.send_message(MSP_codes.MSP_BOX, false, false, get_rc_data); + } + + function get_rc_data() { + MSP.send_message(MSP_codes.MSP_RC, false, false, load_html); } function load_html() { @@ -13,55 +18,39 @@ function tab_initialize_auxiliary_configuration() { } function process_html() { + // 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('AUX ' + (i + 1) + ''); + + // 3 columns per aux channel (this might be requested to change to 6 in the future, so watch out) + main_head.append('\ + \ + \ + \ + '); + } + // translate to user-selected language localize(); - function box_check(num, pos) { - if (bit_check(num, pos)) { // 1 - return ''; - } else { // 0 - return ''; - } - } - - // val = channel value - // aux_num = position of corresponding aux channel in the html table - function box_highlight(val, aux_num) { - var tr = $('table.boxes .switches'); - var pos = 0; // < 1300 - - if (val > 1300 && val < 1700) { - pos = 1; - } else if (val > 1700) { - pos = 2; - } - - $('td:nth-child(' + aux_num + '), td:nth-child(' + (aux_num + 1) + '), td:nth-child(' + (aux_num + 2) + ')', tr).css('background-color', 'transparent'); - $('td:nth-child(' + (aux_num + pos) + ')', tr).css('background-color', 'orange'); - } - // generate table from the supplied AUX names and AUX data for (var i = 0; i < AUX_CONFIG.length; i++) { - $('.boxes > tbody:last').append( - '' + - '' + AUX_CONFIG[i] + '' + - box_check(AUX_CONFIG_values[i], 0) + - box_check(AUX_CONFIG_values[i], 1) + - box_check(AUX_CONFIG_values[i], 2) + + var line = ''; + line += '' + AUX_CONFIG[i] + ''; - box_check(AUX_CONFIG_values[i], 3) + - box_check(AUX_CONFIG_values[i], 4) + - box_check(AUX_CONFIG_values[i], 5) + + for (var j = 0; j < (RC.active_channels - 4) * 3; j++) { + if (bit_check(AUX_CONFIG_values[i], j)) { + line += ''; + } else { + line += ''; + } + } - box_check(AUX_CONFIG_values[i], 6) + - box_check(AUX_CONFIG_values[i], 7) + - box_check(AUX_CONFIG_values[i], 8) + + line += ''; - box_check(AUX_CONFIG_values[i], 9) + - box_check(AUX_CONFIG_values[i], 10) + - box_check(AUX_CONFIG_values[i], 11) + - '' - ); + $('.boxes > tbody:last').append(line); } // UI Hooks @@ -78,7 +67,7 @@ function tab_initialize_auxiliary_configuration() { needle++; - if (needle >= 12) { // 4 aux * 3 checkboxes = 12 bits per line + if (needle >= (RC.active_channels - 4) * 3) { // 1 aux * 3 checkboxes, 4 AUX = 12 bits per line main_needle++; needle = 0; @@ -110,6 +99,25 @@ function tab_initialize_auxiliary_configuration() { } }); + // 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'); + } + // data pulling functions used inside interval timer function get_rc_data() { MSP.send_message(MSP_codes.MSP_RC, false, false, update_ui); @@ -126,16 +134,19 @@ function tab_initialize_auxiliary_configuration() { $('td.name').eq(i).addClass('off'); } } + } - box_highlight(RC.channels[4], 2); // aux 1 - box_highlight(RC.channels[5], 5); // aux 2 - box_highlight(RC.channels[6], 8); // aux 3 - box_highlight(RC.channels[7], 11); // aux 4 + for (var i = 0; i < (RC.active_channels - 4); i++) { + box_highlight(i, RC.channels[i + 4]); + } } + // update ui instantly on first load + update_ui(); + // enable data pulling - GUI.interval_add('aux_data_pull', get_rc_data, 50, true); + GUI.interval_add('aux_data_pull', get_rc_data, 50); // status data pulled via separate timer with static speed GUI.interval_add('status_pull', function() {