Skip to content

Commit 3947308

Browse files
authored
Update gyro sensor info (#4626)
1 parent ac661b6 commit 3947308

File tree

6 files changed

+46
-13
lines changed

6 files changed

+46
-13
lines changed

locales/en/messages.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,10 +1552,6 @@
15521552
"configurationSensorGyroToUseBoth": {
15531553
"message": "Both"
15541554
},
1555-
"configurationSensorGyroEnable": {
1556-
"message": "$t(sensorStatusGyroShort.message)",
1557-
"description": "Don't translate!!!"
1558-
},
15591555
"configurationSensorAlignment": {
15601556
"message": "Sensor Alignment"
15611557
},

src/js/fc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ const FC = {
160160
FC_CONFIG: null,
161161
FEATURE_CONFIG: null,
162162
FILTER_CONFIG: null,
163+
GYRO_SENSOR: null,
163164
GPS_CONFIG: null,
164165
COMPASS_CONFIG: null,
165166
GPS_DATA: null,
@@ -603,6 +604,11 @@ const FC = {
603604
name: 0,
604605
};
605606

607+
this.GYRO_SENSOR = {
608+
gyro_count: 0,
609+
gyro_hardware: [],
610+
};
611+
606612
this.RX_CONFIG = {
607613
serialrx_provider: 0,
608614
stick_max: 0,

src/js/msp/MSPCodes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ const MSPCodes = {
200200
MSP2_SET_LED_STRIP_CONFIG_VALUES: 0x3009,
201201
MSP2_SENSOR_CONFIG_ACTIVE: 0x300a,
202202
MSP2_MCU_INFO: 0x300c,
203+
MSP2_GYRO_SENSOR: 0x300d,
203204

204205
// MSP2_GET_TEXT and MSP2_SET_TEXT variable types
205206
PILOT_NAME: 1,

src/js/msp/MSPHelper.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,14 @@ MspHelper.prototype.process_data = function (dataHandler) {
12531253
};
12541254
}
12551255
break;
1256+
case MSPCodes.MSP2_GYRO_SENSOR:
1257+
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
1258+
FC.GYRO_SENSOR.gyro_count = data.readU8();
1259+
for (let i = 0; i < FC.GYRO_SENSOR.gyro_count; i++) {
1260+
FC.GYRO_SENSOR.gyro_hardware[i] = data.readU8();
1261+
}
1262+
}
1263+
break;
12561264

12571265
case MSPCodes.MSP_LED_STRIP_CONFIG:
12581266
FC.LED_STRIP = [];

src/js/tabs/configuration.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ configuration.initialize = function (callback) {
7575
? MSP.promise(MSPCodes.MSP_COMPASS_CONFIG)
7676
: Promise.resolve(true),
7777
)
78+
.then(() =>
79+
semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)
80+
? MSP.promise(MSPCodes.MSP2_GYRO_SENSOR)
81+
: Promise.resolve(true),
82+
)
7883
.then(() => load_html());
7984
}
8085

@@ -270,12 +275,12 @@ configuration.initialize = function (callback) {
270275
// Create a new gyro alignment div
271276
const gyroBox = $(`<div id="gyro_box_${gyroIndex + 1}"></div>`);
272277
const gyroRow = $(`<div class="gyro_row"></div>`);
278+
const gyroDetected = sensorTypes().gyro.elements[FC.GYRO_SENSOR.gyro_hardware[gyroIndex]];
273279

274-
// Create enable/disable checkbox
275280
const enableCheck = $(`<div class="checkbox enable-checkbox">
276281
<label>
277282
<input type="checkbox" class="toggle" id="gyro_${gyroIndex + 1}_enable">
278-
<span>${i18n.getMessage("configurationSensorGyroEnable")} ${gyroIndex + 1}</span>
283+
<span> ${gyroDetected}</span>
279284
</label>
280285
</div>`);
281286

src/js/tabs/setup.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ setup.initialize = function (callback) {
3535
}
3636

3737
function load_mixer_config() {
38-
MSP.send_message(MSPCodes.MSP_MIXER_CONFIG, false, false, load_html);
38+
MSP.send_message(MSPCodes.MSP_MIXER_CONFIG, false, false, load_gyro_sensor);
39+
}
40+
41+
function load_gyro_sensor() {
42+
MSP.send_message(MSPCodes.MSP_SENSOR_ALIGNMENT, false, false, load_html);
3943
}
4044

4145
function load_html() {
@@ -305,12 +309,25 @@ setup.initialize = function (callback) {
305309
}
306310

307311
MSP.send_message(MSPCodes.MSP2_SENSOR_CONFIG_ACTIVE, false, false, function () {
308-
addSensorInfo(
309-
FC.SENSOR_CONFIG_ACTIVE.gyro_hardware,
310-
sensor_gyro_e,
311-
"gyro",
312-
sensorTypes().gyro.elements,
313-
);
312+
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
313+
MSP.send_message(MSPCodes.MSP2_GYRO_SENSOR, false, false, function () {
314+
let gyroInfoList = [];
315+
for (let i = 0; i < FC.GYRO_SENSOR.gyro_count; i++) {
316+
if ((FC.SENSOR_ALIGNMENT.gyro_enable_mask & (1 << i)) !== 0) {
317+
gyroInfoList.push(sensorTypes().gyro.elements[FC.GYRO_SENSOR.gyro_hardware[i]]);
318+
}
319+
}
320+
sensor_gyro_e.html(gyroInfoList.join(" "));
321+
});
322+
} else {
323+
addSensorInfo(
324+
FC.SENSOR_CONFIG_ACTIVE.gyro_hardware,
325+
sensor_gyro_e,
326+
"gyro",
327+
sensorTypes().gyro.elements,
328+
);
329+
}
330+
314331
addSensorInfo(FC.SENSOR_CONFIG_ACTIVE.acc_hardware, sensor_acc_e, "acc", sensorTypes().acc.elements);
315332
addSensorInfo(
316333
FC.SENSOR_CONFIG_ACTIVE.baro_hardware,

0 commit comments

Comments
 (0)