2014-08-09 17:38:46 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-10-12 14:06:48 +00:00
|
|
|
// code below is highly experimental, although it runs fine on latest firmware
|
|
|
|
// the data inside nested objects needs to be verified if deep copy works properly
|
2014-10-06 14:07:47 +00:00
|
|
|
function configuration_backup(callback) {
|
2014-10-12 14:06:48 +00:00
|
|
|
var activeProfile = null,
|
|
|
|
profilesN = 3;
|
|
|
|
|
|
|
|
var configuration = {
|
2014-10-12 14:16:47 +00:00
|
|
|
'generatedBy': chrome.runtime.getManifest().version,
|
2014-10-12 14:06:48 +00:00
|
|
|
'profiles': []
|
|
|
|
};
|
2014-03-20 21:19:27 +00:00
|
|
|
|
2014-10-12 14:06:48 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_STATUS, false, false, function () {
|
|
|
|
activeProfile = CONFIG.profile;
|
|
|
|
select_profile();
|
|
|
|
});
|
2014-03-20 21:19:27 +00:00
|
|
|
|
2014-10-12 14:06:48 +00:00
|
|
|
function select_profile() {
|
|
|
|
if (activeProfile > 0) {
|
|
|
|
MSP.send_message(MSP_codes.MSP_SELECT_SETTING, [0], false, fetch_specific_data);
|
|
|
|
} else {
|
|
|
|
fetch_specific_data();
|
|
|
|
}
|
2014-03-20 21:19:27 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2015-01-19 19:40:14 +00:00
|
|
|
var profileSpecificData = [
|
2015-01-29 17:27:50 +00:00
|
|
|
MSP_codes.MSP_PID_CONTROLLER,
|
2015-01-19 19:40:14 +00:00
|
|
|
MSP_codes.MSP_PID,
|
|
|
|
MSP_codes.MSP_RC_TUNING,
|
|
|
|
MSP_codes.MSP_ACC_TRIM,
|
|
|
|
MSP_codes.MSP_SERVO_CONF,
|
|
|
|
MSP_codes.MSP_CHANNEL_FORWARDING,
|
|
|
|
MSP_codes.MSP_MODE_RANGES,
|
|
|
|
MSP_codes.MSP_ADJUSTMENT_RANGES
|
|
|
|
];
|
|
|
|
|
2014-10-12 14:06:48 +00:00
|
|
|
function fetch_specific_data() {
|
|
|
|
var fetchingProfile = 0,
|
|
|
|
codeKey = 0;
|
2014-03-20 21:19:27 +00:00
|
|
|
|
2015-01-19 19:40:14 +00:00
|
|
|
function fetch_specific_data_item() {
|
2014-10-12 14:06:48 +00:00
|
|
|
if (fetchingProfile < profilesN) {
|
|
|
|
MSP.send_message(profileSpecificData[codeKey], false, false, function () {
|
|
|
|
codeKey++;
|
|
|
|
|
|
|
|
if (codeKey < profileSpecificData.length) {
|
2015-01-19 19:40:14 +00:00
|
|
|
fetch_specific_data_item();
|
2014-10-12 14:06:48 +00:00
|
|
|
} else {
|
|
|
|
configuration.profiles.push({
|
2015-01-29 20:50:02 +00:00
|
|
|
'PID': jQuery.extend(true, {}, PID),
|
2015-01-29 17:27:50 +00:00
|
|
|
'PIDs': jQuery.extend(true, [], PIDs),
|
2014-10-12 14:06:48 +00:00
|
|
|
'RC': jQuery.extend(true, {}, RC_tuning),
|
2014-10-12 14:55:49 +00:00
|
|
|
'AccTrim': jQuery.extend(true, [], CONFIG.accelerometerTrims),
|
2014-12-21 12:29:36 +00:00
|
|
|
'ServoConfig': jQuery.extend(true, [], SERVO_CONFIG),
|
|
|
|
'ModeRanges': jQuery.extend(true, [], MODE_RANGES),
|
|
|
|
'AdjustmentRanges': jQuery.extend(true, [], ADJUSTMENT_RANGES)
|
2014-10-12 14:06:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
codeKey = 0;
|
|
|
|
fetchingProfile++;
|
2014-10-12 14:16:47 +00:00
|
|
|
|
2015-01-19 19:40:14 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SELECT_SETTING, [fetchingProfile], false, fetch_specific_data_item);
|
2014-10-12 14:06:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2014-10-12 14:16:47 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SELECT_SETTING, [activeProfile], false, fetch_unique_data);
|
2014-10-12 14:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-20 21:19:27 +00:00
|
|
|
|
2014-10-12 14:06:48 +00:00
|
|
|
// start fetching
|
2015-01-19 19:40:14 +00:00
|
|
|
fetch_specific_data_item();
|
2014-10-06 13:24:34 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 19:40:14 +00:00
|
|
|
var uniqueData = [
|
|
|
|
// Not used by cleanflight, and it's wrong anyway - AUX settings are per-profile in baseflight.
|
|
|
|
/*
|
|
|
|
MSP_codes.MSP_BOX,
|
|
|
|
*/
|
|
|
|
MSP_codes.MSP_MISC,
|
|
|
|
MSP_codes.MSP_RCMAP,
|
|
|
|
MSP_codes.MSP_BF_CONFIG,
|
|
|
|
MSP_codes.MSP_CF_SERIAL_CONFIG,
|
|
|
|
MSP_codes.MSP_LED_STRIP_CONFIG
|
|
|
|
];
|
|
|
|
|
2014-10-12 14:06:48 +00:00
|
|
|
function fetch_unique_data() {
|
|
|
|
var codeKey = 0;
|
|
|
|
|
2015-01-19 19:40:14 +00:00
|
|
|
function fetch_unique_data_item() {
|
2014-10-12 14:06:48 +00:00
|
|
|
if (codeKey < uniqueData.length) {
|
|
|
|
MSP.send_message(uniqueData[codeKey], false, false, function () {
|
|
|
|
codeKey++;
|
2015-01-19 19:40:14 +00:00
|
|
|
fetch_unique_data_item();
|
2014-10-12 14:06:48 +00:00
|
|
|
});
|
|
|
|
} else {
|
2014-12-21 12:29:36 +00:00
|
|
|
// Not used by cleanflight, and it's wrong anyway - AUX settings are per-profile in baseflight.
|
|
|
|
/*
|
2014-10-12 14:55:49 +00:00
|
|
|
configuration.AUX = jQuery.extend(true, [], AUX_CONFIG_values);
|
2014-12-21 12:29:36 +00:00
|
|
|
*/
|
2014-10-12 14:55:49 +00:00
|
|
|
configuration.MISC = jQuery.extend(true, {}, MISC);
|
|
|
|
configuration.RCMAP = jQuery.extend(true, [], RC_MAP);
|
|
|
|
configuration.BF_CONFIG = jQuery.extend(true, {}, BF_CONFIG);
|
2015-01-03 00:57:56 +00:00
|
|
|
configuration.SERIAL_CONFIG = jQuery.extend(true, {}, SERIAL_CONFIG);
|
2015-03-11 23:34:24 +00:00
|
|
|
configuration.LED_STRIP = jQuery.extend(true, [], LED_STRIP);
|
2014-10-12 14:06:48 +00:00
|
|
|
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// start fetching
|
2015-01-19 19:40:14 +00:00
|
|
|
fetch_unique_data_item();
|
2014-03-20 21:19:27 +00:00
|
|
|
}
|
|
|
|
|
2014-10-12 14:06:48 +00:00
|
|
|
function save() {
|
2013-06-17 21:36:19 +00:00
|
|
|
var chosenFileEntry = null;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-06-17 21:36:19 +00:00
|
|
|
var accepts = [{
|
|
|
|
extensions: ['txt']
|
|
|
|
}];
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-06-17 21:36:19 +00:00
|
|
|
// generate timestamp for the backup file
|
2014-09-17 07:27:54 +00:00
|
|
|
var d = new Date(),
|
2014-10-12 12:50:55 +00:00
|
|
|
now = (d.getMonth() + 1) + '.' + d.getDate() + '.' + d.getFullYear() + '.' + d.getHours() + '.' + d.getMinutes();
|
2013-06-17 21:36:19 +00:00
|
|
|
|
|
|
|
// create or load the file
|
2014-12-21 12:29:36 +00:00
|
|
|
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'cleanflight_backup_' + now, accepts: accepts}, function (fileEntry) {
|
2014-09-22 19:16:52 +00:00
|
|
|
if (chrome.runtime.lastError) {
|
|
|
|
console.error(chrome.runtime.lastError.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-17 21:36:19 +00:00
|
|
|
if (!fileEntry) {
|
2013-06-17 22:14:49 +00:00
|
|
|
console.log('No file selected, backup aborted.');
|
2013-06-17 21:36:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
|
|
|
chosenFileEntry = fileEntry;
|
2013-06-17 21:36:19 +00:00
|
|
|
|
|
|
|
// echo/console log path specified
|
2014-08-10 04:01:44 +00:00
|
|
|
chrome.fileSystem.getDisplayPath(chosenFileEntry, function (path) {
|
2013-06-17 21:36:19 +00:00
|
|
|
console.log('Backup file path: ' + path);
|
|
|
|
});
|
|
|
|
|
|
|
|
// change file entry from read only to read/write
|
2014-08-10 04:01:44 +00:00
|
|
|
chrome.fileSystem.getWritableEntry(chosenFileEntry, function (fileEntryWritable) {
|
2013-06-17 21:36:19 +00:00
|
|
|
// check if file is writable
|
2014-08-10 04:01:44 +00:00
|
|
|
chrome.fileSystem.isWritableEntry(fileEntryWritable, function (isWritable) {
|
2013-06-17 21:36:19 +00:00
|
|
|
if (isWritable) {
|
|
|
|
chosenFileEntry = fileEntryWritable;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-06-17 21:36:19 +00:00
|
|
|
// crunch the config object
|
|
|
|
var serialized_config_object = JSON.stringify(configuration);
|
|
|
|
var blob = new Blob([serialized_config_object], {type: 'text/plain'}); // first parameter for Blob needs to be an array
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-10 04:01:44 +00:00
|
|
|
chosenFileEntry.createWriter(function (writer) {
|
2013-06-17 21:36:19 +00:00
|
|
|
writer.onerror = function (e) {
|
|
|
|
console.error(e);
|
|
|
|
};
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-22 20:23:06 +00:00
|
|
|
var truncated = false;
|
2014-08-10 04:01:44 +00:00
|
|
|
writer.onwriteend = function () {
|
2014-02-22 20:23:06 +00:00
|
|
|
if (!truncated) {
|
|
|
|
// onwriteend will be fired again when truncation is finished
|
|
|
|
truncated = true;
|
2014-02-22 20:43:17 +00:00
|
|
|
writer.truncate(blob.size);
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-22 20:23:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-06-17 21:36:19 +00:00
|
|
|
console.log('Write SUCCESSFUL');
|
2014-10-06 14:07:47 +00:00
|
|
|
if (callback) callback();
|
2013-06-17 21:36:19 +00:00
|
|
|
};
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-06-17 21:36:19 +00:00
|
|
|
writer.write(blob);
|
|
|
|
}, function (e) {
|
|
|
|
console.error(e);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Something went wrong or file is set to read only and cannot be changed
|
|
|
|
console.log('File appears to be read only, sorry.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-03-20 21:19:27 +00:00
|
|
|
}
|
2013-06-17 21:36:19 +00:00
|
|
|
}
|
|
|
|
|
2014-10-06 14:07:47 +00:00
|
|
|
function configuration_restore(callback) {
|
2013-06-17 21:36:19 +00:00
|
|
|
var chosenFileEntry = null;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-06-17 21:36:19 +00:00
|
|
|
var accepts = [{
|
|
|
|
extensions: ['txt']
|
|
|
|
}];
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-06-17 21:36:19 +00:00
|
|
|
// load up the file
|
2014-08-10 04:01:44 +00:00
|
|
|
chrome.fileSystem.chooseEntry({type: 'openFile', accepts: accepts}, function (fileEntry) {
|
2014-09-22 19:16:52 +00:00
|
|
|
if (chrome.runtime.lastError) {
|
|
|
|
console.error(chrome.runtime.lastError.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-17 21:36:19 +00:00
|
|
|
if (!fileEntry) {
|
2013-06-17 22:14:49 +00:00
|
|
|
console.log('No file selected, restore aborted.');
|
2013-06-17 21:36:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
|
|
|
chosenFileEntry = fileEntry;
|
|
|
|
|
2013-06-17 21:36:19 +00:00
|
|
|
// echo/console log path specified
|
2014-08-10 04:01:44 +00:00
|
|
|
chrome.fileSystem.getDisplayPath(chosenFileEntry, function (path) {
|
2013-06-17 21:36:19 +00:00
|
|
|
console.log('Restore file path: ' + path);
|
2014-03-08 05:25:15 +00:00
|
|
|
});
|
2013-06-17 21:36:19 +00:00
|
|
|
|
|
|
|
// read contents into variable
|
2014-08-10 04:01:44 +00:00
|
|
|
chosenFileEntry.file(function (file) {
|
2013-06-17 21:36:19 +00:00
|
|
|
var reader = new FileReader();
|
|
|
|
|
2014-08-10 04:01:44 +00:00
|
|
|
reader.onprogress = function (e) {
|
2014-01-15 12:07:51 +00:00
|
|
|
if (e.total > 1048576) { // 1 MB
|
|
|
|
// dont allow reading files bigger then 1 MB
|
|
|
|
console.log('File limit (1 MB) exceeded, aborting');
|
|
|
|
reader.abort();
|
|
|
|
}
|
2013-06-17 21:36:19 +00:00
|
|
|
};
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-10 04:01:44 +00:00
|
|
|
reader.onloadend = function (e) {
|
2014-01-15 12:07:51 +00:00
|
|
|
if (e.total != 0 && e.total == e.loaded) {
|
|
|
|
console.log('Read SUCCESSFUL');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-01-15 12:07:51 +00:00
|
|
|
try { // check if string provided is a valid JSON
|
2015-01-07 15:41:34 +00:00
|
|
|
var configuration = JSON.parse(e.target.result);
|
2014-01-15 12:07:51 +00:00
|
|
|
} catch (e) {
|
|
|
|
// data provided != valid json object
|
|
|
|
console.log('Data provided != valid JSON string, restore aborted.');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-01-15 12:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2015-01-07 15:41:34 +00:00
|
|
|
// validate
|
|
|
|
if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.backupFileMinVersionAccepted)) {
|
|
|
|
|
|
|
|
if (configuration.generatedBy != chrome.runtime.getManifest().version) {
|
|
|
|
if (!migrate(configuration)) {
|
|
|
|
GUI.log(chrome.i18n.getMessage('backupFileUnmigratable'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
configuration_upload(configuration, callback);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
GUI.log(chrome.i18n.getMessage('backupFileIncompatible'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-17 21:36:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
reader.readAsText(file);
|
|
|
|
});
|
|
|
|
});
|
2013-06-17 22:14:49 +00:00
|
|
|
|
2015-01-07 15:41:34 +00:00
|
|
|
function compareVersions(generated, required) {
|
|
|
|
var a = generated.split('.'),
|
|
|
|
b = required.split('.');
|
2014-10-12 16:00:44 +00:00
|
|
|
|
2015-01-07 15:41:34 +00:00
|
|
|
for (var i = 0; i < a.length; ++i) {
|
|
|
|
a[i] = Number(a[i]);
|
|
|
|
}
|
|
|
|
for (var i = 0; i < b.length; ++i) {
|
|
|
|
b[i] = Number(b[i]);
|
|
|
|
}
|
|
|
|
if (a.length == 2) {
|
|
|
|
a[2] = 0;
|
|
|
|
}
|
2014-10-06 13:24:34 +00:00
|
|
|
|
2015-01-07 15:41:34 +00:00
|
|
|
if (a[0] > b[0]) return true;
|
|
|
|
if (a[0] < b[0]) return false;
|
2014-10-06 13:24:34 +00:00
|
|
|
|
2015-01-07 15:41:34 +00:00
|
|
|
if (a[1] > b[1]) return true;
|
|
|
|
if (a[1] < b[1]) return false;
|
2013-06-17 22:14:49 +00:00
|
|
|
|
2015-01-07 15:41:34 +00:00
|
|
|
if (a[2] > b[2]) return true;
|
|
|
|
if (a[2] < b[2]) return false;
|
2013-06-17 22:14:49 +00:00
|
|
|
|
2015-01-07 15:41:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-01-15 12:05:19 +00:00
|
|
|
|
2015-01-07 15:41:34 +00:00
|
|
|
function migrate(configuration) {
|
|
|
|
var appliedMigrationsCount = 0;
|
|
|
|
var migratedVersion = configuration.generatedBy;
|
|
|
|
GUI.log(chrome.i18n.getMessage('configMigrationFrom', [migratedVersion]));
|
|
|
|
|
|
|
|
if (!compareVersions(migratedVersion, '0.59.1')) {
|
|
|
|
|
2015-01-19 19:40:14 +00:00
|
|
|
// variable was renamed
|
|
|
|
configuration.MISC.rssi_channel = configuration.MISC.rssi_aux_channel;
|
2015-01-07 15:41:34 +00:00
|
|
|
configuration.MISC.rssi_aux_channel = undefined;
|
|
|
|
|
|
|
|
migratedVersion = '0.59.1';
|
|
|
|
GUI.log(chrome.i18n.getMessage('configMigratedTo', [migratedVersion]));
|
|
|
|
appliedMigrationsCount++;
|
|
|
|
}
|
2015-01-19 19:40:14 +00:00
|
|
|
|
|
|
|
if (!compareVersions(migratedVersion, '0.60.1')) {
|
|
|
|
|
|
|
|
// LED_STRIP support was added.
|
|
|
|
if (!configuration.LED_STRIP) {
|
|
|
|
configuration.LED_STRIP = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
migratedVersion = '0.60.1';
|
|
|
|
GUI.log(chrome.i18n.getMessage('configMigratedTo', [migratedVersion]));
|
|
|
|
appliedMigrationsCount++;
|
|
|
|
}
|
2015-03-11 21:56:02 +00:00
|
|
|
|
2015-01-29 17:27:50 +00:00
|
|
|
if (!compareVersions(migratedVersion, '0.61.0')) {
|
|
|
|
|
|
|
|
// Changing PID controller via UI was added.
|
|
|
|
if (!configuration.PIDs && configuration.PID) {
|
|
|
|
configuration.PIDs = configuration.PID;
|
|
|
|
configuration.PID = {
|
|
|
|
controller: 0 // assume pid controller 0 was used.
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
migratedVersion = '0.61.0';
|
|
|
|
GUI.log(chrome.i18n.getMessage('configMigratedTo', [migratedVersion]));
|
|
|
|
appliedMigrationsCount++;
|
|
|
|
}
|
|
|
|
|
2015-03-11 21:56:02 +00:00
|
|
|
if (!compareVersions(migratedVersion, '0.63.0')) {
|
|
|
|
|
2015-03-11 23:34:24 +00:00
|
|
|
// LED Strip was saved as object instead of array.
|
|
|
|
if (typeof(configuration.LED_STRIP) == 'object') {
|
|
|
|
var fixed_led_strip = [];
|
|
|
|
|
|
|
|
var index = 0;
|
|
|
|
while (configuration.LED_STRIP[index]) {
|
|
|
|
fixed_led_strip.push(configuration.LED_STRIP[index++]);
|
|
|
|
}
|
|
|
|
configuration.LED_STRIP = fixed_led_strip;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Serial configuation redesigned
|
|
|
|
var ports = [];
|
|
|
|
for (var portIndex = 0; portIndex < configuration.SERIAL_CONFIG.ports.length; portIndex++) {
|
|
|
|
var oldPort = configuration.SERIAL_CONFIG.ports[portIndex];
|
|
|
|
|
|
|
|
var newPort = {
|
|
|
|
identifier: oldPort.identifier,
|
|
|
|
functionMask: 0,
|
|
|
|
msp_baudrate: configuration.SERIAL_CONFIG.mspBaudRate,
|
|
|
|
gps_baudrate: configuration.SERIAL_CONFIG.gpsBaudRate,
|
|
|
|
telemetry_baudrate: 0, // auto
|
|
|
|
blackbox_baudrate: 5, // 115200
|
|
|
|
};
|
|
|
|
|
|
|
|
switch(oldPort.scenario) {
|
|
|
|
case 1: // MSP, CLI, TELEMETRY, SMARTPORT TELEMETRY, GPS-PASSTHROUGH
|
|
|
|
case 5: // MSP, CLI, GPS-PASSTHROUGH
|
|
|
|
case 8: // MSP ONLY
|
|
|
|
newPort.functionMask = 1; // FUCNTION_MSP
|
|
|
|
break;
|
|
|
|
case 2: // GPS
|
|
|
|
newPort.functionMask = 2; // FUNCTION_GPS
|
|
|
|
break;
|
|
|
|
case 3: // RX_SERIAL
|
|
|
|
newPort.functionMask = 64; // FUNCTION_RX_SERIAL
|
|
|
|
break;
|
|
|
|
case 10: // BLACKBOX ONLY
|
|
|
|
newPort.functionMask = 128; // FUNCTION_BLACKBOX
|
|
|
|
break;
|
|
|
|
case 11: // MSP, CLI, BLACKBOX, GPS-PASSTHROUGH
|
|
|
|
newPort.functionMask = 1 + 128; // FUNCTION_BLACKBOX
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ports.push(newPort);
|
|
|
|
}
|
2015-03-11 21:56:02 +00:00
|
|
|
configuration.SERIAL_CONFIG = {
|
2015-03-11 23:34:24 +00:00
|
|
|
ports: ports
|
2015-03-11 21:56:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (var profileIndex = 0; profileIndex < 3; profileIndex++) {
|
|
|
|
var RC = configuration.profiles[profileIndex].RC;
|
|
|
|
// TPA breakpoint was added
|
|
|
|
if (!RC.dynamic_THR_breakpoint) {
|
|
|
|
RC.dynamic_THR_breakpoint = 1500; // firmware default
|
|
|
|
}
|
|
|
|
|
|
|
|
// Roll and pitch rates were split
|
|
|
|
RC.roll_rate = RC.roll_pitch_rate;
|
|
|
|
RC.pitch_rate = RC.roll_pitch_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
migratedVersion = '0.63.0';
|
|
|
|
GUI.log(chrome.i18n.getMessage('configMigratedTo', [migratedVersion]));
|
|
|
|
appliedMigrationsCount++;
|
|
|
|
}
|
|
|
|
|
2015-01-07 15:41:34 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('configMigrationSuccessful', [appliedMigrationsCount]));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function configuration_upload(configuration, callback) {
|
2014-10-12 16:00:44 +00:00
|
|
|
function upload() {
|
|
|
|
var activeProfile = null,
|
|
|
|
profilesN = 3;
|
|
|
|
|
|
|
|
var profileSpecificData = [
|
2015-01-29 17:27:50 +00:00
|
|
|
MSP_codes.MSP_SET_PID_CONTROLLER,
|
2014-10-12 16:00:44 +00:00
|
|
|
MSP_codes.MSP_SET_PID,
|
|
|
|
MSP_codes.MSP_SET_RC_TUNING,
|
|
|
|
MSP_codes.MSP_SET_ACC_TRIM,
|
2014-12-21 12:29:36 +00:00
|
|
|
MSP_codes.MSP_SET_SERVO_CONF,
|
|
|
|
MSP_codes.MSP_SET_CHANNEL_FORWARDING
|
2014-10-12 16:00:44 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
MSP.send_message(MSP_codes.MSP_STATUS, false, false, function () {
|
|
|
|
activeProfile = CONFIG.profile;
|
|
|
|
select_profile();
|
|
|
|
});
|
2014-10-06 13:24:34 +00:00
|
|
|
|
2014-10-12 16:00:44 +00:00
|
|
|
function select_profile() {
|
|
|
|
if (activeProfile > 0) {
|
|
|
|
MSP.send_message(MSP_codes.MSP_SELECT_SETTING, [0], false, upload_specific_data);
|
|
|
|
} else {
|
|
|
|
upload_specific_data();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function upload_specific_data() {
|
|
|
|
var savingProfile = 0,
|
|
|
|
codeKey = 0;
|
|
|
|
|
|
|
|
function load_objects(profile) {
|
2015-01-29 17:27:50 +00:00
|
|
|
PID = configuration.profiles[profile].PID;
|
|
|
|
PIDs = configuration.profiles[profile].PIDs;
|
2014-10-12 16:00:44 +00:00
|
|
|
RC_tuning = configuration.profiles[profile].RC;
|
|
|
|
CONFIG.accelerometerTrims = configuration.profiles[profile].AccTrim;
|
|
|
|
SERVO_CONFIG = configuration.profiles[profile].ServoConfig;
|
2014-12-21 12:29:36 +00:00
|
|
|
MODE_RANGES = configuration.profiles[profile].ModeRanges;
|
|
|
|
ADJUSTMENT_RANGES = configuration.profiles[profile].AdjustmentRanges;
|
2014-10-12 16:00:44 +00:00
|
|
|
}
|
|
|
|
|
2014-12-21 12:29:36 +00:00
|
|
|
function upload_using_specific_commands() {
|
2014-10-12 16:00:44 +00:00
|
|
|
MSP.send_message(profileSpecificData[codeKey], MSP.crunch(profileSpecificData[codeKey]), false, function () {
|
|
|
|
codeKey++;
|
|
|
|
|
|
|
|
if (codeKey < profileSpecificData.length) {
|
2014-12-21 12:29:36 +00:00
|
|
|
upload_using_specific_commands();
|
2014-10-12 16:00:44 +00:00
|
|
|
} else {
|
|
|
|
codeKey = 0;
|
|
|
|
savingProfile++;
|
|
|
|
|
|
|
|
if (savingProfile < profilesN) {
|
|
|
|
load_objects(savingProfile);
|
|
|
|
|
|
|
|
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () {
|
2014-12-21 12:29:36 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SELECT_SETTING, [savingProfile], false, upload_using_specific_commands);
|
2014-10-12 16:00:44 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () {
|
|
|
|
MSP.send_message(MSP_codes.MSP_SELECT_SETTING, [activeProfile], false, upload_unique_data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-12-21 12:29:36 +00:00
|
|
|
function upload_mode_ranges() {
|
|
|
|
MSP.sendModeRanges(upload_adjustment_ranges);
|
|
|
|
}
|
|
|
|
|
|
|
|
function upload_adjustment_ranges() {
|
|
|
|
MSP.sendAdjustmentRanges(upload_using_specific_commands);
|
|
|
|
}
|
2014-10-12 16:00:44 +00:00
|
|
|
// start uploading
|
|
|
|
load_objects(0);
|
2014-12-21 12:29:36 +00:00
|
|
|
upload_mode_ranges();
|
2014-10-12 16:00:44 +00:00
|
|
|
}
|
2014-09-17 07:27:54 +00:00
|
|
|
|
2014-10-12 16:00:44 +00:00
|
|
|
function upload_unique_data() {
|
|
|
|
var codeKey = 0;
|
|
|
|
|
2015-01-19 19:40:14 +00:00
|
|
|
var uniqueData = [
|
|
|
|
// Not used by cleanflight, and it's wrong anyway - AUX settings are per-profile in baseflight.
|
|
|
|
/*
|
|
|
|
MSP_codes.MSP_SET_BOX,
|
|
|
|
*/
|
|
|
|
MSP_codes.MSP_SET_MISC,
|
|
|
|
MSP_codes.MSP_SET_RCMAP,
|
|
|
|
MSP_codes.MSP_SET_BF_CONFIG,
|
|
|
|
MSP_codes.MSP_SET_CF_SERIAL_CONFIG
|
|
|
|
];
|
|
|
|
|
2014-10-12 16:00:44 +00:00
|
|
|
function load_objects() {
|
2014-12-21 12:29:36 +00:00
|
|
|
// Disabled, cleanflight does not use MSP_BOX.
|
|
|
|
/*
|
2014-10-12 16:00:44 +00:00
|
|
|
AUX_CONFIG_values = configuration.AUX;
|
2014-12-21 12:29:36 +00:00
|
|
|
*/
|
2014-10-12 16:00:44 +00:00
|
|
|
MISC = configuration.MISC;
|
|
|
|
RC_MAP = configuration.RCMAP;
|
|
|
|
BF_CONFIG = configuration.BF_CONFIG;
|
2015-01-03 00:57:56 +00:00
|
|
|
SERIAL_CONFIG = configuration.SERIAL_CONFIG;
|
2015-01-19 19:40:14 +00:00
|
|
|
LED_STRIP = configuration.LED_STRIP;
|
2014-10-12 16:00:44 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 19:40:14 +00:00
|
|
|
function send_unique_data_item() {
|
2014-10-12 16:00:44 +00:00
|
|
|
if (codeKey < uniqueData.length) {
|
|
|
|
MSP.send_message(uniqueData[codeKey], MSP.crunch(uniqueData[codeKey]), false, function () {
|
|
|
|
codeKey++;
|
2015-01-19 19:40:14 +00:00
|
|
|
send_unique_data_item();
|
2014-10-12 16:00:44 +00:00
|
|
|
});
|
|
|
|
} else {
|
2015-01-19 19:40:14 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, send_led_strip_config);
|
2014-10-12 16:00:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
load_objects();
|
2015-01-19 19:40:14 +00:00
|
|
|
|
|
|
|
// start uploading
|
|
|
|
send_unique_data_item();
|
2014-10-12 16:00:44 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 19:40:14 +00:00
|
|
|
function send_led_strip_config() {
|
|
|
|
MSP.sendLedStripConfig(reboot);
|
|
|
|
}
|
|
|
|
|
2014-10-12 16:00:44 +00:00
|
|
|
function reboot() {
|
2014-10-12 14:06:48 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('eeprom_saved_ok'));
|
2014-10-12 16:00:44 +00:00
|
|
|
|
|
|
|
GUI.tab_switch_cleanup(function() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_SET_REBOOT, false, false, reinitialize);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function reinitialize() {
|
|
|
|
GUI.log(chrome.i18n.getMessage('deviceRebooting'));
|
|
|
|
|
|
|
|
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_IDENT, false, false, function () {
|
|
|
|
GUI.log(chrome.i18n.getMessage('deviceReady'));
|
|
|
|
|
|
|
|
if (callback) callback();
|
|
|
|
});
|
|
|
|
}, 1500); // 1500 ms seems to be just the right amount of delay to prevent data request timeouts
|
|
|
|
}
|
2014-10-12 14:06:48 +00:00
|
|
|
}
|
2014-09-17 07:27:54 +00:00
|
|
|
|
2015-01-07 15:41:34 +00:00
|
|
|
upload();
|
2014-10-12 14:06:48 +00:00
|
|
|
}
|
2013-06-17 21:36:19 +00:00
|
|
|
}
|