From 63c188a4e8ed3314e3d806880bc5c53ada1da471 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Tue, 28 Nov 2023 10:55:23 +0100 Subject: [PATCH] Add MSP2_SENSOR_CONFIG_ACTIVE message (#3644) * Add message for detected sensors * Add gyro sensor info * Add separate sensor info panel --- locales/en/messages.json | 34 +++++++++++-- src/js/fc.js | 3 ++ src/js/msp/MSPCodes.js | 25 ++++----- src/js/msp/MSPHelper.js | 9 ++++ src/js/tabs/setup.js | 107 +++++++++++++++++++++++++++------------ src/tabs/setup.html | 39 +++++++++++--- 6 files changed, 165 insertions(+), 52 deletions(-) diff --git a/locales/en/messages.json b/locales/en/messages.json index 1e58a99eab..9320d5a857 100755 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -867,9 +867,16 @@ "message": "System info" }, "initialSetupInfoHeadHelp": { - "message": "Shows FC flags for disarming, Battery information, RSSI level and Sensors hardware", + "message": "Shows FC flags for disarming, Battery information, RSSI level.", "description": "Message that pops up to describe the System info section" }, + "initialSensorInfoHead": { + "message": "Sensor info" + }, + "initialSensorInfoHeadHelp": { + "message": "Shows sensors hardware", + "description": "Message that pops up to describe the Sensor info section" + }, "initialSetupBattery": { "message": "Battery voltage:" }, @@ -894,11 +901,32 @@ "initialSetupRSSI": { "message": "RSSI:" }, + "initialSetupRSSIValue": { + "message": "$1 dBm" + }, "initialSetupSensorHardware": { "message": "Sensors:" }, - "initialSetupRSSIValue": { - "message": "$1 %" + "initialSetupSensorGyro": { + "message": "Gyro:" + }, + "initialSetupSensorAcc": { + "message": "Acc:" + }, + "initialSetupSensorMag": { + "message": "Mag:" + }, + "initialSetupSensorBaro": { + "message": "Baro:" + }, + "initialSetupSensorGPS": { + "message": "GPS:" + }, + "initialSetupSensorSonar": { + "message": "Sonar:" + }, + "initialSetupSensorRadar": { + "message": "Radar:" }, "initialSetupArmingDisableFlags": { "message": "Arming Disable Flags:" diff --git a/src/js/fc.js b/src/js/fc.js index 72faa27170..2a596d5415 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 = { gyro_hardware: 0, ...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 fbde0dd970..992b18debc 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 095b0952f4..80d330cce7 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -1162,6 +1162,15 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.SENSOR_CONFIG.sonar_hardware = data.readU8(); } break; + case MSPCodes.MSP2_SENSOR_CONFIG_ACTIVE: + FC.SENSOR_CONFIG_ACTIVE.gyro_hardware = data.readU8(); + 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 d2412b3e4a..4758003914 100644 --- a/src/js/tabs/setup.js +++ b/src/js/tabs/setup.js @@ -200,7 +200,11 @@ setup.initialize = function (callback) { heading_e = $('dd.heading'), sonar_e = $('.sonarAltitude'), // Sensor info - sensor_e = $('.sensor-hw'), + sensor_gyro_e = $('.sensor_gyro_hw'), + sensor_acc_e = $('.sensor_acc_hw'), + sensor_mag_e = $('.sensor_mag_hw'), + sensor_baro_e = $('.sensor_baro_hw'), + sensor_sonar_e = $('.sensor_sonar_hw'), // Firmware info msp_api_e = $('.api-version'), build_date_e = $('.build-date'), @@ -277,7 +281,30 @@ setup.initialize = function (callback) { }; const showSensorInfo = function() { - let accElements = [ + const gyroElements = [ + 'NONE', + 'DEFAULT', + 'MPU6050', + 'L3G4200D', + 'MPU3050', + 'L3GD20', + 'MPU6000', + 'MPU6500', + 'MPU9250', + 'ICM20601', + 'ICM20602', + 'ICM20608G', + 'ICM20649', + 'ICM20689', + 'ICM42605', + 'ICM42688P', + 'BMI160', + 'BMI270', + 'LSM6DSO', + 'VIRTUAL', + ]; + + const accElements = [ 'DEFAULT', 'NONE', 'ADXL345', @@ -301,7 +328,7 @@ setup.initialize = function (callback) { 'VIRTUAL', ]; - let baroElements = [ + const baroElements = [ 'DEFAULT', 'NONE', 'BMP085', @@ -315,7 +342,7 @@ setup.initialize = function (callback) { 'VIRTUAL', ]; - let magElements = [ + const magElements = [ 'DEFAULT', 'NONE', 'HMC5883', @@ -327,42 +354,60 @@ setup.initialize = function (callback) { 'IST8310', ]; - let sonarElements = [ + const sonarElements = [ 'NONE', 'HCSR04', 'TFMINI', 'TF02', ]; - MSP.send_message(MSPCodes.MSP_SENSOR_CONFIG, 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]]); - appendComma = true; - } - if (have_sensor(FC.CONFIG.activeSensors, "baro") && FC.SENSOR_CONFIG.baro_hardware > 1) { - if (appendComma) { - sensor_e.append(', '); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) { + MSP.send_message(MSPCodes.MSP2_SENSOR_CONFIG_ACTIVE, false, false, function() { + // Sensor info + const textNA = 'N/A'; + const textDisabled = 'disabled'; + + if (FC.SENSOR_CONFIG_ACTIVE.gyro_hardware == 0xFF) { + sensor_gyro_e.text(textNA); + } else if (have_sensor(FC.CONFIG.activeSensors, "gyro") && FC.SENSOR_CONFIG_ACTIVE.gyro_hardware > 1) { + sensor_gyro_e.text(gyroElements[FC.SENSOR_CONFIG_ACTIVE.gyro_hardware]); + } else { + sensor_gyro_e.text(textDisabled); } - sensor_e.append(i18n.getMessage('sensorStatusBaroShort'), ': ', baroElements[[FC.SENSOR_CONFIG.baro_hardware]]); - appendComma = true; - } - if (have_sensor(FC.CONFIG.activeSensors, "mag") && FC.SENSOR_CONFIG.mag_hardware > 1) { - if (appendComma) { - sensor_e.append(', '); + + if (FC.SENSOR_CONFIG_ACTIVE.acc_hardware == 0xFF) { + sensor_acc_e.text(textNA); + } else if (have_sensor(FC.CONFIG.activeSensors, "acc") && FC.SENSOR_CONFIG_ACTIVE.acc_hardware > 1) { + sensor_acc_e.text(accElements[FC.SENSOR_CONFIG_ACTIVE.acc_hardware]); + } else { + sensor_acc_e.text(textDisabled); } - sensor_e.append(i18n.getMessage('sensorStatusMagShort'), ': ', magElements[[FC.SENSOR_CONFIG.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 (appendComma) { - sensor_e.append(', '); + + if (FC.SENSOR_CONFIG_ACTIVE.baro_hardware == 0xFF) { + sensor_baro_e.text(textNA); + } else if (have_sensor(FC.CONFIG.activeSensors, "baro") && FC.SENSOR_CONFIG_ACTIVE.baro_hardware > 1) { + sensor_baro_e.text(baroElements[FC.SENSOR_CONFIG_ACTIVE.baro_hardware]); + } else { + sensor_baro_e.text(textDisabled); } - sensor_e.append(i18n.getMessage('sensorStatusSonarShort'), ': ', sonarElements[[FC.SENSOR_CONFIG.sonar_hardware]]); - } - }); + + if (FC.SENSOR_CONFIG_ACTIVE.mag_hardware == 0xFF) { + sensor_mag_e.text(textNA); + } else if (have_sensor(FC.CONFIG.activeSensors, "mag") && FC.SENSOR_CONFIG_ACTIVE.mag_hardware > 1) { + sensor_mag_e.text(magElements[FC.SENSOR_CONFIG_ACTIVE.mag_hardware]); + } else { + sensor_mag_e.text(textDisabled); + } + + if (FC.SENSOR_CONFIG_ACTIVE.sonar_hardware == 0xFF) { + sensor_sonar_e.text(textNA); + } else if (have_sensor(FC.CONFIG.activeSensors, "sonar") && FC.SENSOR_CONFIG_ACTIVE.sonar_hardware > 1) { + sensor_sonar_e.text(sonarElements[FC.SENSOR_CONFIG_ACTIVE.sonar_hardware]); + } else { + sensor_sonar_e.text(textDisabled); + } + }); + } }; const showFirmwareInfo = function() { diff --git a/src/tabs/setup.html b/src/tabs/setup.html index a1b500dd39..b6304952bc 100644 --- a/src/tabs/setup.html +++ b/src/tabs/setup.html @@ -117,7 +117,7 @@
- +
@@ -141,7 +141,7 @@
-
+
@@ -157,7 +157,7 @@
-
+
@@ -183,9 +183,36 @@ + +
+ +
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + - - + + @@ -197,7 +224,7 @@
- +