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

[BMI270] Fix bug in data frame size calculation #366

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

jabberrock
Copy link
Contributor

Previously, required_length was always 0 because we shifting by a huge number, rather than the bit position. So the check for incomplete frames would never trigger. The final data frame in a FIFO read is sometimes an incomplete frame, and therefore we would read garbage for the data frame. There are often incomplete frames when we call LEDManager to blink the LED, because the FIFO overruns.

  1. During gyroscope calibration, we often read random gyroscope samples, which throws off the calibration results.
  2. During 6-sided accelerometer calibration, we often read random acceleration samples which causes rest detection to move on to collecting the next side, even if we don't move the tracker.
  3. During normal operation, we will rarely read random gyroscope and accelerometer samples. These are usually one-offs and probably don't affect tracking.

This change fixes the bounds check so that we correctly identify incomplete frames and discard them.

Previously, required_length was always 0 because we shifting by a huge number, rather than the bit position. So the check for incomplete frames would never trigger. The final data frame in a FIFO read is sometimes an incomplete frame, and therefore we would read garbage for the data frame. There are often incomplete frames when we call LEDManager to blink the LED, because the FIFO overruns.

1. During gyroscope calibration, we often read random gyroscope samples, which throws off the calibration results.
2. During 6-sided calibration, we often read random acceleration samples which causes rest detection to move on to collecting the next side, even if we don't move the tracker.
3. During normal operation, we will rarely read random gyroscope and accelerometer samples. These are usually one-offs and probably don't affect tracking.

This change fixes the bounds check so that we correctly identify incomplete frames and discard them.
Copy link
Contributor

@unlogisch04 unlogisch04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me

+ ((header & Fifo::AccelDataBit) >> Fifo::AccelDataBit))
* 6;
uint8_t gyro_data_length
= (header & Fifo::GyrDataBit) == Fifo::GyrDataBit ? 6 : 0;
Copy link
Contributor

@l0ud l0ud Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's enough to (header & Fifo::GyrDataBit ? 6 : 0) afaik (should be even less operations)

similar for accel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@jabberrock
Copy link
Contributor Author

jabberrock commented Nov 21, 2024

@unlogisch04, @l0ud thanks for the review! Could you merge it? I don't have permissions yet

@unlogisch04
Copy link
Contributor

@unlogisch04, @l0ud thanks for the review! Could you merge it? I don't have permissions yet

I also don't have permission to merge. Only @ButterscotchV or @Eirenliel have permission to merge.

@ButterscotchV ButterscotchV merged commit a252292 into SlimeVR:main Nov 21, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants