mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-16 12:55:13 +03:00
callback hell resolving patch, optimize
This commit is contained in:
parent
36a79f8902
commit
82badeece1
10 changed files with 1306 additions and 1226 deletions
|
@ -2,9 +2,41 @@ function tab_initialize_auxiliary_configuration() {
|
|||
ga_tracker.sendAppView('Auxiliary Configuration');
|
||||
GUI.active_tab = 'auxiliary_configuration';
|
||||
|
||||
send_message(MSP_codes.MSP_BOXNAMES, MSP_codes.MSP_BOXNAMES, false, function() {
|
||||
send_message(MSP_codes.MSP_BOX, MSP_codes.MSP_BOX, false, function() {
|
||||
$('#content').load("./tabs/auxiliary_configuration.html", function() {
|
||||
send_message(MSP_codes.MSP_BOXNAMES, MSP_codes.MSP_BOXNAMES, false, get_box_data);
|
||||
|
||||
function get_box_data() {
|
||||
send_message(MSP_codes.MSP_BOX, MSP_codes.MSP_BOX, false, load_html);
|
||||
}
|
||||
|
||||
function load_html() {
|
||||
$('#content').load("./tabs/auxiliary_configuration.html", process_html);
|
||||
}
|
||||
|
||||
function process_html() {
|
||||
function box_check(num, pos) {
|
||||
if (bit_check(num, pos)) { // 1
|
||||
return '<td><input type="checkbox" checked="checked" /></td>';
|
||||
} else { // 0
|
||||
return '<td><input type="checkbox" /></td>';
|
||||
}
|
||||
}
|
||||
|
||||
// val = channel value
|
||||
// aux_num = position of corresponding aux channel in the html table
|
||||
function box_highlight(val, aux_num) {
|
||||
var tr = $('table.boxes tr');
|
||||
var pos = 0; // < 1300
|
||||
|
||||
if (val > 1300 && val < 1700) {
|
||||
pos = 1;
|
||||
} else if (val > 1700) {
|
||||
pos = 2;
|
||||
}
|
||||
|
||||
$(':nth-child(' + aux_num + '), :nth-child(' + (aux_num + 1) + '), :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(
|
||||
|
@ -59,9 +91,9 @@ function tab_initialize_auxiliary_configuration() {
|
|||
AUX_val_buffer_out[needle++] = highByte(AUX_CONFIG_values[i]);
|
||||
}
|
||||
|
||||
send_message(MSP_codes.MSP_SET_BOX, AUX_val_buffer_out);
|
||||
send_message(MSP_codes.MSP_SET_BOX, AUX_val_buffer_out, false, save_to_eeprom);
|
||||
|
||||
// Save changes to EEPROM
|
||||
function save_to_eeprom() {
|
||||
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
|
||||
GUI.log('EEPROM <span style="color: green">saved</span>');
|
||||
|
||||
|
@ -72,12 +104,19 @@ function tab_initialize_auxiliary_configuration() {
|
|||
element.removeClass('success');
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// enable data pulling
|
||||
GUI.interval_add('aux_data_poll', function() {
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
|
||||
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC, false, function() {
|
||||
// data pulling functions used inside interval timer
|
||||
function get_status_data() {
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS, false, get_rc_data);
|
||||
}
|
||||
|
||||
function get_rc_data() {
|
||||
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC, false, update_ui);
|
||||
}
|
||||
|
||||
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');
|
||||
|
@ -94,33 +133,9 @@ function tab_initialize_auxiliary_configuration() {
|
|||
box_highlight(RC.AUX2, 5);
|
||||
box_highlight(RC.AUX3, 8);
|
||||
box_highlight(RC.AUX4, 11);
|
||||
});
|
||||
}, 50, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function box_check(num, pos) {
|
||||
if (bit_check(num, pos)) { // 1
|
||||
return '<td><input type="checkbox" checked="checked" /></td>';
|
||||
} else { // 0
|
||||
return '<td><input type="checkbox" /></td>';
|
||||
// enable data pulling
|
||||
GUI.interval_add('aux_data_poll', get_status_data, 50, true);
|
||||
}
|
||||
}
|
||||
|
||||
// val = channel value
|
||||
// aux_num = position of corresponding aux channel in the html table
|
||||
function box_highlight(val, aux_num) {
|
||||
var tr = $('table.boxes tr');
|
||||
var pos = 0; // < 1300
|
||||
|
||||
if (val > 1300 && val < 1700) {
|
||||
pos = 1;
|
||||
} else if (val > 1700) {
|
||||
pos = 2;
|
||||
}
|
||||
|
||||
$(':nth-child(' + aux_num + '), :nth-child(' + (aux_num + 1) + '), :nth-child(' + (aux_num + 2) + ')', tr).css('background-color', 'transparent');
|
||||
$('td:nth-child(' + (aux_num + pos) + ')', tr).css('background-color', 'orange');
|
||||
}
|
|
@ -6,8 +6,6 @@ function tab_initialize_default() {
|
|||
$('div.changelog.configurator .wrapper').load('./changelog.html');
|
||||
|
||||
// UI Hooks
|
||||
$('a.firmware_flasher').click(function() {
|
||||
tab_initialize_firmware_flasher();
|
||||
});
|
||||
$('a.firmware_flasher').click(tab_initialize_firmware_flasher);
|
||||
});
|
||||
}
|
|
@ -4,19 +4,19 @@
|
|||
<table>
|
||||
<tr>
|
||||
<td style="width: 85px;">Altitude:</td>
|
||||
<td class="alt">0</td>
|
||||
<td class="alt">0 m</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Latitude:</td>
|
||||
<td class="lat">0</td>
|
||||
<td class="lat">0.0000 deg</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Longitude:</td>
|
||||
<td class="lon">0</td>
|
||||
<td class="lon">0.0000 deg</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Speed:</td>
|
||||
<td class="speed">0</td>
|
||||
<td class="speed">0 cm/s</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Sats:</td>
|
||||
|
@ -24,7 +24,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td>Dist to Home:</td>
|
||||
<td class="distToHome">0</td>
|
||||
<td class="distToHome">0 m</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
|
37
tabs/gps.js
37
tabs/gps.js
|
@ -2,11 +2,26 @@ function tab_initialize_gps () {
|
|||
ga_tracker.sendAppView('GPS Page');
|
||||
GUI.active_tab = 'gps';
|
||||
|
||||
send_message(MSP_codes.MSP_RAW_GPS, MSP_codes.MSP_RAW_GPS, false, function() {
|
||||
$('#content').load("./tabs/gps.html", function() {
|
||||
// enable data pulling
|
||||
GUI.interval_add('gps_pull', function() {
|
||||
// Update GPS data
|
||||
send_message(MSP_codes.MSP_RAW_GPS, MSP_codes.MSP_RAW_GPS, false, load_html);
|
||||
|
||||
function load_html() {
|
||||
$('#content').load("./tabs/gps.html", process_html);
|
||||
}
|
||||
|
||||
function process_html() {
|
||||
function get_status_data() {
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS, false, get_raw_gps_data);
|
||||
}
|
||||
|
||||
function get_raw_gps_data() {
|
||||
send_message(MSP_codes.MSP_RAW_GPS, MSP_codes.MSP_RAW_GPS, false, get_gpsvinfo_data);
|
||||
}
|
||||
|
||||
function get_gpsvinfo_data() {
|
||||
send_message(MSP_codes.MSP_GPSSVINFO, MSP_codes.MSP_GPSSVINFO, false, update_ui);
|
||||
}
|
||||
|
||||
function update_ui() {
|
||||
$('.GPS_info td.alt').html(GPS_DATA.alt + ' m');
|
||||
$('.GPS_info td.lat').html((GPS_DATA.lat / 10000000).toFixed(4) + ' deg');
|
||||
$('.GPS_info td.lon').html((GPS_DATA.lon / 10000000).toFixed(4) + ' deg');
|
||||
|
@ -24,11 +39,9 @@ function tab_initialize_gps () {
|
|||
$('td', row).eq(1).html(GPS_DATA.quality[i]);
|
||||
$('td', row).eq(2).find('progress').val(GPS_DATA.cno[i]);
|
||||
}
|
||||
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
|
||||
send_message(MSP_codes.MSP_RAW_GPS, MSP_codes.MSP_RAW_GPS);
|
||||
send_message(MSP_codes.MSP_GPSSVINFO, MSP_codes.MSP_GPSSVINFO);
|
||||
}, 75, true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// enable data pulling
|
||||
GUI.interval_add('gps_pull', get_status_data, 75, true);
|
||||
}
|
||||
}
|
|
@ -2,9 +2,17 @@ function tab_initialize_initial_setup() {
|
|||
ga_tracker.sendAppView('Initial Setup');
|
||||
GUI.active_tab = 'initial_setup';
|
||||
|
||||
send_message(MSP_codes.MSP_ACC_TRIM, MSP_codes.MSP_ACC_TRIM, false, function() {
|
||||
send_message(MSP_codes.MSP_MISC, MSP_codes.MSP_MISC, false, function() {
|
||||
$('#content').load("./tabs/initial_setup.html", function() {
|
||||
send_message(MSP_codes.MSP_ACC_TRIM, MSP_codes.MSP_ACC_TRIM, false, load_misc_data);
|
||||
|
||||
function load_misc_data() {
|
||||
send_message(MSP_codes.MSP_MISC, MSP_codes.MSP_MISC, false, load_html);
|
||||
}
|
||||
|
||||
function load_html() {
|
||||
$('#content').load("./tabs/initial_setup.html", process_html);
|
||||
}
|
||||
|
||||
function process_html() {
|
||||
var yaw_fix = 0.0;
|
||||
|
||||
// Fill in misc stuff
|
||||
|
@ -191,9 +199,9 @@ function tab_initialize_initial_setup() {
|
|||
buffer_out[21] = 0; // vbatlevel_crit (unused)
|
||||
|
||||
// Send over new misc
|
||||
send_message(MSP_codes.MSP_SET_MISC, buffer_out);
|
||||
send_message(MSP_codes.MSP_SET_MISC, buffer_out, false, save_to_eeprom);
|
||||
|
||||
// Save changes to EEPROM
|
||||
function save_to_eeprom() {
|
||||
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
|
||||
GUI.log('EEPROM <span style="color: green">saved</span>');
|
||||
|
||||
|
@ -204,6 +212,7 @@ function tab_initialize_initial_setup() {
|
|||
element.removeClass('success');
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// reset yaw button hook
|
||||
|
@ -216,14 +225,23 @@ function tab_initialize_initial_setup() {
|
|||
|
||||
$('#content .restore').click(configuration_restore);
|
||||
|
||||
GUI.interval_add('initial_setup_data_pull', function() {
|
||||
// data pulling functions used inside interval timer
|
||||
function get_status_data() {
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS, false, get_analog_data);
|
||||
}
|
||||
|
||||
function get_analog_data() {
|
||||
send_message(MSP_codes.MSP_ANALOG, MSP_codes.MSP_ANALOG, false, get_attitude_data);
|
||||
}
|
||||
|
||||
function get_attitude_data() {
|
||||
send_message(MSP_codes.MSP_ATTITUDE, MSP_codes.MSP_ATTITUDE, false, update_ui);
|
||||
}
|
||||
|
||||
function update_ui() {
|
||||
// Update voltage indicator
|
||||
$('.bat-voltage').html(ANALOG.voltage + ' V');
|
||||
|
||||
// Request new data, if transmission fails it doesn't matter as new transmission will be requested after 50ms
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS, false, function() { // cycle time, active sensors, etc...
|
||||
send_message(MSP_codes.MSP_ANALOG, MSP_codes.MSP_ANALOG, false, function() { // battery voltage
|
||||
send_message(MSP_codes.MSP_ATTITUDE, MSP_codes.MSP_ATTITUDE, false, function() { // kinematics
|
||||
// Update cube
|
||||
var cube = $('div#cube');
|
||||
|
||||
|
@ -236,11 +254,8 @@ function tab_initialize_initial_setup() {
|
|||
$('div#compass .pointer').css('-webkit-transform', 'rotate(' + (SENSOR_DATA.kinematicsZ) + 'deg)');
|
||||
$('div#compass .value').html(SENSOR_DATA.kinematicsZ + '°');
|
||||
*/
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 50, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
GUI.interval_add('initial_setup_data_pull', get_status_data, 50, true);
|
||||
}
|
||||
}
|
|
@ -2,9 +2,17 @@ function tab_initialize_motor_outputs() {
|
|||
ga_tracker.sendAppView('Motor Outputs Page');
|
||||
GUI.active_tab = 'motor_outputs';
|
||||
|
||||
send_message(MSP_codes.MSP_MISC, MSP_codes.MSP_MISC, false, function() {
|
||||
send_message(MSP_codes.MSP_MOTOR, MSP_codes.MSP_MOTOR, false, function() {
|
||||
$('#content').load("./tabs/motor_outputs.html", function() {
|
||||
send_message(MSP_codes.MSP_MISC, MSP_codes.MSP_MISC, false, get_motor_data);
|
||||
|
||||
function get_motor_data() {
|
||||
send_message(MSP_codes.MSP_MOTOR, MSP_codes.MSP_MOTOR, false, load_html);
|
||||
}
|
||||
|
||||
function load_html() {
|
||||
$('#content').load("./tabs/motor_outputs.html", process_html);
|
||||
}
|
||||
|
||||
function process_html() {
|
||||
// if CAP_DYNBALANCE is true
|
||||
if (bit_check(CONFIG.capability, 2)) {
|
||||
$('div.motor_testing').show();
|
||||
|
@ -67,14 +75,20 @@ function tab_initialize_motor_outputs() {
|
|||
}
|
||||
});
|
||||
|
||||
// enable Motor data pulling
|
||||
GUI.interval_add('motor_poll', function() {
|
||||
// Request New data
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS, false, function() {
|
||||
send_message(MSP_codes.MSP_MOTOR, MSP_codes.MSP_MOTOR, false, function() {
|
||||
send_message(MSP_codes.MSP_SERVO, MSP_codes.MSP_SERVO, false, function() {
|
||||
// Update UI
|
||||
// data pulling functions used inside interval timer
|
||||
function get_status_data() {
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS, false, get_motor_data);
|
||||
}
|
||||
|
||||
function get_motor_data() {
|
||||
send_message(MSP_codes.MSP_MOTOR, MSP_codes.MSP_MOTOR, false, get_servo_data);
|
||||
}
|
||||
|
||||
function get_servo_data() {
|
||||
send_message(MSP_codes.MSP_SERVO, MSP_codes.MSP_SERVO, false, update_ui);
|
||||
}
|
||||
|
||||
function update_ui() {
|
||||
var block_height = $('div.m-block:first').height();
|
||||
|
||||
for (var i = 0; i < MOTOR_DATA.length; i++) {
|
||||
|
@ -94,11 +108,9 @@ function tab_initialize_motor_outputs() {
|
|||
|
||||
$('.servo-' + i + ' .indicator').css({'margin-top' : margin_top + 'px', 'height' : height + 'px', 'background-color' : 'rgb(' + color + ',0,0)'});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 50, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// enable Motor data pulling
|
||||
GUI.interval_add('motor_poll', get_status_data, 50, true);
|
||||
}
|
||||
}
|
|
@ -2,9 +2,17 @@ function tab_initialize_pid_tuning() {
|
|||
ga_tracker.sendAppView('PID Tuning');
|
||||
GUI.active_tab = 'pid_tuning';
|
||||
|
||||
send_message(MSP_codes.MSP_PID, MSP_codes.MSP_PID, false, function() {
|
||||
send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING, false, function() {
|
||||
$('#content').load("./tabs/pid_tuning.html", function() {
|
||||
send_message(MSP_codes.MSP_PID, MSP_codes.MSP_PID, false, get_rc_tuning_data);
|
||||
|
||||
function get_rc_tuning_data() {
|
||||
send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING, false, load_html);
|
||||
}
|
||||
|
||||
function load_html() {
|
||||
$('#content').load("./tabs/pid_tuning.html", process_html);
|
||||
}
|
||||
|
||||
function process_html() {
|
||||
// Fill in the data from PIDs array
|
||||
var i = 0;
|
||||
$('.pid_tuning .ROLL input').each(function() {
|
||||
|
@ -245,8 +253,9 @@ function tab_initialize_pid_tuning() {
|
|||
}
|
||||
|
||||
// Send over the PID changes
|
||||
send_message(MSP_codes.MSP_SET_PID, PID_buffer_out);
|
||||
send_message(MSP_codes.MSP_SET_PID, PID_buffer_out, false, send_rc_tuning_changes);
|
||||
|
||||
function send_rc_tuning_changes() {
|
||||
// catch RC_tuning changes
|
||||
RC_tuning.roll_pitch_rate = parseFloat($('.rate-tpa input[name="roll-pitch"]').val());
|
||||
RC_tuning.yaw_rate = parseFloat($('.rate-tpa input[name="yaw"]').val());
|
||||
|
@ -262,9 +271,10 @@ function tab_initialize_pid_tuning() {
|
|||
RC_tuning_buffer_out[6] = parseInt(RC_tuning.throttle_EXPO * 100);
|
||||
|
||||
// Send over the RC_tuning changes
|
||||
send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out);
|
||||
send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out, false, save_to_eeprom);
|
||||
}
|
||||
|
||||
// Save changes to EEPROM
|
||||
function save_to_eeprom() {
|
||||
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
|
||||
GUI.log('EEPROM <span style="color: green">saved</span>');
|
||||
|
||||
|
@ -275,13 +285,12 @@ function tab_initialize_pid_tuning() {
|
|||
element.removeClass('success');
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// enable data pulling
|
||||
GUI.interval_add('pid_data_poll', function() {
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
|
||||
}, 50);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -2,9 +2,17 @@ function tab_initialize_receiver() {
|
|||
ga_tracker.sendAppView('Receiver Page');
|
||||
GUI.active_tab = 'receiver';
|
||||
|
||||
send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING, false, function() {
|
||||
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC, false, function() {
|
||||
$('#content').load("./tabs/receiver.html", function() {
|
||||
send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING, false, get_rc_data);
|
||||
|
||||
function get_rc_data() {
|
||||
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC, false, load_html);
|
||||
}
|
||||
|
||||
function load_html() {
|
||||
$('#content').load("./tabs/receiver.html", process_html);
|
||||
}
|
||||
|
||||
function process_html() {
|
||||
// fill in data from RC_tuning
|
||||
$('.tunings .throttle input[name="mid"]').val(RC_tuning.throttle_MID.toFixed(2));
|
||||
$('.tunings .throttle input[name="expo"]').val(RC_tuning.throttle_EXPO.toFixed(2));
|
||||
|
@ -144,9 +152,9 @@ function tab_initialize_receiver() {
|
|||
RC_tuning_buffer_out[6] = parseInt(RC_tuning.throttle_EXPO * 100);
|
||||
|
||||
// Send over the RC_tuning changes
|
||||
send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out);
|
||||
send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out, false, save_to_eeprom);
|
||||
|
||||
// Save changes to EEPROM
|
||||
function save_to_eeprom() {
|
||||
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
|
||||
GUI.log('EEPROM <span style="color: green">saved</span>');
|
||||
|
||||
|
@ -157,17 +165,24 @@ function tab_initialize_receiver() {
|
|||
element.removeClass('success');
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('select[name="rx_refresh_rate"]').change(function() {
|
||||
var plot_update_rate = parseInt($(this).val());
|
||||
|
||||
// timer initialization
|
||||
GUI.interval_remove('receiver_poll');
|
||||
// save update rate
|
||||
chrome.storage.local.set({'rx_refresh_rate': plot_update_rate});
|
||||
|
||||
// enable RC data pulling
|
||||
GUI.interval_add('receiver_poll', function() {
|
||||
// Update UI with latest data
|
||||
function get_status_data() {
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS, false, get_rc_data);
|
||||
}
|
||||
|
||||
function get_rc_data() {
|
||||
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC, false, update_ui);
|
||||
}
|
||||
|
||||
function update_ui() {
|
||||
$('.tab-receiver meter:eq(0)').val(RC.throttle);
|
||||
$('.tab-receiver .value:eq(0)').html(RC.throttle);
|
||||
|
||||
|
@ -227,16 +242,13 @@ function tab_initialize_receiver() {
|
|||
{data: RX_plot_data[7], label: "AUX4"} ], RX_plot_options);
|
||||
|
||||
samples_i++;
|
||||
}
|
||||
|
||||
// Request new data
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
|
||||
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC);
|
||||
}, plot_update_rate, true);
|
||||
// timer initialization
|
||||
GUI.interval_remove('receiver_poll');
|
||||
|
||||
chrome.storage.local.set({'rx_refresh_rate': plot_update_rate});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
// enable RC data pulling
|
||||
GUI.interval_add('receiver_poll', get_status_data, plot_update_rate, true);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -198,7 +198,6 @@ function tab_initialize_sensors() {
|
|||
'debug': parseInt($('.tab-sensors select').eq(4).val())
|
||||
};
|
||||
|
||||
|
||||
// handling of "data pulling" is a little bit funky here, as MSP_RAW_IMU contains values for gyro/accel/mag but not baro
|
||||
// this means that setting a slower refresh rate on any of the attributes would have no effect
|
||||
// what we will do instead is = determinate the fastest refresh rate for those 3 attributes, use that as a "polling rate"
|
||||
|
@ -213,6 +212,9 @@ function tab_initialize_sensors() {
|
|||
fastest = rates.mag;
|
||||
}
|
||||
|
||||
// store current/latest refresh rates in the storage
|
||||
chrome.storage.local.set({'sensor_refresh_rates': rates});
|
||||
|
||||
// timer initialization
|
||||
GUI.interval_kill_all(['port_handler', 'port_usage']);
|
||||
|
||||
|
@ -236,7 +238,7 @@ function tab_initialize_sensors() {
|
|||
}
|
||||
|
||||
Flotr.draw(e_graph_baro, [
|
||||
{data: baro_data[0], label: "X - meters [" + SENSOR_DATA.altitude.toFixed(2) + "]"} ], baro_options);
|
||||
{data: baro_data[0], label: "Meters [" + SENSOR_DATA.altitude.toFixed(2) + "]"} ], baro_options);
|
||||
|
||||
samples_baro_i++;
|
||||
}, rates.baro);
|
||||
|
@ -319,15 +321,12 @@ function tab_initialize_sensors() {
|
|||
}
|
||||
|
||||
Flotr.draw(e_graph_mag, [
|
||||
{data: mag_data[1], label: "X - Ga [" + SENSOR_DATA.magnetometer[0].toFixed(2) + "]"},
|
||||
{data: mag_data[0], label: "Y - Ga [" + SENSOR_DATA.magnetometer[1].toFixed(2) + "]"},
|
||||
{data: mag_data[2], label: "Z - Ga [" + SENSOR_DATA.magnetometer[2].toFixed(2) + "]"} ], mag_options);
|
||||
{data: mag_data[1], label: "X - gauss [" + SENSOR_DATA.magnetometer[0].toFixed(2) + "]"},
|
||||
{data: mag_data[0], label: "Y - gauss [" + SENSOR_DATA.magnetometer[1].toFixed(2) + "]"},
|
||||
{data: mag_data[2], label: "Z - gauss [" + SENSOR_DATA.magnetometer[2].toFixed(2) + "]"} ], mag_options);
|
||||
|
||||
samples_mag_i++;
|
||||
}, rates.mag, true);
|
||||
|
||||
// store current/latest refresh rates in the storage
|
||||
chrome.storage.local.set({'sensor_refresh_rates': rates});
|
||||
});
|
||||
});
|
||||
}
|
355
tabs/servos.js
355
tabs/servos.js
|
@ -9,11 +9,187 @@ function tab_initialize_servos() {
|
|||
ga_tracker.sendAppView('Servos');
|
||||
GUI.active_tab = 'servos';
|
||||
|
||||
// request current Servos Config
|
||||
send_message(MSP_codes.MSP_IDENT, MSP_codes.MSP_IDENT, false, function() {
|
||||
send_message(MSP_codes.MSP_SERVO_CONF, MSP_codes.MSP_SERVO_CONF, false, function() {
|
||||
send_message(MSP_codes.MSP_BOXNAMES, MSP_codes.MSP_BOXNAMES, false, function() {
|
||||
$('#content').load("./tabs/servos.html", function() {
|
||||
send_message(MSP_codes.MSP_IDENT, MSP_codes.MSP_IDENT, false, get_servo_conf_data);
|
||||
|
||||
function get_servo_conf_data() {
|
||||
send_message(MSP_codes.MSP_SERVO_CONF, MSP_codes.MSP_SERVO_CONF, false, get_boxnames_data);
|
||||
}
|
||||
|
||||
function get_boxnames_data() {
|
||||
send_message(MSP_codes.MSP_BOXNAMES, MSP_codes.MSP_BOXNAMES, false, load_html);
|
||||
}
|
||||
|
||||
function load_html() {
|
||||
$('#content').load("./tabs/servos.html", process_html);
|
||||
}
|
||||
|
||||
function process_html() {
|
||||
function process_directions(name, obj, bitpos) {
|
||||
$('div.direction_wrapper').show();
|
||||
|
||||
var val;
|
||||
|
||||
$('div.tab-servos table.directions').append('\
|
||||
<tr>\
|
||||
<td class="name" style="text-align: center">' + name + '</td>\
|
||||
<td class="direction" style="text-align: right">\
|
||||
<select name="direction">\
|
||||
<option value="0">Normal</option>\
|
||||
<option value="1">Reverse</option>\
|
||||
</select>\
|
||||
</td>\
|
||||
</tr>\
|
||||
');
|
||||
|
||||
if (bit_check(SERVO_CONFIG[obj].rate, bitpos)) val = 1;
|
||||
else val = 0;
|
||||
|
||||
$('div.tab-servos table.directions tr:last select').val(val);
|
||||
$('div.tab-servos table.directions tr:last select').data('info', {'obj': obj, 'bitpos': bitpos});
|
||||
}
|
||||
|
||||
function process_servos(name, alternate, obj, directions) {
|
||||
$('div.supported_wrapper').show();
|
||||
|
||||
$('div.tab-servos table.fields').append('\
|
||||
<tr> \
|
||||
<td style="text-align: center">' + name + '</td>\
|
||||
<td class="middle"><input type="number" min="1000" max="2000" value="' + ((SERVO_CONFIG[obj].middle <= 7) ? 1500 : SERVO_CONFIG[obj].middle) + '" /></td>\
|
||||
<td class="min"><input type="number" min="1000" max="2000" value="' + SERVO_CONFIG[obj].min +'" /></td>\
|
||||
<td class="max"><input type="number" min="1000" max="2000" value="' + SERVO_CONFIG[obj].max +'" /></td>\
|
||||
<td class="channel">\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
</td>\
|
||||
<td class="direction">\
|
||||
<input class="first" type="checkbox"/><span class="name">' + name + '</span>\
|
||||
<input class="second" type="checkbox"/><span class="alternate">' + alternate + '</span>\
|
||||
</td>\
|
||||
</tr> \
|
||||
');
|
||||
|
||||
if (SERVO_CONFIG[obj].middle <= 7) {
|
||||
$('div.tab-servos table.fields tr:last td.middle input').prop('disabled', true);
|
||||
$('div.tab-servos table.fields tr:last td.channel').find('input').eq(SERVO_CONFIG[obj].middle).prop('checked', true);
|
||||
}
|
||||
|
||||
if (directions == true) {
|
||||
$('div.tab-servos table.fields tr:last td.direction input:first').prop('checked', bit_check(SERVO_CONFIG[obj].rate, 0));
|
||||
$('div.tab-servos table.fields tr:last td.direction input:last').prop('checked', bit_check(SERVO_CONFIG[obj].rate, 1));
|
||||
} else if (directions == 2) {
|
||||
// removing checkboxes
|
||||
$('div.tab-servos table.fields tr:last td.direction').html('');
|
||||
|
||||
// adding select box and generating options
|
||||
$('div.tab-servos table.fields tr:last td.direction').append('\
|
||||
<select class="rate" name="rate"></select>\
|
||||
');
|
||||
|
||||
var select = $('div.tab-servos table.fields tr:last td.direction select');
|
||||
|
||||
for (var i = 100; i > -101; i--) {
|
||||
select.append('<option value="' + i + '">Rate: ' + i + '%</option>');
|
||||
}
|
||||
|
||||
// select current rate
|
||||
select.val(SERVO_CONFIG[obj].rate);
|
||||
} else {
|
||||
// removing checkboxes
|
||||
$('div.tab-servos table.fields tr:last td.direction').html('');
|
||||
}
|
||||
|
||||
$('div.tab-servos table.fields tr:last').data('info', {'obj': obj});
|
||||
|
||||
// UI hooks
|
||||
$('div.tab-servos table.fields tr:last td.channel').find('input').click(function() {
|
||||
if($(this).is(':checked')) {
|
||||
$(this).parent().parent().find('td.middle input').prop('disabled', true);
|
||||
$(this).parent().find('input').not($(this)).prop('checked', false);
|
||||
} else {
|
||||
$(this).parent().parent().find('td.middle input').prop('disabled', false).val(1500);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function servos_update(save_to_eeprom) {
|
||||
// update bitfields
|
||||
$('div.tab-servos table.directions tr:not(".main")').each(function() {
|
||||
var info = $('select', this).data('info');
|
||||
var val = parseInt($('select', this).val());
|
||||
|
||||
// in this stage we need to know which bitfield and which bitposition needs to be flipped
|
||||
if (val) SERVO_CONFIG[info.obj].rate = bit_set(SERVO_CONFIG[info.obj].rate, info.bitpos);
|
||||
else SERVO_CONFIG[info.obj].rate = bit_clear(SERVO_CONFIG[info.obj].rate, info.bitpos);
|
||||
});
|
||||
|
||||
// update the rest
|
||||
$('div.tab-servos table.fields tr:not(".main")').each(function() {
|
||||
var info = $(this).data('info');
|
||||
|
||||
if ($('.middle input', this).is(':disabled')) {
|
||||
var val = $('.channel input:checked', this).index();
|
||||
|
||||
SERVO_CONFIG[info.obj].middle = parseInt(val);
|
||||
} else {
|
||||
SERVO_CONFIG[info.obj].middle = parseInt($('.middle input', this).val());
|
||||
}
|
||||
|
||||
SERVO_CONFIG[info.obj].min = parseInt($('.min input', this).val());
|
||||
SERVO_CONFIG[info.obj].max = parseInt($('.max input', this).val());
|
||||
|
||||
// update rate if direction fields exist
|
||||
if ($('.direction input', this).length) {
|
||||
if ($('.direction input:first', this).is(':checked')) SERVO_CONFIG[info.obj].rate = bit_set(SERVO_CONFIG[info.obj].rate, 0);
|
||||
else SERVO_CONFIG[info.obj].rate = bit_clear(SERVO_CONFIG[info.obj].rate, 0);
|
||||
|
||||
if ($('.direction input:last', this).is(':checked')) SERVO_CONFIG[info.obj].rate = bit_set(SERVO_CONFIG[info.obj].rate, 1);
|
||||
else SERVO_CONFIG[info.obj].rate = bit_clear(SERVO_CONFIG[info.obj].rate, 1);
|
||||
} else if ($('.direction select', this).length) {
|
||||
var val = parseInt($('.direction select', this).val());
|
||||
SERVO_CONFIG[info.obj].rate = val;
|
||||
}
|
||||
});
|
||||
|
||||
// send settings over to mcu
|
||||
var buffer_out = [];
|
||||
|
||||
var needle = 0;
|
||||
for (var i = 0; i < SERVO_CONFIG.length; i++) {
|
||||
buffer_out[needle++] = lowByte(SERVO_CONFIG[i].min);
|
||||
buffer_out[needle++] = highByte(SERVO_CONFIG[i].min);
|
||||
|
||||
buffer_out[needle++] = lowByte(SERVO_CONFIG[i].max);
|
||||
buffer_out[needle++] = highByte(SERVO_CONFIG[i].max);
|
||||
|
||||
buffer_out[needle++] = lowByte(SERVO_CONFIG[i].middle);
|
||||
buffer_out[needle++] = highByte(SERVO_CONFIG[i].middle);
|
||||
|
||||
buffer_out[needle++] = lowByte(SERVO_CONFIG[i].rate);
|
||||
}
|
||||
|
||||
send_message(MSP_codes.MSP_SET_SERVO_CONF, buffer_out);
|
||||
|
||||
if (save_to_eeprom) {
|
||||
// Save changes to EEPROM
|
||||
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
|
||||
GUI.log('EEPROM <span style="color: green">saved</span>');
|
||||
|
||||
var element = $('a.update');
|
||||
element.addClass('success');
|
||||
|
||||
GUI.timeout_add('success_highlight', function() {
|
||||
element.removeClass('success');
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// drop previous table
|
||||
$('div.tab-servos table.fields tr:not(:first)').remove();
|
||||
|
||||
|
@ -124,174 +300,5 @@ function tab_initialize_servos() {
|
|||
GUI.interval_add('servos_data_poll', function() {
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
|
||||
}, 50);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function servos_update(save_to_eeprom) {
|
||||
// update bitfields
|
||||
$('div.tab-servos table.directions tr:not(".main")').each(function() {
|
||||
var info = $('select', this).data('info');
|
||||
var val = parseInt($('select', this).val());
|
||||
|
||||
// in this stage we need to know which bitfield and which bitposition needs to be flipped
|
||||
if (val) SERVO_CONFIG[info.obj].rate = bit_set(SERVO_CONFIG[info.obj].rate, info.bitpos);
|
||||
else SERVO_CONFIG[info.obj].rate = bit_clear(SERVO_CONFIG[info.obj].rate, info.bitpos);
|
||||
});
|
||||
|
||||
// update the rest
|
||||
$('div.tab-servos table.fields tr:not(".main")').each(function() {
|
||||
var info = $(this).data('info');
|
||||
|
||||
if ($('.middle input', this).is(':disabled')) {
|
||||
var val = $('.channel input:checked', this).index();
|
||||
|
||||
SERVO_CONFIG[info.obj].middle = parseInt(val);
|
||||
} else {
|
||||
SERVO_CONFIG[info.obj].middle = parseInt($('.middle input', this).val());
|
||||
}
|
||||
|
||||
SERVO_CONFIG[info.obj].min = parseInt($('.min input', this).val());
|
||||
SERVO_CONFIG[info.obj].max = parseInt($('.max input', this).val());
|
||||
|
||||
// update rate if direction fields exist
|
||||
if ($('.direction input', this).length) {
|
||||
if ($('.direction input:first', this).is(':checked')) SERVO_CONFIG[info.obj].rate = bit_set(SERVO_CONFIG[info.obj].rate, 0);
|
||||
else SERVO_CONFIG[info.obj].rate = bit_clear(SERVO_CONFIG[info.obj].rate, 0);
|
||||
|
||||
if ($('.direction input:last', this).is(':checked')) SERVO_CONFIG[info.obj].rate = bit_set(SERVO_CONFIG[info.obj].rate, 1);
|
||||
else SERVO_CONFIG[info.obj].rate = bit_clear(SERVO_CONFIG[info.obj].rate, 1);
|
||||
} else if ($('.direction select', this).length) {
|
||||
var val = parseInt($('.direction select', this).val());
|
||||
SERVO_CONFIG[info.obj].rate = val;
|
||||
}
|
||||
});
|
||||
|
||||
// send settings over to mcu
|
||||
var buffer_out = [];
|
||||
|
||||
var needle = 0;
|
||||
for (var i = 0; i < SERVO_CONFIG.length; i++) {
|
||||
buffer_out[needle++] = lowByte(SERVO_CONFIG[i].min);
|
||||
buffer_out[needle++] = highByte(SERVO_CONFIG[i].min);
|
||||
|
||||
buffer_out[needle++] = lowByte(SERVO_CONFIG[i].max);
|
||||
buffer_out[needle++] = highByte(SERVO_CONFIG[i].max);
|
||||
|
||||
buffer_out[needle++] = lowByte(SERVO_CONFIG[i].middle);
|
||||
buffer_out[needle++] = highByte(SERVO_CONFIG[i].middle);
|
||||
|
||||
buffer_out[needle++] = lowByte(SERVO_CONFIG[i].rate);
|
||||
}
|
||||
|
||||
send_message(MSP_codes.MSP_SET_SERVO_CONF, buffer_out);
|
||||
|
||||
if (save_to_eeprom) {
|
||||
// Save changes to EEPROM
|
||||
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
|
||||
GUI.log('EEPROM <span style="color: green">saved</span>');
|
||||
|
||||
var element = $('a.update');
|
||||
element.addClass('success');
|
||||
|
||||
GUI.timeout_add('success_highlight', function() {
|
||||
element.removeClass('success');
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function process_directions(name, obj, bitpos) {
|
||||
$('div.direction_wrapper').show();
|
||||
|
||||
var val;
|
||||
|
||||
$('div.tab-servos table.directions').append('\
|
||||
<tr>\
|
||||
<td class="name" style="text-align: center">' + name + '</td>\
|
||||
<td class="direction" style="text-align: right">\
|
||||
<select name="direction">\
|
||||
<option value="0">Normal</option>\
|
||||
<option value="1">Reverse</option>\
|
||||
</select>\
|
||||
</td>\
|
||||
</tr>\
|
||||
');
|
||||
|
||||
if (bit_check(SERVO_CONFIG[obj].rate, bitpos)) val = 1;
|
||||
else val = 0;
|
||||
|
||||
$('div.tab-servos table.directions tr:last select').val(val);
|
||||
$('div.tab-servos table.directions tr:last select').data('info', {'obj': obj, 'bitpos': bitpos});
|
||||
}
|
||||
|
||||
function process_servos(name, alternate, obj, directions) {
|
||||
$('div.supported_wrapper').show();
|
||||
|
||||
$('div.tab-servos table.fields').append('\
|
||||
<tr> \
|
||||
<td style="text-align: center">' + name + '</td>\
|
||||
<td class="middle"><input type="number" min="1000" max="2000" value="' + ((SERVO_CONFIG[obj].middle <= 7) ? 1500 : SERVO_CONFIG[obj].middle) + '" /></td>\
|
||||
<td class="min"><input type="number" min="1000" max="2000" value="' + SERVO_CONFIG[obj].min +'" /></td>\
|
||||
<td class="max"><input type="number" min="1000" max="2000" value="' + SERVO_CONFIG[obj].max +'" /></td>\
|
||||
<td class="channel">\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
<input type="checkbox"/>\
|
||||
</td>\
|
||||
<td class="direction">\
|
||||
<input class="first" type="checkbox"/><span class="name">' + name + '</span>\
|
||||
<input class="second" type="checkbox"/><span class="alternate">' + alternate + '</span>\
|
||||
</td>\
|
||||
</tr> \
|
||||
');
|
||||
|
||||
if (SERVO_CONFIG[obj].middle <= 7) {
|
||||
$('div.tab-servos table.fields tr:last td.middle input').prop('disabled', true);
|
||||
$('div.tab-servos table.fields tr:last td.channel').find('input').eq(SERVO_CONFIG[obj].middle).prop('checked', true);
|
||||
}
|
||||
|
||||
if (directions == true) {
|
||||
$('div.tab-servos table.fields tr:last td.direction input:first').prop('checked', bit_check(SERVO_CONFIG[obj].rate, 0));
|
||||
$('div.tab-servos table.fields tr:last td.direction input:last').prop('checked', bit_check(SERVO_CONFIG[obj].rate, 1));
|
||||
} else if (directions == 2) {
|
||||
// removing checkboxes
|
||||
$('div.tab-servos table.fields tr:last td.direction').html('');
|
||||
|
||||
// adding select box and generating options
|
||||
$('div.tab-servos table.fields tr:last td.direction').append('\
|
||||
<select class="rate" name="rate"></select>\
|
||||
');
|
||||
|
||||
var select = $('div.tab-servos table.fields tr:last td.direction select');
|
||||
|
||||
for (var i = 100; i > -101; i--) {
|
||||
select.append('<option value="' + i + '">Rate: ' + i + '%</option>');
|
||||
}
|
||||
|
||||
// select current rate
|
||||
select.val(SERVO_CONFIG[obj].rate);
|
||||
} else {
|
||||
// removing checkboxes
|
||||
$('div.tab-servos table.fields tr:last td.direction').html('');
|
||||
}
|
||||
|
||||
$('div.tab-servos table.fields tr:last').data('info', {'obj': obj});
|
||||
|
||||
// UI hooks
|
||||
$('div.tab-servos table.fields tr:last td.channel').find('input').click(function() {
|
||||
if($(this).is(':checked')) {
|
||||
$(this).parent().parent().find('td.middle input').prop('disabled', true);
|
||||
$(this).parent().find('input').not($(this)).prop('checked', false);
|
||||
} else {
|
||||
$(this).parent().parent().find('td.middle input').prop('disabled', false).val(1500);
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue