upload section for the restore function
parent
9ad8534f0c
commit
29343686c5
|
@ -24,7 +24,7 @@ function configuration_backup() {
|
|||
// create or load the file
|
||||
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'bf_mw_backup_' + now, accepts: accepts}, function(fileEntry) {
|
||||
if (!fileEntry) {
|
||||
console.log('No file selected');
|
||||
console.log('No file selected, backup aborted.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ function configuration_backup() {
|
|||
|
||||
// create config object that will be used to store all downloaded data
|
||||
var configuration = {
|
||||
VERSION: CONFIG.version, // not really useful yet
|
||||
PID: PIDs,
|
||||
AUX_val: AUX_CONFIG_values,
|
||||
RC: RC_tuning,
|
||||
|
@ -88,7 +89,7 @@ function configuration_restore() {
|
|||
// load up the file
|
||||
chrome.fileSystem.chooseEntry({type: 'openFile', accepts: accepts}, function(fileEntry) {
|
||||
if (!fileEntry) {
|
||||
console.log('No file selected');
|
||||
console.log('No file selected, restore aborted.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -115,17 +116,110 @@ function configuration_restore() {
|
|||
var deserialized_configuration_object = JSON.parse(e.target.result);
|
||||
} catch (e) {
|
||||
// data provided != valid json object
|
||||
console.log('Data provided != valid JSON string. ABORTING !!!');
|
||||
console.log('Data provided != valid JSON string, restore aborted.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// replacing "old configuration" with configuration from backup file
|
||||
var configuration = deserialized_configuration_object;
|
||||
console.log(configuration);
|
||||
|
||||
// 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;
|
||||
|
||||
// all of the arrays/objects are set, upload changes
|
||||
configuration_upload();
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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();
|
||||
var 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
|
||||
send_message(MSP_codes.MSP_SET_PID, PID_buffer_out);
|
||||
|
||||
|
||||
// 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
|
||||
send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out);
|
||||
|
||||
|
||||
// AUX section
|
||||
var AUX_val_buffer_out = new Array();
|
||||
|
||||
var 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
|
||||
send_message(MSP_codes.MSP_SET_BOX, AUX_val_buffer_out);
|
||||
|
||||
|
||||
// Trim section (baseflight specific)
|
||||
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
|
||||
send_message(MSP_codes.MSP_SET_ACC_TRIM, buffer_out);
|
||||
|
||||
|
||||
// Save changes to EEPROM
|
||||
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE);
|
||||
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
<a class="backup" href="#">Backup</a>
|
||||
<a class="restore" href="#">Restore</a>
|
||||
<p>
|
||||
<strong>Backup</strong> your configuration in case of accident.
|
||||
<strong>Backup</strong> your configuration in case of an accident.
|
||||
</p>
|
||||
</div>
|
||||
<div id="interactive_block">
|
||||
|
|
Loading…
Reference in New Issue