diff --git a/js/backup_restore.js b/js/backup_restore.js index 061aabe70c..fae213705d 100644 --- a/js/backup_restore.js +++ b/js/backup_restore.js @@ -187,86 +187,19 @@ function configuration_restore() { } function configuration_upload() { - // this "cloned" function contains all the upload sequences for the respective array/objects - // that are currently scattered in separate tabs (ergo - pid_tuning.js/initial_setup.js/etc) - // for current purposes, this approach works, but its not really "valid" and this approach - // should be reworked in the future, so the same code won't be cloned over !!! - - // PID section - var PID_buffer_out = new Array(), - PID_buffer_needle = 0; - - for (var i = 0; i < PIDs.length; i++) { - switch (i) { - case 0: - case 1: - case 2: - case 3: - case 7: - case 8: - case 9: - PID_buffer_out[PID_buffer_needle] = parseInt(PIDs[i][0] * 10); - PID_buffer_out[PID_buffer_needle + 1] = parseInt(PIDs[i][1] * 1000); - PID_buffer_out[PID_buffer_needle + 2] = parseInt(PIDs[i][2]); - break; - case 4: - PID_buffer_out[PID_buffer_needle] = parseInt(PIDs[i][0] * 100); - PID_buffer_out[PID_buffer_needle + 1] = parseInt(PIDs[i][1] * 100); - PID_buffer_out[PID_buffer_needle + 2] = parseInt(PIDs[i][2]); - break; - case 5: - case 6: - PID_buffer_out[PID_buffer_needle] = parseInt(PIDs[i][0] * 10); - PID_buffer_out[PID_buffer_needle + 1] = parseInt(PIDs[i][1] * 100); - PID_buffer_out[PID_buffer_needle + 2] = parseInt(PIDs[i][2] * 1000); - break; - } - - PID_buffer_needle += 3; - } - // Send over the PID changes - MSP.send_message(MSP_codes.MSP_SET_PID, PID_buffer_out, false, rc_tuning); + MSP.send_message(MSP_codes.MSP_SET_PID, MSP.crunch('PIDs'), false, rc_tuning); - function rc_tuning() { - // RC Tuning section - var RC_tuning_buffer_out = new Array(); - RC_tuning_buffer_out[0] = parseInt(RC_tuning.RC_RATE * 100); - RC_tuning_buffer_out[1] = parseInt(RC_tuning.RC_EXPO * 100); - RC_tuning_buffer_out[2] = parseInt(RC_tuning.roll_pitch_rate * 100); - RC_tuning_buffer_out[3] = parseInt(RC_tuning.yaw_rate * 100); - RC_tuning_buffer_out[4] = parseInt(RC_tuning.dynamic_THR_PID * 100); - RC_tuning_buffer_out[5] = parseInt(RC_tuning.throttle_MID * 100); - RC_tuning_buffer_out[6] = parseInt(RC_tuning.throttle_EXPO * 100); - - // Send over the RC_tuning changes - MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out, false, aux); + function rc_tuning() { // Send over the RC_tuning changes + MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch('RC_tuning'), false, aux); } - function aux() { - // AUX section - var AUX_val_buffer_out = new Array(), - needle = 0; - - for (var i = 0; i < AUX_CONFIG_values.length; i++) { - AUX_val_buffer_out[needle++] = lowByte(AUX_CONFIG_values[i]); - AUX_val_buffer_out[needle++] = highByte(AUX_CONFIG_values[i]); - } - - // Send over the AUX changes - MSP.send_message(MSP_codes.MSP_SET_BOX, AUX_val_buffer_out, false, trim); + function aux() { // Send over the AUX changes + MSP.send_message(MSP_codes.MSP_SET_BOX, MSP.crunch('AUX_CONFIG_values'), false, trim); } - // Trim section - function trim() { - var buffer_out = new Array(); - buffer_out[0] = lowByte(CONFIG.accelerometerTrims[0]); - buffer_out[1] = highByte(CONFIG.accelerometerTrims[0]); - buffer_out[2] = lowByte(CONFIG.accelerometerTrims[1]); - buffer_out[3] = highByte(CONFIG.accelerometerTrims[1]); - - // Send over the new trims - MSP.send_message(MSP_codes.MSP_SET_ACC_TRIM, buffer_out, false, misc); + function trim() { // Send over the new trims + MSP.send_message(MSP_codes.MSP_SET_ACC_TRIM, MSP.crunch('accelerometerTrims'), false, misc); } function misc() { diff --git a/js/msp.js b/js/msp.js index c3c8e54038..0d910a0f30 100644 --- a/js/msp.js +++ b/js/msp.js @@ -577,6 +577,55 @@ MSP.crunch = function (name) { buffer.push(specificByte(BF_CONFIG.board_align_yaw, 0)); buffer.push(specificByte(BF_CONFIG.board_align_yaw, 1)); break; + case 'PIDs': + for (var i = 0; i < PIDs.length; i++) { + switch (i) { + case 0: + case 1: + case 2: + case 3: + case 7: + case 8: + case 9: + buffer.push(parseInt(PIDs[i][0] * 10)); + buffer.push(parseInt(PIDs[i][1] * 1000)); + buffer.push(parseInt(PIDs[i][2])); + break; + case 4: + buffer.push(parseInt(PIDs[i][0] * 100)); + buffer.push(parseInt(PIDs[i][1] * 100)); + buffer.push(parseInt(PIDs[i][2])); + break; + case 5: + case 6: + buffer.push(parseInt(PIDs[i][0] * 10)); + buffer.push(parseInt(PIDs[i][1] * 100)); + buffer.push(parseInt(PIDs[i][2] * 1000)); + break; + } + } + break; + case 'RC_tuning': + buffer.push(parseInt(RC_tuning.RC_RATE * 100)); + buffer.push(parseInt(RC_tuning.RC_EXPO * 100)); + buffer.push(parseInt(RC_tuning.roll_pitch_rate * 100)); + buffer.push(parseInt(RC_tuning.yaw_rate * 100)); + buffer.push(parseInt(RC_tuning.dynamic_THR_PID * 100)); + buffer.push(parseInt(RC_tuning.throttle_MID * 100)); + buffer.push(parseInt(RC_tuning.throttle_EXPO * 100)); + break; + case 'AUX_CONFIG_values': + for (var i = 0; i < AUX_CONFIG_values.length; i++) { + buffer.push(lowByte(AUX_CONFIG_values[i])); + buffer.push(highByte(AUX_CONFIG_values[i])); + } + break; + case 'accelerometerTrims': + buffer.push(lowByte(CONFIG.accelerometerTrims[0])); + buffer.push(highByte(CONFIG.accelerometerTrims[0])); + buffer.push(lowByte(CONFIG.accelerometerTrims[1])); + buffer.push(highByte(CONFIG.accelerometerTrims[1])); + break; default: return false; diff --git a/tabs/auxiliary_configuration.js b/tabs/auxiliary_configuration.js index 1e928ac382..8427b17447 100644 --- a/tabs/auxiliary_configuration.js +++ b/tabs/auxiliary_configuration.js @@ -64,8 +64,9 @@ TABS.auxiliary_configuration.initialize = function (callback) { // UI Hooks $('a.update').click(function () { // catch the input changes - var main_needle = 0; - var needle = 0; + var main_needle = 0, + needle = 0; + $('.boxes input').each(function () { if ($(this).is(':checked')) { AUX_CONFIG_values[main_needle] = bit_set(AUX_CONFIG_values[main_needle], needle); @@ -77,26 +78,17 @@ TABS.auxiliary_configuration.initialize = function (callback) { if (needle >= (RC.active_channels - 4) * 3) { // 1 aux * 3 checkboxes, 4 AUX = 12 bits per line main_needle++; - needle = 0; } }); - // send over data - // current code will only handle 4 AUX as the variable length is 16bits - var AUX_val_buffer_out = []; - for (var i = 0; i < AUX_CONFIG_values.length; i++) { - AUX_val_buffer_out.push(lowByte(AUX_CONFIG_values[i])); - AUX_val_buffer_out.push(highByte(AUX_CONFIG_values[i])); - } - - MSP.send_message(MSP_codes.MSP_SET_BOX, AUX_val_buffer_out, false, save_to_eeprom); - function save_to_eeprom() { MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () { GUI.log(chrome.i18n.getMessage('auxiliaryEepromSaved')); }); } + + MSP.send_message(MSP_codes.MSP_SET_BOX, MSP.crunch('AUX_CONFIG_values'), false, save_to_eeprom); }); // val = channel value diff --git a/tabs/pid_tuning.js b/tabs/pid_tuning.js index ffd053c4e6..e2c59b94c4 100644 --- a/tabs/pid_tuning.js +++ b/tabs/pid_tuning.js @@ -253,54 +253,13 @@ TABS.pid_tuning.initialize = function (callback) { PIDs[8][i++] = parseFloat($(this).val()); }); - var PID_buffer_out = new Array(); - for (var i = 0, needle = 0; i < PIDs.length; i++, needle += 3) { - switch (i) { - case 0: - case 1: - case 2: - case 3: - case 7: - case 8: - case 9: - PID_buffer_out[needle] = parseInt(PIDs[i][0] * 10); - PID_buffer_out[needle + 1] = parseInt(PIDs[i][1] * 1000); - PID_buffer_out[needle + 2] = parseInt(PIDs[i][2]); - break; - case 4: - PID_buffer_out[needle] = parseInt(PIDs[i][0] * 100); - PID_buffer_out[needle + 1] = parseInt(PIDs[i][1] * 100); - PID_buffer_out[needle + 2] = parseInt(PIDs[i][2]); - break; - case 5: - case 6: - PID_buffer_out[needle] = parseInt(PIDs[i][0] * 10); - PID_buffer_out[needle + 1] = parseInt(PIDs[i][1] * 100); - PID_buffer_out[needle + 2] = parseInt(PIDs[i][2] * 1000); - break; - } - } - - // Send over the PID changes - MSP.send_message(MSP_codes.MSP_SET_PID, PID_buffer_out, false, 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()); + RC_tuning.dynamic_THR_PID = parseFloat($('.rate-tpa input[name="tpa"]').val()); 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()); - RC_tuning.dynamic_THR_PID = parseFloat($('.rate-tpa input[name="tpa"]').val()); - - var RC_tuning_buffer_out = new Array(); - RC_tuning_buffer_out[0] = parseInt(RC_tuning.RC_RATE * 100); - RC_tuning_buffer_out[1] = parseInt(RC_tuning.RC_EXPO * 100); - RC_tuning_buffer_out[2] = parseInt(RC_tuning.roll_pitch_rate * 100); - RC_tuning_buffer_out[3] = parseInt(RC_tuning.yaw_rate * 100); - RC_tuning_buffer_out[4] = parseInt(RC_tuning.dynamic_THR_PID * 100); - RC_tuning_buffer_out[5] = parseInt(RC_tuning.throttle_MID * 100); - RC_tuning_buffer_out[6] = parseInt(RC_tuning.throttle_EXPO * 100); - - // Send over the RC_tuning changes - MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out, false, save_to_eeprom); + MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch('RC_tuning'), false, save_to_eeprom); } function save_to_eeprom() { @@ -308,6 +267,8 @@ TABS.pid_tuning.initialize = function (callback) { GUI.log(chrome.i18n.getMessage('pidTuningEepromSaved')); }); } + + MSP.send_message(MSP_codes.MSP_SET_PID, MSP.crunch('PIDs'), false, send_rc_tuning_changes); }); // status data pulled via separate timer with static speed diff --git a/tabs/receiver.js b/tabs/receiver.js index 9fab5defac..0a9fda69fe 100644 --- a/tabs/receiver.js +++ b/tabs/receiver.js @@ -143,23 +143,13 @@ TABS.receiver.initialize = function (callback) { RC_tuning.RC_RATE = parseFloat($('.tunings .rate input[name="rate"]').val()); RC_tuning.RC_EXPO = parseFloat($('.tunings .rate input[name="expo"]').val()); - var RC_tuning_buffer_out = new Array(); - RC_tuning_buffer_out[0] = parseInt(RC_tuning.RC_RATE * 100, 10); - RC_tuning_buffer_out[1] = parseInt(RC_tuning.RC_EXPO * 100, 10); - RC_tuning_buffer_out[2] = parseInt(RC_tuning.roll_pitch_rate * 100, 10); - RC_tuning_buffer_out[3] = parseInt(RC_tuning.yaw_rate * 100, 10); - RC_tuning_buffer_out[4] = parseInt(RC_tuning.dynamic_THR_PID * 100, 10); - RC_tuning_buffer_out[5] = parseInt(RC_tuning.throttle_MID * 100, 10); - RC_tuning_buffer_out[6] = parseInt(RC_tuning.throttle_EXPO * 100, 10); - - // Send over the RC_tuning changes - MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out, false, save_to_eeprom); - function save_to_eeprom() { MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () { GUI.log(chrome.i18n.getMessage('receiverEepromSaved')); }); } + + MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch('RC_tuning'), false, save_to_eeprom); }); $('select[name="rx_refresh_rate"]').change(function () {