Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve some settings issues on Tuning tab and make settings saving #2063

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3075,7 +3075,6 @@ var mspHelper = (function () {
};

self._getSetting = function (name) {
console.log("Getting setting " + name);
if (FC.SETTINGS[name]) {
return Promise.resolve(FC.SETTINGS[name]);
}
Expand Down
39 changes: 30 additions & 9 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ var Settings = (function () {
var settingName = input.data('setting');
var inputUnit = input.data('unit');

let elementId = input.attr('id');
if (elementId === undefined) {

// If the element ID is not defined, we need to create one
// based on the setting name. If this ID exists, we will not create it
if ($('#' + settingName).length === 0) {
input.attr('id', settingName);
}
}

if (globalSettings.showProfileParameters) {
if (FC.isBatteryProfileParameter(settingName)) {
input.css("background-color","#fef2d5");
Expand Down Expand Up @@ -149,7 +159,8 @@ var Settings = (function () {
input.data('setting-info', s.setting);
if (input.data('live')) {
input.on('change', function () {
self.saveInput(input);
const settingPair = self.processInput(input);
return mspHelper.setSetting(settingPair.setting, settingPair.value);
});
}
});
Expand Down Expand Up @@ -528,15 +539,14 @@ var Settings = (function () {
};
}

self.saveInput = function(input) {
self.processInput = function(input) {
var settingName = input.data('setting');
var setting = input.data('setting-info');
var value;

if (typeof setting == 'undefined') {
return null;
}

if (setting.table) {
if (input.attr('type') == 'checkbox') {
value = input.prop('checked') ? 1 : 0;
Expand Down Expand Up @@ -585,8 +595,7 @@ var Settings = (function () {
}
}
}

return mspHelper.setSetting(settingName, value);
return {setting: settingName, value: value};
};

self.countDecimals = function(value) {
Expand All @@ -604,14 +613,26 @@ var Settings = (function () {
return 0;
};

self.saveInputs = function() {
self.pickAndSaveSingleInput = function(inputs, finalCallback) {
if (inputs.length > 0) {
var input = inputs.shift();
var settingPair = self.processInput(input);
return mspHelper.setSetting(settingPair.setting, settingPair.value, function() {
return self.pickAndSaveSingleInput(inputs, finalCallback);
});
} else {
if (finalCallback) {
finalCallback();
}
}
};

self.saveInputs = function(finalCallback) {
var inputs = [];
$('[data-setting!=""][data-setting]').each(function() {
inputs.push($(this));
});
return mapSeries(inputs, function (input, ii) {
return self.saveInput(input);
});
self.pickAndSaveSingleInput(inputs, finalCallback);
};

self.processHtml = function(callback) {
Expand Down
4 changes: 3 additions & 1 deletion locale/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,9 @@
"auxiliaryEepromSaved": {
"message": "EEPROM <span style=\"color: #37a8db\">saved</span>"
},

"eepromSaved": {
"message": "EEPROM <span style=\"color: #37a8db\">saved</span>"
},
"adjustmentsHelp": {
"message": "Configure adjustment switches. See the 'in-flight adjustments' section of the manual for details. The changes that adjustment functions make are not saved automatically. There are 4 slots. Each switch used to concurrently make adjustments requires exclusive use of a slot."
},
Expand Down
2 changes: 1 addition & 1 deletion tabs/advanced_tuning.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
</div>

<div class="number">
<input type="number" id="cruiseYawRate" data-setting="nav_fw_cruise_yaw_rate" data-setting-multiplier="1" step="1" min="0" max="60" />
<input type="number" id="cruiseYawRate" data-setting="nav_cruise_yaw_rate" data-setting-multiplier="1" step="1" min="0" max="60" />
<label for="cruiseYawRate"><span data-i18n="cruiseYawRateLabel"></span></label>
<div for="cruiseYawRate" class="helpicon cf_tip" data-i18n_title="cruiseYawRateHelp"></div>
</div>
Expand Down
39 changes: 15 additions & 24 deletions tabs/advanced_tuning.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ TABS.advanced_tuning.initialize = function (callback) {

loadHtml();

function save_to_eeprom() {
console.log('save_to_eeprom');
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () {
GUI.log(i18n.getMessage('eepromSaved'));

GUI.tab_switch_cleanup(function () {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, function () {
GUI.log(i18n.getMessage('deviceRebooting'));
GUI.handleReconnect($('.tab_advanced_tuning a'));
});
});
});
}

function loadHtml() {
GUI.load(path.join(__dirname, "advanced_tuning.html"), Settings.processHtml(function () {

Expand Down Expand Up @@ -68,35 +82,12 @@ TABS.advanced_tuning.initialize = function (callback) {
TABS.advanced_tuning.checkRequirements_LinearDescent();

$('a.save').on('click', function () {
Settings.saveInputs().then(function () {
var self = this;
MSP.promise(MSPCodes.MSP_EEPROM_WRITE);
var oldText = $(this).text();
$(this).html("Saved");
setTimeout(function () {
$(self).html(oldText);
}, 2000);
reboot();
});
Settings.saveInputs(save_to_eeprom);
});
GUI.content_ready(callback);

}));
}

function reboot() {
//noinspection JSUnresolvedVariable
GUI.log(i18n.getMessage('configurationEepromSaved'));
GUI.tab_switch_cleanup(function () {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitialize);
});
}

function reinitialize() {
//noinspection JSUnresolvedVariable
GUI.log(i18n.getMessage('deviceRebooting'));
GUI.handleReconnect($('.tab_advanced_tuning a'));
}
};


Expand Down
2 changes: 1 addition & 1 deletion tabs/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
];

function saveSettings(onComplete) {
Settings.saveInputs().then(onComplete);
Settings.saveInputs(onComplete);
}

saveChainer.setChain(saveChain);
Expand Down
33 changes: 13 additions & 20 deletions tabs/failsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,22 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {

load_failssafe_config();

function savePhaseTwo() {
Settings.saveInputs().then(function () {
var self = this;
MSP.promise(MSPCodes.MSP_EEPROM_WRITE);
setTimeout(function () {
$(self).html('');
}, 2000);
reboot();
});
}

function reboot() {
//noinspection JSUnresolvedVariable
GUI.log(i18n.getMessage('configurationEepromSaved'));
GUI.tab_switch_cleanup(function () {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitialize);
function save_to_eeprom() {
console.log('save_to_eeprom');
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () {
GUI.log(i18n.getMessage('eepromSaved'));

GUI.tab_switch_cleanup(function () {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, function () {
GUI.log(i18n.getMessage('deviceRebooting'));
GUI.handleReconnect($('.tab_failsafe a'));
});
});
});
}

function reinitialize() {
//noinspection JSUnresolvedVariable
GUI.log(i18n.getMessage('deviceRebooting'));
GUI.handleReconnect($('.tab_failsafe a'));
function savePhaseTwo() {
Settings.saveInputs(save_to_eeprom);
}
};

Expand Down
2 changes: 1 addition & 1 deletion tabs/gps.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ TABS.gps.initialize = function (callback) {
];

function saveSettings(onComplete) {
Settings.saveInputs().then(onComplete);
Settings.saveInputs(onComplete);
}

saveChainer.setChain(saveChain);
Expand Down
2 changes: 1 addition & 1 deletion tabs/mixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TABS.mixer.initialize = function (callback, scrollPosition) {
saveChainer.setExitPoint(reboot);

function saveSettings(onComplete) {
Settings.saveInputs().then(onComplete);
Settings.saveInputs(onComplete);
}

function reboot() {
Expand Down
25 changes: 15 additions & 10 deletions tabs/osd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3256,6 +3256,20 @@ TABS.osd.initialize = function (callback) {
GUI.active_tab = 'osd';
}

function save_to_eeprom() {
console.log('save_to_eeprom');
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () {
GUI.log(i18n.getMessage('eepromSaved'));

GUI.tab_switch_cleanup(function () {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, function () {
GUI.log(i18n.getMessage('deviceRebooting'));
GUI.handleReconnect($('.tab_osd a'));
});
});
});
}

GUI.load(path.join(__dirname, "osd.html"), Settings.processHtml(function () {
// translate to user-selected language
i18n.localize();
Expand All @@ -3274,16 +3288,7 @@ TABS.osd.initialize = function (callback) {
});

$('a.save').on('click', function () {
Settings.saveInputs().then(function () {
var self = this;
MSP.promise(MSPCodes.MSP_EEPROM_WRITE);
GUI.log(i18n.getMessage('osdSettingsSaved'));
var oldText = $(this).text();
$(this).html("Saved");
setTimeout(function () {
$(self).html(oldText);
}, 2000);
});
Settings.saveInputs(save_to_eeprom);
});

// Initialise guides checkbox
Expand Down
2 changes: 1 addition & 1 deletion tabs/outputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ TABS.outputs.initialize = function (callback) {
}

function saveSettings(onComplete) {
Settings.saveInputs().then(onComplete);
Settings.saveInputs(onComplete);
}

function onLoad() {
Expand Down
12 changes: 6 additions & 6 deletions tabs/pid_tuning.html
Original file line number Diff line number Diff line change
Expand Up @@ -444,19 +444,19 @@ <h3 data-i18n="axisYaw"></h3>
<tr class="not-for-ez-tune">
<th class="roll" data-i18n="pidTuning_RollRate"></th>
<td class="roll">
<div class="pidTuning_number"><input type="number" class="rate-tpa_input" data-setting="roll_rate" data-unit="decadegps" /></div>
<div class="pidTuning_number"><input id="rate-roll" type="number" class="rate-tpa_input" data-setting="roll_rate" data-unit="decadegps" /></div>
</td>
</tr>
<tr class="not-for-ez-tune">
<th class="pitch" data-i18n="pidTuning_PitchRate"></th>
<td class="pitch">
<div class="pidTuning_number"><input type="number" class="rate-tpa_input" data-setting="pitch_rate" data-unit="decadegps" /></div>
<div class="pidTuning_number"><input id="rate-pitch" type="number" class="rate-tpa_input" data-setting="pitch_rate" data-unit="decadegps" /></div>
</td>
</tr>
<tr class="not-for-ez-tune">
<th class="yaw" data-i18n="pidTuning_YawRate"></th>
<td class="yaw">
<div class="pidTuning_number"><input type="number" class="rate-tpa_input" data-setting="yaw_rate" data-unit="decadegps" /></div>
<div class="pidTuning_number"><input id="rate-yaw" type="number" class="rate-tpa_input" data-setting="yaw_rate" data-unit="decadegps" /></div>
</td>
</tr>
<tr class="not-for-ez-tune">
Expand Down Expand Up @@ -495,19 +495,19 @@ <h3 data-i18n="axisYaw"></h3>
<tr>
<th class="roll" data-i18n="pidTuning_ManualRollRate"></th>
<td class="roll">
<div class="pidTuning_number"><input type="number" class="rate-tpa_input" data-setting="manual_roll_rate" data-unit="percent" /></div>
<div class="pidTuning_number"><input id="rate-manual-roll" type="number" class="rate-tpa_input" data-setting="manual_roll_rate" data-unit="percent" /></div>
</td>
</tr>
<tr>
<th class="pitch" data-i18n="pidTuning_ManualPitchRate"></th>
<td class="pitch">
<div class="pidTuning_number"><input type="number" class="rate-tpa_input" data-setting="manual_pitch_rate" data-unit="percent" /></div>
<div class="pidTuning_number"><input id="rate-manual-pitch" type="number" class="rate-tpa_input" data-setting="manual_pitch_rate" data-unit="percent" /></div>
</td>
</tr>
<tr>
<th class="yaw" data-i18n="pidTuning_ManualYawRate"></th>
<td class="yaw">
<div class="pidTuning_number"><input type="number" class="rate-tpa_input" data-setting="manual_yaw_rate" data-unit="percent" /></div>
<div class="pidTuning_number"><input id="rate-manual-yaw" type="number" class="rate-tpa_input" data-setting="manual_yaw_rate" data-unit="percent" /></div>
</td>
</tr>
</tbody>
Expand Down
6 changes: 3 additions & 3 deletions tabs/pid_tuning.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ TABS.pid_tuning.initialize = function (callback) {
FC.RC_tuning.pitch_rate = parseFloat($('#rate-pitch').val());
FC.RC_tuning.yaw_rate = parseFloat($('#rate-yaw').val());

FC.RC_tuning.dynamic_THR_PID = parseInt($('#tpa').val());
FC.RC_tuning.dynamic_THR_breakpoint = parseInt($('#tpa-breakpoint').val());
FC.RC_tuning.dynamic_THR_PID = parseInt($('#tpaRate').val());
FC.RC_tuning.dynamic_THR_breakpoint = parseInt($('#tpaBreakpoint').val());

FC.RC_tuning.manual_roll_rate = $('#rate-manual-roll').val();
FC.RC_tuning.manual_pitch_rate = $('#rate-manual-pitch').val();
Expand Down Expand Up @@ -350,7 +350,7 @@ TABS.pid_tuning.initialize = function (callback) {
}

function saveSettings() {
Settings.saveInputs().then(save_to_eeprom);
Settings.saveInputs(save_to_eeprom);
}

function save_to_eeprom() {
Expand Down
2 changes: 1 addition & 1 deletion tabs/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TABS.receiver.initialize = function (callback) {
}

function saveSettings(onComplete) {
Settings.saveInputs().then(onComplete);
Settings.saveInputs(onComplete);
}

function drawRollPitchExpo() {
Expand Down
Loading