Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IMU sensor refresh rate selection #3642

Merged
merged 3 commits into from Dec 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/js/tabs/sensors.js
Expand Up @@ -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}});
Expand Down