1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-24 00:35:26 +03:00

add SERVO_CONFIG to backup file, restoring old version will throw compatibility error

This commit is contained in:
cTn 2014-10-06 15:24:34 +02:00
parent 2c9fafe4b1
commit cd4c7a8160
4 changed files with 64 additions and 42 deletions

View file

@ -38,6 +38,9 @@
"message": "Device - <span style=\"color: green\">Ready</span>" "message": "Device - <span style=\"color: green\">Ready</span>"
}, },
"backupFileIncompatible": {
"message": "Backup file provided was generated for older version of configurator and is incompatible with this version of configurator. Sorry"
},
"tabSetup": { "tabSetup": {
"message": "Setup" "message": "Setup"

View file

@ -32,7 +32,11 @@ function configuration_backup() {
} }
function get_misc_data() { function get_misc_data() {
MSP.send_message(MSP_codes.MSP_MISC, false, false, backup); MSP.send_message(MSP_codes.MSP_MISC, false, false, get_servo_config_data);
}
function get_servo_config_data() {
MSP.send_message(MSP_codes.MSP_SERVO_CONF, false, false, backup);
} }
function backup() { function backup() {
@ -80,7 +84,8 @@ function configuration_backup() {
'AUX_val': AUX_CONFIG_values, 'AUX_val': AUX_CONFIG_values,
'RC': RC_tuning, 'RC': RC_tuning,
'AccelTrim': CONFIG.accelerometerTrims, 'AccelTrim': CONFIG.accelerometerTrims,
'MISC': MISC 'MISC': MISC,
'SERVO_CONFIG': SERVO_CONFIG
}; };
// crunch the config object // crunch the config object
@ -173,19 +178,7 @@ function configuration_restore() {
return; return;
} }
// replacing "old configuration" with configuration from backup file configuration_upload(deserialized_configuration_object);
var configuration = deserialized_configuration_object;
// some configuration.VERSION code goes here? will see
PIDs = configuration.PID;
AUX_CONFIG_values = configuration.AUX_val;
RC_tuning = configuration.RC;
CONFIG.accelerometerTrims = configuration.AccelTrim;
MISC = configuration.MISC;
// all of the arrays/objects are set, upload changes
configuration_upload();
} }
}; };
@ -194,7 +187,32 @@ function configuration_restore() {
}); });
} }
function configuration_upload() { function configuration_upload(configuration) {
// check if all attributes that we will be saving exist inside the configuration object
var validate = [
'PID',
'AUX_val',
'RC',
'AccelTrim',
'MISC',
'SERVO_CONFIG'
];
for (var i = 0; i < validate.length; i++) {
if (typeof (configuration[i]) === 'undefined') {
GUI.log(chrome.i18n.getMessage('backupFileIncompatible'));
return;
}
}
// replace data
PIDs = configuration.PID;
AUX_CONFIG_values = configuration.AUX_val;
RC_tuning = configuration.RC;
CONFIG.accelerometerTrims = configuration.AccelTrim;
MISC = configuration.MISC;
SERVO_CONFIG = configuration.SERVO_CONFIG;
function rc_tuning() { // Send over the RC_tuning changes function rc_tuning() { // Send over the RC_tuning changes
MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch(MSP_codes.MSP_SET_RC_TUNING), false, aux); MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch(MSP_codes.MSP_SET_RC_TUNING), false, aux);
} }
@ -208,7 +226,11 @@ function configuration_upload() {
} }
function misc() { // Send ove the new MISC 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); MSP.send_message(MSP_codes.MSP_SET_MISC, MSP.crunch(MSP_codes.MSP_SET_MISC), false, servo_conf);
}
function servo_conf() { // send over the new SERVO_CONF
MSP.send_message(MSP_codes.MSP_SET_SERVO_CONF, MSP.crunch(MSP_codes.MSP_SET_SERVO_CONF), false, save_eeprom);
} }
function save_eeprom() { function save_eeprom() {

View file

@ -671,6 +671,20 @@ MSP.crunch = function (code) {
buffer.push(MISC.vbatmaxcellvoltage); buffer.push(MISC.vbatmaxcellvoltage);
buffer.push(MISC.placeholder3); buffer.push(MISC.placeholder3);
break; break;
case MSP_codes.MSP_SET_SERVO_CONF:
for (var i = 0; i < SERVO_CONFIG.length; i++) {
buffer.push(lowByte(SERVO_CONFIG[i].min));
buffer.push(highByte(SERVO_CONFIG[i].min));
buffer.push(lowByte(SERVO_CONFIG[i].max));
buffer.push(highByte(SERVO_CONFIG[i].max));
buffer.push(lowByte(SERVO_CONFIG[i].middle));
buffer.push(highByte(SERVO_CONFIG[i].middle));
buffer.push(lowByte(SERVO_CONFIG[i].rate));
}
break;
default: default:
return false; return false;

View file

@ -164,31 +164,14 @@ TABS.servos.initialize = function (callback) {
} }
}); });
// send settings over to mcu MSP.send_message(MSP_codes.MSP_SET_SERVO_CONF, MSP.crunch(MSP_codes.MSP_SET_SERVO_CONF), false, function () {
var buffer_out = []; if (save_to_eeprom) {
// Save changes to EEPROM
var needle = 0; MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () {
for (var i = 0; i < SERVO_CONFIG.length; i++) { GUI.log(chrome.i18n.getMessage('servosEepromSave'));
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);
}
MSP.send_message(MSP_codes.MSP_SET_SERVO_CONF, buffer_out);
if (save_to_eeprom) {
// Save changes to EEPROM
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () {
GUI.log(chrome.i18n.getMessage('servosEepromSave'));
});
}
} }
// drop previous table // drop previous table