Skip to content

Commit

Permalink
Merge pull request #2195 from iNavFlight/MrD_Fix-defaults-bug
Browse files Browse the repository at this point in the history
Cracked it!
  • Loading branch information
MrD-RC authored Sep 19, 2024
2 parents 50b2c2a + 9b268d5 commit 50cc482
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 25 deletions.
9 changes: 9 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,15 @@
"loadedBatteryProfile": {
"message": "Loaded Battery Profile: <strong style=\"color: #37a8db\">$1</strong>"
},
"setControlProfile" : {
"message": "Set Control Profile: <strong style=\"color: #37a8db\">$1</strong>"
},
"setMixerProfile": {
"message": "Setting Mixer Profile: <strong style=\"color: #37a8db\">$1</strong>"
},
"setBatteryProfile": {
"message": "Setting Battery Profile: <strong style=\"color: #37a8db\">$1</strong>"
},
"pidTuningDataRefreshed": {
"message": "PID data <strong>refreshed</strong>"
},
Expand Down
28 changes: 18 additions & 10 deletions js/defaults_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

var helper = helper || {};
var savingDefaultsModal;
var processingDefaults = false;

helper.defaultsDialog = (function () {

Expand Down Expand Up @@ -1130,6 +1131,7 @@ helper.defaultsDialog = (function () {
};

privateScope.finalize = function (selectedDefaultPreset) {
processingDefaults = false;
mspHelper.saveToEeprom(function () {
//noinspection JSUnresolvedVariable
GUI.log(chrome.i18n.getMessage('configurationEepromSaved'));
Expand Down Expand Up @@ -1206,9 +1208,6 @@ helper.defaultsDialog = (function () {
]);
}

settingsChainer.setChain(miscChain);
settingsChainer.execute();

// Set profiles

for (let ps = 0; ps < 3; ps++) {
Expand Down Expand Up @@ -1242,20 +1241,29 @@ helper.defaultsDialog = (function () {
MSP.send_message(MSPCodes.MSP2_INAV_SELECT_BATTERY_PROFILE, [currentBatteryProfile], false, callback);
});


for (let pc = 0; pc < 3; pc++) {
profileChainer[pc].setChain(profileChain[pc]);

if (pc < 2) {
profileChainer[pc].setExitPoint(function () {
profileChainer[pc+1].execute();
});
}
}

processingDefaults = true;
settingsChainer.setChain(miscChain);
settingsChainer.setExitPoint(function () {
updateActivatedTab();
profileChainer[0].execute();
});
settingsChainer.execute();

profileChainer[2].setExitPoint(function () {
updateActivatedTab();
privateScope.finalize(selectedDefaultPreset);
});

let timeout = (miscChain.length * 150) + 2000;
let timeOut0 = setTimeout(profileChainer[0].execute, timeout);
timeout+= (profileChain[0].length * 150) + 4000;
let timeOut1 = setTimeout(profileChainer[1].execute, timeout);
timeout+= (profileChain[1].length * 150) + 4000;
let timeOut2 = setTimeout(profileChainer[2].execute, timeout);
}

privateScope.onPresetClick = function (event) {
Expand Down
24 changes: 16 additions & 8 deletions js/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,22 @@ GUI_control.prototype.updateStatusBar = function() {
};

GUI_control.prototype.updateProfileChange = function(refresh) {
$('#mixerprofilechange').val(CONFIG.mixer_profile);
$('#profilechange').val(CONFIG.profile);
$('#batteryprofilechange').val(CONFIG.battery_profile);
if (refresh) {
GUI.log(chrome.i18n.getMessage('loadedMixerProfile', [CONFIG.mixer_profile + 1]));
GUI.log(chrome.i18n.getMessage('pidTuning_LoadedProfile', [CONFIG.profile + 1]));
GUI.log(chrome.i18n.getMessage('loadedBatteryProfile', [CONFIG.battery_profile + 1]));
updateActivatedTab();
if ((processingDefaults != undefined && processingDefaults === true) === false) {
$('#mixerprofilechange').val(CONFIG.mixer_profile);
$('#profilechange').val(CONFIG.profile);
$('#batteryprofilechange').val(CONFIG.battery_profile);
if (refresh > 0) {
if (refresh & mspHelper.PROFILES_CHANGED.MIXER) {
GUI.log(chrome.i18n.getMessage('loadedMixerProfile', [CONFIG.mixer_profile + 1]));
}
if (refresh & mspHelper.PROFILES_CHANGED.CONTROL) {
GUI.log(chrome.i18n.getMessage('pidTuning_LoadedProfile', [CONFIG.profile + 1]));
}
if (refresh & mspHelper.PROFILES_CHANGED.BATTERY) {
GUI.log(chrome.i18n.getMessage('loadedBatteryProfile', [CONFIG.battery_profile + 1]));
}
updateActivatedTab();
}
}
};

Expand Down
20 changes: 16 additions & 4 deletions js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
var mspHelper = (function (gui) {
var self = {};

self.PROFILES_CHANGED = {
'CONTROL' : 1,
'BATTERY' : 2,
'MIXER' : 4
};

self.BAUD_RATES_post1_6_3 = [
'AUTO',
'1200',
Expand Down Expand Up @@ -69,7 +75,7 @@ var mspHelper = (function (gui) {
color;
if (!dataHandler.unsupported || dataHandler.unsupported) switch (dataHandler.code) {
case MSPCodes.MSPV2_INAV_STATUS:
let profile_changed = false;
let profile_changed = 0;
CONFIG.cycleTime = data.getUint16(offset, true);
offset += 2;
CONFIG.i2cError = data.getUint16(offset, true);
Expand All @@ -81,11 +87,15 @@ var mspHelper = (function (gui) {

profile_byte = data.getUint8(offset++)
let profile = profile_byte & 0x0F;
profile_changed |= (profile !== CONFIG.profile) && (CONFIG.profile !==-1);
if ((profile !== CONFIG.profile) && (CONFIG.profile !==-1)) {
profile_changed |= this.PROFILES_CHANGED.CONTROL;
}
CONFIG.profile = profile;

let battery_profile = (profile_byte & 0xF0) >> 4;
profile_changed |= (battery_profile !== CONFIG.battery_profile) && (CONFIG.battery_profile !==-1);
if ((battery_profile !== CONFIG.battery_profile) && (CONFIG.battery_profile !==-1)) {
profile_changed |= this.PROFILES_CHANGED.BATTERY;
}
CONFIG.battery_profile = battery_profile;

CONFIG.armingFlags = data.getUint32(offset, true);
Expand All @@ -95,7 +105,9 @@ var mspHelper = (function (gui) {
//read mixer profile as the last byte in the the message
profile_byte = data.getUint8(dataHandler.message_length_expected - 1);
let mixer_profile = profile_byte & 0x0F;
profile_changed |= (mixer_profile !== CONFIG.mixer_profile) && (CONFIG.mixer_profile !==-1);
if ((mixer_profile !== CONFIG.mixer_profile) && (CONFIG.mixer_profile !==-1)) {
profile_changed |= this.PROFILES_CHANGED.MIXER;
}
CONFIG.mixer_profile = mixer_profile;

gui.updateStatusBar();
Expand Down
6 changes: 3 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ $(document).ready(function () {
mixerprofile_e.change(function () {
var mixerprofile = parseInt($(this).val());
MSP.send_message(MSPCodes.MSP2_INAV_SELECT_MIXER_PROFILE, [mixerprofile], false, function () {
GUI.log(chrome.i18n.getMessage('loadedMixerProfile', [mixerprofile + 1]));
GUI.log(chrome.i18n.getMessage('setMixerProfile', [mixerprofile + 1]));
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, function () {
GUI.log(chrome.i18n.getMessage('deviceRebooting'));
GUI.handleReconnect();
Expand All @@ -588,7 +588,7 @@ $(document).ready(function () {
profile_e.change(function () {
var profile = parseInt($(this).val());
MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [profile], false, function () {
GUI.log(chrome.i18n.getMessage('pidTuning_LoadedProfile', [profile + 1]));
GUI.log(chrome.i18n.getMessage('setControlProfile', [profile + 1]));
});
});

Expand All @@ -597,7 +597,7 @@ $(document).ready(function () {
batteryprofile_e.change(function () {
var batteryprofile = parseInt($(this).val());
MSP.send_message(MSPCodes.MSP2_INAV_SELECT_BATTERY_PROFILE, [batteryprofile], false, function () {
GUI.log(chrome.i18n.getMessage('loadedBatteryProfile', [batteryprofile + 1]));
GUI.log(chrome.i18n.getMessage('setBatteryProfile', [batteryprofile + 1]));
});
});
});
Expand Down

0 comments on commit 50cc482

Please sign in to comment.