From 22001241141c8cc049bdff481b6cd348b27464e0 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Fri, 24 Nov 2023 16:59:16 +0100 Subject: [PATCH 1/3] Fix sensor refresh rate selection --- src/js/tabs/sensors.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/js/tabs/sensors.js b/src/js/tabs/sensors.js index 5fab4783ba..3735b51456 100644 --- a/src/js/tabs/sensors.js +++ b/src/js/tabs/sensors.js @@ -346,14 +346,27 @@ sensors.initialize = function (callback) { const scales = { 'gyro': parseFloat($('.tab-sensors select[name="gyro_scale"]').val()), 'accel': parseFloat($('.tab-sensors select[name="accel_scale"]').val()), - 'mag': parseFloat($('.tab-sensors select[name="mag_scale"]').val()), + 'mag': parseInt($('.tab-sensors select[name="mag_scale"]').val(), 10), }; // handling of "data pulling" is a little bit funky here, as MSP_RAW_IMU contains values for gyro/accel/mag but not altitude // this means that setting a slower refresh rate on any of the attributes would have no effect // what we will do instead is = determinate the fastest refresh rate for those 3 attributes, use that as a "polling rate" // and use the "slower" refresh rates only for re-drawing the graphs (to save resources/computing power) - const fastest = d3.min([rates.gyro, rates.accel, rates.mag]); + + let fastest; + const attr = $(this).attr('name'); + + // if any of the refresh rates change, we need to re-determine the fastest refresh rate + if (attr === 'gyro_refresh_rate' || attr === 'accel_refresh_rate' || attr === 'mag_refresh_rate') { + fastest = $(this).val(); + + $('.tab-sensors select[name="gyro_refresh_rate"]').val(fastest); + $('.tab-sensors select[name="accel_refresh_rate"]').val(fastest); + $('.tab-sensors select[name="mag_refresh_rate"]').val(fastest); + } else { + fastest = d3.max([rates.gyro, rates.accel, rates.mag]); + } // store current/latest refresh rates in the storage setConfig({'sensor_settings': {'rates': rates, 'scales': scales}}); From 4e1dd4b4929b4aee83827e1953ce1c8fa2833c29 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Sat, 25 Nov 2023 11:56:52 +0100 Subject: [PATCH 2/3] Fix html --- src/js/tabs/sensors.js | 2 ++ src/tabs/sensors.html | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/tabs/sensors.js b/src/js/tabs/sensors.js index 3735b51456..6727c20893 100644 --- a/src/js/tabs/sensors.js +++ b/src/js/tabs/sensors.js @@ -357,6 +357,8 @@ sensors.initialize = function (callback) { let fastest; const attr = $(this).attr('name'); + + console.log('attr', attr); // if any of the refresh rates change, we need to re-determine the fastest refresh rate if (attr === 'gyro_refresh_rate' || attr === 'accel_refresh_rate' || attr === 'mag_refresh_rate') { fastest = $(this).val(); diff --git a/src/tabs/sensors.html b/src/tabs/sensors.html index ec45e47500..8861904faf 100644 --- a/src/tabs/sensors.html +++ b/src/tabs/sensors.html @@ -128,7 +128,7 @@
- From 39f48d1d19868ab2240a07beb538e39dda5f9135 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Sat, 25 Nov 2023 12:14:34 +0100 Subject: [PATCH 3/3] Refactor --- src/js/tabs/sensors.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/js/tabs/sensors.js b/src/js/tabs/sensors.js index 6727c20893..46ea2af440 100644 --- a/src/js/tabs/sensors.js +++ b/src/js/tabs/sensors.js @@ -355,12 +355,8 @@ sensors.initialize = function (callback) { // and use the "slower" refresh rates only for re-drawing the graphs (to save resources/computing power) let fastest; - const attr = $(this).attr('name'); - - - console.log('attr', attr); // if any of the refresh rates change, we need to re-determine the fastest refresh rate - if (attr === 'gyro_refresh_rate' || attr === 'accel_refresh_rate' || attr === 'mag_refresh_rate') { + if (['gyro_refresh_rate', 'accel_refresh_rate', 'mag_refresh_rate'].includes($(this).attr('name'))) { fastest = $(this).val(); $('.tab-sensors select[name="gyro_refresh_rate"]').val(fastest);