1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-18 05:45:31 +03:00

Add support for backup and restore of led strip config.

Various minor code cleanups.
This commit is contained in:
Dominic Clifton 2015-01-19 20:40:14 +01:00
parent b0743f6bae
commit 8c10f39606
4 changed files with 84 additions and 46 deletions

View file

@ -1,3 +1,7 @@
<span>2015.01.19 - 0.60.1 - cleanflight</span>
<p>
- Add support for backup and restore of LED strip configuration.<br />
</p>
<span>2015.01.08 - 0.60.0 - cleanflight</span> <span>2015.01.08 - 0.60.0 - cleanflight</span>
<p> <p>
- Add LED strip tab for LED configuration - requires v1.6.0 firmware to save.<br /> - Add LED strip tab for LED configuration - requires v1.6.0 firmware to save.<br />

View file

@ -6,27 +6,6 @@ function configuration_backup(callback) {
var activeProfile = null, var activeProfile = null,
profilesN = 3; profilesN = 3;
var profileSpecificData = [
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
];
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
];
var configuration = { var configuration = {
'generatedBy': chrome.runtime.getManifest().version, 'generatedBy': chrome.runtime.getManifest().version,
'profiles': [] 'profiles': []
@ -45,17 +24,27 @@ function configuration_backup(callback) {
} }
} }
var profileSpecificData = [
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
];
function fetch_specific_data() { function fetch_specific_data() {
var fetchingProfile = 0, var fetchingProfile = 0,
codeKey = 0; codeKey = 0;
function query() { function fetch_specific_data_item() {
if (fetchingProfile < profilesN) { if (fetchingProfile < profilesN) {
MSP.send_message(profileSpecificData[codeKey], false, false, function () { MSP.send_message(profileSpecificData[codeKey], false, false, function () {
codeKey++; codeKey++;
if (codeKey < profileSpecificData.length) { if (codeKey < profileSpecificData.length) {
query(); fetch_specific_data_item();
} else { } else {
configuration.profiles.push({ configuration.profiles.push({
'PID': jQuery.extend(true, [], PIDs), 'PID': jQuery.extend(true, [], PIDs),
@ -69,7 +58,7 @@ function configuration_backup(callback) {
codeKey = 0; codeKey = 0;
fetchingProfile++; fetchingProfile++;
MSP.send_message(MSP_codes.MSP_SELECT_SETTING, [fetchingProfile], false, query); MSP.send_message(MSP_codes.MSP_SELECT_SETTING, [fetchingProfile], false, fetch_specific_data_item);
} }
}); });
} else { } else {
@ -78,17 +67,29 @@ function configuration_backup(callback) {
} }
// start fetching // start fetching
query(); fetch_specific_data_item();
} }
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
];
function fetch_unique_data() { function fetch_unique_data() {
var codeKey = 0; var codeKey = 0;
function query() { function fetch_unique_data_item() {
if (codeKey < uniqueData.length) { if (codeKey < uniqueData.length) {
MSP.send_message(uniqueData[codeKey], false, false, function () { MSP.send_message(uniqueData[codeKey], false, false, function () {
codeKey++; codeKey++;
query(); fetch_unique_data_item();
}); });
} else { } else {
// Not used by cleanflight, and it's wrong anyway - AUX settings are per-profile in baseflight. // Not used by cleanflight, and it's wrong anyway - AUX settings are per-profile in baseflight.
@ -99,13 +100,14 @@ function configuration_backup(callback) {
configuration.RCMAP = jQuery.extend(true, [], RC_MAP); configuration.RCMAP = jQuery.extend(true, [], RC_MAP);
configuration.BF_CONFIG = jQuery.extend(true, {}, BF_CONFIG); configuration.BF_CONFIG = jQuery.extend(true, {}, BF_CONFIG);
configuration.SERIAL_CONFIG = jQuery.extend(true, {}, SERIAL_CONFIG); configuration.SERIAL_CONFIG = jQuery.extend(true, {}, SERIAL_CONFIG);
configuration.LED_STRIP = jQuery.extend(true, {}, LED_STRIP);
save(); save();
} }
} }
// start fetching // start fetching
query(); fetch_unique_data_item();
} }
function save() { function save() {
@ -290,13 +292,27 @@ function configuration_restore(callback) {
if (!compareVersions(migratedVersion, '0.59.1')) { if (!compareVersions(migratedVersion, '0.59.1')) {
configuration.MISC.rssi_channel = configuration.MISC.rssi_aux_channel; // variable was renamed // variable was renamed
configuration.MISC.rssi_channel = configuration.MISC.rssi_aux_channel;
configuration.MISC.rssi_aux_channel = undefined; configuration.MISC.rssi_aux_channel = undefined;
migratedVersion = '0.59.1'; migratedVersion = '0.59.1';
GUI.log(chrome.i18n.getMessage('configMigratedTo', [migratedVersion])); GUI.log(chrome.i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++; appliedMigrationsCount++;
} }
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++;
}
GUI.log(chrome.i18n.getMessage('configMigrationSuccessful', [appliedMigrationsCount])); GUI.log(chrome.i18n.getMessage('configMigrationSuccessful', [appliedMigrationsCount]));
return true; return true;
} }
@ -314,17 +330,6 @@ function configuration_restore(callback) {
MSP_codes.MSP_SET_CHANNEL_FORWARDING MSP_codes.MSP_SET_CHANNEL_FORWARDING
]; ];
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
];
MSP.send_message(MSP_codes.MSP_STATUS, false, false, function () { MSP.send_message(MSP_codes.MSP_STATUS, false, false, function () {
activeProfile = CONFIG.profile; activeProfile = CONFIG.profile;
select_profile(); select_profile();
@ -391,6 +396,17 @@ function configuration_restore(callback) {
function upload_unique_data() { function upload_unique_data() {
var codeKey = 0; var codeKey = 0;
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
];
function load_objects() { function load_objects() {
// Disabled, cleanflight does not use MSP_BOX. // Disabled, cleanflight does not use MSP_BOX.
/* /*
@ -400,22 +416,28 @@ function configuration_restore(callback) {
RC_MAP = configuration.RCMAP; RC_MAP = configuration.RCMAP;
BF_CONFIG = configuration.BF_CONFIG; BF_CONFIG = configuration.BF_CONFIG;
SERIAL_CONFIG = configuration.SERIAL_CONFIG; SERIAL_CONFIG = configuration.SERIAL_CONFIG;
LED_STRIP = configuration.LED_STRIP;
} }
function query() { function send_unique_data_item() {
if (codeKey < uniqueData.length) { if (codeKey < uniqueData.length) {
MSP.send_message(uniqueData[codeKey], MSP.crunch(uniqueData[codeKey]), false, function () { MSP.send_message(uniqueData[codeKey], MSP.crunch(uniqueData[codeKey]), false, function () {
codeKey++; codeKey++;
query(); send_unique_data_item();
}); });
} else { } else {
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, reboot); MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, send_led_strip_config);
} }
} }
// start uploading
load_objects(); load_objects();
query();
// start uploading
send_unique_data_item();
}
function send_led_strip_config() {
MSP.sendLedStripConfig(reboot);
} }
function reboot() { function reboot() {

View file

@ -939,6 +939,10 @@ MSP.sendModeRanges = function(onCompleteCallback) {
var modeRangeIndex = 0; var modeRangeIndex = 0;
if (MODE_RANGES.length == 0) {
onCompleteCallback();
}
send_next_mode_range(); send_next_mode_range();
@ -968,6 +972,10 @@ MSP.sendAdjustmentRanges = function(onCompleteCallback) {
var adjustmentRangeIndex = 0; var adjustmentRangeIndex = 0;
if (ADJUSTMENT_RANGES.length == 0) {
onCompleteCallback();
}
send_next_adjustment_range(); send_next_adjustment_range();
@ -1000,6 +1008,10 @@ MSP.sendLedStripConfig = function(onCompleteCallback) {
var ledIndex = 0; var ledIndex = 0;
if (LED_STRIP.length == 0) {
onCompleteCallback();
}
send_next_led_strip_config(); send_next_led_strip_config();
function send_next_led_strip_config() { function send_next_led_strip_config() {

View file

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"minimum_chrome_version": "38", "minimum_chrome_version": "38",
"version": "0.60.0", "version": "0.60.1",
"author": "Hydra", "author": "Hydra",
"name": "Cleanflight - Configurator", "name": "Cleanflight - Configurator",
"short_name": "cleanflight", "short_name": "cleanflight",