Skip to content

Commit 5e7f229

Browse files
authored
Merge pull request #1346 from McGiverGim/fujin-improve-board-and-gyro-alignment
Show/Hide gyro elements
2 parents 06c2044 + 14167c6 commit 5e7f229

File tree

6 files changed

+70
-47
lines changed

6 files changed

+70
-47
lines changed

locales/en/messages.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,10 @@
10421042
"configurationSensorGyroToUse": {
10431043
"message": "GYRO/ACCEL"
10441044
},
1045-
"configurationSensorGyroToUseDefaultOption": {
1045+
"configurationSensorGyroToUseNotFound": {
1046+
"message": "Warning: No Gyro/Acc found"
1047+
},
1048+
"configurationSensorGyroToUseFirst": {
10461049
"message": "First"
10471050
},
10481051
"configurationSensorGyroToUseSecond": {

src/css/tabs/configuration.css

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@
216216
.tab-configuration .gyro_alignment_inputs {
217217
margin-bottom: 5px;
218218
padding-bottom: 5px;
219-
border-bottom: 1px solid #ddd;
220219
width: 33.3%;
221220
float: left;
222221
white-space: nowrap;
@@ -492,12 +491,11 @@
492491
margin-top: 3px;
493492
}
494493

494+
.tab-configuration .board_align_content,
495495
.tab-configuration .gyro_align_content {
496496
width: 100%;
497-
}
498-
499-
.tab-configuration .board_align_content {
500-
width: 100%;
497+
border-bottom: 1px solid #ddd;
498+
display: inline-block;
501499
}
502500

503501
.tab-configuration .sensoralignment span {

src/js/fc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ var FC = {
336336
align_gyro: 0,
337337
align_acc: 0,
338338
align_mag: 0,
339-
use_multi_gyro: 0,
339+
gyro_detection_flags: 0,
340340
gyro_to_use: 0,
341341
gyro_1_align: 0,
342342
gyro_2_align: 0,

src/js/msp/MSPHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ MspHelper.prototype.process_data = function(dataHandler) {
538538
SENSOR_ALIGNMENT.align_mag = data.readU8();
539539

540540
if (semver.gte(CONFIG.apiVersion, '1.41.0')) {
541-
SENSOR_ALIGNMENT.use_multi_gyro = data.readU8();
541+
SENSOR_ALIGNMENT.gyro_detection_flags = data.readU8();
542542
SENSOR_ALIGNMENT.gyro_to_use = data.readU8();
543543
SENSOR_ALIGNMENT.gyro_1_align = data.readU8();
544544
SENSOR_ALIGNMENT.gyro_2_align = data.readU8();

src/js/tabs/configuration.js

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -311,26 +311,6 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
311311
// translate to user-selected language
312312
i18n.localizePage();
313313

314-
var gyro_align_content_e = $('.tab-configuration .gyro_align_content');
315-
var legacy_gyro_alignment_e = $('.tab-configuration .legacy_gyro_alignment');
316-
var legacy_accel_alignment_e = $('.tab-configuration .legacy_accel_alignment');
317-
318-
// Hide the new multi gyro element by default
319-
gyro_align_content_e.hide();
320-
321-
// If we are sent USE_MULTI_GYRO flag from the target, show the new element, while hiding the old ones.
322-
if (SENSOR_ALIGNMENT.use_multi_gyro == 1) {
323-
gyro_align_content_e.show();
324-
legacy_gyro_alignment_e.hide();
325-
legacy_accel_alignment_e.hide();
326-
}
327-
328-
// As the gyro_to_use does not have a 'DEFAULT' 0th element enum like alingments, the 0th element 'First' is excluded from here.
329-
var gyros = [
330-
i18n.getMessage('configurationSensorGyroToUseSecond'),
331-
i18n.getMessage('configurationSensorGyroToUseBoth')
332-
];
333-
334314
var alignments = [
335315
'CW 0°',
336316
'CW 90°',
@@ -342,6 +322,10 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
342322
'CW 270° flip'
343323
];
344324

325+
var gyro_align_content_e = $('.tab-configuration .gyro_align_content');
326+
var legacy_gyro_alignment_e = $('.tab-configuration .legacy_gyro_alignment');
327+
var legacy_accel_alignment_e = $('.tab-configuration .legacy_accel_alignment');
328+
345329
var orientation_gyro_e = $('select.gyroalign');
346330
var orientation_acc_e = $('select.accalign');
347331
var orientation_mag_e = $('select.magalign');
@@ -350,28 +334,62 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
350334
var orientation_gyro_1_align_e = $('select.gyro_1_align');
351335
var orientation_gyro_2_align_e = $('select.gyro_2_align');
352336

337+
gyro_align_content_e.hide(); // default value
353338
if (semver.lt(CONFIG.apiVersion, "1.15.0")) {
354339
$('.tab-configuration .sensoralignment').hide();
355340
} else {
356-
for (var i = 0; i< gyros.length; i++) {
357-
orientation_gyro_to_use_e.append('<option value="' + (i+1) + '">'+ gyros[i] + '</option>');
358-
}
341+
359342
for (var i = 0; i < alignments.length; i++) {
360343
orientation_gyro_e.append('<option value="' + (i+1) + '">'+ alignments[i] + '</option>');
361344
orientation_acc_e.append('<option value="' + (i+1) + '">'+ alignments[i] + '</option>');
362345
orientation_mag_e.append('<option value="' + (i+1) + '">'+ alignments[i] + '</option>');
363-
364-
orientation_gyro_1_align_e.append('<option value="' + (i+1) + '">'+ alignments[i] + '</option>');
365-
orientation_gyro_2_align_e.append('<option value="' + (i+1) + '">'+ alignments[i] + '</option>');
366346
}
347+
367348
orientation_gyro_e.val(SENSOR_ALIGNMENT.align_gyro);
368349
orientation_acc_e.val(SENSOR_ALIGNMENT.align_acc);
369350
orientation_mag_e.val(SENSOR_ALIGNMENT.align_mag);
370351

371-
orientation_gyro_to_use_e.val(SENSOR_ALIGNMENT.gyro_to_use);
352+
// Multi gyro config
353+
if (semver.gte(CONFIG.apiVersion, "1.41.0")) {
354+
355+
gyro_align_content_e.show();
356+
legacy_gyro_alignment_e.hide();
357+
legacy_accel_alignment_e.hide();
358+
359+
const GYRO_DETECTION_FLAGS = {
360+
DETECTED_GYRO_1: (1 << 0),
361+
DETECTED_GYRO_2: (1 << 1),
362+
DETECTED_DUAL_GYROS: (1 << 7)
363+
};
364+
365+
var detected_gyro_1 = (SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_GYRO_1) != 0;
366+
var detected_gyro_2 = (SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_GYRO_2) != 0;
367+
var detected_dual_gyros = (SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_DUAL_GYROS) != 0;
368+
369+
if (detected_gyro_1) {
370+
orientation_gyro_to_use_e.append('<option value="0">'+ i18n.getMessage('configurationSensorGyroToUseFirst') + '</option>');
371+
}
372+
if (detected_gyro_2) {
373+
orientation_gyro_to_use_e.append('<option value="1">'+ i18n.getMessage('configurationSensorGyroToUseSecond') + '</option>');
374+
}
375+
if (detected_dual_gyros) {
376+
orientation_gyro_to_use_e.append('<option value="2">'+ i18n.getMessage('configurationSensorGyroToUseBoth') + '</option>');
377+
}
372378

373-
orientation_gyro_1_align_e.val(SENSOR_ALIGNMENT.gyro_1_align);
374-
orientation_gyro_2_align_e.val(SENSOR_ALIGNMENT.gyro_2_align);
379+
for (var i = 0; i < alignments.length; i++) {
380+
orientation_gyro_1_align_e.append('<option value="' + (i+1) + '">'+ alignments[i] + '</option>');
381+
orientation_gyro_2_align_e.append('<option value="' + (i+1) + '">'+ alignments[i] + '</option>');
382+
}
383+
384+
orientation_gyro_to_use_e.val(SENSOR_ALIGNMENT.gyro_to_use);
385+
orientation_gyro_1_align_e.val(SENSOR_ALIGNMENT.gyro_1_align);
386+
orientation_gyro_2_align_e.val(SENSOR_ALIGNMENT.gyro_2_align);
387+
388+
$('.gyro_alignment_inputs_first').toggle(detected_gyro_1);
389+
$('.gyro_alignment_inputs_second').toggle(detected_gyro_2);
390+
$('.gyro_alignment_inputs_selection').toggle(detected_gyro_1 || detected_gyro_2);
391+
$('.gyro_alignment_inputs_notfound').toggle(!detected_gyro_1 && !detected_gyro_2);
392+
}
375393
}
376394

377395
// ESC protocols

src/tabs/configuration.html

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,33 +272,37 @@
272272
</div>
273273
</div>
274274
<div class="gyro_align_content">
275-
<div class="gyro_alignment_inputs">
275+
<div class="gyro_alignment_inputs gyro_alignment_inputs_selection">
276276
<label>
277277
<select class="gyro_to_use">
278-
<option i18n="configurationSensorGyroToUseDefaultOption" value="0"></option>
279278
<!-- list generated here -->
280279
</select>
281280
<span i18n="configurationSensorGyroToUse"></span>
282281
</label>
283282
</div>
284-
<div class="gyro_alignment_inputs">
283+
<div class="gyro_alignment_inputs gyro_alignment_inputs_first">
285284
<label>
286-
<select class="gyro_1_align">
287-
<option i18n="configurationSensorAlignmentDefaultOption" value="0"></option>
288-
<!-- list generated here -->
289-
</select>
290-
<span i18n="configurationSensorAlignmentGyro1"></span>
285+
<span>
286+
<select class="gyro_1_align">
287+
<option i18n="configurationSensorAlignmentDefaultOption" value="0"></option>
288+
<!-- list generated here -->
289+
</select>
290+
<span i18n="configurationSensorAlignmentGyro1"></span>
291+
</span>
291292
</label>
292293
</div>
293-
<div class="gyro_alignment_inputs">
294-
<label>
294+
<div class="gyro_alignment_inputs gyro_alignment_inputs_second">
295+
<label>
295296
<select class="gyro_2_align">
296297
<option i18n="configurationSensorAlignmentDefaultOption" value="0"></option>
297298
<!-- list generated here -->
298299
</select>
299300
<span i18n="configurationSensorAlignmentGyro2"></span>
300301
</label>
301302
</div>
303+
<div class="gyro_alignment_inputs gyro_alignment_inputs_notfound">
304+
<span class="message-negative" i18n="configurationSensorGyroToUseNotFound"/>
305+
</div>
302306
</div>
303307
<div class="sensor_align_content">
304308
<div class="legacy_gyro_alignment select">

0 commit comments

Comments
 (0)