finishing touches to the crunching mechanism, backup and restore is all cleaned up now

10.3.x-maintenance
cTn 2014-09-17 09:27:54 +02:00
parent e626fbeb7b
commit e9c4a533af
6 changed files with 51 additions and 53 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 () {