From 6156a2e2118d862afebee0d258c682b4b26e8060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kiripolszky=20K=C3=A1roly?= Date: Thu, 23 Feb 2023 23:18:58 +0100 Subject: [PATCH] Display heading from mag --- locales/en/messages.json | 5 +- .../TestThrottleSelector/container.html | 11 +++++ src/js/VirtualFC.js | 2 + src/js/tabs/gps.js | 19 ++++--- src/js/tabs/map.js | 49 +++++++++---------- src/tabs/gps.html | 4 ++ 6 files changed, 58 insertions(+), 32 deletions(-) create mode 100644 src/components/shared/TestThrottleSelector/container.html diff --git a/locales/en/messages.json b/locales/en/messages.json index dfe2e2f1e0b..3b4682c69e5 100644 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -2479,6 +2479,9 @@ "gpsLon": { "message": "Longitude:" }, + "gpsHeading": { + "message": "Heading:" + }, "gpsSpeed": { "message": "Speed:" }, @@ -4875,7 +4878,7 @@ }, "osdTextElementVTXchannelVariantPower": { "message": "VTX power", - "description": "One of the variants of the VTX channel element of the OSD" + "description": "One of the variants of the VTX channel element of the OSD" }, "osdTextElementVTXchannelVariantFull": { "message": "Band:Channel:Pwr:Pit", diff --git a/src/components/shared/TestThrottleSelector/container.html b/src/components/shared/TestThrottleSelector/container.html new file mode 100644 index 00000000000..9b08f5287b2 --- /dev/null +++ b/src/components/shared/TestThrottleSelector/container.html @@ -0,0 +1,11 @@ + + + + + +
+ Throttle + +
+
+
diff --git a/src/js/VirtualFC.js b/src/js/VirtualFC.js index be7093ed399..26e49325fb5 100644 --- a/src/js/VirtualFC.js +++ b/src/js/VirtualFC.js @@ -156,6 +156,8 @@ const VirtualFC = { mag_hardware: 1, }; + virtualFC.SENSOR_DATA = { ...FC.SENSOR_DATA }; + virtualFC.RC = { channels: Array.from({length: 16}), active_channels: 16, diff --git a/src/js/tabs/gps.js b/src/js/tabs/gps.js index 3823e711121..bea0171786f 100644 --- a/src/js/tabs/gps.js +++ b/src/js/tabs/gps.js @@ -21,6 +21,8 @@ gps.initialize = async function (callback) { await MSP.promise(MSPCodes.MSP_GPS_CONFIG); await MSP.promise(MSPCodes.MSP_STATUS); + const hasMag = have_sensor(FC.CONFIG.activeSensors, 'mag'); + load_html(); function load_html() { @@ -52,7 +54,11 @@ gps.initialize = async function (callback) { } function get_gpsvinfo_data() { - MSP.send_message(MSPCodes.MSP_GPS_SV_INFO, false, false, update_ui); + MSP.send_message(MSPCodes.MSP_GPS_SV_INFO, false, false, hasMag ? get_imu_data : update_ui); + } + + function get_imu_data() { + MSP.send_message(MSPCodes.MSP_RAW_IMU, false, false, update_ui); } // To not flicker the divs while the fix is unstable @@ -178,6 +184,10 @@ gps.initialize = async function (callback) { const lat = FC.GPS_DATA.lat / 10000000; const lon = FC.GPS_DATA.lon / 10000000; const url = `https://maps.google.com/?q=${lat},${lon}`; + const heading = hasMag + ? Math.atan2(FC.SENSOR_DATA.magnetometer[1], FC.SENSOR_DATA.magnetometer[0]) + : undefined; + const headingDeg = heading === undefined ? 0 : heading * 180 / Math.PI; const gnssArray = ['GPS', 'SBAS', 'Galileo', 'BeiDou', 'IMES', 'QZSS', 'Glonass']; const qualityArray = ['gnssQualityNoSignal', 'gnssQualitySearching', 'gnssQualityAcquired', 'gnssQualityUnusable', 'gnssQualityLocked', 'gnssQualityFullyLocked', 'gnssQualityFullyLocked', 'gnssQualityFullyLocked']; @@ -189,6 +199,7 @@ gps.initialize = async function (callback) { $('.GPS_info td.alt').text(`${alt} m`); $('.GPS_info td.lat a').prop('href', url).text(`${lat.toFixed(4)} deg`); $('.GPS_info td.lon a').prop('href', url).text(`${lon.toFixed(4)} deg`); + $('.GPS_info td.heading').text(`${headingDeg.toFixed(4)} deg`); $('.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`); @@ -263,6 +274,7 @@ gps.initialize = async function (callback) { action: 'center', lat: lat, lon: lon, + heading: heading, }; frame = document.getElementById('map'); @@ -295,11 +307,6 @@ gps.initialize = async function (callback) { // enable data pulling GUI.interval_add('gps_pull', function gps_update() { - // avoid usage of the GPS commands until a GPS sensor is detected for targets that are compiled without GPS support. - if (!have_sensor(FC.CONFIG.activeSensors, 'gps')) { - //return; - } - get_raw_gps_data(); }, 75, true); diff --git a/src/js/tabs/map.js b/src/js/tabs/map.js index 7c9f0217c6e..bc014a9314f 100644 --- a/src/js/tabs/map.js +++ b/src/js/tabs/map.js @@ -76,31 +76,30 @@ function initializeMap() { } function processMapEvents(e) { - try { - switch(e.data.action) { - - case 'zoom_in': - mapView.setZoom(mapView.getZoom() + 1); - break; - - case 'zoom_out': - mapView.setZoom(mapView.getZoom() - 1); - break; - - case 'center': - iconFeature.setStyle(iconStyle); - const center = ol.proj.fromLonLat([e.data.lon, e.data.lat]); - mapView.setCenter(center); - iconGeometry.setCoordinates(center); - break; - - case 'nofix': - iconFeature.setStyle(iconStyleNoFix); - break; + switch (e.data.action) { + case 'zoom_in': + mapView.setZoom(mapView.getZoom() + 1); + break; + + case 'zoom_out': + mapView.setZoom(mapView.getZoom() - 1); + break; + + case 'center': + iconFeature.setStyle(iconStyle); + const center = ol.proj.fromLonLat([e.data.lon, e.data.lat]); + mapView.setCenter(center); + const heading = e.data.heading === undefined ? 0 : e.data.heading; + mapView.setRotation(heading); + iconGeometry.setCoordinates(center); + break; + + case 'nofix': + iconFeature.setStyle(iconStyleNoFix); + break; } - - } catch (err) { - console.log(`Map error ${err}`); - } + } catch (err) { + console.error('Map error', err); + } } diff --git a/src/tabs/gps.html b/src/tabs/gps.html index f9e5d33e48b..ef94e12d492 100644 --- a/src/tabs/gps.html +++ b/src/tabs/gps.html @@ -100,6 +100,10 @@ 0.0000 deg + + + 0.0000 deg + 0 cm/s