Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MSP2_SENSOR_CONFIG_ACTIVE message #3644

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
},
Expand All @@ -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:"
Expand Down
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 = { gyro_hardware: 0, ...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
9 changes: 9 additions & 0 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
107 changes: 76 additions & 31 deletions src/js/tabs/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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',
Expand All @@ -301,7 +328,7 @@ setup.initialize = function (callback) {
'VIRTUAL',
];

let baroElements = [
const baroElements = [
'DEFAULT',
'NONE',
'BMP085',
Expand All @@ -315,7 +342,7 @@ setup.initialize = function (callback) {
'VIRTUAL',
];

let magElements = [
const magElements = [
'DEFAULT',
'NONE',
'HMC5883',
Expand All @@ -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() {
Expand Down
39 changes: 33 additions & 6 deletions src/tabs/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<div class="helpicon cf_tip" i18n_title="initialSetupGPSHeadHelp"></div>
</div>
<div class="spacer_box GPS_info">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="cf_table">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="cf_table" role="presentation">
<tbody>
<tr>
<td i18n="gps3dFix"></td>
Expand All @@ -141,7 +141,7 @@
<div class="helpicon cf_tip" i18n_title="initialSetupSonarHeadHelp"></div>
</div>
<div class="spacer_box">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="cf_table">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="cf_table" role="presentation">
<tbody>
<tr>
<td id="sonarAltitude" i18n="initialSetupAltitudeSonar"></td>
Expand All @@ -157,7 +157,7 @@
<div class="helpicon cf_tip" i18n_title="initialSetupInfoHeadHelp"></div>
</div>
<div class="spacer_box">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="cf_table">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="cf_table" role="presentation">
<tbody>
<tr>
<td id="arming-disable-flag" i18n="initialSetupArmingDisableFlags" class="cf_tip"></td>
Expand All @@ -183,9 +183,36 @@
<td id="cpu-temp" i18n="initialSetupCpuTemp"></td>
<td class="cpu-temp">0 &#8451;</td>
</tr>
</table>
</div>
</div>
<div class="gui_box grey">
<div class="gui_box_titlebar">
<div class="spacer_box_title" i18n="initialSensorInfoHead"></div>
<div class="helpicon cf_tip" i18n_title="initialSensorInfoHeadHelp"></div>
</div>
<div class="spacer_box">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="cf_table" role="presentation">
<tbody>
<tr>
<td id="sensor_gyro_hw" i18n="initialSetupSensorGyro"></td>
<td class="sensor_gyro_hw"></td>
</tr>
<tr>
<td id="sensor_acc_hw" i18n="initialSetupSensorAcc"></td>
<td class="sensor_acc_hw"></td>
</tr>
<tr>
<td id="sensor_baro_hw" i18n="initialSetupSensorBaro"></td>
<td class="sensor_baro_hw"></td>
</tr>
<tr>
<td id="sensor-mag-hw" i18n="initialSetupSensorMag"></td>
<td class="sensor_mag_hw"></td>
</tr>
<tr>
<td id="sensor-hw" i18n="initialSetupSensorHardware"></td>
<td class="sensor-hw"></td>
<td id="sensor-sonar-hw" i18n="initialSetupSensorSonar"></td>
<td class="sensor_sonar_hw"></td>
</tr>
</tbody>
</table>
Expand All @@ -197,7 +224,7 @@
<div class="helpicon cf_tip" i18n_title="initialSetupInfoBuildHelp"></div>
</div>
<div class="spacer_box">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="cf_table">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="cf_table" role="presentation">
<tbody>
<tr>
<td id="api-version" i18n="initialSetupInfoAPIversion"></td>
Expand Down