Skip to content

Commit

Permalink
Resolve some settings issues on Tuning tab and make settings saving
Browse files Browse the repository at this point in the history
a chain of MSP fames instead of flooding the MSP queue
  • Loading branch information
DzikuVx committed May 5, 2024
1 parent f931341 commit a4c3490
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
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);
});
} 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
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

0 comments on commit a4c3490

Please sign in to comment.