Skip to content

Commit

Permalink
Clarify GPS Signal Strength (#3705)
Browse files Browse the repository at this point in the history
Hide GPS Signal Strength if GPS is not active
  • Loading branch information
haslinghuis authored Apr 10, 2024
1 parent be0103f commit e1f5f24
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 58 deletions.
3 changes: 3 additions & 0 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2852,6 +2852,9 @@
"gpsSignalStr": {
"message": "Signal Strength"
},
"gpsSignalLost": {
"message": "The GPS icon lights up only when the connection to the GPS module is confirmed.<br /><br />It will be red at first, changing to yellow when the 3D fix is attained.<br /><br />If the GPS icon does not light up, check your wiring and configuration, and confirm that the GPS module is receiving power.<br /><br />The CLI 'status' command provides more information about the state of the GPS connection."
},
"gpsSignalGnssId": {
"message": "Gnss ID"
},
Expand Down
128 changes: 70 additions & 58 deletions src/js/tabs/gps.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ gps.initialize = async function (callback) {
$('div.mag_declination').hide();
}

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
const positionalDop = FC.GPS_DATA.positionalDop / 100;
$('.GPS_info td.positionalDop').text(`${positionalDop.toFixed(2)}`);
} else {
$('.GPS_info td.positionalDop').parent().hide();
}

const {
mapView,
iconStyleMag,
Expand All @@ -214,45 +221,22 @@ gps.initialize = async function (callback) {

// End GPS Configuration

function update_ui() {
const lat = FC.GPS_DATA.lat / 10000000;
const lon = FC.GPS_DATA.lon / 10000000;
const url = `https://maps.google.com/?q=${lat},${lon}`;
const imuHeadingDegrees = FC.SENSOR_DATA.kinematics[2];
// Convert to radians and add 180 degrees to make icon point in the right direction
const imuHeadingRadians = (imuHeadingDegrees + 180) * Math.PI / 180;
// These are not used, but could be used to show the heading from the magnetometer
// const magHeadingDegrees = hasMag ? Math.atan2(FC.SENSOR_DATA.magnetometer[1], FC.SENSOR_DATA.magnetometer[0]) : undefined;
// const magHeadingRadians = magHeadingDegrees === undefined ? 0 : magHeadingDegrees * Math.PI / 180;
const gpsHeading = FC.GPS_DATA.ground_course / 10;
const gnssArray = ['GPS', 'SBAS', 'Galileo', 'BeiDou', 'IMES', 'QZSS', 'Glonass'];
const qualityArray = ['gnssQualityNoSignal', 'gnssQualitySearching', 'gnssQualityAcquired', 'gnssQualityUnusable', 'gnssQualityLocked',
'gnssQualityFullyLocked', 'gnssQualityFullyLocked', 'gnssQualityFullyLocked'];
const usedArray = ['gnssUsedUnused', 'gnssUsedUsed'];
let alt = FC.GPS_DATA.alt;
const gnssArray = ['GPS', 'SBAS', 'Galileo', 'BeiDou', 'IMES', 'QZSS', 'Glonass'];
const qualityArray = ['gnssQualityNoSignal', 'gnssQualitySearching', 'gnssQualityAcquired', 'gnssQualityUnusable', 'gnssQualityLocked', 'gnssQualityFullyLocked', 'gnssQualityFullyLocked', 'gnssQualityFullyLocked'];
const usedArray = ['gnssUsedUnused', 'gnssUsedUsed'];

$('.GPS_info span.colorToggle').text(FC.GPS_DATA.fix ? i18n.getMessage('gpsFixTrue') : i18n.getMessage('gpsFixFalse'));
$('.GPS_info span.colorToggle').toggleClass('ready', FC.GPS_DATA.fix != 0);
// GPS Signal Strengths
function updateSignalStrengths() {
const eSsTable = $('div.GPS_signal_strength table');
const hasGPS = have_sensor(FC.CONFIG.activeSensors, 'gps');

const gpsUnitText = i18n.getMessage('gpsPositionUnit');
$('.GPS_info td.alt').text(`${alt} m`);
$('.GPS_info td.latLon a').prop('href', url).text(`${lat.toFixed(6)} / ${lon.toFixed(6)} ${gpsUnitText}`);
$('.GPS_info td.heading').text(`${imuHeadingDegrees.toFixed(0)} / ${gpsHeading.toFixed(0)} ${gpsUnitText}`);
$('.GPS_info td.speed').text(`${FC.GPS_DATA.speed} cm/s`);
$('.GPS_info td.sats').text(FC.GPS_DATA.numSat);
$('.GPS_info td.distToHome').text(`${FC.GPS_DATA.distanceToHome} m`);
$('.signal_strength').toggle(!hasGPS);
eSsTable.html('');

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
const positionalDop = FC.GPS_DATA.positionalDop / 100;
$('.GPS_info td.positionalDop').text(`${positionalDop.toFixed(2)}`);
} else {
$('.GPS_info td.positionalDop').parent().hide();
if (!hasGPS) {
return;
}

// Update GPS Signal Strengths
const eSsTable = $('div.GPS_signal_strength table');

eSsTable.html('');
eSsTable.append(`
<tr class="titles">
<td style="text-align: left; width: 12%;" i18n="gpsSignalGnssId">${i18n.getMessage('gpsSignalGnssId')}</td>
Expand All @@ -263,30 +247,7 @@ gps.initialize = async function (callback) {
</tr>
`);

if (FC.GPS_DATA.chn.length <= 16) {
// Legacy code path: old BF firmware or old ublox module
for (let i = 0; i < FC.GPS_DATA.chn.length; i++) {
eSsTable.append(`
<tr>
<td>-</td>
<td>${FC.GPS_DATA.svid[i]}</td>
<td><meter value="${FC.GPS_DATA.cno[i]}" max="55"></meter></td>
<td>${FC.GPS_DATA.quality[i]}</td>
</tr>
`);
}
// Cleanup the rest of the table
for (let i = FC.GPS_DATA.chn.length; i < 32; i++) {
eSsTable.append(`
<tr>
<td>-</td>
<td>-</td>
<td><meter value="0" max="55"></meter></td>
<td> </td>
</tr>
`);
}
} else {
if (FC.GPS_DATA.chn.length > 16) {
// M8N/M9N on newer firmware

const maxUIChannels = 32; //the list in html can only show 32 channels but future firmware could send more
Expand Down Expand Up @@ -336,7 +297,58 @@ gps.initialize = async function (callback) {
}
eSsTable.append(`<tr>${rowContent}</tr>`);
}
} else {
// Legacy code path: old BF firmware or old ublox module
for (let i = 0; i < FC.GPS_DATA.chn.length; i++) {
eSsTable.append(`
<tr>
<td>-</td>
<td>${FC.GPS_DATA.svid[i]}</td>
<td><meter value="${FC.GPS_DATA.cno[i]}" max="55"></meter></td>
<td>${FC.GPS_DATA.quality[i]}</td>
</tr>
`);
}

// Cleanup the rest of the table
for (let i = FC.GPS_DATA.chn.length; i < 32; i++) {
eSsTable.append(`
<tr>
<td>-</td>
<td>-</td>
<td><meter value="0" max="55"></meter></td>
<td> </td>
</tr>
`);
}
}
}

function update_ui() {
const lat = FC.GPS_DATA.lat / 10000000;
const lon = FC.GPS_DATA.lon / 10000000;
const url = `https://maps.google.com/?q=${lat},${lon}`;
const imuHeadingDegrees = FC.SENSOR_DATA.kinematics[2];
// Convert to radians and add 180 degrees to make icon point in the right direction
const imuHeadingRadians = (imuHeadingDegrees + 180) * Math.PI / 180;
// These are not used, but could be used to show the heading from the magnetometer
// const magHeadingDegrees = hasMag ? Math.atan2(FC.SENSOR_DATA.magnetometer[1], FC.SENSOR_DATA.magnetometer[0]) : undefined;
// const magHeadingRadians = magHeadingDegrees === undefined ? 0 : magHeadingDegrees * Math.PI / 180;
const gpsHeading = FC.GPS_DATA.ground_course / 10;
let alt = FC.GPS_DATA.alt;

$('.GPS_info span.colorToggle').text(FC.GPS_DATA.fix ? i18n.getMessage('gpsFixTrue') : i18n.getMessage('gpsFixFalse'));
$('.GPS_info span.colorToggle').toggleClass('ready', FC.GPS_DATA.fix != 0);

const gpsUnitText = i18n.getMessage('gpsPositionUnit');
$('.GPS_info td.alt').text(`${alt} m`);
$('.GPS_info td.latLon a').prop('href', url).text(`${lat.toFixed(6)} / ${lon.toFixed(6)} ${gpsUnitText}`);
$('.GPS_info td.heading').text(`${imuHeadingDegrees.toFixed(0)} / ${gpsHeading.toFixed(0)} ${gpsUnitText}`);
$('.GPS_info td.speed').text(`${FC.GPS_DATA.speed} cm/s`);
$('.GPS_info td.sats').text(FC.GPS_DATA.numSat);
$('.GPS_info td.distToHome').text(`${FC.GPS_DATA.distanceToHome} m`);

updateSignalStrengths();

let gpsFoundPosition = false;

Expand Down
1 change: 1 addition & 0 deletions src/tabs/gps.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<div class="helpicon cf_tip" i18n_title="gpsSignalStrHeadHelp"></div>
</div>
<div class="spacer_box GPS_signal_strength">
<div class="signal_strength note" i18n="gpsSignalLost"></div>
<table class="cf_table">
<!-- Contents generated in gps.js -->
</table>
Expand Down

0 comments on commit e1f5f24

Please sign in to comment.