Skip to content

Commit

Permalink
Add gyro sensor info
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Nov 27, 2023
1 parent 5ff4d71 commit b8960be
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 38 deletions.
25 changes: 23 additions & 2 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -894,11 +894,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
2 changes: 1 addition & 1 deletion src/js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ const FC = {
sonar_hardware: 0,
};

this.SENSOR_CONFIG_ACTIVE = { ...this.SENSOR_CONFIG };
this.SENSOR_CONFIG_ACTIVE = { gyro_hardware: 0, ...this.SENSOR_CONFIG };

this.RX_CONFIG = {
serialrx_provider: 0,
Expand Down
7 changes: 7 additions & 0 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1163,12 +1163,19 @@ MspHelper.prototype.process_data = function(dataHandler) {
}
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();
}

console.log(FC.SENSOR_CONFIG_ACTIVE.gyro_hardware);
console.log(FC.SENSOR_CONFIG_ACTIVE.acc_hardware);
console.log(FC.SENSOR_CONFIG_ACTIVE.baro_hardware);
console.log(FC.SENSOR_CONFIG_ACTIVE.mag_hardware);
console.log(FC.SENSOR_CONFIG_ACTIVE.sonar_hardware);
break;

case MSPCodes.MSP_LED_STRIP_CONFIG:
Expand Down
104 changes: 72 additions & 32 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,47 +354,60 @@ setup.initialize = function (callback) {
'IST8310',
];

let sonarElements = [
const sonarElements = [
'NONE',
'HCSR04',
'TFMINI',
'TF02',
];

MSP.send_message(MSPCodes.MSP2_SENSOR_CONFIG_ACTIVE, false, false, function() {
// Sensor info
sensor_e.text('');
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('sensorStatusAccelShort')}: `);
if (FC.SENSOR_CONFIG_ACTIVE.acc_hardware == 0xFF) {
sensor_e.append('N/A');
} else if (have_sensor(FC.CONFIG.activeSensors, "acc") && FC.SENSOR_CONFIG_ACTIVE.acc_hardware > 1) {
sensor_e.append(accElements[FC.SENSOR_CONFIG_ACTIVE.acc_hardware]);
}
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(`<br>${i18n.getMessage('sensorStatusBaroShort')}: `);
if (FC.SENSOR_CONFIG_ACTIVE.baro_hardware == 0xFF) {
sensor_e.append('N/A');
} else if (have_sensor(FC.CONFIG.activeSensors, "baro") && FC.SENSOR_CONFIG_ACTIVE.baro_hardware > 1) {
sensor_e.append(baroElements[FC.SENSOR_CONFIG_ACTIVE.baro_hardware]);
}
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(`<br>${i18n.getMessage('sensorStatusMagShort')}: `);
if (FC.SENSOR_CONFIG_ACTIVE.mag_hardware == 0xFF) {
sensor_e.append('N/A');
} else if (have_sensor(FC.CONFIG.activeSensors, "mag") && FC.SENSOR_CONFIG_ACTIVE.mag_hardware > 1) {
sensor_e.append(magElements[FC.SENSOR_CONFIG_ACTIVE.mag_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 (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
sensor_e.append(`<br>${i18n.getMessage('sensorStatusSonarShort')}: `);
if (FC.SENSOR_CONFIG_ACTIVE.sonar_hardware == 0xFF) {
sensor_e.append('N/A');
sensor_sonar_e.text(textNA);
} else if (have_sensor(FC.CONFIG.activeSensors, "sonar") && FC.SENSOR_CONFIG_ACTIVE.sonar_hardware > 1) {
sensor_e.append(sonarElements[FC.SENSOR_CONFIG_ACTIVE.sonar_hardware]);
sensor_sonar_e.text(sonarElements[FC.SENSOR_CONFIG_ACTIVE.sonar_hardware]);
} else {
sensor_sonar_e.text(textDisabled);
}
}
});
});
}
};

const showFirmwareInfo = function() {
Expand Down
21 changes: 18 additions & 3 deletions src/tabs/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,25 @@
<td class="cpu-temp">0 &#8451;</td>
</tr>
<tr>
<td id="sensor-hw" i18n="initialSetupSensorHardware"></td>
<td class="sensor-hw"></td>
<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-sonar-hw" i18n="initialSetupSensorSonar"></td>
<td class="sensor_sonar_hw"></td>
</tr>
</tbody>
</table>
</div>
</div>
Expand Down

0 comments on commit b8960be

Please sign in to comment.