From e77d9cf09a7edfe47dc273c4768a62a7e46be97b Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Sun, 26 Nov 2023 18:07:01 +0100 Subject: [PATCH] Add message for detected sensors --- src/js/fc.js | 3 +++ src/js/msp/MSPCodes.js | 25 +++++++++++++------------ src/js/msp/MSPHelper.js | 8 ++++++++ src/js/tabs/setup.js | 23 ++++++++++++++--------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/js/fc.js b/src/js/fc.js index 72faa27170c..e3886807947 100644 --- a/src/js/fc.js +++ b/src/js/fc.js @@ -153,6 +153,7 @@ const FC = { SDCARD: null, SENSOR_ALIGNMENT: null, SENSOR_CONFIG: null, + SENSOR_CONFIG_ACTIVE: null, SENSOR_DATA: null, SERIAL_CONFIG: null, SERVO_CONFIG: null, @@ -541,6 +542,8 @@ const FC = { sonar_hardware: 0, }; + this.SENSOR_CONFIG_ACTIVE = { ...this.SENSOR_CONFIG }; + this.RX_CONFIG = { serialrx_provider: 0, stick_max: 0, diff --git a/src/js/msp/MSPCodes.js b/src/js/msp/MSPCodes.js index fbde0dd9703..992b18debc8 100644 --- a/src/js/msp/MSPCodes.js +++ b/src/js/msp/MSPCodes.js @@ -184,20 +184,21 @@ const MSPCodes = { MSP_DEBUG: 254, // MSPv2 Common - MSP2_COMMON_SERIAL_CONFIG: 0x1009, - MSP2_COMMON_SET_SERIAL_CONFIG: 0x100A, + MSP2_COMMON_SERIAL_CONFIG: 0x1009, + MSP2_COMMON_SET_SERIAL_CONFIG: 0x100A, // MSPv2 Betaflight specific - MSP2_BETAFLIGHT_BIND: 0x3000, - MSP2_MOTOR_OUTPUT_REORDERING: 0x3001, - MSP2_SET_MOTOR_OUTPUT_REORDERING: 0x3002, - MSP2_SEND_DSHOT_COMMAND: 0x3003, - MSP2_GET_VTX_DEVICE_STATUS: 0x3004, - MSP2_GET_OSD_WARNINGS: 0x3005, - MSP2_GET_TEXT: 0x3006, - MSP2_SET_TEXT: 0x3007, - MSP2_GET_LED_STRIP_CONFIG_VALUES: 0x3008, - MSP2_SET_LED_STRIP_CONFIG_VALUES: 0x3009, + MSP2_BETAFLIGHT_BIND: 0x3000, + MSP2_MOTOR_OUTPUT_REORDERING: 0x3001, + MSP2_SET_MOTOR_OUTPUT_REORDERING: 0x3002, + MSP2_SEND_DSHOT_COMMAND: 0x3003, + MSP2_GET_VTX_DEVICE_STATUS: 0x3004, + MSP2_GET_OSD_WARNINGS: 0x3005, + MSP2_GET_TEXT: 0x3006, + MSP2_SET_TEXT: 0x3007, + MSP2_GET_LED_STRIP_CONFIG_VALUES: 0x3008, + MSP2_SET_LED_STRIP_CONFIG_VALUES: 0x3009, + MSP2_SENSOR_CONFIG_ACTIVE: 0x300A, // MSP2_GET_TEXT and MSP2_SET_TEXT variable types PILOT_NAME: 1, diff --git a/src/js/msp/MSPHelper.js b/src/js/msp/MSPHelper.js index 095b0952f4f..f1e8e02747a 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -1162,6 +1162,14 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.SENSOR_CONFIG.sonar_hardware = data.readU8(); } break; + case MSPCodes.MSP2_SENSOR_CONFIG_ACTIVE: + FC.SENSOR_CONFIG_ACTIVE.acc_hardware = data.readU8(); + FC.SENSOR_CONFIG_ACTIVE.baro_hardware = data.readU8(); + FC.SENSOR_CONFIG_ACTIVE.mag_hardware = data.readU8(); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) { + FC.SENSOR_CONFIG_ACTIVE.sonar_hardware = data.readU8(); + } + break; case MSPCodes.MSP_LED_STRIP_CONFIG: FC.LED_STRIP = []; diff --git a/src/js/tabs/setup.js b/src/js/tabs/setup.js index d2412b3e4a1..24a1b113511 100644 --- a/src/js/tabs/setup.js +++ b/src/js/tabs/setup.js @@ -334,34 +334,39 @@ setup.initialize = function (callback) { 'TF02', ]; - MSP.send_message(MSPCodes.MSP_SENSOR_CONFIG, false, false, function() { + MSP.send_message(MSPCodes.MSP2_SENSOR_CONFIG_ACTIVE, false, false, function() { // Sensor info let appendComma = false; sensor_e.text(''); - if (have_sensor(FC.CONFIG.activeSensors, "acc") && FC.SENSOR_CONFIG.acc_hardware > 1) { - sensor_e.append(i18n.getMessage('sensorStatusAccelShort'), ': ', accElements[[FC.SENSOR_CONFIG.acc_hardware]]); + if (have_sensor(FC.CONFIG.activeSensors, "acc") && FC.SENSOR_CONFIG_ACTIVE.acc_hardware > 1) { + sensor_e.append(i18n.getMessage('sensorStatusAccelShort'), ': ', accElements[FC.SENSOR_CONFIG_ACTIVE.acc_hardware]); appendComma = true; } - if (have_sensor(FC.CONFIG.activeSensors, "baro") && FC.SENSOR_CONFIG.baro_hardware > 1) { + if (have_sensor(FC.CONFIG.activeSensors, "baro") && FC.SENSOR_CONFIG_ACTIVE.baro_hardware > 1) { if (appendComma) { sensor_e.append(', '); } - sensor_e.append(i18n.getMessage('sensorStatusBaroShort'), ': ', baroElements[[FC.SENSOR_CONFIG.baro_hardware]]); + sensor_e.append(i18n.getMessage('sensorStatusBaroShort'), ': ', baroElements[FC.SENSOR_CONFIG_ACTIVE.baro_hardware]); appendComma = true; } - if (have_sensor(FC.CONFIG.activeSensors, "mag") && FC.SENSOR_CONFIG.mag_hardware > 1) { + if (have_sensor(FC.CONFIG.activeSensors, "mag") && FC.SENSOR_CONFIG_ACTIVE.mag_hardware > 1) { if (appendComma) { sensor_e.append(', '); } - sensor_e.append(i18n.getMessage('sensorStatusMagShort'), ': ', magElements[[FC.SENSOR_CONFIG.mag_hardware]]); + sensor_e.append(i18n.getMessage('sensorStatusMagShort'), ': ', magElements[FC.SENSOR_CONFIG_ACTIVE.mag_hardware]); appendComma = true; } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46) && have_sensor(FC.CONFIG.activeSensors, "sonar") && FC.SENSOR_CONFIG.sonar_hardware > 1) { + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46) && have_sensor(FC.CONFIG.activeSensors, "sonar") && FC.SENSOR_CONFIG_ACTIVE.sonar_hardware > 1) { if (appendComma) { sensor_e.append(', '); } - sensor_e.append(i18n.getMessage('sensorStatusSonarShort'), ': ', sonarElements[[FC.SENSOR_CONFIG.sonar_hardware]]); + sensor_e.append(i18n.getMessage('sensorStatusSonarShort'), ': ', sonarElements[FC.SENSOR_CONFIG_ACTIVE.sonar_hardware]); } + + if (FC.SENSOR_CONFIG_ACTIVE.acc_hardware == 0xFF) sensor_e.append('
ACC not available'); + if (FC.SENSOR_CONFIG_ACTIVE.baro_hardware == 0xFF) sensor_e.append('
BARO not available'); + if (FC.SENSOR_CONFIG_ACTIVE.mag_hardware == 0xFF) sensor_e.append('
MAG not available'); + if (FC.SENSOR_CONFIG_ACTIVE.sonar_hardware == 0xFF) sensor_e.append('
SONAR not available'); }); };