Skip to content

Commit 6704267

Browse files
committed
Fix sensor refresh rate selection
1 parent 3d9ae79 commit 6704267

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/js/tabs/sensors.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,27 @@ sensors.initialize = function (callback) {
346346
const scales = {
347347
'gyro': parseFloat($('.tab-sensors select[name="gyro_scale"]').val()),
348348
'accel': parseFloat($('.tab-sensors select[name="accel_scale"]').val()),
349-
'mag': parseFloat($('.tab-sensors select[name="mag_scale"]').val()),
349+
'mag': parseInt($('.tab-sensors select[name="mag_scale"]').val(), 10),
350350
};
351351

352352
// handling of "data pulling" is a little bit funky here, as MSP_RAW_IMU contains values for gyro/accel/mag but not altitude
353353
// this means that setting a slower refresh rate on any of the attributes would have no effect
354354
// what we will do instead is = determinate the fastest refresh rate for those 3 attributes, use that as a "polling rate"
355355
// and use the "slower" refresh rates only for re-drawing the graphs (to save resources/computing power)
356-
const fastest = d3.min([rates.gyro, rates.accel, rates.mag]);
356+
357+
let fastest;
358+
const attr = $(this).attr('name');
359+
360+
// if any of the refresh rates change, we need to re-determine the fastest refresh rate
361+
if (attr === 'gyro_refresh_rate' || attr === 'accel_refresh_rate' || attr === 'mag_refresh_rate') {
362+
fastest = $(this).val();
363+
364+
$('.tab-sensors select[name="gyro_refresh_rate"]').val(fastest),
365+
$('.tab-sensors select[name="accel_refresh_rate"]').val(fastest),
366+
$('.tab-sensors select[name="mag_refresh_rate"]').val(fastest);
367+
} else {
368+
fastest = d3.max([rates.gyro, rates.accel, rates.mag]);
369+
}
357370

358371
// store current/latest refresh rates in the storage
359372
setConfig({'sensor_settings': {'rates': rates, 'scales': scales}});

0 commit comments

Comments
 (0)