From e9c4a533af4b15f58443bb0762fa14d13f155eee Mon Sep 17 00:00:00 2001 From: cTn Date: Wed, 17 Sep 2014 09:27:54 +0200 Subject: [PATCH] finishing touches to the crunching mechanism, backup and restore is all cleaned up now --- js/backup_restore.js | 56 +++++++++------------------------ js/msp.js | 38 +++++++++++++++++----- tabs/auxiliary_configuration.js | 2 +- tabs/initial_setup.js | 2 +- tabs/pid_tuning.js | 4 +-- tabs/receiver.js | 2 +- 6 files changed, 51 insertions(+), 53 deletions(-) diff --git a/js/backup_restore.js b/js/backup_restore.js index fae21370..73f3f472 100644 --- a/js/backup_restore.js +++ b/js/backup_restore.js @@ -43,11 +43,11 @@ function configuration_backup() { }]; // generate timestamp for the backup file - var d = new Date(); - var now = d.getUTCFullYear() + '.' + d.getDate() + '.' + (d.getMonth() + 1) + '.' + d.getHours() + '.' + d.getMinutes(); + var d = new Date(), + now = d.getUTCFullYear() + '.' + d.getDate() + '.' + (d.getMonth() + 1) + '.' + d.getHours() + '.' + d.getMinutes(); // create or load the file - chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'bf_mw_backup_' + now, accepts: accepts}, function (fileEntry) { + chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'baseflight_backup_' + now, accepts: accepts}, function (fileEntry) { if (!fileEntry) { console.log('No file selected, backup aborted.'); @@ -187,54 +187,28 @@ function configuration_restore() { } function configuration_upload() { - // Send over the PID changes - MSP.send_message(MSP_codes.MSP_SET_PID, MSP.crunch('PIDs'), false, rc_tuning); - function rc_tuning() { // Send over the RC_tuning changes - MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch('RC_tuning'), false, aux); + MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch(MSP_codes.MSP_SET_RC_TUNING), false, aux); } function aux() { // Send over the AUX changes - MSP.send_message(MSP_codes.MSP_SET_BOX, MSP.crunch('AUX_CONFIG_values'), false, trim); + MSP.send_message(MSP_codes.MSP_SET_BOX, MSP.crunch(MSP_codes.MSP_SET_BOX), false, trim); } function trim() { // Send over the new trims - MSP.send_message(MSP_codes.MSP_SET_ACC_TRIM, MSP.crunch('accelerometerTrims'), false, misc); + MSP.send_message(MSP_codes.MSP_SET_ACC_TRIM, MSP.crunch(MSP_codes.MSP_SET_ACC_TRIM), false, misc); } - function misc() { - // MISC - // we also have to fill the unsupported bytes - var buffer_out = new Array(); - buffer_out[0] = 0; // powerfailmeter - buffer_out[1] = 0; - buffer_out[2] = lowByte(MISC.minthrottle); - buffer_out[3] = highByte(MISC.minthrottle); - buffer_out[4] = lowByte(MISC.maxthrottle); - buffer_out[5] = highByte(MISC.maxthrottle); - buffer_out[6] = lowByte(MISC.mincommand); - buffer_out[7] = highByte(MISC.mincommand); - buffer_out[8] = lowByte(MISC.failsafe_throttle); - buffer_out[9] = highByte(MISC.failsafe_throttle); - buffer_out[10] = 0; - buffer_out[11] = 0; - buffer_out[12] = 0; - buffer_out[13] = 0; - buffer_out[14] = 0; - buffer_out[15] = 0; - buffer_out[16] = lowByte(MISC.mag_declination); - buffer_out[17] = highByte(MISC.mag_declination); - buffer_out[18] = MISC.vbatscale; - buffer_out[19] = MISC.vbatmincellvoltage; - buffer_out[20] = MISC.vbatmaxcellvoltage; - buffer_out[21] = 0; // vbatlevel_crit (unused) + function misc() { // Send ove the new MISC + MSP.send_message(MSP_codes.MSP_SET_MISC, MSP.crunch(MSP_codes.MSP_SET_MISC), false, save_eeprom); + } - // Send ove the new MISC - MSP.send_message(MSP_codes.MSP_SET_MISC, buffer_out, false, function () { - // Save changes to EEPROM - MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () { - GUI.log(chrome.i18n.getMessage('eeprom_saved_ok')); - }); + function save_eeprom() { + MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () { + GUI.log(chrome.i18n.getMessage('eeprom_saved_ok')); }); } + + // Send over the PID changes + MSP.send_message(MSP_codes.MSP_SET_PID, MSP.crunch(MSP_codes.MSP_SET_PID), false, rc_tuning); } \ No newline at end of file diff --git a/js/msp.js b/js/msp.js index 0d910a0f..2429500c 100644 --- a/js/msp.js +++ b/js/msp.js @@ -559,11 +559,11 @@ MSP.send_message = function(code, data, callback_sent, callback_msp) { return true; }; -MSP.crunch = function (name) { +MSP.crunch = function (code) { var buffer = []; - switch (name) { - case 'BF_CONFIG': + switch (code) { + case MSP_codes.MSP_SET_CONFIG: buffer.push(BF_CONFIG.mixerConfiguration); buffer.push(specificByte(BF_CONFIG.features, 0)); buffer.push(specificByte(BF_CONFIG.features, 1)); @@ -577,7 +577,7 @@ 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': + case MSP_codes.MSP_SET_PID: for (var i = 0; i < PIDs.length; i++) { switch (i) { case 0: @@ -605,7 +605,7 @@ MSP.crunch = function (name) { } } break; - case 'RC_tuning': + case MSP_codes.MSP_SET_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)); @@ -614,18 +614,42 @@ MSP.crunch = function (name) { buffer.push(parseInt(RC_tuning.throttle_MID * 100)); buffer.push(parseInt(RC_tuning.throttle_EXPO * 100)); break; - case 'AUX_CONFIG_values': + case MSP_codes.MSP_SET_BOX: 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': + case MSP_codes.MSP_SET_ACC_TRIM: 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; + case MSP_codes.MSP_SET_MISC: + buffer.push(lowByte(MISC.midrc)); + buffer.push(highByte(MISC.midrc)); + buffer.push(lowByte(MISC.minthrottle)); + buffer.push(highByte(MISC.minthrottle)); + buffer.push(lowByte(MISC.maxthrottle)); + buffer.push(highByte(MISC.maxthrottle)); + buffer.push(lowByte(MISC.mincommand)); + buffer.push(highByte(MISC.mincommand)); + buffer.push(lowByte(MISC.failsafe_throttle)); + buffer.push(highByte(MISC.failsafe_throttle)); + buffer.push(MISC.gps_type); + buffer.push(MISC.gps_baudrate); + buffer.push(MISC.gps_ubx_sbas); + buffer.push(MISC.placeholder1); + buffer.push(lowByte(MISC.placeholder2)); + buffer.push(highByte(MISC.placeholder2)); + buffer.push(lowByte(MISC.mag_declination)); + buffer.push(highByte(MISC.mag_declination)); + buffer.push(MISC.vbatscale); + buffer.push(MISC.vbatmincellvoltage); + buffer.push(MISC.vbatmaxcellvoltage); + buffer.push(MISC.placeholder3); + break; default: return false; diff --git a/tabs/auxiliary_configuration.js b/tabs/auxiliary_configuration.js index 8427b174..5baf5c48 100644 --- a/tabs/auxiliary_configuration.js +++ b/tabs/auxiliary_configuration.js @@ -88,7 +88,7 @@ TABS.auxiliary_configuration.initialize = function (callback) { }); } - MSP.send_message(MSP_codes.MSP_SET_BOX, MSP.crunch('AUX_CONFIG_values'), false, save_to_eeprom); + MSP.send_message(MSP_codes.MSP_SET_BOX, MSP.crunch(MSP_codes.MSP_SET_BOX), false, save_to_eeprom); }); // val = channel value diff --git a/tabs/initial_setup.js b/tabs/initial_setup.js index 938d441e..aa1b857a 100644 --- a/tabs/initial_setup.js +++ b/tabs/initial_setup.js @@ -109,7 +109,7 @@ TABS.initial_setup.initialize = function (callback) { }); } - MSP.send_message(MSP_codes.MSP_SET_CONFIG, MSP.crunch('BF_CONFIG'), false, save_to_eeprom); // TODO reply byte is missing on the firmware side so this is where it fails + MSP.send_message(MSP_codes.MSP_SET_CONFIG, MSP.crunch(MSP_codes.MSP_SET_CONFIG), false, save_to_eeprom); }); } else { // old stuff diff --git a/tabs/pid_tuning.js b/tabs/pid_tuning.js index e2c59b94..0146f8e0 100644 --- a/tabs/pid_tuning.js +++ b/tabs/pid_tuning.js @@ -259,7 +259,7 @@ TABS.pid_tuning.initialize = function (callback) { RC_tuning.dynamic_THR_PID = parseFloat($('.rate-tpa input[name="tpa"]').val()); function send_rc_tuning_changes() { - MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch('RC_tuning'), false, save_to_eeprom); + MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch(MSP_codes.MSP_SET_RC_TUNING), false, save_to_eeprom); } function save_to_eeprom() { @@ -268,7 +268,7 @@ TABS.pid_tuning.initialize = function (callback) { }); } - MSP.send_message(MSP_codes.MSP_SET_PID, MSP.crunch('PIDs'), false, send_rc_tuning_changes); + MSP.send_message(MSP_codes.MSP_SET_PID, MSP.crunch(MSP_codes.MSP_SET_PID), 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 0a9fda69..bd4efa54 100644 --- a/tabs/receiver.js +++ b/tabs/receiver.js @@ -149,7 +149,7 @@ TABS.receiver.initialize = function (callback) { }); } - MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch('RC_tuning'), false, save_to_eeprom); + MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch(MSP_codes.MSP_SET_RC_TUNING), false, save_to_eeprom); }); $('select[name="rx_refresh_rate"]').change(function () {