Skip to content

Commit df6c4f7

Browse files
authored
Merge pull request #860 from iNavFlight/dzikuvx-defaults-dialog-to-2-3-1
Defaults dialog in 2.3.1
2 parents 73b4dd6 + 85893d0 commit df6c4f7

File tree

6 files changed

+578
-192
lines changed

6 files changed

+578
-192
lines changed

_locales/en/messages.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3224,5 +3224,11 @@
32243224
},
32253225
"vtxDisclaimer": {
32263226
"message": "Use only bands, channels and power levels that are legal in a place you fly! Always refer to VTX user manual and local regulations!"
3227+
},
3228+
"defaultsDialogTitle": {
3229+
"message": "Default values"
3230+
},
3231+
"defaultsDialogInfo": {
3232+
"message": "INAV Configurator would like to know which kind of UAV you are configuring. Based on this information it will modify some default values to unlock the best flying performance. "
32273233
}
32283234
}

gulpfile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ sources.css = [
5050
'./js/libraries/switchery/switchery.css',
5151
'./js/libraries/jbox/jBox.css',
5252
'./node_modules/openlayers/dist/ol.css',
53-
'./src/css/logic.css'
53+
'./src/css/logic.css',
54+
'./src/css/defaults_dialog.css'
5455
];
5556

5657
sources.js = [
@@ -113,6 +114,7 @@ sources.js = [
113114
'./tabs/advanced_tuning.js',
114115
'./js/peripherals.js',
115116
'./js/appUpdater.js',
117+
'./js/defaults_dialog.js',
116118
'./node_modules/openlayers/dist/ol.js'
117119
];
118120

js/defaults_dialog.js

Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
'use strict';
2+
3+
var helper = helper || {};
4+
5+
helper.defaultsDialog = (function() {
6+
7+
let publicScope = {},
8+
privateScope = {};
9+
10+
let $container;
11+
12+
let data = [{
13+
"title": 'Mini Quad with 3"-7" propellers',
14+
"settings": [
15+
{
16+
key: "gyro_hardware_lpf",
17+
value: "256HZ"
18+
},
19+
{
20+
key: "looptime",
21+
value: 500
22+
},
23+
{
24+
key: "gyro_lpf_hz",
25+
value: 100
26+
},
27+
{
28+
key: "gyro_lpf_type",
29+
value: "PT1"
30+
},
31+
{
32+
key: "gyro_stage2_lowpass_hz",
33+
value: 200
34+
},
35+
{
36+
key: "dterm_lpf_hz",
37+
value: 90
38+
},
39+
{
40+
key: "use_dterm_fir_filter",
41+
value: "OFF"
42+
},
43+
{
44+
key: "mc_iterm_relax_type",
45+
value: "RP"
46+
},
47+
{
48+
key: "d_boost_factor",
49+
value: 1.5
50+
},
51+
{
52+
key: "antigravity_gain",
53+
value: 2
54+
},
55+
{
56+
key: "antigravity_accelerator",
57+
value: 5
58+
},
59+
{
60+
key: "rc_yaw_expo",
61+
value: 70
62+
},
63+
{
64+
key: "rc_expo",
65+
value: 70
66+
},
67+
{
68+
key: "roll_rate",
69+
value: 70
70+
},
71+
{
72+
key: "pitch_rate",
73+
value: 70
74+
},
75+
{
76+
key: "yaw_rate",
77+
value: 60
78+
},
79+
{
80+
key: "mc_p_pitch",
81+
value: 44
82+
},
83+
{
84+
key: "mc_i_pitch",
85+
value: 60
86+
},
87+
{
88+
key: "mc_d_pitch",
89+
value: 25
90+
},
91+
{
92+
key: "mc_p_roll",
93+
value: 40
94+
},
95+
{
96+
key: "mc_i_roll",
97+
value: 50
98+
},
99+
{
100+
key: "mc_d_roll",
101+
value: 25
102+
},
103+
{
104+
key: "mc_p_yaw",
105+
value: 45
106+
},
107+
{
108+
key: "mc_i_yaw",
109+
value: 70
110+
},
111+
{
112+
key: "mc_airmode_type",
113+
value: "THROTTLE_THRESHOLD"
114+
},
115+
{
116+
key: "applied_defaults",
117+
value: 2
118+
}
119+
],
120+
"features":[
121+
{
122+
bit: 5, // Enable DYNAMIC_FILTERS
123+
state: true
124+
}
125+
]
126+
},
127+
{
128+
"title": 'Airplane',
129+
"id": 3,
130+
"settings": [
131+
{
132+
key: "rc_yaw_expo",
133+
value: 70
134+
},
135+
{
136+
key: "rc_expo",
137+
value: 70
138+
},
139+
{
140+
key: "roll_rate",
141+
value: 30
142+
},
143+
{
144+
key: "pitch_rate",
145+
value: 20
146+
},
147+
{
148+
key: "yaw_rate",
149+
value: 10
150+
},
151+
{
152+
key: "small_angle",
153+
value: 180
154+
},
155+
{
156+
key: "applied_defaults",
157+
value: 3
158+
}
159+
],
160+
"features":[
161+
{
162+
bit: 4, // Enable MOTOR_STOP
163+
state: true
164+
}
165+
]
166+
},
167+
{
168+
"title": 'Custom UAV - INAV legacy defaults',
169+
"settings": [
170+
{
171+
key: "applied_defaults",
172+
value: 1
173+
}
174+
]
175+
},
176+
{
177+
"title": 'Keep current settings',
178+
"settings": [
179+
{
180+
key: "applied_defaults",
181+
value: 1
182+
}
183+
]
184+
}
185+
]
186+
187+
publicScope.init = function() {
188+
mspHelper.getSetting("applied_defaults").then(privateScope.onInitSettingReturned);
189+
$container = $("#defaults-wrapper");
190+
};
191+
192+
privateScope.setFeaturesBits = function (selectedDefaultPreset) {
193+
194+
if (selectedDefaultPreset.features && selectedDefaultPreset.features.length > 0) {
195+
196+
for (let i in selectedDefaultPreset.features) {
197+
if (selectedDefaultPreset.features.hasOwnProperty(i)) {
198+
let feature = selectedDefaultPreset.features[i];
199+
200+
if (feature.state) {
201+
BF_CONFIG.features = bit_set(BF_CONFIG.features, feature.bit);
202+
} else {
203+
BF_CONFIG.features = bit_clear(BF_CONFIG.features, feature.bit);
204+
}
205+
}
206+
}
207+
208+
mspHelper.saveBfConfig(function () {
209+
privateScope.setSettings(selectedDefaultPreset);
210+
});
211+
} else {
212+
privateScope.setSettings(selectedDefaultPreset);
213+
}
214+
};
215+
216+
privateScope.setSettings = function (selectedDefaultPreset) {
217+
Promise.mapSeries(selectedDefaultPreset.settings, function (input, ii) {
218+
return mspHelper.getSetting(input.key);
219+
}).then(function () {
220+
Promise.mapSeries(selectedDefaultPreset.settings, function (input, ii) {
221+
return mspHelper.setSetting(input.key, input.value);
222+
}).then(function () {
223+
mspHelper.saveToEeprom(function () {
224+
//noinspection JSUnresolvedVariable
225+
GUI.log(chrome.i18n.getMessage('configurationEepromSaved'));
226+
227+
GUI.tab_switch_cleanup(function() {
228+
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, function () {
229+
//noinspection JSUnresolvedVariable
230+
GUI.log(chrome.i18n.getMessage('deviceRebooting'));
231+
GUI.handleReconnect();
232+
});
233+
});
234+
});
235+
})
236+
});
237+
};
238+
239+
privateScope.onPresetClick = function(event) {
240+
$container.hide();
241+
let selectedDefaultPreset = data[$(event.currentTarget).data("index")];
242+
if (selectedDefaultPreset && selectedDefaultPreset.settings) {
243+
244+
mspHelper.loadBfConfig(function () {
245+
privateScope.setFeaturesBits(selectedDefaultPreset)
246+
});
247+
}
248+
};
249+
250+
privateScope.render = function() {
251+
let $place = $container.find('.defaults-dialog__options');
252+
$place.html("");
253+
for (let i in data) {
254+
if (data.hasOwnProperty(i)) {
255+
let preset = data[i];
256+
let $element = $("<div class='default_btn defaults_btn'>\
257+
<a class='confirm' href='#'></a>\
258+
</div>")
259+
260+
$element.find("a").html(preset.title);
261+
$element.data("index", i).click(privateScope.onPresetClick)
262+
$element.appendTo($place);
263+
}
264+
}
265+
}
266+
267+
privateScope.onInitSettingReturned = function(promise) {
268+
if (promise.value > 0) {
269+
return; //Defaults were applied, we can just ignore
270+
}
271+
272+
privateScope.render();
273+
$container.show();
274+
}
275+
276+
return publicScope;
277+
})();

js/serial_backend.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ function onValidFirmware()
199199
GUI.allowedTabs = GUI.defaultAllowedTabsWhenConnected.slice();
200200
onConnect();
201201

202+
if (semver.gte(CONFIG.flightControllerVersion, "2.3.0")) {
203+
helper.defaultsDialog.init();
204+
}
205+
202206
$('#tabs ul.mode-connected .tab_setup a').click();
203207
});
204208
});

0 commit comments

Comments
 (0)