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) {
|
2016-07-18 07:51:55 +00:00
|
|
|
var activeProfile = null;
|
2014-10-12 14:06:48 +00:00
|
|
|
|
|
|
|
var configuration = {
|
2014-10-12 14:16:47 +00:00
|
|
|
'generatedBy': chrome.runtime.getManifest().version,
|
2015-03-22 09:18:30 +00:00
|
|
|
'apiVersion': CONFIG.apiVersion,
|
2015-03-22 09:25:32 +00:00
|
|
|
'profiles': [],
|
2014-10-12 14:06:48 +00:00
|
|
|
};
|
2015-12-12 19:41:32 +00:00
|
|
|
|
2015-01-19 19:40:14 +00:00
|
|
|
var profileSpecificData = [
|
2016-08-06 13:31:10 +00:00
|
|
|
MSPCodes.MSP_PID_CONTROLLER,
|
|
|
|
MSPCodes.MSP_PID,
|
|
|
|
MSPCodes.MSP_RC_TUNING,
|
|
|
|
MSPCodes.MSP_ACC_TRIM,
|
|
|
|
MSPCodes.MSP_SERVO_CONFIGURATIONS,
|
|
|
|
MSPCodes.MSP_MODE_RANGES,
|
|
|
|
MSPCodes.MSP_ADJUSTMENT_RANGES
|
2015-01-19 19:40:14 +00:00
|
|
|
];
|
|
|
|
|
2015-07-12 23:02:58 +00:00
|
|
|
function update_profile_specific_data_list() {
|
2017-03-19 23:03:28 +00:00
|
|
|
if (semver.gt(CONFIG.apiVersion, "1.12.0")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
profileSpecificData.push(MSPCodes.MSP_SERVO_MIX_RULES);
|
2015-07-12 23:02:58 +00:00
|
|
|
}
|
2015-12-12 19:41:32 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
profileSpecificData.push(MSPCodes.MSP_RC_DEADBAND);
|
2015-12-12 19:41:32 +00:00
|
|
|
}
|
2015-07-12 23:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update_profile_specific_data_list();
|
|
|
|
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_STATUS, false, false, function () {
|
2015-12-12 19:41:32 +00:00
|
|
|
activeProfile = CONFIG.profile;
|
|
|
|
select_profile();
|
|
|
|
});
|
|
|
|
|
|
|
|
function select_profile() {
|
|
|
|
if (activeProfile > 0) {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [0], false, fetch_specific_data);
|
2015-12-12 19:41:32 +00:00
|
|
|
} else {
|
|
|
|
fetch_specific_data();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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() {
|
2016-07-18 07:51:55 +00:00
|
|
|
if (fetchingProfile < CONFIG.numProfiles) {
|
2014-10-12 14:06:48 +00:00
|
|
|
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),
|
2015-07-12 23:02:58 +00:00
|
|
|
'ServoRules': jQuery.extend(true, [], SERVO_RULES),
|
2014-12-21 12:29:36 +00:00
|
|
|
'ModeRanges': jQuery.extend(true, [], MODE_RANGES),
|
|
|
|
'AdjustmentRanges': jQuery.extend(true, [], ADJUSTMENT_RANGES)
|
2014-10-12 14:06:48 +00:00
|
|
|
});
|
|
|
|
|
2015-12-12 19:41:32 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
|
2017-03-19 23:03:28 +00:00
|
|
|
configuration.profiles[fetchingProfile].RCdeadband = jQuery.extend(true, {}, RC_DEADBAND_CONFIG);
|
2015-12-12 19:41:32 +00:00
|
|
|
}
|
2014-10-12 14:06:48 +00:00
|
|
|
codeKey = 0;
|
|
|
|
fetchingProfile++;
|
2014-10-12 14:16:47 +00:00
|
|
|
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [fetchingProfile], false, fetch_specific_data_item);
|
2014-10-12 14:06:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.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 = [
|
2016-08-06 13:31:10 +00:00
|
|
|
MSPCodes.MSP_RX_MAP,
|
|
|
|
MSPCodes.MSP_CF_SERIAL_CONFIG,
|
|
|
|
MSPCodes.MSP_LED_STRIP_CONFIG,
|
|
|
|
MSPCodes.MSP_LED_COLORS
|
2015-01-19 19:40:14 +00:00
|
|
|
];
|
|
|
|
|
2015-03-29 13:51:28 +00:00
|
|
|
function update_unique_data_list() {
|
2015-05-07 21:10:26 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.8.0")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
uniqueData.push(MSPCodes.MSP_LOOP_TIME);
|
|
|
|
uniqueData.push(MSPCodes.MSP_ARMING_CONFIG);
|
2015-03-29 13:51:28 +00:00
|
|
|
}
|
2015-11-16 22:28:21 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.14.0")) {
|
2017-03-19 23:03:28 +00:00
|
|
|
uniqueData.push(MSPCodes.MSP_MOTOR_3D_CONFIG);
|
2015-11-16 22:28:21 +00:00
|
|
|
}
|
2015-12-14 23:06:25 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
uniqueData.push(MSPCodes.MSP_SENSOR_ALIGNMENT);
|
|
|
|
uniqueData.push(MSPCodes.MSP_RX_CONFIG);
|
|
|
|
uniqueData.push(MSPCodes.MSP_FAILSAFE_CONFIG);
|
|
|
|
uniqueData.push(MSPCodes.MSP_RXFAIL_CONFIG);
|
2015-12-14 23:06:25 +00:00
|
|
|
}
|
2016-06-26 21:02:28 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.19.0")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
uniqueData.push(MSPCodes.MSP_LED_STRIP_MODECOLOR);
|
2016-06-25 13:25:38 +00:00
|
|
|
}
|
2015-03-29 13:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update_unique_data_list();
|
|
|
|
|
2014-10-12 14:06:48 +00:00
|
|
|
function fetch_unique_data() {
|
|
|
|
var codeKey = 0;
|
2015-03-29 13:51:28 +00:00
|
|
|
|
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-10-12 14:55:49 +00:00
|
|
|
configuration.RCMAP = jQuery.extend(true, [], RC_MAP);
|
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);
|
2016-06-25 13:25:38 +00:00
|
|
|
configuration.LED_COLORS = jQuery.extend(true, [], LED_COLORS);
|
|
|
|
|
2016-06-26 21:02:28 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.19.0")) {
|
2016-06-25 13:25:38 +00:00
|
|
|
configuration.LED_MODE_COLORS = jQuery.extend(true, [], LED_MODE_COLORS);
|
|
|
|
}
|
2015-05-07 21:10:26 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.8.0")) {
|
2015-04-14 12:29:22 +00:00
|
|
|
configuration.FC_CONFIG = jQuery.extend(true, {}, FC_CONFIG);
|
|
|
|
configuration.ARMING_CONFIG = jQuery.extend(true, {}, ARMING_CONFIG);
|
|
|
|
}
|
2015-11-16 22:28:21 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.14.0")) {
|
2017-03-19 23:03:28 +00:00
|
|
|
configuration.MOTOR_3D_CONFIG = jQuery.extend(true, {}, MOTOR_3D_CONFIG);
|
2015-11-16 22:28:21 +00:00
|
|
|
}
|
2015-12-14 23:06:25 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
|
|
|
|
configuration.SENSOR_ALIGNMENT = jQuery.extend(true, {}, SENSOR_ALIGNMENT);
|
2015-11-20 20:42:40 +00:00
|
|
|
configuration.RX_CONFIG = jQuery.extend(true, {}, RX_CONFIG);
|
|
|
|
configuration.FAILSAFE_CONFIG = jQuery.extend(true, {}, FAILSAFE_CONFIG);
|
|
|
|
configuration.RXFAIL_CONFIG = jQuery.extend(true, [], RXFAIL_CONFIG);
|
2015-12-14 23:06:25 +00:00
|
|
|
}
|
2017-03-19 23:03:28 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.33.0")) {
|
|
|
|
configuration.RSSI_CONFIG = jQuery.extend(true, {}, RSSI_CONFIG);
|
|
|
|
configuration.FEATURE_CONFIG = jQuery.extend(true, {}, FEATURE_CONFIG);
|
|
|
|
}
|
2014-10-12 14:06:48 +00:00
|
|
|
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
}
|
2015-03-29 13:51:28 +00:00
|
|
|
|
2014-10-12 14:06:48 +00:00
|
|
|
// 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
|
|
|
|
2017-04-11 11:10:26 +00:00
|
|
|
var prefix = 'backup';
|
2017-03-03 00:35:24 +00:00
|
|
|
var suffix = 'json';
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2017-03-03 00:35:24 +00:00
|
|
|
var filename = generateFilename(prefix, suffix);
|
2017-03-02 22:31:39 +00:00
|
|
|
|
2017-03-19 23:03:28 +00:00
|
|
|
var accepts = [{
|
|
|
|
extensions: [suffix]
|
|
|
|
}];
|
|
|
|
|
2013-06-17 21:36:19 +00:00
|
|
|
// create or load the file
|
2017-03-19 23:03:28 +00:00
|
|
|
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename, 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
|
2016-10-05 19:20:43 +00:00
|
|
|
var serialized_config_object = JSON.stringify(configuration, null, '\t');
|
2013-06-17 21:36:19 +00:00
|
|
|
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
|
|
|
|
2015-12-15 21:00:01 +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 = [{
|
2017-03-03 00:35:24 +00:00
|
|
|
extensions: ['json']
|
2013-06-17 21:36:19 +00:00
|
|
|
}];
|
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
|
|
|
|
2017-03-03 00:35:24 +00:00
|
|
|
|
2015-01-07 15:41:34 +00:00
|
|
|
// validate
|
|
|
|
if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.backupFileMinVersionAccepted)) {
|
|
|
|
|
2015-03-22 09:18:30 +00:00
|
|
|
if (!migrate(configuration)) {
|
|
|
|
GUI.log(chrome.i18n.getMessage('backupFileUnmigratable'));
|
|
|
|
return;
|
2015-01-07 15:41:34 +00:00
|
|
|
}
|
2017-03-03 00:35:24 +00:00
|
|
|
|
|
|
|
if (configuration.BF_CONFIG.features._featureMask) {
|
|
|
|
var features = new Features(CONFIG);
|
|
|
|
features.setMask(configuration.BF_CONFIG.features._featureMask);
|
|
|
|
configuration.BF_CONFIG.features = features;
|
|
|
|
}
|
|
|
|
|
2015-01-07 15:41:34 +00:00
|
|
|
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) {
|
2015-03-22 09:18:30 +00:00
|
|
|
if (generated == undefined) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-07 21:10:26 +00:00
|
|
|
return semver.gte(generated, required);
|
2015-01-07 15:41:34 +00:00
|
|
|
}
|
2015-12-15 21:00:01 +00:00
|
|
|
|
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
|
2017-03-19 23:03:28 +00:00
|
|
|
configuration.RSSI_CONFIG.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-22 09:18:30 +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-05-07 21:10:26 +00:00
|
|
|
if (configuration.apiVersion == undefined) {
|
|
|
|
configuration.apiVersion = "1.0.0" // a guess that will satisfy the rest of the code
|
|
|
|
}
|
|
|
|
// apiVersion previously stored without patchlevel
|
|
|
|
if (!semver.parse(configuration.apiVersion)) {
|
|
|
|
configuration.apiVersion += ".0";
|
|
|
|
if (!semver.parse(configuration.apiVersion)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (compareVersions(migratedVersion, '0.63.0') && !compareVersions(configuration.apiVersion, '1.7.0')) {
|
2015-03-22 09:18:30 +00:00
|
|
|
// Serial configuation redesigned, 0.63.0 saves old and new configurations.
|
2015-03-11 23:34:24 +00:00
|
|
|
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,
|
2015-03-22 09:18:30 +00:00
|
|
|
functions: [],
|
|
|
|
msp_baudrate: String(configuration.SERIAL_CONFIG.mspBaudRate),
|
|
|
|
gps_baudrate: String(configuration.SERIAL_CONFIG.gpsBaudRate),
|
|
|
|
telemetry_baudrate: 'AUTO',
|
|
|
|
blackbox_baudrate: '115200',
|
2015-03-11 23:34:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
switch(oldPort.scenario) {
|
|
|
|
case 1: // MSP, CLI, TELEMETRY, SMARTPORT TELEMETRY, GPS-PASSTHROUGH
|
|
|
|
case 5: // MSP, CLI, GPS-PASSTHROUGH
|
|
|
|
case 8: // MSP ONLY
|
2015-03-22 09:18:30 +00:00
|
|
|
newPort.functions.push('MSP');
|
2015-03-11 23:34:24 +00:00
|
|
|
break;
|
|
|
|
case 2: // GPS
|
2015-03-22 09:18:30 +00:00
|
|
|
newPort.functions.push('GPS');
|
2015-03-11 23:34:24 +00:00
|
|
|
break;
|
|
|
|
case 3: // RX_SERIAL
|
2015-03-22 09:18:30 +00:00
|
|
|
newPort.functions.push('RX_SERIAL');
|
2015-03-11 23:34:24 +00:00
|
|
|
break;
|
|
|
|
case 10: // BLACKBOX ONLY
|
2015-03-22 09:18:30 +00:00
|
|
|
newPort.functions.push('BLACKBOX');
|
2015-03-11 23:34:24 +00:00
|
|
|
break;
|
|
|
|
case 11: // MSP, CLI, BLACKBOX, GPS-PASSTHROUGH
|
2015-03-22 09:18:30 +00:00
|
|
|
newPort.functions.push('MSP');
|
|
|
|
newPort.functions.push('BLACKBOX');
|
2015-03-11 23:34:24 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
appliedMigrationsCount++;
|
|
|
|
}
|
2015-03-22 09:18:30 +00:00
|
|
|
|
2015-05-07 21:10:26 +00:00
|
|
|
if (compareVersions(migratedVersion, '0.63.0') && !compareVersions(configuration.apiVersion, '1.8.0')) {
|
2015-03-29 13:51:28 +00:00
|
|
|
// api 1.8 exposes looptime and arming config
|
|
|
|
|
|
|
|
if (configuration.FC_CONFIG == undefined) {
|
|
|
|
configuration.FC_CONFIG = {
|
|
|
|
loopTime: 3500
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (configuration.ARMING_CONFIG == undefined) {
|
|
|
|
configuration.ARMING_CONFIG = {
|
|
|
|
auto_disarm_delay: 5,
|
|
|
|
disarm_kill_switch: 1
|
|
|
|
};
|
|
|
|
}
|
|
|
|
appliedMigrationsCount++;
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:25:45 +00:00
|
|
|
if (compareVersions(migratedVersion, '0.63.0')) {
|
2015-04-14 12:29:22 +00:00
|
|
|
// backups created with 0.63.0 for firmwares with api < 1.8 were saved with incorrect looptime
|
2015-04-14 12:25:45 +00:00
|
|
|
if (configuration.FC_CONFIG.loopTime == 0) {
|
|
|
|
//reset it to the default
|
|
|
|
configuration.FC_CONFIG.loopTime = 3500;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-12 23:02:58 +00:00
|
|
|
if (semver.lt(migratedVersion, '0.66.0')) {
|
|
|
|
// api 1.12 updated servo configuration protocol and added servo mixer rules
|
2015-11-14 00:41:23 +00:00
|
|
|
for (var profileIndex = 0; profileIndex < configuration.profiles.length; profileIndex++) {
|
2015-07-12 23:02:58 +00:00
|
|
|
|
|
|
|
if (semver.eq(configuration.apiVersion, '1.10.0')) {
|
|
|
|
// drop two unused servo configurations
|
|
|
|
while (configuration.profiles[profileIndex].ServoConfig.length > 8) {
|
|
|
|
configuration.profiles[profileIndex].ServoConfig.pop();
|
|
|
|
}
|
|
|
|
}
|
2015-07-13 01:01:19 +00:00
|
|
|
|
2015-07-12 23:02:58 +00:00
|
|
|
for (var i = 0; i < configuration.profiles[profileIndex].ServoConfig.length; i++) {
|
|
|
|
var servoConfig = profiles[profileIndex].ServoConfig;
|
2015-07-13 01:01:19 +00:00
|
|
|
|
2016-01-11 14:37:36 +00:00
|
|
|
servoConfig[i].angleAtMin = 45;
|
|
|
|
servoConfig[i].angleAtMax = 45;
|
2015-07-12 23:02:58 +00:00
|
|
|
servoConfig[i].reversedInputSources = 0;
|
2015-07-13 01:01:19 +00:00
|
|
|
|
|
|
|
// set the rate to 0 if an invalid value is detected.
|
|
|
|
if (servoConfig[i].rate < -100 || servoConfig[i].rate > 100) {
|
|
|
|
servoConfig[i].rate = 0;
|
|
|
|
}
|
2015-07-12 23:02:58 +00:00
|
|
|
}
|
2015-07-13 01:01:19 +00:00
|
|
|
|
2015-07-12 23:02:58 +00:00
|
|
|
configuration.profiles[profileIndex].ServoRules = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
migratedVersion = '0.66.0';
|
|
|
|
|
|
|
|
appliedMigrationsCount++;
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:41:23 +00:00
|
|
|
if (semver.lt(configuration.apiVersion, '1.14.0') && semver.gte(CONFIG.apiVersion, "1.14.0")) {
|
|
|
|
// api 1.14 removed old pid controllers
|
|
|
|
for (var profileIndex = 0; profileIndex < configuration.profiles.length; profileIndex++) {
|
|
|
|
var newPidControllerIndex = configuration.profiles[profileIndex].PID.controller;
|
|
|
|
switch (newPidControllerIndex) {
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
newPidControllerIndex = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
configuration.profiles[profileIndex].PID.controller = newPidControllerIndex;
|
|
|
|
}
|
|
|
|
appliedMigrationsCount++;
|
|
|
|
}
|
|
|
|
|
2015-11-16 22:28:21 +00:00
|
|
|
|
|
|
|
if (compareVersions(migratedVersion, '0.66.0') && !compareVersions(configuration.apiVersion, '1.14.0')) {
|
|
|
|
// api 1.14 exposes 3D configuration
|
|
|
|
|
2017-03-19 23:03:28 +00:00
|
|
|
if (configuration.MOTOR_3D_CONFIG == undefined) {
|
|
|
|
configuration.MOTOR_3D_CONFIG = {
|
2015-11-16 22:28:21 +00:00
|
|
|
deadband3d_low: 1406,
|
|
|
|
deadband3d_high: 1514,
|
2017-03-19 23:03:28 +00:00
|
|
|
neutral: 1460,
|
2015-11-16 22:28:21 +00:00
|
|
|
deadband3d_throttle: 50
|
|
|
|
};
|
|
|
|
}
|
|
|
|
appliedMigrationsCount++;
|
|
|
|
}
|
|
|
|
|
2015-12-14 23:06:25 +00:00
|
|
|
|
2015-12-09 23:56:42 +00:00
|
|
|
if (compareVersions(migratedVersion, '0.66.0') && !compareVersions(configuration.apiVersion, '1.15.0')) {
|
2015-12-27 23:36:37 +00:00
|
|
|
// api 1.15 exposes RCdeadband and sensor alignment
|
2015-12-12 19:41:32 +00:00
|
|
|
|
2015-12-09 23:56:42 +00:00
|
|
|
|
2015-12-12 19:41:32 +00:00
|
|
|
for (var profileIndex = 0; profileIndex < configuration.profiles.length; profileIndex++) {
|
2015-12-27 23:36:37 +00:00
|
|
|
if (configuration.profiles[profileIndex].RCdeadband == undefined) {
|
|
|
|
configuration.profiles[profileIndex].RCdeadband = {
|
2015-12-09 23:56:42 +00:00
|
|
|
deadband: 0,
|
|
|
|
yaw_deadband: 0,
|
|
|
|
alt_hold_deadband: 40,
|
2015-12-12 19:41:32 +00:00
|
|
|
};
|
|
|
|
}
|
2015-12-09 23:56:42 +00:00
|
|
|
}
|
2015-12-14 23:06:25 +00:00
|
|
|
if (configuration.SENSOR_ALIGNMENT == undefined) {
|
|
|
|
configuration.SENSOR_ALIGNMENT = {
|
|
|
|
align_gyro: 0,
|
|
|
|
align_acc: 0,
|
|
|
|
align_mag: 0
|
|
|
|
};
|
|
|
|
}
|
2015-12-09 23:56:42 +00:00
|
|
|
|
2015-11-20 20:42:40 +00:00
|
|
|
// api 1.15 exposes RX_CONFIG, FAILSAFE_CONFIG and RXFAIL_CONFIG configuration
|
|
|
|
|
|
|
|
if (configuration.RX_CONFIG == undefined) {
|
|
|
|
configuration.RX_CONFIG = {
|
|
|
|
serialrx_provider: 0,
|
|
|
|
spektrum_sat_bind: 0,
|
2017-03-19 23:03:28 +00:00
|
|
|
stick_center: 1500,
|
|
|
|
stick_min: 1100,
|
|
|
|
stick_max: 1900,
|
2015-11-20 20:42:40 +00:00
|
|
|
rx_min_usec: 885,
|
|
|
|
rx_max_usec: 2115
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (configuration.FAILSAFE_CONFIG == undefined) {
|
|
|
|
configuration.FAILSAFE_CONFIG = {
|
|
|
|
failsafe_delay: 10,
|
|
|
|
failsafe_off_delay: 200,
|
|
|
|
failsafe_throttle: 1000,
|
|
|
|
failsafe_kill_switch: 0,
|
|
|
|
failsafe_throttle_low_delay: 100,
|
|
|
|
failsafe_procedure: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (configuration.RXFAIL_CONFIG == undefined) {
|
|
|
|
configuration.RXFAIL_CONFIG = [
|
|
|
|
{mode: 0, value: 1500},
|
|
|
|
{mode: 0, value: 1500},
|
|
|
|
{mode: 0, value: 1500},
|
|
|
|
{mode: 0, value: 875}
|
|
|
|
];
|
|
|
|
|
|
|
|
for (var i = 0; i < 14; i++) {
|
|
|
|
var rxfailChannel = {
|
|
|
|
mode: 1,
|
|
|
|
value: 1500
|
|
|
|
};
|
|
|
|
configuration.RXFAIL_CONFIG.push(rxfailChannel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
appliedMigrationsCount++;
|
|
|
|
}
|
|
|
|
|
2016-01-12 10:24:53 +00:00
|
|
|
if (compareVersions(migratedVersion, '1.2.0')) {
|
|
|
|
// old version of the configurator incorrectly had a 'disabled' option for GPS SBAS mode.
|
2017-03-19 23:03:28 +00:00
|
|
|
if (GPS_CONFIG.ublox_sbas < 0) {
|
|
|
|
GPS_CONFIG.ublox_sbas = 0;
|
2016-01-12 10:24:53 +00:00
|
|
|
}
|
|
|
|
migratedVersion = '1.2.0';
|
|
|
|
|
|
|
|
appliedMigrationsCount++;
|
|
|
|
}
|
|
|
|
|
2016-06-26 21:02:28 +00:00
|
|
|
if (!compareVersions(migratedVersion, '1.3.1')) {
|
2016-06-25 13:25:38 +00:00
|
|
|
|
|
|
|
// LED_COLORS & LED_MODE_COLORS support was added.
|
|
|
|
if (!configuration.LED_COLORS) {
|
|
|
|
configuration.LED_COLORS = [];
|
|
|
|
}
|
|
|
|
if (!configuration.LED_MODE_COLORS) {
|
|
|
|
configuration.LED_MODE_COLORS = [];
|
|
|
|
}
|
|
|
|
|
2016-06-26 21:02:28 +00:00
|
|
|
migratedVersion = '1.3.1';
|
2016-06-25 13:25:38 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('configMigratedTo', [migratedVersion]));
|
|
|
|
appliedMigrationsCount++;
|
|
|
|
}
|
|
|
|
|
2015-03-22 09:18:30 +00:00
|
|
|
if (appliedMigrationsCount > 0) {
|
|
|
|
GUI.log(chrome.i18n.getMessage('configMigrationSuccessful', [appliedMigrationsCount]));
|
2015-12-15 21:00:01 +00:00
|
|
|
}
|
2015-01-07 15:41:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function configuration_upload(configuration, callback) {
|
2014-10-12 16:00:44 +00:00
|
|
|
function upload() {
|
2016-07-18 07:51:55 +00:00
|
|
|
var activeProfile = null;
|
|
|
|
var numProfiles = CONFIG.numProfiles;
|
|
|
|
if (configuration.profiles.length < numProfiles) {
|
|
|
|
numProfiles = configuration.profiles.length;
|
|
|
|
}
|
2014-10-12 16:00:44 +00:00
|
|
|
|
|
|
|
var profileSpecificData = [
|
2016-08-06 13:31:10 +00:00
|
|
|
MSPCodes.MSP_SET_PID_CONTROLLER,
|
|
|
|
MSPCodes.MSP_SET_PID,
|
|
|
|
MSPCodes.MSP_SET_RC_TUNING,
|
|
|
|
MSPCodes.MSP_SET_ACC_TRIM
|
2014-10-12 16:00:44 +00:00
|
|
|
];
|
|
|
|
|
2015-12-12 19:41:32 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
profileSpecificData.push(MSPCodes.MSP_SET_RC_DEADBAND);
|
2015-12-12 19:41:32 +00:00
|
|
|
}
|
|
|
|
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_STATUS, false, false, function () {
|
2014-10-12 16:00:44 +00:00
|
|
|
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) {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [0], false, upload_specific_data);
|
2014-10-12 16:00:44 +00:00
|
|
|
} 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;
|
2015-07-12 23:02:58 +00:00
|
|
|
SERVO_RULES = configuration.profiles[profile].ServoRules;
|
2014-12-21 12:29:36 +00:00
|
|
|
MODE_RANGES = configuration.profiles[profile].ModeRanges;
|
|
|
|
ADJUSTMENT_RANGES = configuration.profiles[profile].AdjustmentRanges;
|
2017-03-19 23:03:28 +00:00
|
|
|
RC_DEADBAND_CONFIG = configuration.profiles[profile].RCdeadband;
|
2014-10-12 16:00:44 +00:00
|
|
|
}
|
|
|
|
|
2014-12-21 12:29:36 +00:00
|
|
|
function upload_using_specific_commands() {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(profileSpecificData[codeKey], mspHelper.crunch(profileSpecificData[codeKey]), false, function () {
|
2014-10-12 16:00:44 +00:00
|
|
|
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++;
|
|
|
|
|
2016-07-18 07:51:55 +00:00
|
|
|
if (savingProfile < numProfiles) {
|
2014-10-12 16:00:44 +00:00
|
|
|
load_objects(savingProfile);
|
|
|
|
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () {
|
|
|
|
MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [savingProfile], false, upload_using_specific_commands);
|
2014-10-12 16:00:44 +00:00
|
|
|
});
|
|
|
|
} else {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () {
|
|
|
|
MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [activeProfile], false, upload_unique_data);
|
2014-10-12 16:00:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-07-12 23:02:58 +00:00
|
|
|
function upload_servo_configuration() {
|
2016-08-13 13:15:14 +00:00
|
|
|
mspHelper.sendServoConfigurations(upload_mode_ranges);
|
2015-07-12 23:02:58 +00:00
|
|
|
}
|
|
|
|
|
2014-12-21 12:29:36 +00:00
|
|
|
function upload_mode_ranges() {
|
2016-08-13 13:15:14 +00:00
|
|
|
mspHelper.sendModeRanges(upload_adjustment_ranges);
|
2014-12-21 12:29:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function upload_adjustment_ranges() {
|
2016-08-13 13:15:14 +00:00
|
|
|
mspHelper.sendAdjustmentRanges(upload_using_specific_commands);
|
2014-12-21 12:29:36 +00:00
|
|
|
}
|
2014-10-12 16:00:44 +00:00
|
|
|
// start uploading
|
|
|
|
load_objects(0);
|
2015-07-12 23:02:58 +00:00
|
|
|
upload_servo_configuration();
|
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 = [
|
2016-08-06 13:31:10 +00:00
|
|
|
MSPCodes.MSP_SET_RX_MAP,
|
|
|
|
MSPCodes.MSP_SET_CF_SERIAL_CONFIG
|
2015-01-19 19:40:14 +00:00
|
|
|
];
|
2015-03-29 13:51:28 +00:00
|
|
|
|
|
|
|
function update_unique_data_list() {
|
2015-05-07 21:10:26 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.8.0")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
uniqueData.push(MSPCodes.MSP_SET_LOOP_TIME);
|
|
|
|
uniqueData.push(MSPCodes.MSP_SET_ARMING_CONFIG);
|
2015-03-29 13:51:28 +00:00
|
|
|
}
|
2015-11-16 22:28:21 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.14.0")) {
|
2017-03-19 23:03:28 +00:00
|
|
|
uniqueData.push(MSPCodes.MSP_SET_MOTOR_3D_CONFIG);
|
2015-11-16 22:28:21 +00:00
|
|
|
}
|
2015-12-14 23:06:25 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
uniqueData.push(MSPCodes.MSP_SET_SENSOR_ALIGNMENT);
|
|
|
|
uniqueData.push(MSPCodes.MSP_SET_RX_CONFIG);
|
|
|
|
uniqueData.push(MSPCodes.MSP_SET_FAILSAFE_CONFIG);
|
2015-12-14 23:06:25 +00:00
|
|
|
}
|
2017-03-19 23:03:28 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.33.0")) {
|
|
|
|
uniqueData.push(MSPCodes.MSP_SET_FEATURE_CONFIG);
|
|
|
|
uniqueData.push(MSPCodes.MSP_SET_MOTOR_CONFIG);
|
|
|
|
uniqueData.push(MSPCodes.MSP_SET_GPS_CONFIG);
|
|
|
|
uniqueData.push(MSPCodes.MSP_SET_COMPASS_CONFIG);
|
|
|
|
uniqueData.push(MSPCodes.MSP_SET_RSSI_CONFIG);
|
|
|
|
}
|
2015-03-29 13:51:28 +00:00
|
|
|
}
|
|
|
|
|
2014-10-12 16:00:44 +00:00
|
|
|
function load_objects() {
|
|
|
|
MISC = configuration.MISC;
|
|
|
|
RC_MAP = configuration.RCMAP;
|
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;
|
2016-06-25 13:25:38 +00:00
|
|
|
LED_COLORS = configuration.LED_COLORS;
|
|
|
|
LED_MODE_COLORS = configuration.LED_MODE_COLORS;
|
2015-03-29 13:51:28 +00:00
|
|
|
ARMING_CONFIG = configuration.ARMING_CONFIG;
|
|
|
|
FC_CONFIG = configuration.FC_CONFIG;
|
2017-03-19 23:03:28 +00:00
|
|
|
MOTOR_3D_CONFIG = configuration.MOTOR_3D_CONFIG;
|
2015-12-15 06:27:55 +00:00
|
|
|
SENSOR_ALIGNMENT = configuration.SENSOR_ALIGNMENT;
|
2015-11-20 20:42:40 +00:00
|
|
|
RX_CONFIG = configuration.RX_CONFIG;
|
|
|
|
FAILSAFE_CONFIG = configuration.FAILSAFE_CONFIG;
|
|
|
|
RXFAIL_CONFIG = configuration.RXFAIL_CONFIG;
|
2017-03-19 23:03:28 +00:00
|
|
|
FEATURE_CONFIG = configuration.FEATURE_CONFIG;
|
|
|
|
MOTOR_CONFIG = configuration.MOTOR_CONFIG;
|
|
|
|
GPS_CONFIG = configuration.GPS_CONFIG;
|
|
|
|
COMPASS_CONFIG = configuration.COMPASS_CONFIG;
|
|
|
|
RSSI_CONFIG = configuration.RSSI_CONFIG;
|
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) {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(uniqueData[codeKey], mspHelper.crunch(uniqueData[codeKey]), false, function () {
|
2014-10-12 16:00:44 +00:00
|
|
|
codeKey++;
|
2015-01-19 19:40:14 +00:00
|
|
|
send_unique_data_item();
|
2014-10-12 16:00:44 +00:00
|
|
|
});
|
|
|
|
} else {
|
2015-12-16 21:19:27 +00:00
|
|
|
send_led_strip_config();
|
2014-10-12 16:00:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
load_objects();
|
2015-03-29 13:51:28 +00:00
|
|
|
|
|
|
|
update_unique_data_list();
|
|
|
|
|
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() {
|
2016-08-13 13:15:14 +00:00
|
|
|
mspHelper.sendLedStripConfig(send_led_strip_colors);
|
2016-06-25 13:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function send_led_strip_colors() {
|
2016-08-13 13:15:14 +00:00
|
|
|
mspHelper.sendLedStripColors(send_led_strip_mode_colors);
|
2016-06-25 13:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function send_led_strip_mode_colors() {
|
2016-06-26 21:02:28 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.19.0"))
|
2016-08-13 13:15:14 +00:00
|
|
|
mspHelper.sendLedStripModeColors(send_rxfail_config);
|
2016-06-25 13:25:38 +00:00
|
|
|
else
|
|
|
|
send_rxfail_config();
|
2015-12-12 20:36:05 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 23:39:58 +00:00
|
|
|
function send_rxfail_config() {
|
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
|
2016-08-13 13:15:14 +00:00
|
|
|
mspHelper.sendRxFailConfig(save_to_eeprom);
|
2015-12-15 23:39:58 +00:00
|
|
|
} else {
|
|
|
|
save_to_eeprom();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-12 20:36:05 +00:00
|
|
|
function save_to_eeprom() {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, reboot);
|
2015-01-19 19:40:14 +00:00
|
|
|
}
|
2015-12-15 23:39:58 +00:00
|
|
|
|
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() {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitialize);
|
2014-10-12 16:00:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function reinitialize() {
|
|
|
|
GUI.log(chrome.i18n.getMessage('deviceRebooting'));
|
|
|
|
|
|
|
|
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_STATUS, false, false, function() {
|
2014-10-12 16:00:44 +00:00
|
|
|
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
|
|
|
}
|
2015-12-15 21:00:01 +00:00
|
|
|
}
|