Skip to content

Commit 20fbd87

Browse files
authored
Add magnetic declination info (#4336)
* Add magnetic declination info * Fix race condition
1 parent 49edb41 commit 20fbd87

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

locales/en/messages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@
14041404
"message": "The magnetometer alignment is the orientation of the magnetometer sensor on the flight controller board. The default is usually correct, but if you have a custom build or a flight controller with a different magnetometer orientation, you may need to adjust this setting."
14051405
},
14061406
"configurationMagDeclination": {
1407-
"message": "Magnetometer Declination"
1407+
"message": "Magnetic Declination"
14081408
},
14091409
"configurationMagDeclinationInput": {
14101410
"message": "Declination Degrees"

src/js/tabs/gps.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ gps.initialize = async function (callback) {
2020
GUI.active_tab = "gps";
2121

2222
await MSP.promise(MSPCodes.MSP_FEATURE_CONFIG);
23-
24-
// mag support added in 1.46
25-
const hasMag = have_sensor(FC.CONFIG.activeSensors, "mag") && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46);
26-
2723
await MSP.promise(MSPCodes.MSP_GPS_CONFIG);
2824

2925
load_html();
@@ -48,6 +44,9 @@ gps.initialize = async function (callback) {
4844
// translate to user-selected languageconsole.log('Online');
4945
i18n.localizePage();
5046

47+
const hasMag =
48+
have_sensor(FC.CONFIG.activeSensors, "mag") && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46);
49+
5150
function get_raw_gps_data() {
5251
MSP.send_message(MSPCodes.MSP_RAW_GPS, false, false, get_comp_gps_data);
5352
}
@@ -65,7 +64,15 @@ gps.initialize = async function (callback) {
6564
}
6665

6766
function get_imu_data() {
68-
MSP.send_message(MSPCodes.MSP_RAW_IMU, false, false, update_ui);
67+
MSP.send_message(MSPCodes.MSP_RAW_IMU, false, false, get_mag_data);
68+
}
69+
70+
function get_mag_data() {
71+
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
72+
MSP.send_message(MSPCodes.MSP_COMPASS_CONFIG, false, false, update_ui);
73+
} else {
74+
update_ui();
75+
}
6976
}
7077

7178
// GPS Configuration
@@ -338,6 +345,13 @@ gps.initialize = async function (callback) {
338345
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
339346
const positionalDop = FC.GPS_DATA.positionalDop / 100;
340347
$(".GPS_info td.positionalDop").text(`${positionalDop.toFixed(2)}`);
348+
if (hasMag) {
349+
$(".GPS_info td.magDeclination").text(
350+
`${FC.COMPASS_CONFIG.mag_declination.toFixed(1)} ${gpsUnitText}`,
351+
);
352+
} else {
353+
$(".GPS_info td.magDeclination").parent().hide();
354+
}
341355
}
342356

343357
updateSignalStrengths();
@@ -367,14 +381,7 @@ gps.initialize = async function (callback) {
367381
}
368382

369383
// enable data pulling
370-
GUI.interval_add(
371-
"gps_pull",
372-
function gps_update() {
373-
get_raw_gps_data();
374-
},
375-
75,
376-
true,
377-
);
384+
GUI.interval_add("gps_pull", get_raw_gps_data, 100, true);
378385

379386
//check for internet connection on load
380387
if (ispConnected()) {

src/tabs/gps.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@
117117
<td i18n="gpsPositionalDop"></td>
118118
<td class="positionalDop"></td>
119119
</tr>
120+
<tr>
121+
<td i18n="configurationMagDeclination"></td>
122+
<td class="magDeclination"></td>
123+
</tr>
120124
</table>
121125
</div>
122126
</div>

0 commit comments

Comments
 (0)