Skip to content

Commit 50cc482

Browse files
authored
Merge pull request #2195 from iNavFlight/MrD_Fix-defaults-bug
Cracked it!
2 parents 50b2c2a + 9b268d5 commit 50cc482

File tree

5 files changed

+62
-25
lines changed

5 files changed

+62
-25
lines changed

_locales/en/messages.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,15 @@
15961596
"loadedBatteryProfile": {
15971597
"message": "Loaded Battery Profile: <strong style=\"color: #37a8db\">$1</strong>"
15981598
},
1599+
"setControlProfile" : {
1600+
"message": "Set Control Profile: <strong style=\"color: #37a8db\">$1</strong>"
1601+
},
1602+
"setMixerProfile": {
1603+
"message": "Setting Mixer Profile: <strong style=\"color: #37a8db\">$1</strong>"
1604+
},
1605+
"setBatteryProfile": {
1606+
"message": "Setting Battery Profile: <strong style=\"color: #37a8db\">$1</strong>"
1607+
},
15991608
"pidTuningDataRefreshed": {
16001609
"message": "PID data <strong>refreshed</strong>"
16011610
},

js/defaults_dialog.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
var helper = helper || {};
55
var savingDefaultsModal;
6+
var processingDefaults = false;
67

78
helper.defaultsDialog = (function () {
89

@@ -1130,6 +1131,7 @@ helper.defaultsDialog = (function () {
11301131
};
11311132

11321133
privateScope.finalize = function (selectedDefaultPreset) {
1134+
processingDefaults = false;
11331135
mspHelper.saveToEeprom(function () {
11341136
//noinspection JSUnresolvedVariable
11351137
GUI.log(chrome.i18n.getMessage('configurationEepromSaved'));
@@ -1206,9 +1208,6 @@ helper.defaultsDialog = (function () {
12061208
]);
12071209
}
12081210

1209-
settingsChainer.setChain(miscChain);
1210-
settingsChainer.execute();
1211-
12121211
// Set profiles
12131212

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

1244+
12451245
for (let pc = 0; pc < 3; pc++) {
12461246
profileChainer[pc].setChain(profileChain[pc]);
1247+
1248+
if (pc < 2) {
1249+
profileChainer[pc].setExitPoint(function () {
1250+
profileChainer[pc+1].execute();
1251+
});
1252+
}
12471253
}
12481254

1255+
processingDefaults = true;
1256+
settingsChainer.setChain(miscChain);
1257+
settingsChainer.setExitPoint(function () {
1258+
updateActivatedTab();
1259+
profileChainer[0].execute();
1260+
});
1261+
settingsChainer.execute();
1262+
12491263
profileChainer[2].setExitPoint(function () {
1264+
updateActivatedTab();
12501265
privateScope.finalize(selectedDefaultPreset);
12511266
});
1252-
1253-
let timeout = (miscChain.length * 150) + 2000;
1254-
let timeOut0 = setTimeout(profileChainer[0].execute, timeout);
1255-
timeout+= (profileChain[0].length * 150) + 4000;
1256-
let timeOut1 = setTimeout(profileChainer[1].execute, timeout);
1257-
timeout+= (profileChain[1].length * 150) + 4000;
1258-
let timeOut2 = setTimeout(profileChainer[2].execute, timeout);
12591267
}
12601268

12611269
privateScope.onPresetClick = function (event) {

js/gui.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,22 @@ GUI_control.prototype.updateStatusBar = function() {
261261
};
262262

263263
GUI_control.prototype.updateProfileChange = function(refresh) {
264-
$('#mixerprofilechange').val(CONFIG.mixer_profile);
265-
$('#profilechange').val(CONFIG.profile);
266-
$('#batteryprofilechange').val(CONFIG.battery_profile);
267-
if (refresh) {
268-
GUI.log(chrome.i18n.getMessage('loadedMixerProfile', [CONFIG.mixer_profile + 1]));
269-
GUI.log(chrome.i18n.getMessage('pidTuning_LoadedProfile', [CONFIG.profile + 1]));
270-
GUI.log(chrome.i18n.getMessage('loadedBatteryProfile', [CONFIG.battery_profile + 1]));
271-
updateActivatedTab();
264+
if ((processingDefaults != undefined && processingDefaults === true) === false) {
265+
$('#mixerprofilechange').val(CONFIG.mixer_profile);
266+
$('#profilechange').val(CONFIG.profile);
267+
$('#batteryprofilechange').val(CONFIG.battery_profile);
268+
if (refresh > 0) {
269+
if (refresh & mspHelper.PROFILES_CHANGED.MIXER) {
270+
GUI.log(chrome.i18n.getMessage('loadedMixerProfile', [CONFIG.mixer_profile + 1]));
271+
}
272+
if (refresh & mspHelper.PROFILES_CHANGED.CONTROL) {
273+
GUI.log(chrome.i18n.getMessage('pidTuning_LoadedProfile', [CONFIG.profile + 1]));
274+
}
275+
if (refresh & mspHelper.PROFILES_CHANGED.BATTERY) {
276+
GUI.log(chrome.i18n.getMessage('loadedBatteryProfile', [CONFIG.battery_profile + 1]));
277+
}
278+
updateActivatedTab();
279+
}
272280
}
273281
};
274282

js/msp/MSPHelper.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
var mspHelper = (function (gui) {
55
var self = {};
66

7+
self.PROFILES_CHANGED = {
8+
'CONTROL' : 1,
9+
'BATTERY' : 2,
10+
'MIXER' : 4
11+
};
12+
713
self.BAUD_RATES_post1_6_3 = [
814
'AUTO',
915
'1200',
@@ -69,7 +75,7 @@ var mspHelper = (function (gui) {
6975
color;
7076
if (!dataHandler.unsupported || dataHandler.unsupported) switch (dataHandler.code) {
7177
case MSPCodes.MSPV2_INAV_STATUS:
72-
let profile_changed = false;
78+
let profile_changed = 0;
7379
CONFIG.cycleTime = data.getUint16(offset, true);
7480
offset += 2;
7581
CONFIG.i2cError = data.getUint16(offset, true);
@@ -81,11 +87,15 @@ var mspHelper = (function (gui) {
8187

8288
profile_byte = data.getUint8(offset++)
8389
let profile = profile_byte & 0x0F;
84-
profile_changed |= (profile !== CONFIG.profile) && (CONFIG.profile !==-1);
90+
if ((profile !== CONFIG.profile) && (CONFIG.profile !==-1)) {
91+
profile_changed |= this.PROFILES_CHANGED.CONTROL;
92+
}
8593
CONFIG.profile = profile;
8694

8795
let battery_profile = (profile_byte & 0xF0) >> 4;
88-
profile_changed |= (battery_profile !== CONFIG.battery_profile) && (CONFIG.battery_profile !==-1);
96+
if ((battery_profile !== CONFIG.battery_profile) && (CONFIG.battery_profile !==-1)) {
97+
profile_changed |= this.PROFILES_CHANGED.BATTERY;
98+
}
8999
CONFIG.battery_profile = battery_profile;
90100

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

101113
gui.updateStatusBar();

main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ $(document).ready(function () {
575575
mixerprofile_e.change(function () {
576576
var mixerprofile = parseInt($(this).val());
577577
MSP.send_message(MSPCodes.MSP2_INAV_SELECT_MIXER_PROFILE, [mixerprofile], false, function () {
578-
GUI.log(chrome.i18n.getMessage('loadedMixerProfile', [mixerprofile + 1]));
578+
GUI.log(chrome.i18n.getMessage('setMixerProfile', [mixerprofile + 1]));
579579
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, function () {
580580
GUI.log(chrome.i18n.getMessage('deviceRebooting'));
581581
GUI.handleReconnect();
@@ -588,7 +588,7 @@ $(document).ready(function () {
588588
profile_e.change(function () {
589589
var profile = parseInt($(this).val());
590590
MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [profile], false, function () {
591-
GUI.log(chrome.i18n.getMessage('pidTuning_LoadedProfile', [profile + 1]));
591+
GUI.log(chrome.i18n.getMessage('setControlProfile', [profile + 1]));
592592
});
593593
});
594594

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

0 commit comments

Comments
 (0)