Skip to content

Commit

Permalink
Add message for detected sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Nov 26, 2023
1 parent 11279cd commit e77d9cf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 13 additions & 12 deletions src/js/msp/MSPCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
23 changes: 14 additions & 9 deletions src/js/tabs/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<br>ACC not available');
if (FC.SENSOR_CONFIG_ACTIVE.baro_hardware == 0xFF) sensor_e.append('<br>BARO not available');
if (FC.SENSOR_CONFIG_ACTIVE.mag_hardware == 0xFF) sensor_e.append('<br>MAG not available');
if (FC.SENSOR_CONFIG_ACTIVE.sonar_hardware == 0xFF) sensor_e.append('<br>SONAR not available');
});
};

Expand Down

0 comments on commit e77d9cf

Please sign in to comment.